/* چرک‌نویس — styles
 * A reading-room palette: stone paper, library-green leather board with a tooled gold rule,
 * premium squares dyed oxblood, cognac, navy and slate; bone tiles set in Markazi Text.
 * The most recent move is marked the way a reader marks a page: with a highlighter.
 */
:root {
  --page: #E6E5E1;
  --sheet: #F3F2EE;
  --ink: #23262C;
  --ink-2: #5B5F67;
  --ink-3: #959890;
  --rule: rgba(35, 38, 44, .13);
  --rule-2: rgba(35, 38, 44, .26);
  --hover: rgba(35, 38, 44, .05);

  --leather: #22392F;
  --grout: #1A2D25;
  --cell: #2A463B;
  --cell-ink: rgba(236, 226, 200, .5);
  --gold: #C6A766;

  --tw: #7A2B2E;  --tw-ink: #F2D9CF;
  --dw: #9B6B50;  --dw-ink: #F6E4D6;
  --tl: #2E4568;  --tl-ink: #DCE5F2;
  --dl: #557784;  --dl-ink: #E3EEF0;

  --tile-top: #F5F1E7;
  --tile-bottom: #E5DDCB;
  --tile-ink: #1F2228;
  --tile-blank-ink: #7A2B2E;
  --recent-top: #F7E8A6;
  --recent-bottom: #EBD47D;

  --accent: #23262C;
  --accent-ink: #F3F0E8;
  --mark: #B98A2E;
  --good: #3D6B4F;
  --bad: #8E2F2F;

  --serif: 'Markazi', 'Noto Naskh Arabic', 'Times New Roman', serif;
  --sans: 'Estedad', 'Vazirmatn', 'Tahoma', system-ui, sans-serif;
  --shadow-sheet: 0 30px 70px -30px rgba(20, 22, 28, .45), 0 1px 3px rgba(20, 22, 28, .1);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --page: #15171B;
  --sheet: #1E2126;
  --ink: #E8E5DE;
  --ink-2: #A9AAA7;
  --ink-3: #6E7175;
  --rule: rgba(232, 229, 222, .10);
  --rule-2: rgba(232, 229, 222, .2);
  --hover: rgba(232, 229, 222, .05);

  --leather: #1A2C25;
  --grout: #12201B;
  --cell: #20372F;

  --tw: #74292C;
  --dw: #86593F;
  --tl: #2A3F60;
  --dl: #4A6A76;

  --accent: #E8E5DE;
  --accent-ink: #16181C;
  --mark: #D6AE5A;
  --good: #8DB89A;
  --bad: #E08C80;
  --shadow-sheet: 0 30px 70px -30px rgba(0, 0, 0, .7), 0 1px 3px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--mark); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .55em;
  height: 42px; padding: 0 16px;
  border: 1px solid var(--rule-2); border-radius: 6px;
  background: transparent; font-weight: 500; font-size: 14.5px;
  transition: background-color .15s, border-color .15s, opacity .15s;
  white-space: nowrap; text-decoration: none;
}
.btn:hover:not(:disabled) { background: var(--hover); border-color: var(--ink-3); }
.btn:disabled { opacity: .35; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent); opacity: .9; }
.btn.quiet { border-color: transparent; }
.btn.small { height: 32px; padding: 0 10px; font-size: 13.5px; }
.btn.danger { color: var(--bad); }
.btn .pts { font-family: var(--serif); font-weight: 700; font-size: 21px; line-height: 1; }

.seg { display: inline-flex; border: 1px solid var(--rule-2); border-radius: 6px; overflow: hidden; }
.seg button {
  border: 0; background: transparent; padding: 0 14px; height: 36px;
  font-size: 14px; color: var(--ink-2);
}
.seg button + button { border-inline-start: 1px solid var(--rule); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--page); font-weight: 600; }

.field {
  height: 42px; padding: 0 12px; width: 100%;
  border: 1px solid var(--rule-2); border-radius: 6px; background: var(--sheet);
}
.field:focus { outline: none; border-color: var(--ink); }

