:root {
  color-scheme: light;
  --paper: oklch(97.8% 0.008 50); --paper-2: oklch(94.4% 0.013 45); --paper-3: oklch(90.5% 0.018 45);
  --ink: oklch(25% 0.02 20); --ink-2: oklch(40% 0.02 20); --muted: oklch(52% 0.02 20);
  --rule: oklch(88% 0.018 40);
  --accent: oklch(60% 0.16 12); --accent-soft: oklch(94% 0.03 12); --accent-mid: oklch(87% 0.06 12); --accent-ink: oklch(38% 0.11 12);
  --red: oklch(56% 0.18 18); --black: oklch(26% 0.02 260);
  --face: oklch(99.5% 0.003 60);
  --font: "Figtree", system-ui, sans-serif;
  --radius: 18px; --pill: 999px;
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-7: 48px;
  --t-sm: 0.875rem; --t-md: 1rem; --t-lg: 1.25rem; --t-xl: 1.7rem; --t-2xl: 2.4rem; --t-3xl: 3.2rem;
  --dur: 140ms; --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --page: 30rem;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-x: clip; }
body { margin: 0; min-height: 100dvh; background: var(--paper); color: var(--ink); font: 400 var(--t-md)/1.5 var(--font); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overflow-x: clip; }
h1, h2, p, ol, ul { margin: 0; }
h1, h2 { font-weight: 800; line-height: 1.02; letter-spacing: -0.02em; text-wrap: balance; overflow-wrap: break-word; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; }
[hidden] { display: none !important; }
.noscript { padding: var(--s-5); }

.page { max-width: var(--page); margin-inline: auto; padding: calc(var(--s-6) + var(--safe-t)) calc(var(--s-4) + var(--safe-r)) calc(var(--s-7) + var(--safe-b)) calc(var(--s-4) + var(--safe-l)); }

.masthead h1 { font-size: var(--t-3xl); }
.masthead h1::after { content: ""; display: inline-block; width: 0.24em; height: 0.24em; margin-left: 0.07em; border-radius: 50%; box-shadow: inset 0 0 0 0.065em var(--accent); }
.lead { margin-top: var(--s-2); color: var(--ink-2); font-size: var(--t-lg); line-height: 1.35; max-width: 32ch; text-wrap: pretty; }
.lead--sm { font-size: var(--t-md); }
.quiet { margin-top: var(--s-3); font-size: var(--t-sm); font-weight: 600; color: var(--accent-ink); }

