:root {
  --bg: #f0f3ff;
  --bg-warm: #fff5e6;
  --card: #ffffff;
  --ink: #1a1c2e;
  --ink-soft: #6b6f8a;
  --primary: #ff5722;
  --primary-deep: #d84315;
  --secondary: #2962ff;
  --retrieval: #00c896;
  --retrieval-soft: #d4f8ee;
  --slow: #ffb300;
  --slow-soft: #fff0c4;
  --miss: #8c93b0;
  --miss-soft: #e6e8f0;
  --gold: #ffd166;
  --purple: #7c4dff;
  --pink: #ff4081;
  --radius: 20px;
  --shadow: 0 4px 16px rgba(26, 28, 46, 0.08);
  --shadow-big: 0 12px 40px rgba(26, 28, 46, 0.18);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: linear-gradient(180deg, var(--bg) 0%, #f7f4ff 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app {
  max-width: 540px;
  margin: 0 auto;
  padding: 16px 18px 32px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

h1, h2, h3 { margin: 0; }

/* ---------- Home ---------- */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.home-header h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.header-actions {
  display: flex;
  gap: 8px;
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  font-size: 20px;
}
.intro {
  color: var(--ink-soft);
  font-size: 15px;
  margin: 0 0 18px;
}
.tafel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.tafel-card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 14px 14px;
  box-shadow: var(--shadow);
  text-align: left;
  transition: transform 0.08s ease;
  overflow: hidden;
}
.tafel-card:active { transform: scale(0.97); }
.tafel-stripe {
  position: absolute;
  inset: 0 0 auto 0;
  height: 6px;
  background: var(--c);
}
.tafel-card .tafel-label {
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 600;
  margin-top: 2px;
}
.tafel-num-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin: 4px 0 6px;
}
.tafel-card .tafel-num {
  font-size: 38px;
  font-weight: 800;
  line-height: 1;
  color: var(--c);
}
.tafel-card.mastered {
  background: linear-gradient(135deg, color-mix(in srgb, var(--c) 18%, white) 0%, white 70%);
  outline: 2px solid var(--c);
}
.tafel-card.mastered .tafel-num { color: var(--c); }
.tafel-card.grayed {
  background: #f3f4fa;
  outline: none;
}
.tafel-card.grayed .tafel-stripe { background: var(--miss); opacity: 0.4; }
.tafel-card.grayed .tafel-num { color: var(--miss); }
.tafel-card.grayed .tafel-label { color: var(--miss); }
.tafel-card.grayed .dot.filled { background: var(--miss); }
.tafel-card.grayed .speed-icon { opacity: 0.45; filter: grayscale(0.6); }
.tafel-progress-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.tafel-progress-bar {
  flex: 1;
  height: 6px;
  background: var(--miss-soft);
  border-radius: 99px;
  overflow: hidden;
}
.tafel-progress-bar-fill {
  height: 100%;
  background: var(--c);
  border-radius: 99px;
  transition: width 0.3s ease;
}
.tafel-progress-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.5px;
  min-width: 32px;
  text-align: right;
}
.tafel-card.grayed .tafel-progress-bar-fill { background: var(--miss); }
.tafel-card.grayed .tafel-progress-count {
  color: var(--miss);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}
.speed-icon {
  font-size: 24px;
  line-height: 1;
  display: inline-block;
  flex-shrink: 0;
}
.speed-icon-big {
  font-size: 38px;
  line-height: 1;
  display: inline-block;
  margin: 0 auto;
}

.dots {
  display: flex;
  gap: 2px;
}
.dot {
  flex: 1;
  height: 5px;
  border-radius: 2px;
  background: var(--miss-soft);
}
.dot.filled { background: var(--c, var(--retrieval)); }

/* ---------- Badges on home ---------- */
.badges-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 26px 0 12px;
}
.badges-header h2 { font-size: 18px; font-weight: 800; }
.badges-count { font-size: 13px; color: var(--ink-soft); font-weight: 600; }

.badges-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.badge-tile {
  background: var(--card);
  border-radius: 14px;
  padding: 10px 6px 8px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform 0.08s ease;
}
.badge-tile:active { transform: scale(0.95); }
.badge-emblem-mini {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
}
.badge-emblem-mini svg { width: 100%; height: 100%; }
.badge-tile-title {
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  color: var(--ink);
  line-height: 1.15;
  min-height: 26px;
}
.badge-tile.locked { opacity: 0.55; }
.badge-tile.locked .badge-tile-title { color: var(--ink-soft); font-weight: 600; }

