/* ═══════════════════════════════════════════════════════════════════════
   GameYar / گیم‌یار — shared design system
   Direction: "human-approachable" (Airbnb / Duolingo posture).
   Light palette is bound verbatim; dark is the default because sessions
   happen at night. All colour lives in this token block.
   ═══════════════════════════════════════════════════════════════════════ */

@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/Vazirmatn-var.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Lalezar';
  src: url('fonts/Lalezar-arabic.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+200C-200E, U+2010-2011,
                 U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: 'Lalezar';
  src: url('fonts/Lalezar-latin.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2122;
}

/* ─── tokens ─────────────────────────────────────────────────────────── */
:root,
[data-theme='dark'] {
  --bg:      oklch(18% 0.018 255);
  --surface: oklch(23.5% 0.021 255);
  --raised:  oklch(28% 0.023 255);
  --fg:      oklch(96% 0.006 255);
  --muted:   oklch(71% 0.016 255);
  --border:  oklch(33% 0.020 255);

  --accent:        oklch(80% 0.130 170);  /* accent text / eyebrow */
  --accent-fill:   oklch(74% 0.130 170);  /* solid button background */
  --accent-fill-fg:oklch(17% 0.030 170);  /* text on the solid button */
  --accent-soft:   color-mix(in oklch, var(--accent) 16%, transparent);

  --god:      oklch(82% 0.140 78);   /* moderator only */
  --god-soft: color-mix(in oklch, var(--god) 16%, transparent);
  --mafia:    oklch(70% 0.160 22);
  --citizen:  oklch(76% 0.110 235);
  --win:      oklch(78% 0.150 150);
  --fg-soft:  color-mix(in oklch, var(--fg) 8%, transparent);
  --stage:    oklch(13% 0.014 255);

  --font-display: 'Lalezar', 'Avenir Next', system-ui, sans-serif;
  --font-body: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  --font-num: 'Vazirmatn', ui-monospace, 'SF Mono', Menlo, monospace;

  --fs-title: 26px;
  --fs-h2: 19px;
  --fs-h3: 16px;
  --fs-body: 15px;
  --fs-meta: 13px;

  --gap-xs: 6px;
  --gap-sm: 10px;
  --gap-md: 16px;
  --gap-lg: 24px;
  --gap-xl: 36px;

  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 26px;
  --tap: 48px;
}

[data-theme='light'] {
  --bg:      oklch(98% 0.004 240);
  --surface: oklch(100% 0 0);
  --raised:  oklch(96.5% 0.005 240);
  --fg:      oklch(20% 0.02 240);
  --muted:   oklch(46% 0.018 240);
  --border:  oklch(90% 0.006 240);

  --accent:        oklch(45% 0.120 170);
  --accent-fill:   oklch(48% 0.115 170);
  --accent-fill-fg:oklch(99% 0 0);
  --accent-soft:   color-mix(in oklch, var(--accent) 12%, transparent);

  --god:      oklch(48% 0.130 62);
  --god-soft: color-mix(in oklch, var(--god) 12%, transparent);
  --mafia:    oklch(48% 0.170 24);
  --citizen:  oklch(46% 0.120 250);
  --win:      oklch(45% 0.130 150);
  --fg-soft:  color-mix(in oklch, var(--fg) 5%, transparent);
  --stage:    oklch(92% 0.006 240);
}

/* Latin mode uses a true mono for numerals; Persian keeps Vazirmatn,
   which is the only face here that carries Persian digits. */
[dir='ltr'] { --font-num: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, monospace; }

/* ─── reset ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--stage);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; }
input, select, textarea { font: inherit; color: inherit; }
p { margin: 0; text-wrap: pretty; }
h1, h2, h3, h4 { margin: 0; text-wrap: balance; }
ul, ol { margin: 0; padding: 0; list-style: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ─── device stage ───────────────────────────────────────────────────── */
.stage {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--gap-lg);
  gap: var(--gap-lg);
}
.phone {
  position: relative;
  width: 390px;
  height: 844px;
  max-height: calc(100dvh - 48px);
  background: var(--bg);
  border: 10px solid oklch(9% 0.01 255);
  border-radius: 52px;
  overflow: hidden;
  box-shadow: 0 40px 90px -30px oklch(0% 0 0 / 0.65);
  display: flex;
  flex-direction: column;
}
.statusbar {
  flex: none;
  height: 46px;
  padding-inline: 26px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding-bottom: 4px;
  font-family: var(--font-num);
  font-size: 12px;
  color: var(--fg);
  letter-spacing: 0.02em;
}
.statusbar .sb-right { display: flex; gap: 5px; align-items: center; opacity: 0.9; }
.statusbar svg { width: 15px; height: 11px; }

