/* ── Fonts ──────────────────────────────────────────────────────────────────── */
@font-face {
  font-family: 'BricolageGrotesque';
  src: url('../fonts/BricolageGrotesque-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'BricolageGrotesque';
  src: url('../fonts/BricolageGrotesque-SemiBold.ttf') format('truetype');
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: 'BricolageGrotesque';
  src: url('../fonts/BricolageGrotesque-ExtraBold.ttf') format('truetype');
  font-weight: 800;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrainsMono';
  src: url('../fonts/JetBrainsMono-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrainsMono';
  src: url('../fonts/JetBrainsMono-SemiBold.ttf') format('truetype');
  font-weight: 600;
  font-display: swap;
}

/* ── Design tokens (light mode default) ────────────────────────────────────── */
:root {
  --canvas:    #F6F1E7;
  --ink:       #1F1B16;
  --blue:      #2447A6;
  --red:       #C8322E;
  --muted:     #7A6F60;
  --body:      #5C5347;
  --line:      #C9BFAD;
  --line-soft: #DED6C6;
  --card:      #FFFDF8;
  --green:     #2E7D4F;
  --gold:      #B8860B;
  --grid:      rgba(31,27,22,0.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas:    #111010;
    --ink:       #F0EBE1;
    --blue:      #6B8FE8;
    --red:       #E05550;
    --muted:     #8A8070;
    --body:      #A09285;
    --line:      #3A3730;
    --line-soft: #2A2925;
    --card:      #1C1B19;
    --green:     #3DBE6A;
    --gold:      #D4A017;
    --grid:      rgba(240,235,225,0.06);
  }
}
[data-theme="dark"] {
  --canvas:    #111010;
  --ink:       #F0EBE1;
  --blue:      #6B8FE8;
  --red:       #E05550;
  --muted:     #8A8070;
  --body:      #A09285;
  --line:      #3A3730;
  --line-soft: #2A2925;
  --card:      #1C1B19;
  --green:     #3DBE6A;
  --gold:      #D4A017;
  --grid:      rgba(240,235,225,0.06);
}

/* ── Reset & base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font-family: 'BricolageGrotesque', system-ui, sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
img { display: block; }

/* ── Typography helpers ─────────────────────────────────────────────────────── */
.display-extrabold  { font-family: 'BricolageGrotesque'; font-weight: 800; }
.display-semibold   { font-family: 'BricolageGrotesque'; font-weight: 600; }
.mono-text          { font-family: 'JetBrainsMono'; font-weight: 400; }
.mono-semibold      { font-family: 'JetBrainsMono'; font-weight: 600; }
.eyebrow {
  font-family: 'JetBrainsMono'; font-weight: 400;
  font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted);
}
.body-text  { color: var(--body); }
.muted-text { color: var(--muted); font-size: 13px; }

/* ── App shell ──────────────────────────────────────────────────────────────── */
#app {
  max-width: 900px;
  margin: 0 auto;
  height: 100dvh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ── Screen containers ──────────────────────────────────────────────────────── */
.screen { height: 100%; display: flex; flex-direction: column; }
.screen-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 20px 0;
  gap: 0;
}
.screen-inner--scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 20px;
}

/* ── Shared components ──────────────────────────────────────────────────────── */
.spacer { flex: 1; }

.pill-btn {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 52px;
  border-radius: 9999px;
  font-family: 'BricolageGrotesque'; font-weight: 600; font-size: 17px;
  transition: opacity 0.15s, transform 0.1s;
}
.pill-btn:active { transform: scale(0.97); opacity: 0.85; }
.pill-btn--filled  { background: var(--ink); color: var(--canvas); }
.pill-btn--outline { border: 1.5px solid var(--line); color: var(--ink); height: 48px; font-size: 15px; }
.pill-btn--red     { background: var(--red); color: #fff; }
.pill-btn--ghost   {
  background: var(--canvas); color: var(--ink);
  border: 1.5px solid var(--line-soft);
  width: auto; height: 44px;
  padding: 0 22px; font-size: 15px;
}
.pill-btn--lock { font-size: 16px; }

.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  border: 1.5px solid var(--line-soft);
  color: var(--muted);
  background: transparent;
}
.circle-btn {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1.5px solid var(--line);
  color: var(--ink); background: transparent;
  flex-shrink: 0;
}