/* ---------- Support footer ---------- */
.support-footer {
  margin-top: 32px;
  padding: 22px 16px 8px;
  text-align: center;
  border-top: 1px solid var(--miss-soft);
}
.support-footer p {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 10px;
}
.bmc-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 10px 18px;
  background: #ffdd00;
  color: #1a1c2e;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.08s ease;
  box-shadow: 0 4px 12px rgba(255, 221, 0, 0.4);
}
.bmc-link:active { transform: scale(0.96); }

/* ---------- Ready ---------- */
.ready {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  padding: 30px 16px;
}
.ready-badge {
  background: var(--c);
  color: white;
  padding: 6px 16px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.ready h2 {
  font-size: 96px;
  font-weight: 800;
  line-height: 0.9;
  color: var(--c);
}
.ready p { color: var(--ink-soft); margin: 0; }
.ready .stats {
  display: flex;
  gap: 22px;
  justify-content: center;
  margin: 12px 0;
}
.ready .stat .v { font-size: 22px; font-weight: 800; }
.ready .stat .l { font-size: 12px; color: var(--ink-soft); }

.btn-primary {
  background: var(--primary);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
  color: white;
  border-radius: 99px;
  padding: 16px 32px;
  font-size: 18px;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(255, 87, 34, 0.35);
  transition: transform 0.08s ease;
}
.btn-primary:active { transform: scale(0.96); }
.btn-secondary {
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 15px;
  padding: 10px 18px;
}
.btn-outlined {
  background: white;
  color: var(--ink);
  border-radius: 99px;
  padding: 14px 24px;
  font-size: 15px;
  font-weight: 700;
  border: 2px solid var(--miss-soft);
  transition: transform 0.08s ease;
  width: 100%;
}
.btn-outlined:active { transform: scale(0.97); }

/* ---------- Session ---------- */
.session {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.session-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.close-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--card);
  display: grid;
  place-items: center;
  font-size: 18px;
  color: var(--ink-soft);
  box-shadow: var(--shadow);
}
.progress {
  flex: 1;
  height: 8px;
  background: var(--miss-soft);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.3s ease;
}
.progress-count {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
  min-width: 52px;
  text-align: right;
}

.som-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 26px;
  padding-bottom: 20px;
}
.som {
  font-size: clamp(56px, 14vw, 88px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  text-align: center;
  user-select: none;
  color: var(--ink);
}
.timer-bar {
  width: 70%;
  height: 6px;
  background: var(--miss-soft);
  border-radius: 99px;
  overflow: hidden;
}
.timer-fill {
  height: 100%;
  background: var(--tafel-accent, var(--primary));
  border-radius: 99px;
  width: 100%;
  transform-origin: left center;
}
.timer-fill.running { transition: transform linear; }

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}
.option {
  background: var(--card);
  border-radius: var(--radius);
  height: 84px;
  font-size: 30px;
  font-weight: 800;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, background 0.15s ease, color 0.15s ease;
  display: grid;
  place-items: center;
  color: var(--ink);
}
.option:active { transform: scale(0.96); }
.option.picked-retrieval { background: var(--retrieval); color: white; }
.option.picked-slow { background: var(--slow); color: white; }
.option.picked-miss { background: var(--miss-soft); color: var(--ink-soft); }
.option.reveal { background: var(--retrieval-soft); color: var(--retrieval); outline: 3px solid var(--retrieval); }

.feedback-text {
  min-height: 22px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-top: -10px;
}
.feedback-text.retrieval { color: var(--retrieval); }
.feedback-text.slow { color: var(--slow); }