.icon-btn {
  width: 38px; height: 38px; border-radius: 6px; border: 0;
  background: transparent; display: grid; place-items: center; color: var(--ink-2);
}
.icon-btn:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn svg { width: 20px; height: 20px; }

/* ------------------------------------------------------------ tiles */
.tile {
  position: relative;
  display: grid; place-items: center;
  width: 1em; height: 1em;
  border-radius: 9%;
  background: linear-gradient(170deg, var(--tile-top), var(--tile-bottom));
  box-shadow:
    inset 0 .012em 0 rgba(255, 255, 255, .8),
    inset 0 -.04em 0 rgba(90, 70, 30, .2),
    0 .02em .04em rgba(10, 12, 10, .35),
    0 .07em .14em -.04em rgba(10, 12, 10, .35);
  color: var(--tile-ink);
  font-family: var(--serif); font-weight: 700;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}
.tile .ch { font-size: .66em; line-height: 1; transform: translateY(-.02em); }
.tile .v {
  position: absolute; left: 10%; bottom: 6%;
  font-family: var(--sans); font-weight: 600; font-size: .19em; line-height: 1;
  opacity: .6;
}
.tile.blank .ch { color: var(--tile-blank-ink); }
.tile.blank .v { display: none; }
.tile.recent { background: linear-gradient(170deg, var(--recent-top), var(--recent-bottom)); }

/* ------------------------------------------------------------ setup screen: a leather-bound cover */
.setup {
  /* Re-tint every control on this page for the green leather ground. */
  --ink: #EFE6CF;
  --ink-2: rgba(239, 230, 207, .74);
  --ink-3: rgba(239, 230, 207, .5);
  --rule: rgba(198, 167, 102, .22);
  --rule-2: rgba(198, 167, 102, .42);
  --hover: rgba(239, 230, 207, .06);
  --sheet: rgba(8, 18, 13, .28);
  --page: var(--leather);
  --accent: var(--gold);
  --accent-ink: #15241D;
  --mark: var(--gold);
  color: var(--ink);
  background:
    radial-gradient(90% 60% at 50% 0%, rgba(255, 255, 255, .06), transparent 70%),
    radial-gradient(120% 90% at 50% 120%, rgba(0, 0, 0, .28), transparent 60%),
    var(--leather);
  min-height: 100dvh; overflow-x: hidden;
  display: grid; place-items: start center;
  padding: clamp(48px, 10vh, 112px) 30px 56px;
}
/* The tooled gold rule around the cover. */
.setup::before {
  content: ''; position: fixed; inset: 12px; pointer-events: none; border-radius: 3px;
  border: 1px solid rgba(198, 167, 102, .55);
  box-shadow: 0 0 0 4px var(--leather), 0 0 0 5px rgba(198, 167, 102, .28);
}
.setup-inner { width: min(560px, 100%); position: relative; }
.ornament { display: block; width: 30px; height: 30px; color: var(--gold); margin-bottom: 22px; }
.headword {
  font-family: var(--serif); font-weight: 700;
  font-size: clamp(64px, 16vw, 112px); line-height: .95;
  margin: 0; color: var(--gold);
}
.entry {
  margin: 20px 0 44px; max-width: 46ch;
  font-family: var(--serif); font-weight: 500; font-size: 21px; line-height: 1.55; color: var(--ink-2);
}
.entry .pron { direction: ltr; unicode-bidi: isolate; color: var(--ink-3); }
.entry .gram { color: var(--ink-3); }
.setup h2 { font-size: 13.5px; font-weight: 600; color: var(--ink-3); margin: 0 0 8px; }
.setup .field::placeholder { color: var(--ink-3); }
.setup .field:focus { border-color: var(--gold); }
.roster { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.roster li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--rule);
}
.roster .level { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; color: var(--ink-2); font-size: 14px; }
.roster .remove {
  width: 34px; height: 34px; border: 0; background: transparent; border-radius: 6px;
  color: var(--ink-3); font-size: 20px; line-height: 1;
}
.roster .remove:hover { color: #E7A89B; background: var(--hover); }
.add-player { margin: 4px 0 0; padding: 0; height: 40px; color: var(--ink-2); }
.add-player:hover:not(:disabled) { background: transparent; color: var(--ink); }
.setup-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 34px; }
.setup-actions .btn.primary { flex: 1 1 200px; height: 52px; font-size: 16px; }
.setup-actions .btn { height: 52px; }
.setup-note { color: var(--ink-3); font-size: 13.5px; margin: 12px 0 0; }
.link {
  border: 0; background: transparent; padding: 0; font-size: inherit; color: var(--ink-2);
  text-decoration: underline; text-underline-offset: 4px; text-decoration-color: var(--rule-2);
}
.link:hover { color: var(--ink); }
.setup-foot { margin-top: 30px; display: flex; gap: 4px; flex-wrap: wrap; border-top: 1px solid var(--rule); padding-top: 14px; }
.setup-foot .btn { height: 34px; font-weight: 400; color: var(--ink-2); padding: 0 10px; }
.setup-foot .btn:hover { color: var(--ink); }