/* ── Grid background ────────────────────────────────────────────────────────── */
.grid-bg {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  border-radius: inherit;
  pointer-events: none;
}

/* ── Stage frame ────────────────────────────────────────────────────────────── */
.stage-frame {
  position: relative;
  border-radius: 16px;
  border: 2px dashed var(--line);
  overflow: hidden;
}

/* ── Silhouettes ────────────────────────────────────────────────────────────── */
.silhouette {
  position: absolute;
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  background-color: var(--blue);
}
.ref-sil  { background-color: var(--blue); }
.tgt-sil  { background-color: var(--red); }
.ghost-sil { background-color: var(--ink); }
.result-sil {
  width: 28px; height: 28px;
  background-color: var(--ink);
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

.stage-label {
  position: absolute;
  text-align: center;
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ref-label  { color: var(--blue); }
.tgt-label  { color: var(--red); }

.ground-line {
  position: absolute; left: 0; right: 0; height: 2px;
  background: rgba(31,27,22,0.7);
}
[data-theme="dark"] .ground-line,
@media (prefers-color-scheme: dark) { .ground-line { background: rgba(240,235,225,0.7); } }

.resize-handle {
  position: absolute;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  cursor: grab; touch-action: none;
  z-index: 10;
}
.resize-handle::after {
  content: '';
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--canvas);
  border: 2px solid var(--red);
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
  display: block;
}
.resize-handle:active { cursor: grabbing; }

/* ── HOME SCREEN ────────────────────────────────────────────────────────────── */
.home-header {
  display: flex; align-items: center;
  gap: 8px; margin-bottom: 12px;
  flex-shrink: 0;
  position: relative;
}
.appstore-btn {
  display: block;
  text-decoration: none;
  animation: appstore-pop 2.4s ease-in-out infinite;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.appstore-btn:active { opacity: 0.75; }
@keyframes appstore-pop {
  0%, 100% { transform: scale(1); box-shadow: 0 2px 8px rgba(0,0,0,0.18); }
  50%       { transform: scale(1.06); box-shadow: 0 4px 16px rgba(0,0,0,0.26); }
}

.home-hero {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
}
.hero-stage {
  flex: 1;
  width: 100%;
  min-height: 160px;
}
.hero-objects {
  position: absolute; inset: 0;
}
.home-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  padding-bottom: 8px;
}
.hero-breathe {
  animation: breathe 1.3s ease-in-out infinite alternate;
  transform-origin: bottom center;
}
@keyframes breathe {
  from { transform: scaleY(0.75) scaleX(0.75); }
  to   { transform: scaleY(1.0) scaleX(1.0); }
}

.handle-knob {
  position: absolute;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--canvas);
  border: 2px solid var(--red);
  box-shadow: 0 2px 3px rgba(0,0,0,0.18);
  right: -11px; top: -11px;
  animation: knob-pulse 0.8s ease-in-out infinite alternate;
}
@keyframes knob-pulse {
  from { transform: scale(1); }
  to   { transform: scale(1.15); }
}

.home-title {
  display: flex; flex-direction: column;
  line-height: 1;
}
.home-title-line {
  font-size: clamp(36px, 5vw, 52px);
  letter-spacing: -1.5px;
  line-height: 1;
  color: var(--ink);
}
.home-subtitle {
  font-size: clamp(14px, 1.8vw, 17px);
  line-height: 1.6;
}

/* ── THEMES SCREEN ──────────────────────────────────────────────────────────── */
.themes-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.themes-title {
  font-size: 34px; letter-spacing: -0.7px;
  color: var(--ink);
  margin-bottom: 16px;
}
.themes-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; margin-bottom: 10px;
}
.theme-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px;
  min-height: 72px;
  background: var(--card);
  border-radius: 16px;
  border: 1.5px solid var(--line);
  text-align: start;
  transition: opacity 0.15s;
}
.theme-card:active { opacity: 0.75; }
.theme-icon {
  width: 44px; height: 44px;
  border-radius: 12px; flex-shrink: 0;
  object-fit: cover;
}
.theme-card-text {
  display: flex; flex-direction: column; gap: 3px;
  min-width: 0;
}
.theme-card-name { font-size: 17px; color: var(--ink); line-height: 1.3; }
.theme-card-desc { font-size: 13px; }