/* ---------- End ---------- */
.end {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-top: 24px;
}
.end h2 {
  font-size: 32px;
  font-weight: 800;
  text-align: center;
  color: var(--c, var(--primary));
}
.end-stats {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.end-stats .stat .v { font-size: 26px; font-weight: 800; color: var(--c, var(--ink)); }
.end-stats .stat .l { font-size: 12px; color: var(--ink-soft); }
.headline {
  font-size: 15px;
  text-align: center;
  color: var(--ink-soft);
  margin: -4px 0 0;
}
.headline.pr { color: var(--c, var(--primary)); font-weight: 700; }
.tafel-progress {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.tafel-progress .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.tafel-progress h3 { font-size: 15px; font-weight: 700; }
.tafel-progress .count { font-size: 13px; color: var(--ink-soft); font-weight: 700; }

.dots-12 .dot { height: 8px; border-radius: 4px; }
.tafel-progress .dot.filled { background: var(--c, var(--retrieval)); }

.end-actions {
  margin-top: auto;
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

/* ---------- Badge popup ---------- */
.badge-popup {
  position: fixed;
  inset: 0;
  background: rgba(26, 28, 46, 0.7);
  display: grid;
  place-items: center;
  z-index: 10;
  padding: 18px;
  animation: fade 0.2s ease;
  overflow-y: auto;
}
.badge-card {
  background: white;
  border-radius: 28px;
  padding: 20px 18px;
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-big);
  animation: pop 0.32s cubic-bezier(0.2, 0.9, 0.4, 1.3);
}
.celebrate-banner {
  background: linear-gradient(135deg, var(--gold) 0%, var(--primary) 100%);
  color: white;
  font-weight: 800;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 99px;
  display: inline-block;
  margin-bottom: 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.car-card-wrap {
  width: 100%;
  margin: 0 auto 14px;
  border-radius: 20px;
  overflow: hidden;
}
.car-card-wrap svg { width: 100%; height: auto; display: block; }

.photo-card {
  width: 100%;
  margin: 0 auto 14px;
  border-radius: 22px;
  padding: 18px 16px 16px;
  color: white;
  background: linear-gradient(135deg, var(--bc) 0%, var(--bc-dark) 100%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.photo-title {
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  margin-bottom: 12px;
  letter-spacing: -0.01em;
}
.photo-frame {
  border-radius: 14px;
  overflow: hidden;
  background: #1a1c2e;
  aspect-ratio: 16 / 10;
  margin-bottom: 14px;
}
.photo-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-footer { text-align: center; }
.photo-footer .car-name {
  font-size: 17px;
  font-weight: 800;
}
.photo-footer .car-meta {
  font-size: 12px;
  opacity: 0.88;
  margin-top: 2px;
}

.session-tier {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  text-align: center;
}
.session-tier .session-tier-label {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
}
.badge-desc {
  color: var(--ink-soft);
  font-size: 14px;
  margin: 8px 0 16px;
}
.badge-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}
.badge-actions .btn-primary { width: 100%; }

.locked-card .locked-emblem {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--miss-soft);
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  font-size: 44px;
  color: var(--ink-soft);
  font-weight: 800;
}
.locked-card h3 { font-size: 20px; font-weight: 800; margin-bottom: 8px; }
.locked-card p { color: var(--ink-soft); margin: 0 0 6px; font-size: 14px; }
.locked-card .hint { font-style: italic; font-size: 13px; margin-bottom: 18px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------- Settings sheet ---------- */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(26, 28, 46, 0.4);
  z-index: 9;
  display: flex;
  align-items: flex-end;
}
.sheet-card {
  background: white;
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
  border-radius: 24px 24px 0 0;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  animation: slide 0.25s ease;
}
@keyframes slide { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-card h2 { font-size: 20px; font-weight: 800; margin-bottom: 16px; }
.sheet-card.about {
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  position: sticky;
  top: 0;
  background: white;
  padding-bottom: 6px;
  z-index: 1;
}
.sheet-header h2 { margin-bottom: 0; }
.sheet-close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--miss-soft);
  display: grid;
  place-items: center;
  font-size: 18px;
  color: var(--ink-soft);
}
.about-section { margin-bottom: 22px; }
.about-section h3 {
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 8px;
  color: var(--primary);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.about-section p {
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  margin: 0 0 8px;
}
.about-section p.small {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 8px;
}
.about-section ul {
  margin: 6px 0 0;
  padding-left: 20px;
}
.about-section li {
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 5px;
}
.about-icon-table {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px 12px;
  font-size: 14px;
  align-items: center;
  padding: 4px 0;
}
.about-icon-table .e { font-size: 22px; line-height: 1; }
.about-icon-table .n { font-weight: 700; }
.about-icon-table .t {
  color: var(--ink-soft);
  font-size: 12px;
  text-align: right;
  font-weight: 600;
}
.badges-list li { margin-bottom: 7px; }

.reward-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}
.reward-btn { width: 100%; }
.reward-btn.locked {
  color: var(--ink-soft);
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--miss-soft);
}

.video-popup {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade 0.2s ease;
}
.video-card {
  background: white;
  border-radius: 24px;
  padding: 22px 18px 18px;
  width: 100%;
  max-width: 480px;
  text-align: center;
  animation: pop 0.3s ease;
}
.video-banner {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  color: white;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  padding: 6px 14px;
  border-radius: 99px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.video-title {
  font-size: 22px;
  font-weight: 800;
  margin: 0 0 4px;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.video-subtitle {
  font-size: 14px;
  color: var(--ink-soft);
  margin: 0 0 14px;
}
.video-iframe-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 14px;
}
.video-iframe-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
}
.setting-row label { font-size: 15px; }
.setting-row .seg {
  display: flex;
  background: var(--miss-soft);
  border-radius: 99px;
  padding: 3px;
}
.setting-row .seg button {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  border-radius: 99px;
  color: var(--ink-soft);
}
.setting-row .seg button.active {
  background: white;
  color: var(--ink);
  box-shadow: var(--shadow);
}
.danger {
  margin-top: 14px;
  font-size: 13px;
  color: var(--ink-soft);
  text-decoration: underline;
  padding: 8px;
}