.appbar {
  flex: none;
  min-height: 54px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: var(--gap-xs);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.appbar-title {
  font-family: var(--font-display);
  font-size: 20px;
  line-height: 1.35;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.appbar-sub { display: block; font-family: var(--font-body); font-size: 11px; color: var(--muted); line-height: 1.3; }

/* A step panel is a flex child of .phone and holds its own scrolling .screen
   plus an optional pinned footer. Without this the footer and the tab bar
   are pushed outside the frame. */
[data-step] {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--gap-md) var(--gap-md) var(--gap-xl);
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
}
.screen.flush { padding-inline: 0; }
.screen.center { justify-content: center; align-items: center; text-align: center; }

.tabbar {
  flex: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding-bottom: 14px;
}
.tabbar a {
  min-height: var(--tap);
  padding: 8px 2px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  color: var(--muted);
  transition: color 0.15s ease, background 0.15s ease;
}
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a:hover { color: var(--fg); background: var(--fg-soft); }
.tabbar a[aria-current='page'] { color: var(--accent); }

@media (max-width: 520px) {
  .stage { padding: 0; display: block; }
  .phone { width: 100%; height: 100dvh; max-height: none; border: 0; border-radius: 0; box-shadow: none; }
  .stage-note { display: none; }
}

/* ─── type ───────────────────────────────────────────────────────────── */
.title { font-family: var(--font-display); font-size: var(--fs-title); line-height: 1.3; }
.title-xl { font-family: var(--font-display); font-size: 40px; line-height: 1.22; }
h2, .h2 { font-family: var(--font-display); font-size: var(--fs-h2); line-height: 1.4; font-weight: 400; }
h3, .h3 { font-size: var(--fs-h3); font-weight: 600; line-height: 1.4; }
.eyebrow {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}
[dir='rtl'] .eyebrow { letter-spacing: 0; text-transform: none; font-size: 12px; }
.lead { color: var(--muted); line-height: 1.7; }
.meta { font-size: var(--fs-meta); color: var(--muted); }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.strong { font-weight: 700; }
.center-text { text-align: center; }

/* ─── buttons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.06s ease;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primary { background: var(--accent-fill); color: var(--accent-fill-fg); border-color: var(--accent-fill); }
.btn-primary:hover { background: color-mix(in oklch, var(--accent-fill) 88%, var(--fg)); border-color: color-mix(in oklch, var(--accent-fill) 88%, var(--fg)); color: var(--accent-fill-fg); }
.btn-secondary { background: var(--surface); color: var(--fg); border-color: var(--border); }
.btn-secondary:hover { background: var(--raised); border-color: var(--muted); color: var(--fg); }
.btn-quiet { background: transparent; color: var(--fg); border-color: transparent; }
.btn-quiet:hover { background: var(--fg-soft); color: var(--fg); }
.btn-danger { background: transparent; color: var(--mafia); border-color: var(--mafia); }
.btn-danger:hover { background: color-mix(in oklch, var(--mafia) 16%, transparent); color: var(--mafia); }
.btn-god { background: var(--god); color: oklch(17% 0.02 78); border-color: var(--god); }
[data-theme='light'] .btn-god { color: oklch(99% 0 0); }
.btn-god:hover { background: color-mix(in oklch, var(--god) 86%, var(--fg)); border-color: color-mix(in oklch, var(--god) 86%, var(--fg)); }
.btn-block { width: 100%; }
.btn-lg { min-height: 58px; font-size: 17px; border-radius: var(--radius-lg); }
/* Disabled is the one state allowed to lower contrast. Hover must not change
   the pair, or a solid button would put dark text on a dark surface. */
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary:disabled:hover { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--accent-fill-fg); }
.btn-secondary:disabled:hover { background: var(--surface); border-color: var(--border); color: var(--fg); }
.btn-god:disabled:hover { background: var(--god); border-color: var(--god); }
.btn-quiet:disabled:hover { background: transparent; }

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--fg);
  transition: background 0.15s ease;
}
.icon-btn:hover { background: var(--fg-soft); color: var(--fg); }
.icon-btn svg { width: 21px; height: 21px; }
[dir='rtl'] .icon-back svg { transform: scaleX(-1); }