.random-card {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1.5px solid var(--gold);
  background: rgba(184,134,11,0.06);
  text-align: start;
  margin-bottom: 12px;
  transition: opacity 0.15s;
}
[data-theme="dark"] .random-card { background: rgba(212,160,23,0.06); }
.random-card:active { opacity: 0.75; }
.random-card--locked { opacity: 0.55; }
.random-card--locked:active { opacity: 0.4; }

.theme-card--locked { opacity: 0.5; }
.theme-lock-icon { margin-left: auto; flex-shrink: 0; color: var(--muted); }

.app-promo-banner {
  display: flex; align-items: center; gap: 14px;
  padding: 16px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--ink) 0%, #2447A6 100%);
  text-decoration: none;
  margin-bottom: 12px;
  transition: opacity 0.15s;
}
.app-promo-banner:active { opacity: 0.85; }
.app-promo-text {
  flex: 1; display: flex; flex-direction: column; gap: 4px;
}
.app-promo-title { font-size: 16px; color: #fff; }
.app-promo-sub { font-size: 12px; color: rgba(255,255,255,0.7); line-height: 1.4; }
.app-promo-badge { height: 28px; width: auto; flex-shrink: 0; }

.random-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--gold);
  display: flex; align-items: center; justify-content: center;
  color: #fff; flex-shrink: 0;
}
.random-text {
  display: flex; flex-direction: column; gap: 2px;
}
.random-text .display-semibold { font-size: 20px; color: var(--ink); }

/* ── GAME SCREEN ────────────────────────────────────────────────────────────── */
.game-layout {
  flex: 1; display: flex; flex-direction: column;
  padding: 12px 20px 16px;
  gap: 10px;
}
.game-header {
  display: flex; align-items: center; gap: 8px;
}
.game-header-center {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.round-dots {
  display: flex; gap: 3px; width: 44px; justify-content: flex-end; flex-shrink: 0;
}
.round-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--line-soft);
}
.round-dot--active { background: var(--red); }

.timer-track {
  height: 4px; border-radius: 9999px;
  background: var(--line-soft);
  overflow: hidden;
}
.timer-fill {
  height: 100%; border-radius: 9999px;
  background: var(--blue);
  transition: width 0.9s linear, background-color 0.3s;
}

.stage-wrap {
  flex: 1;
  display: flex;
  min-height: 0;
}
.game-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#stage-objects { position: absolute; inset: 0; }

.game-bottom { flex-shrink: 0; }

/* ── Reveal card ────────────────────────────────────────────────────────────── */
.reveal-card {
  background: var(--ink);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 8px;
  animation: slideUp 0.25s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
.reveal-top {
  display: flex; align-items: baseline; justify-content: space-between;
}
.reveal-accuracy {
  font-size: 30px; letter-spacing: -0.6px;
}
.reveal-verdict {
  font-size: 12px; color: var(--line);
}
.reveal-sizes {
  font-size: 12px; color: var(--line);
}
.reveal-trivia {
  font-size: 14px; line-height: 1.5;
  color: var(--canvas);
}
.reveal-bottom { display: flex; justify-content: flex-end; }

/* Colors in reveal card */
.reveal-card .reveal-accuracy { color: inherit; }

/* ── Quit dialog ────────────────────────────────────────────────────────────── */
.quit-dialog {
  position: fixed; inset: 0;
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.quit-dialog[hidden] { display: none; }
.quit-dialog-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.5);
}
.quit-dialog-box {
  position: relative; z-index: 1;
  background: var(--card);
  border-radius: 20px;
  padding: 24px 20px 20px;
  width: 100%; max-width: 320px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.quit-btns {
  display: flex; gap: 10px;
}
.quit-btns .pill-btn { flex: 1; }

/* ── END SCREEN ─────────────────────────────────────────────────────────────── */
.end-main {
  flex: 1;
  padding-top: 12px;
}
.end-title {
  font-size: 44px; letter-spacing: -1.3px;
  color: var(--ink); line-height: 1.1;
}
.end-score {
  font-size: 72px; letter-spacing: -2.9px;
  line-height: 1; margin-bottom: 12px;
}
.results-list {
  display: flex; flex-direction: column;
  border-top: 1px dashed var(--line);
}
.result-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 13px;
}
.result-sil-wrap { width: 28px; height: 28px; flex-shrink: 0; }
.result-name { flex: 1; color: var(--ink); }
.result-pct { font-size: 13px; }