.settings .option { margin-top: 20px; }
.settings .option h3 { font-size: 14px; font-weight: 600; margin: 0 0 8px; }
.settings .option p { margin: 8px 0 0; font-size: 14px; min-height: 1.7em; }

/* ------------------------------------------------------------ game layout */
.game {
  --board: min(calc(100dvh - 232px), calc(100vw - 420px), 780px);
  height: 100dvh;
  display: grid;
  grid-template-columns: 320px 1fr;
  overflow: hidden;
}
.side {
  display: flex; flex-direction: column; min-height: 0;
  padding: 22px 24px 16px;
  border-inline-end: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.logo { font-family: var(--serif); font-weight: 700; font-size: 34px; line-height: 1; }

.players { list-style: none; margin: 0; padding: 0; }
.player {
  display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--rule);
}
.player:last-child { border-bottom: 0; }
.player .name { font-weight: 500; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.player .name::before {
  content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  margin-inline-end: 9px; vertical-align: 2px; background: transparent; border: 1px solid var(--rule-2);
}
.player .meta { display: inline; font-size: 12.5px; color: var(--ink-3); margin-inline-start: 8px; }
.player .score { font-family: var(--serif); font-weight: 700; font-size: 30px; line-height: 1; color: var(--ink-2); }
.player.is-current .name, .player.is-current .score { color: var(--ink); }
.player.is-current .name { font-weight: 600; }
.player.is-current .name::before { background: var(--mark); border-color: var(--mark); }
.thinking::after { content: ''; display: inline-block; width: 1.2em; text-align: start; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

.bag { display: flex; align-items: baseline; justify-content: space-between; margin: 6px 0 0; padding: 8px 0; color: var(--ink-3); font-size: 13.5px; white-space: nowrap; }
.bag button { border: 0; background: transparent; color: var(--ink-2); padding: 2px 0; font-size: 13.5px; text-decoration: underline; text-underline-offset: 4px; text-decoration-color: var(--rule-2); }
.bag button:hover { color: var(--ink); }

.ledger { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-top: 14px; }
.ledger-head { display: flex; align-items: center; justify-content: space-between; padding-bottom: 6px; border-bottom: 1px solid var(--ink); }
.ledger-head h2 { font-family: var(--serif); font-weight: 700; font-size: 21px; margin: 0; }
.ledger ol { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; scrollbar-width: thin; }
.row {
  display: grid; grid-template-columns: 2.2em 4.8em 1fr auto; gap: 8px; align-items: baseline;
  padding: 7px 6px; border-bottom: 1px solid var(--rule); cursor: pointer;
  transition: background-color .12s;
}
.row:hover, .row.is-traced { background: var(--hover); }
.row.is-pinned { background: color-mix(in srgb, var(--recent-top) 45%, transparent); }
.row.is-step { box-shadow: inset 3px 0 0 var(--mark); }
.row .n { color: var(--ink-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.row .who { color: var(--ink-2); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .what { font-family: var(--serif); font-weight: 500; font-size: 18px; line-height: 1.35; overflow-wrap: anywhere; }
.row .what small { font-family: var(--serif); color: var(--ink-3); font-size: 16px; }
.row .what.muted { font-family: var(--sans); font-size: 13.5px; color: var(--ink-3); }
.row .pts { font-family: var(--serif); font-weight: 700; font-size: 19px; }
.ledger .empty { color: var(--ink-3); font-size: 14px; padding: 10px 0; }

.play {
  min-width: 0; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 18px 24px; gap: 14px;
}

/* ------------------------------------------------------------ board */
.board {
  direction: ltr;
  width: var(--board); height: var(--board);
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  gap: calc(var(--board) * .004);
  padding: calc(var(--board) * .026);
  background: var(--grout);
  border-radius: calc(var(--board) * .012);
  box-shadow:
    inset 0 0 0 calc(var(--board) * .011) var(--leather),
    inset 0 0 0 calc(var(--board) * .0125) color-mix(in srgb, var(--gold) 55%, transparent),
    0 1px 2px rgba(0, 0, 0, .2), 0 18px 40px -24px rgba(10, 20, 15, .6);
  container-type: inline-size;
  flex: none;
}
.cell {
  position: relative;
  display: grid; place-items: center;
  background: var(--cell);
  border-radius: 6%;
  color: var(--cell-ink);
  min-width: 0; min-height: 0;
}
.cell[data-p="T"] { background: var(--tw); color: var(--tw-ink); }
.cell[data-p="D"], .cell[data-p="*"] { background: var(--dw); color: var(--dw-ink); }
.cell[data-p="t"] { background: var(--tl); color: var(--tl-ink); }
.cell[data-p="d"] { background: var(--dl); color: var(--dl-ink); }
.cell .lbl {
  display: flex; flex-direction: column; align-items: center;
  font-size: 1.75cqi; line-height: 1.15; font-weight: 500; text-align: center;
  pointer-events: none; opacity: .92;
}
.cell .lbl b { font-family: var(--serif); font-weight: 700; font-size: 1.6em; line-height: 1; }
.cell .star { width: 64%; height: 64%; color: var(--gold); pointer-events: none; }
@container (max-width: 560px) {
  .cell .lbl small { display: none; }
  .cell .lbl b { font-size: 2.7cqi; }
}
.cell .tile { position: absolute; inset: 0; width: auto; height: auto; font-size: 6.05cqi; cursor: default; }
.cell .tile.pending {
  box-shadow: 0 0 0 .05em var(--gold), 0 .14em .26em -.06em rgba(0, 0, 0, .55);
  transform: translateY(-4%);
  z-index: 2; cursor: grab;
}
.cell .tile.settle { animation: settle .2s ease-out; }
@keyframes settle { from { transform: scale(1.1); } to { transform: translateY(-4%); } }
.cell .tile.trace { box-shadow: 0 0 0 .06em var(--gold), 0 0 0 .12em rgba(198, 167, 102, .35); z-index: 1; }
.cell.hover { outline: 2px dashed var(--gold); outline-offset: -2px; }
.cell.cursor { box-shadow: inset 0 0 0 2px var(--gold); }
.cell.cursor::after {
  content: attr(data-arrow);
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 3.4cqi; font-weight: 700; color: var(--gold);
  animation: blink 1.1s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: .25; } }

/* ------------------------------------------------------------ dock */
.dock { width: var(--board); max-width: 100%; display: flex; flex-direction: column; gap: 12px; }
.status {
  min-height: 30px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px;
  font-size: 14px; color: var(--ink-2);
}
.status .err.bad { color: var(--bad); }
.chip {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 0 10px; border-radius: 4px; border: 1px solid var(--rule-2);
  font-family: var(--serif); font-weight: 500; font-size: 18px; line-height: 1.5; color: var(--ink);
}
.chip b { font-weight: 700; }
.chip.bad { color: var(--bad); border-color: currentColor; }
.chip.bad a { font-family: var(--sans); font-size: 12.5px; color: inherit; text-underline-offset: 3px; }
.chip.bonus { border-color: var(--mark); }
.status .fix { display: inline-flex; gap: 4px; }

.rack-row { display: flex; align-items: center; gap: 12px; }
.rack {
  --s: 54px;
  flex: 1;
  display: flex; gap: 7px; justify-content: center;
  min-height: calc(var(--s) + 18px);
  padding: 9px; border-radius: 8px;
  background: var(--leather);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--gold) 35%, transparent);
  direction: rtl;
}
.rack .tile { font-size: var(--s); cursor: grab; transition: transform .12s; }
.rack .tile.selected { transform: translateY(-7px); box-shadow: 0 0 0 .045em var(--gold), 0 .14em .26em -.06em rgba(0, 0, 0, .55); }
.rack .tile.dragging, .cell .tile.dragging { opacity: .25; }
.rack.drop { outline: 2px dashed var(--gold); outline-offset: 2px; }
.rack .veil { flex: 1; display: grid; place-items: center; color: var(--cell-ink); font-size: 14.5px; text-align: center; color: #E6DECB; opacity: .8; }
.rack .veil .btn { color: inherit; border-color: rgba(230, 222, 203, .35); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .spacer { flex: 1; }
.actions .btn.primary { min-width: 140px; }

.ghost {
  position: fixed; z-index: 1000; pointer-events: none;
  transform: translate(-50%, -60%) scale(1.06) rotate(-2deg);
  filter: drop-shadow(0 12px 14px rgba(0, 0, 0, .3));
}

/* ------------------------------------------------------------ replay */
.replay { width: var(--board); max-width: 100%; display: flex; flex-direction: column; gap: 10px; }
.replay .caption { min-height: 30px; font-size: 14px; color: var(--ink-2); display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.replay .caption b { font-family: var(--serif); font-weight: 700; font-size: 19px; color: var(--ink); }
.replay .track { display: flex; align-items: center; gap: 12px; direction: ltr; }
.replay input[type="range"] { flex: 1; accent-color: var(--ink); height: 28px; }
.replay .controls { display: flex; align-items: center; gap: 4px; direction: ltr; }
.replay .controls .exit { margin-inline-start: auto; direction: rtl; }
.replay .step-count { font-size: 13px; color: var(--ink-3); min-width: 5em; text-align: center; font-variant-numeric: tabular-nums; direction: rtl; }

/* ------------------------------------------------------------ overlays & sheets */
.overlay {
  position: fixed; inset: 0; z-index: 500;
  display: grid; place-items: center; padding: 20px;
  background: color-mix(in srgb, var(--page) 70%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  animation: fade .16s ease-out;
}
.overlay.solid { background: var(--page); backdrop-filter: none; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: min(460px, 100%); max-height: calc(100dvh - 40px); overflow-y: auto;
  background: var(--sheet); border-radius: 10px; padding: 26px 28px 22px;
  border: 1px solid var(--rule);
  box-shadow: var(--shadow-sheet);
  animation: rise .2s cubic-bezier(.2, .8, .3, 1);
}
.sheet.wide { width: min(640px, 100%); }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }
.sheet h2 { margin: 0 0 6px; font-family: var(--serif); font-weight: 700; font-size: 28px; line-height: 1.2; }
.sheet p { margin: 0 0 14px; color: var(--ink-2); }
.sheet .row-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.sheet .row-actions .btn { min-width: 92px; }

.menu { list-style: none; margin: 6px 0 0; padding: 0; }
.menu li + li { border-top: 1px solid var(--rule); }
.menu button {
  width: 100%; text-align: start; border: 0; background: transparent;
  padding: 12px 2px; font-size: 15.5px; display: flex; justify-content: space-between; align-items: center;
}
.menu button:hover { color: var(--mark); }
.menu .hint { color: var(--ink-3); font-size: 13.5px; }

.handoff { text-align: center; }
.handoff .label { color: var(--ink-3); margin: 0; font-size: 14px; }
.handoff .big { font-family: var(--serif); font-weight: 700; font-size: clamp(56px, 12vw, 96px); line-height: 1.05; margin: 0 0 6px; }
.handoff .sub { color: var(--ink-2); margin: 0 auto 30px; max-width: 36ch; }
.handoff .btn { height: 50px; padding: 0 30px; font-size: 16px; }

.picker { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; direction: rtl; margin-top: 8px; }
.picker button { border: 0; padding: 0; background: transparent; font-size: 44px; display: grid; place-items: center; }
.picker button .tile { font-size: inherit; }
.picker button:hover .tile, .picker button:focus-visible .tile { transform: translateY(-3px); }
@media (max-width: 420px) { .picker button { font-size: 36px; } }

.swap { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; font-size: min(46px, calc((100vw - 120px) / 7)); direction: rtl; margin: 14px 0 4px; }
.swap button { border: 0; padding: 0; background: transparent; font-size: inherit; }
.swap button .tile { transition: transform .12s; }
.swap button[aria-pressed="true"] .tile { transform: translateY(-8px); box-shadow: 0 0 0 .045em var(--bad), 0 .14em .26em -.06em rgba(0, 0, 0, .45); }

.results { list-style: none; margin: 18px 0 0; padding: 0; border-top: 1px solid var(--ink); }
.results li { display: grid; grid-template-columns: 1fr auto auto; gap: 14px; align-items: baseline; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.results li:first-child .rn { font-weight: 700; }
.results .rs { font-family: var(--serif); font-weight: 700; font-size: 28px; line-height: 1; }
.results .adj { color: var(--ink-3); font-size: 13px; min-width: 3em; text-align: end; }
.sheet .winner { font-family: var(--serif); font-weight: 700; font-size: 44px; line-height: 1.1; margin: 2px 0 0; color: var(--ink); }

.unseen { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 10px 8px; direction: rtl; margin-top: 10px; }
.unseen div { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 38px; }
.unseen .n { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.unseen .zero { opacity: .28; }

.lookup .field { font-family: var(--serif); font-weight: 500; font-size: 22px; height: 52px; }
.lookup .verdict { margin-top: 12px; min-height: 3.4em; font-size: 15px; }
.lookup .verdict .yes { color: var(--good); font-weight: 600; }
.lookup .verdict .no { color: var(--bad); font-weight: 600; }
.lookup .verdict small { display: block; color: var(--ink-3); }
.lookup .verdict .links { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.custom { margin-top: 18px; border-top: 1px solid var(--rule); padding-top: 12px; }
.custom h3 { font-size: 14px; margin: 0 0 6px; color: var(--ink-2); font-weight: 600; }
.custom ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.custom li { display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--rule-2); border-radius: 4px; padding: 0 4px 0 10px; font-family: var(--serif); font-size: 18px; }
.custom li button { border: 0; background: transparent; color: var(--ink-3); font-size: 16px; width: 26px; height: 26px; border-radius: 4px; }
.custom li button:hover { color: var(--bad); }
.custom .none { color: var(--ink-3); font-size: 13.5px; }

.rules { font-size: 14.5px; }
.rules ul { margin: 6px 0 14px; padding-inline-start: 20px; }
.rules li { margin-bottom: 6px; }
.rules h3 { font-family: var(--serif); font-weight: 700; font-size: 20px; margin: 18px 0 4px; }
.rules kbd { font-family: inherit; font-size: 12.5px; padding: 1px 7px; border: 1px solid var(--rule-2); border-bottom-width: 2px; border-radius: 4px; background: var(--page); }
.values { display: grid; grid-template-columns: auto 1fr; gap: 0 18px; margin-top: 6px; align-items: baseline; }
.values div { display: contents; }
.values .pv { font-size: 13.5px; color: var(--ink-2); white-space: nowrap; }
.values .letters { font-family: var(--serif); font-weight: 700; font-size: 22px; word-spacing: .35em; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 4px 0 12px; font-size: 13.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 15px; height: 15px; border-radius: 3px; display: inline-block; }

.toast {
  position: fixed; z-index: 900; left: 50%; top: 18px; transform: translateX(-50%);
  background: var(--ink); color: var(--page);
  padding: 9px 16px; border-radius: 6px; font-size: 14.5px; width: max-content; max-width: calc(100vw - 32px);
  box-shadow: var(--shadow-sheet);
  animation: toast-in .2s cubic-bezier(.2, .8, .3, 1);
}
.toast.out { opacity: 0; transform: translate(-50%, -8px); transition: opacity .25s, transform .25s; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -10px); } }

/* ------------------------------------------------------------ narrow screens */
@media (max-width: 900px) {
  .game {
    --board: min(calc(100vw - 16px), calc(100dvh - 268px), 640px);
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .side { padding: 10px 12px 0; border: 0; }
  .brand { margin-bottom: 4px; }
  .logo { font-size: 28px; }
  .players { display: flex; gap: 6px 26px; flex-wrap: wrap; border-bottom: 1px solid var(--rule); padding-bottom: 4px; }
  .player { display: flex; align-items: baseline; gap: 8px; min-width: 0; border: 0; padding: 2px 0; }
  .player .meta { display: none; }
  .player .name { font-size: 14px; }
  .player .score { font-size: 24px; }
  .bag, .ledger { display: none; }
  .play { padding: 8px 8px 12px; justify-content: flex-start; gap: 10px; }
  .rack { --s: min(46px, calc((100vw - 74px) / 7)); gap: 5px; padding: 7px; }
  .actions { gap: 6px; }
  .actions .btn { padding: 0 12px; height: 42px; font-size: 14px; }
  .actions .btn.primary { min-width: 0; flex: 1; }
  .actions .spacer { display: none; }
  .status { font-size: 13.5px; }
  .toast { top: auto; bottom: max(16px, env(safe-area-inset-bottom)); }
}
@media (min-width: 901px) { .show-narrow { display: none !important; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
body:has(.setup) { background: var(--leather); }

/* ------------------------------------------------------------ shared games */
.online-block { margin-top: 34px; border-top: 1px solid var(--rule); padding-top: 22px; }
.online-block .setup-note { margin: 0 0 14px; }
.online-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.online-actions .btn { flex: 1 1 180px; height: 48px; }
.resume { list-style: none; margin: 14px 0 0; padding: 0; }
.resume li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--rule); font-size: 14px;
}
.resume-what { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.resume-what b { font-family: var(--serif); font-weight: 700; font-size: 18px; color: var(--ink); margin-inline-end: 6px; }
.status-tag { color: var(--ink-3); font-size: 13px; }

.headword.small { font-size: clamp(48px, 11vw, 72px); }
.lobby-code {
  margin: 6px 0 14px; font-family: var(--serif); font-weight: 700;
  font-size: clamp(56px, 14vw, 88px); line-height: 1; letter-spacing: .12em; color: var(--gold);
  text-align: right;
}
.lobby-share { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 36px; }
.lobby-players li { grid-template-columns: minmax(0, 1fr) auto; padding: 14px 0; font-size: 16px; }
.lobby-name { display: inline-flex; align-items: center; gap: 10px; }
.lobby-tag { color: var(--ink-3); font-size: 13.5px; }
.presence { width: 8px; height: 8px; border-radius: 50%; border: 1px solid var(--rule-2); display: inline-block; }
.presence.on { background: #8FCB9B; border-color: #8FCB9B; }

.share-code { font-family: var(--serif); font-weight: 700; font-size: 52px; line-height: 1; letter-spacing: .1em; margin: 4px 0 14px !important; color: var(--ink) !important; text-align: right; }
.online-form label { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; font-size: 14px; color: var(--ink-2); }
.online-form .note { margin: 8px 0 0; font-size: 13.5px; min-height: 1.6em; color: var(--ink-3); }
.online-form .code-field { font-family: var(--serif); font-weight: 700; font-size: 26px; letter-spacing: .2em; height: 54px; text-align: center; }
.bag-links { display: inline-flex; gap: 12px; }