/* ─── cards, tiles, lists ────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--gap-md);
}
.card-tight { padding: var(--gap-sm) var(--gap-md); }

.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--gap-md);
  min-height: 104px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-align: start;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}
.tile:hover { background: var(--raised); border-color: var(--muted); transform: translateY(-2px); }
.tile-mark { width: 30px; height: 30px; color: var(--fg); margin-bottom: 4px; }
.tile-mark svg { width: 100%; height: 100%; }
.tile-name { font-size: 16px; font-weight: 700; }
.tile-sub { font-size: 12px; color: var(--muted); line-height: 1.45; }

.list { display: flex; flex-direction: column; }
.list-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  min-height: 56px;
  padding: 8px 12px;
  border-radius: var(--radius);
  text-align: start;
  transition: background 0.15s ease;
}
.list-row:hover { background: var(--fg-soft); }
.list-row + .list-row { border-top: 1px solid var(--border); border-radius: var(--radius); }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .row-name { font-weight: 600; }
.list-row.is-selected { background: var(--accent-soft); }
.list-row.is-selected:hover { background: color-mix(in oklch, var(--accent) 24%, transparent); }

.avatar {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--raised);
  border: 1px solid var(--border);
  font-weight: 700;
  font-size: 15px;
  color: var(--fg);
}
.avatar-sm { width: 30px; height: 30px; font-size: 12px; }
.avatar-lg { width: 68px; height: 68px; font-size: 25px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap-sm); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap-sm); }
.row { display: flex; align-items: center; gap: var(--gap-sm); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--gap-sm); }
.stack { display: flex; flex-direction: column; gap: var(--gap-sm); }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.rule { border: 0; border-top: 1px solid var(--border); margin: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── chips, pills, badges ───────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.chip:hover { background: var(--raised); border-color: var(--muted); color: var(--fg); }
.chip[aria-pressed='true'] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip[aria-pressed='true']:hover { background: color-mix(in oklch, var(--accent) 24%, transparent); color: var(--accent); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--surface);
}
.pill svg { width: 12px; height: 12px; }
.pill-mafia { color: var(--mafia); border-color: color-mix(in oklch, var(--mafia) 45%, transparent); background: color-mix(in oklch, var(--mafia) 12%, transparent); }
.pill-citizen { color: var(--citizen); border-color: color-mix(in oklch, var(--citizen) 45%, transparent); background: color-mix(in oklch, var(--citizen) 12%, transparent); }
.pill-god { color: var(--god); border-color: color-mix(in oklch, var(--god) 45%, transparent); background: var(--god-soft); }
.pill-win { color: var(--win); border-color: color-mix(in oklch, var(--win) 45%, transparent); background: color-mix(in oklch, var(--win) 12%, transparent); }

/* ─── forms ──────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
  font-size: 16px;
}
.input::placeholder { color: var(--muted); }
.input:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
textarea.input { min-height: 78px; resize: vertical; line-height: 1.6; }
select.input { appearance: none; padding-inline-end: 34px; }

.seg {
  display: flex;
  padding: 3px;
  gap: 3px;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.seg button {
  flex: 1;
  min-height: 38px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease;
}
.seg button:hover { background: var(--fg-soft); color: var(--fg); }
.seg button[aria-pressed='true'] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 3px oklch(0% 0 0 / 0.22); }

.switch {
  position: relative;
  flex: none;
  width: 50px;
  height: 30px;
  border-radius: 999px;
  background: var(--raised);
  border: 1px solid var(--border);
  transition: background 0.18s ease, border-color 0.18s ease;
}
.switch::after {
  content: '';
  position: absolute;
  inset-block-start: 3px;
  inset-inline-start: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--fg);
  transition: transform 0.18s ease, background 0.18s ease;
}
.switch[aria-checked='true'] { background: var(--accent-fill); border-color: var(--accent-fill); }
.switch[aria-checked='true']::after { background: var(--accent-fill-fg); transform: translateX(20px); }
[dir='rtl'] .switch[aria-checked='true']::after { transform: translateX(-20px); }
.switch:hover { border-color: var(--muted); }

/* ─── data table (scoreboards, standings) ────────────────────────────── */
.dt { width: 100%; border-collapse: collapse; font-size: 14px; }
.dt th, .dt td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: start; }
.dt th { font-size: 11px; color: var(--muted); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
[dir='rtl'] .dt th { letter-spacing: 0; text-transform: none; font-size: 12px; }
.dt .n { font-family: var(--font-num); font-variant-numeric: tabular-nums; text-align: end; }
.dt tbody tr:hover { background: var(--fg-soft); }
.dt .rank { width: 26px; color: var(--muted); font-family: var(--font-num); }
.dt .lead-row td { font-weight: 700; }
.dt .lead-row .rank { color: var(--accent); }

/* ─── sheet / dialog ─────────────────────────────────────────────────── */
.backdrop {
  position: absolute;
  inset: 0;
  background: oklch(8% 0.01 255 / 0.62);
  z-index: 40;
  display: grid;
  align-items: end;
  animation: fade 0.16s ease;
}
.sheet {
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--gap-md);
  max-height: 86%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
  animation: rise 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.sheet-grab { width: 40px; height: 4px; border-radius: 999px; background: var(--border); margin: 0 auto; }
@keyframes rise { from { transform: translateY(28px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ─── toast ──────────────────────────────────────────────────────────── */
.toast {
  position: absolute;
  inset-inline: 16px;
  bottom: 88px;
  z-index: 60;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  box-shadow: 0 12px 30px -12px oklch(0% 0 0 / 0.6);
  animation: rise 0.2s ease;
}
.toast button { color: var(--accent); font-weight: 700; font-size: 14px; }
.toast button:hover { text-decoration: underline; }

/* ─── empty state ────────────────────────────────────────────────────── */
.empty {
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: var(--gap-lg) var(--gap-md);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
  align-items: center;
  color: var(--muted);
}
.empty .empty-mark { width: 30px; height: 30px; color: var(--muted); }

/* ─── images ─────────────────────────────────────────────────────────── */
.content-img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
/* Intentional decorative crop: the picker thumbnail is a recognition aid,
   the game name and rules carry the content. */
.thumb {
  flex: none;
  width: 58px;
  height: 58px;
  border-radius: var(--radius);
  object-fit: cover;
  border: 1px solid var(--border);
}

/* ─── progress / steps ───────────────────────────────────────────────── */
.steps { display: flex; gap: 5px; }
.steps span { height: 3px; flex: 1; border-radius: 999px; background: var(--border); }
.steps span.on { background: var(--accent); }

.bar { height: 8px; border-radius: 999px; background: var(--raised); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--accent-fill); }
.bar.mafia > i { background: var(--mafia); }
.bar.citizen > i { background: var(--citizen); }

/* ─── god mode skin ──────────────────────────────────────────────────── */
.god-mode .appbar { border-bottom-color: var(--god); background: var(--god-soft); }
.god-mode .appbar-title { color: var(--god); }
.god-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--god-soft);
  border: 1px solid color-mix(in oklch, var(--god) 40%, transparent);
  border-radius: var(--radius);
  color: var(--god);
  font-size: 12.5px;
  font-weight: 700;
}
.god-strip svg { width: 15px; height: 15px; flex: none; }

/* ─── stage note (desktop only helper text beside the phone) ─────────── */
.stage-note {
  max-width: 390px;
  text-align: center;
  color: color-mix(in oklch, var(--fg) 62%, transparent);
  font-size: 12.5px;
  line-height: 1.7;
}
.stage-note a { color: var(--accent); font-weight: 600; }
.stage-note a:hover { text-decoration: underline; }
