:root {
  --primary: #8B1A2B;
  --primary-hover: #721524;
  --primary-light: #fdf2f4;
  --accent: #A52A3A;
  --dark: #0e1111;
  --text: #111827;
  --muted: #6b7280;
  --bg: #f9fafb;
  --panel: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow: 0 4px 18px rgba(17,24,39,.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { overflow-x: hidden; max-width: 100%; }
img, canvas, svg { max-width: 100%; }
input, button, select, textarea, fieldset { min-width: 0; max-width: 100%; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Audi Type', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
main { flex: 1 0 auto; }
footer { flex-shrink: 0; }

header {
  padding: 0;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 10;
}
.brand {
  display: flex; align-items: center; gap: .75rem;
  max-width: 1200px; margin: 0 auto;
  padding: .85rem 1.25rem;
  width: 100%;
  text-decoration: none;
  color: inherit;
}
.brand--link:hover .back-arrow { color: var(--primary); }
@media (max-width: 720px) { .brand { padding: .75rem .85rem; } }
.logo-dot {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: .75rem; letter-spacing: .05em;
}
.logo-dot::before { content: 'MS'; }
header h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--dark);
}
header p { margin: 0; color: var(--muted); font-size: .8rem; }
.back-arrow {
  margin-left: auto;
  font-size: .82rem;
  color: var(--muted);
  font-weight: 500;
  transition: color .15s;
  white-space: nowrap;
}

main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}
@media (max-width: 720px) {
  main { padding: .85rem; gap: .85rem; }
  .panel { padding: 1rem !important; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.section-title {
  margin: 0 0 1rem;
  font-size: .9rem;
  font-weight: 600;
  letter-spacing: -.005em;
  color: var(--dark);
}

.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .85rem; }
.field:last-child { margin-bottom: 0; }
.field label {
  font-weight: 500; font-size: .8rem; color: #374151;
}

input[type="text"], input[type="number"], input[type="url"] {
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text);
  padding: .6rem .8rem;
  font: inherit;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:focus, input[type="number"]:focus, input[type="url"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(139,26,43,.12);
}
input[type="range"] { width: 100%; accent-color: var(--primary); }

.group {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .85rem 1rem 1rem;
  margin: 0 0 .85rem;
  display: flex; flex-direction: column; gap: .55rem;
  background: #fcfcfd;
}
.group legend {
  padding: 0 .4rem;
  font-size: .7rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.audi-row { display: flex; gap: .4rem; align-items: stretch; }
.audi-row #audiCommission { flex: 1 1 auto; min-width: 0; }
.audi-row #audiYear {
  flex: 0 0 auto;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: .6rem .4rem;
  font: inherit;
  color: var(--text);
  cursor: pointer;
}
.audi-row #audiYear:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(139,26,43,.12);
}
.audi-row #audiYear.detecting {
  border-color: var(--primary);
  animation: detectPulse 1s ease-in-out infinite;
}
@keyframes detectPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(139,26,43,0); }
  50%      { box-shadow: 0 0 0 3px rgba(139,26,43,.18); }
}

.hint { margin: .25rem 0 0; color: var(--muted); font-size: .75rem; }

.btn {
  border: 0;
  border-radius: 10px;
  padding: .85rem 1rem;
  font: inherit; font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .05s, box-shadow .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary {
  background: var(--primary); color: #fff; width: 100%;
  box-shadow: 0 2px 8px rgba(139,26,43,.25);
}
.btn--primary:not(:disabled):hover { background: var(--primary-hover); }
.btn--primary:not(:disabled):active { transform: translateY(1px); }
.btn--secondary {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--primary);
  width: 100%;
  margin-top: .65rem;
}
.btn--secondary:not(:disabled):hover { background: var(--primary-light); }

.btn-link {
  background: transparent;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: .78rem;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
.btn-link:hover { color: var(--primary); }

.status {
  margin-top: .65rem;
  font-size: .82rem;
  color: var(--muted);
  min-height: 1.2em;
}
.status.is-loading { color: var(--primary); }
.status.is-error { color: #dc2626; }
.status.is-ok { color: #16a34a; }

/* ---- Canvas / ad blocks ---- */
.panel--canvas {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.ad-block {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.ad-block__head {
  display: flex; justify-content: space-between; align-items: center;
  gap: .5rem;
}
.ad-block__label {
  font-size: .8rem; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
}
.ad-stage {
  background: #f3f4f6;
  border-radius: 10px;
  padding: 1rem;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  overflow-x: auto;
}
.ad-stage canvas {
  display: block;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.ad-stage canvas:active { cursor: grabbing; }
.ad-stage canvas[data-format="wide"] {
  max-width: 100%;
  height: auto;
}

.ad-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: .65rem .85rem;
  background: #fcfcfd;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.photo-ctl {
  flex: 1 1 200px;
  min-width: 0;
}
.photo-ctl strong {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: .25rem;
}
.photo-ctl label {
  font-size: .75rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.val {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: .75rem;
  font-weight: 500;
  margin-left: auto;
}
.photo-ctl label > .val { float: right; }

footer {
  padding: 1rem 1.5rem;
  color: var(--muted); font-size: .78rem;
  border-top: 1px solid var(--border);
  display: flex; gap: .5rem; justify-content: center;
  background: var(--panel);
  margin-top: 1rem;
}
.sep { opacity: .5; }