.block { margin-top: var(--s-6); display: grid; gap: var(--s-2); }
.label { display: block; font-size: var(--t-sm); font-weight: 600; color: var(--ink-2); }
.note { font-size: var(--t-sm); color: var(--muted); text-wrap: pretty; }
.note:empty { display: none; }
.foot { margin-top: var(--s-6); font-size: var(--t-sm); color: var(--muted); text-wrap: pretty; }
.title { font-size: var(--t-2xl); margin-top: var(--s-2); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); min-height: 48px; padding: var(--s-2) var(--s-5); border: 0; border-radius: var(--pill); background: var(--paper-2); color: var(--ink); font-weight: 600; font-size: var(--t-md); cursor: pointer; touch-action: manipulation; transition: background-color var(--dur) linear, transform var(--dur) var(--ease); }
.btn:hover { background: var(--paper-3); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn--primary { background: var(--ink); color: var(--paper); }
.btn--primary:hover { background: var(--ink-2); }
.btn--quiet { background: transparent; box-shadow: inset 0 0 0 1.5px var(--rule); }
.btn--quiet:hover { background: var(--paper-2); }
.btn--wide { width: 100%; }
.btn--big { min-height: 60px; font-size: var(--t-lg); }
.btn--warn { background: var(--accent-soft); color: var(--accent-ink); box-shadow: none; }
.btn--warn:hover { background: var(--accent-mid); }
.link { align-self: flex-start; background: none; border: 0; min-height: 44px; padding: var(--s-2) 0; font-size: var(--t-sm); font-weight: 600; color: var(--ink-2); text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 0.25em; cursor: pointer; }
.link:hover { color: var(--ink); }

.panel { padding: var(--s-4) var(--s-5); border-radius: var(--radius); background: var(--paper-2); }
.panel__stat { font-weight: 600; color: var(--ink-2); text-wrap: pretty; }

.players { list-style: none; padding: 0; display: grid; gap: var(--s-2); counter-reset: p; }
.players:empty { display: none; }
.player { display: flex; align-items: center; gap: var(--s-2); counter-increment: p; }
.player::before { content: counter(p); width: 1.4em; flex: none; text-align: right; font-size: var(--t-sm); color: var(--muted); font-variant-numeric: tabular-nums; }
.player input { flex: 1; min-width: 0; min-height: 48px; padding: var(--s-2) var(--s-4); border: 0; border-radius: var(--pill); background: var(--paper-2); font-size: var(--t-md); }
.player input:hover { background: var(--paper-3); }
.player input:focus { background: var(--paper); box-shadow: inset 0 0 0 2px var(--accent); outline: none; }
.player input::placeholder { color: var(--muted); }
.remove { flex: none; width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; }
.remove:hover { background: var(--paper-2); color: var(--ink); }

.topline { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); min-height: 44px; margin-top: calc(var(--s-3) * -1); }
.step { font-size: var(--t-sm); font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.step b { color: var(--accent-ink); font-weight: 800; }
.kicker { font-size: var(--t-sm); font-weight: 600; color: var(--ink-2); text-align: center; min-height: 1.5em; overflow-wrap: anywhere; }

/* the table: one screen, card in the middle, rule under it, draw button within thumb reach */
.table { min-height: 100dvh; max-width: var(--page); margin-inline: auto; display: flex; flex-direction: column; gap: var(--s-3); padding: calc(var(--s-4) + var(--safe-t)) calc(var(--s-4) + var(--safe-r)) calc(var(--s-5) + var(--safe-b)) calc(var(--s-4) + var(--safe-l)); }

.card { --w: min(100%, 19rem, max(9rem, calc((100dvh - 365px) * 0.714))); position: relative; align-self: center; flex: none; width: var(--w); aspect-ratio: 5 / 7; padding: 0; border: 0; border-radius: var(--radius); background: none; cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; perspective: 900px; }
.card:disabled { cursor: default; }
.card__inner { position: absolute; inset: 0; display: block; border-radius: inherit; container-type: inline-size; transform-origin: 50% 50%; }
.card.flip .card__inner { animation: flip 260ms var(--ease); }
@keyframes flip { from { transform: rotateY(80deg) scale(0.96); opacity: 0.4; } to { transform: none; opacity: 1; } }
.card:active:not(:disabled) .card__inner { transform: scale(0.985); }

/* back: rings on a soft ground */
.back { position: absolute; inset: 0; display: grid; place-items: center; border-radius: inherit; background: var(--accent-soft); box-shadow: inset 0 0 0 6cqi var(--accent-soft), inset 0 0 0 calc(6cqi + 2px) var(--accent-mid); overflow: hidden; }
.back::before { content: ""; position: absolute; inset: 9cqi; border-radius: 10px; background: repeating-radial-gradient(circle at 50% 50%, transparent 0 7cqi, var(--accent-mid) 7cqi calc(7cqi + 2px)); opacity: 0.8; }
.back span { position: relative; padding: 2cqi 6cqi; border-radius: var(--pill); background: var(--accent-soft); color: var(--accent-ink); font-size: 8.5cqi; font-weight: 800; letter-spacing: -0.01em; }

/* face: my own plain design, rank huge in the middle, corner indices */
.face { position: absolute; inset: 0; border-radius: inherit; background: var(--face); box-shadow: 0 1px 2px oklch(30% 0.03 30 / 0.12), 0 10px 28px -12px oklch(30% 0.04 30 / 0.3), inset 0 0 0 1px var(--rule); color: var(--black); }
.face.red { color: var(--red); }
.idx { position: absolute; display: grid; justify-items: center; gap: 1cqi; top: 5cqi; left: 6cqi; font-size: 13cqi; font-weight: 800; line-height: 1; letter-spacing: -0.04em; }
.idx svg { width: 9cqi; height: 9cqi; }
.idx--b { top: auto; left: auto; bottom: 5cqi; right: 6cqi; }
.mid { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 3cqi; }
.mid b { font-size: 40cqi; font-weight: 800; line-height: 0.85; letter-spacing: -0.06em; }
.mid svg { width: 26cqi; height: 26cqi; }
.face.ten .mid b { font-size: 34cqi; letter-spacing: -0.08em; }
.face.last { box-shadow: 0 0 0 4px var(--accent-mid), 0 10px 28px -12px oklch(30% 0.04 30 / 0.3), inset 0 0 0 1px var(--rule); }

.rule { text-align: center; display: grid; gap: var(--s-1); padding-inline: var(--s-2); }
.rule__title { font-size: var(--t-xl); }
.rule__text { font-size: var(--t-lg); line-height: 1.3; color: var(--ink-2); text-wrap: balance; overflow-wrap: break-word; }
.rule.end { padding: var(--s-4) var(--s-4); border-radius: var(--radius); background: var(--accent-soft); }
.rule.end .rule__title, .rule.end .rule__text { color: var(--accent-ink); }

.dock { margin-top: auto; display: grid; gap: var(--s-2); }
.turn { text-align: center; font-size: var(--t-lg); font-weight: 800; min-height: 1.5em; overflow-wrap: anywhere; line-height: 1.2; }
.turn:empty { display: none; }
.dock__row { display: flex; gap: var(--s-2); }
.dock__row .btn--quiet { flex: none; min-height: 60px; padding-inline: var(--s-5); }
.dock__main { flex: 1; }

/* rules editor */
.edit { list-style: none; padding: 0; margin-top: var(--s-5); display: grid; gap: var(--s-3); }
.rank { display: grid; grid-template-columns: 3rem 1fr; gap: var(--s-1) var(--s-3); padding: var(--s-3) var(--s-4) var(--s-3) var(--s-3); border-radius: var(--radius); background: var(--paper-2); }
.rank__tag { grid-row: span 2; align-self: start; display: grid; place-items: center; width: 3rem; height: 3.6rem; border-radius: 10px; background: var(--face); box-shadow: inset 0 0 0 1px var(--rule); font-size: var(--t-lg); font-weight: 800; letter-spacing: -0.04em; }
.rank--last { background: var(--accent-soft); }
.rank--last .rank__tag { font-size: var(--t-sm); line-height: 1.1; text-align: center; color: var(--accent-ink); }
.rank input, .rank textarea { width: 100%; min-width: 0; border: 0; border-radius: 10px; background: transparent; padding: var(--s-1) var(--s-2); margin-left: calc(var(--s-2) * -1); }
.rank input { min-height: 44px; font-size: var(--t-lg); font-weight: 800; }
.rank textarea { resize: none; field-sizing: content; min-height: 3.2em; color: var(--ink-2); line-height: 1.35; }
.rank input:hover, .rank textarea:hover { background: oklch(100% 0 0 / 0.5); }
.rank input:focus, .rank textarea:focus { background: var(--paper); box-shadow: inset 0 0 0 2px var(--accent); outline: none; }
.rank.changed .rank__tag { box-shadow: inset 0 0 0 2px var(--accent); }
.stack { display: grid; gap: var(--s-2); margin-top: var(--s-5); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media (max-width: 22.6rem) { :root { --t-3xl: 2.6rem; --t-2xl: 2rem; --t-xl: 1.45rem; --t-lg: 1.12rem; } }
@media (max-height: 700px) { :root { --t-xl: 1.4rem; --t-lg: 1.08rem; } .table { gap: var(--s-2); } }

/* back to games.el.zone, on the home screen only */
.back-home { display: inline-flex; align-items: center; gap: 2px; align-self: flex-start; min-height: 44px; margin: -12px 0 4px -6px; padding: 0 10px 0 4px; border-radius: 999px; color: inherit; opacity: 0.6; font-size: 0.875rem; font-weight: 600; line-height: 1; text-decoration: none; transition: opacity 140ms linear; }
.back-home:hover, .back-home:focus-visible { opacity: 1; }
.back-home svg { flex: none; }