.end-actions {
  display: flex; flex-direction: column;
  gap: 10px;
  padding: 16px 0 4px;
}

/* ── Settings overlay ───────────────────────────────────────────────────────── */
.settings-overlay {
  position: fixed; inset: 0;
  z-index: 300;
  display: flex; align-items: flex-end; justify-content: center;
}
.settings-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.4);
  opacity: 0; transition: opacity 0.3s;
}
.settings-overlay--open .settings-backdrop { opacity: 1; }

.settings-sheet {
  position: relative; z-index: 1;
  background: var(--canvas);
  border-radius: 24px 24px 0 0;
  width: 100%; max-width: 420px;
  max-height: 90dvh; max-height: 90vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
  -webkit-overflow-scrolling: touch;
}
.settings-overlay--open .settings-sheet { transform: translateY(0); }

.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 28px 20px 24px;
  position: sticky; top: 0;
  background: var(--canvas);
  z-index: 1;
}
.settings-title { font-size: 24px; color: var(--ink); }
.close-btn {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--line-soft); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
}

.settings-body {
  display: flex; flex-direction: column; gap: 28px;
  padding: 0 20px 40px;
}
.settings-section { display: flex; flex-direction: column; gap: 10px; }
.settings-section-label { margin-bottom: 0; }

.settings-row-btn {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: var(--card);
  border-radius: 14px;
  border: 1.5px solid var(--line-soft);
  color: var(--muted);
  transition: opacity 0.15s;
}
.settings-row-btn:active { opacity: 0.7; }
.settings-link { display: flex; }

.lang-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.lang-btn {
  display: flex; align-items: center; justify-content: space-between;
  gap: 4px;
  padding: 12px;
  background: var(--card);
  border-radius: 12px;
  border: 1.5px solid var(--line-soft);
  font-family: 'BricolageGrotesque'; font-weight: 600; font-size: 14px;
  color: var(--ink);
  transition: opacity 0.15s;
}
.lang-btn--active {
  background: rgba(36,71,166,0.06);
  border-color: rgba(36,71,166,0.35);
  color: var(--ink);
}
[data-theme="dark"] .lang-btn--active {
  background: rgba(107,143,232,0.1);
  border-color: rgba(107,143,232,0.4);
}
.lang-btn svg { color: var(--blue); flex-shrink: 0; }

.appearance-row { display: flex; gap: 8px; }
.appearance-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px;
  background: var(--card);
  border-radius: 12px;
  border: 1.5px solid var(--line-soft);
  font-family: 'BricolageGrotesque'; font-weight: 600; font-size: 13px;
  color: var(--ink);
  transition: all 0.15s;
}
.appearance-btn--active {
  background: var(--ink); color: var(--canvas);
  border-color: var(--ink);
}
.appearance-icon { font-size: 14px; }

/* ── Ad slot ─────────────────────────────────────────────────────────────────── */
.ad-slot {
  margin-top: auto;
  padding-top: 12px;
  min-height: 60px;
  flex-shrink: 0;
}

/* Themes screen: match home screen bottom gap (80px = 8 + 12 + 60) */
.screen-themes .screen-inner--scroll { padding-bottom: 8px; }

/* ── RTL support ─────────────────────────────────────────────────────────────── */
[dir="rtl"] .home-title { align-items: flex-end; }
[dir="rtl"] .home-header { flex-direction: row-reverse; }
[dir="rtl"] .game-header { flex-direction: row-reverse; }
[dir="rtl"] .themes-header { flex-direction: row-reverse; }

/* ── Scrollbar ──────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
