:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --ink: #1f1d1a;
  --muted: #6b665d;
  --line: #d9d3c6;
  --felt: #2f6b4f;
  --felt-ink: #f1efe8;
  --accent: #c2412d;
  --select: #f2b632;
  --card: #ffffff;
  --card-low: #e3f4e6;
  --card-ink: #1f1d1a;
  --back: #29466b;
  --back-2: #3c5f8c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161513;
    --panel: #201f1c;
    --ink: #ece8df;
    --muted: #a19b8f;
    --line: #38352f;
    --felt: #1f4a37;
    --felt-ink: #e8e5dc;
    --accent: #e0644f;
    --card: #f7f5ef;
    --card-low: #d6efda;
    --back: #2a3f5e;
    --back-2: #3a5679;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}
[hidden] { display: none !important; }
button {
  font: inherit;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.small { padding: 4px 10px; font-size: 13px; }
input, select {
  font: inherit;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-width: 0;
}
main { max-width: 980px; margin: 0 auto; padding: 12px 16px 120px; }
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--ink); text-decoration: none; letter-spacing: .04em; }
.name { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.name input { width: 150px; }
.bar { flex-wrap: wrap; }
@media (max-width: 480px) { .name input { width: 120px; } }

/* accounts (ACCT-13) */
.account { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.account-user { color: var(--muted); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-form { display: flex; flex-direction: column; gap: 12px; width: min(400px, 100%); }
.account-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.account-form .hint { font-size: 12px; }
.account-about { margin: 0; font-size: 13px; color: var(--muted); }
.account-about:empty, .account-error:empty { display: none; }
.account-error { margin: 0; color: var(--accent); font-weight: 600; }
a.account-user { text-decoration: underline; }
button.danger { color: var(--accent); border-color: var(--accent); }
#account-page .account-form { margin-top: 20px; }
#account-page .account-form h2 { margin: 0; }
#account-page .account-form p:not(.account-error) { margin: 0; font-size: 13px; color: var(--muted); }
/* lifetime stats (STAT-11) */
.acct-stats h2 { margin: 20px 0 8px; }
.acct-stats h3 { margin: 16px 0 6px; font-size: 14px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 0; }
.stat-grid div { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.stat-grid dt { font-size: 12px; color: var(--muted); }
.stat-grid dd { margin: 2px 0 0; font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.partners { margin: 0; padding-left: 22px; }
.partners .games { color: var(--muted); font-size: 13px; }
.acct-rooms h2 { margin: 20px 0 8px; }
.acct-room-list { margin: 0; padding-left: 22px; }
.acct-room-list a { font-family: ui-monospace, monospace; font-weight: 600; }
.acct-room-list .about { color: var(--muted); font-size: 13px; }
.acct-device-list { margin: 0 0 8px; padding-left: 22px; }
.acct-device-list li { margin: 4px 0; }
.acct-device-list .about { color: var(--muted); font-size: 13px; }
.recovery-code { display: block; padding: 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 18px; text-align: center; overflow-wrap: anywhere; user-select: all; }
button.link { background: none; border: 0; padding: 4px; color: var(--muted); text-decoration: underline; }

/* the cookie notice (ACCT-14) */
.cookies {
  position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 9; margin: 0 auto; max-width: 640px;
  display: flex; gap: 12px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.25); font-size: 13px;
}
.cookies p { margin: 0; flex: 1; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; margin: 12px 0;
}
.panel h1 { margin-top: 0; }
.panel h2 { margin: 0 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.settings-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0 0 14px; }
.settings-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.room-settings { flex-basis: 100%; font-size: 12px; color: var(--muted); }
.join { display: flex; gap: 8px; margin-top: 12px; }
.join input { text-transform: uppercase; width: 140px; }
.roombar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.roombar strong { font-family: ui-monospace, monospace; letter-spacing: .12em; font-size: 18px; }
.roomid { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.watch-tag, .observers {
  font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px;
}
.watch-tag, .watch-only { display: none; }
.watching .watch-tag, .watching .watch-only { display: inline-block; }
.watching .player-only { display: none; }
.status { margin: 10px 0 6px; min-height: 22px; font-weight: 600; }
.status .komino { color: var(--accent); }
.status.offline { color: var(--muted); }

.table {
  background: var(--felt); color: var(--felt-ink); border-radius: 16px;
  padding: 12px; display: flex; flex-direction: column; gap: 14px;
}
.opponents { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.hand { padding: 8px; border-radius: 10px; border: 2px solid transparent; }
.hand.turn { border-color: var(--select); }
.hand .who { font-size: 13px; display: flex; gap: 6px; align-items: center; justify-content: center; margin-bottom: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #888; display: inline-block; }
.dot.on { background: #5fd38a; }
.slots { display: grid; grid-template-columns: repeat(var(--cols, 2), auto); gap: 6px; justify-content: center; }
.center { display: flex; gap: 18px; justify-content: center; align-items: center; }
.pile { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; }
.mine .slots { gap: 10px; }

.card {
  width: 54px; height: 76px; padding: 0; border: 0; background: none; border-radius: 7px;
  display: inline-block; position: relative;
  /* card art and slot numbers carry their own contrast; forced colors (e.g.
     Firefox's color override) would turn the back's center circle white over
     the number */
  forced-color-adjust: none;
}
.mine .card, .pile .card { width: 68px; height: 96px; }
/* wide hands (SET-5) shrink to fit a 360px screen */
@media (max-width: 480px) {
  .slots.wide .card { width: 40px; height: 57px; }
  .mine .slots.wide { gap: 6px; }
  .mine .slots.wide .card { width: 50px; height: 71px; }
}
.card svg { width: 100%; height: 100%; display: block; }
.card.empty { border: 2px dashed rgba(255,255,255,.25); border-radius: 7px; }
.card.sel { outline: 3px solid var(--select); outline-offset: 2px; }
.card.peeked { outline: 3px solid #8fd3ff; outline-offset: 2px; }
/* a sent match waiting for its window to settle */
.card.claiming { outline: 3px dashed var(--select); outline-offset: 2px; animation: claiming .5s ease-in-out infinite alternate; }
@keyframes claiming { to { outline-offset: 5px; } }
.card .lock {
  position: absolute; top: -6px; right: -6px; background: var(--accent); color: #fff;
  font-size: 10px; border-radius: 6px; padding: 1px 4px;
}
/* slot numbers (UI-31): centered on a back or an empty slot, a tab above a face */
.card .slot-no {
  position: absolute; top: -7px; left: 50%; transform: translateX(-50%); z-index: 1;
  min-width: 16px; padding: 0 4px; border-radius: 6px; pointer-events: none;
  background: var(--ink); color: var(--bg); font-size: 11px; font-weight: 700; line-height: 15px; text-align: center;
}
.card.down .slot-no, .card.empty .slot-no {
  top: 50%; transform: translate(-50%, -50%); min-width: 0; padding: 0;
  background: none; color: #fff; font-size: 18px; line-height: 1;
}
.card.empty .slot-no { color: rgba(255,255,255,.35); }
/* emptied by a right match, waiting for the matcher's card (RULE-19) */
.card.empty.owed {
  border-color: transparent; outline: 3px dashed var(--select); outline-offset: 2px;
  animation: claiming .5s ease-in-out infinite alternate;
}
.card.empty.owed .slot-no { color: var(--select); }
button.card:not(:disabled):hover { transform: translateY(-2px); }
button.card:disabled { opacity: 1; cursor: default; }

/* the prompt and action buttons stick to the bottom of the screen while the
   table runs past it (UI-33) */
.actionbar {
  position: sticky; bottom: 0; z-index: 6;
  margin: 12px -16px 0; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line); box-shadow: 0 -6px 14px rgba(0,0,0,.12);
}
.prompt { text-align: center; font-weight: 600; margin: 0 0 8px; }
.prompt:empty { display: none; }
.prompt.owe { color: var(--accent); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 0; }
.controls .move-peek_own { background: #2f6fd6; border-color: #2f6fd6; }
.controls .move-peek_other { background: #e07a1f; border-color: #e07a1f; }
.controls .move-blind_swap { background: #7b4bc9; border-color: #7b4bc9; }
.controls .move-look_swap { background: #d0393b; border-color: #d0393b; }
.controls .komino-btn {
  font-weight: 800; letter-spacing: .08em; background: var(--accent); color: #fff; border-color: var(--accent);
  padding: 10px 22px;
}
/* the confirm dialog sits in the middle of the screen over the table */
.confirm-backdrop {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(0,0,0,.45);
}
.confirm {
  width: min(420px, 100%);
  background: var(--panel); border: 3px solid var(--select); border-radius: 16px;
  padding: 20px; box-shadow: 0 12px 40px rgba(0,0,0,.4);
}
.confirm p { margin: 0 0 18px; font-size: 19px; font-weight: 600; text-align: center; }
.confirm-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.confirm-buttons button { min-height: 52px; font-size: 18px; font-weight: 600; }
/* the rules guide (UI-34) */
.guide-btn { margin-left: auto; }
.modal {
  width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 18px 20px; box-shadow: 0 12px 40px rgba(0,0,0,.4);
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.modal-head h2 { margin: 0; font-size: 20px; }
.guide-room { font-size: 12px; color: var(--muted); }
.guide h3 { margin: 16px 0 4px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.guide p, .guide ul, .guide ol { margin: 4px 0; }
.guide ul, .guide ol { padding-left: 20px; }
.guide .guide-moves { list-style: none; padding: 0; display: grid; gap: 8px; margin: 8px 0; }
.guide-moves li { display: flex; gap: 10px; align-items: center; }
.guide-cards { display: flex; gap: 4px; flex: none; }
.guide-cards .card { width: 34px; height: 48px; }
.columns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .columns { grid-template-columns: 1fr; gap: 0; } }
.members { list-style: none; margin: 0; padding: 0; }
.members li { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.members .tag { font-size: 11px; color: var(--muted); }
.members button { margin-left: auto; }
.log { margin: 0; padding-left: 18px; max-height: 220px; overflow: auto; font-size: 13px; }
.scroll { overflow-x: auto; }
.stats { border-collapse: collapse; width: 100%; font-size: 13px; }
.stats th, .stats td { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.stats th:first-child, .stats td:first-child { text-align: left; }
.toast {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 8px; z-index: 20;
  max-width: calc(100% - 32px);
}
.score { font-weight: 700; }
.won { color: var(--select); }

/* action effects (UI-24 - UI-26) */
.table-wrap { position: relative; }
.caption {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 5;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  width: max-content; max-width: calc(100% - 24px); pointer-events: none;
}
.caption div {
  background: rgba(0,0,0,.78); color: #fff; padding: 6px 14px; border-radius: 999px;
  font-size: 14px; font-weight: 600; text-align: center; animation: caption-in .2s ease-out;
}
.caption div.about-you { background: var(--accent); box-shadow: 0 0 0 3px var(--select); }
@keyframes caption-in { from { opacity: 0; transform: translateY(-8px); } }

.fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 8; }
.ghost {
  position: fixed; animation: fly .7s cubic-bezier(.3,.7,.3,1) both;
  filter: drop-shadow(0 8px 10px rgba(0,0,0,.45));
}
.ghost svg { width: 100%; height: 100%; display: block; }
@keyframes fly {
  from { transform: translate(var(--dx), var(--dy)); }
  45% { transform: translate(calc(var(--dx) * .5), calc(var(--dy) * .5 - 28px)) scale(1.15); }
  85% { transform: none; opacity: 1; }
  to { transform: none; opacity: 0; }
}

.card.fx-flip { animation: fx-flip .5s ease-out; }
@keyframes fx-flip { from { transform: perspective(400px) rotateY(90deg); } }
.card.fx-peek { animation: fx-peek 1.3s ease-in-out; transform-origin: 50% 100%; }
@keyframes fx-peek {
  25%, 70% { transform: perspective(300px) translateY(-10px) rotateX(35deg); box-shadow: 0 0 0 4px #8fd3ff; }
}
.card.fx-swap { animation: fx-swap 1s ease-in-out; }
@keyframes fx-swap {
  30% { transform: scale(1.18); box-shadow: 0 0 0 4px #c9a4ff; }
  60% { transform: scale(.94); box-shadow: 0 0 0 4px #c9a4ff; }
}
.card.fx-pulse, .card.fx-land { animation: fx-pulse .6s ease-out; }
@keyframes fx-pulse { 40% { transform: scale(1.12); box-shadow: 0 0 0 4px var(--select); } }
.card.fx-miss { animation: fx-miss .5s; }
@keyframes fx-miss {
  20%, 60% { transform: translateX(-6px); box-shadow: 0 0 0 4px var(--accent); }
  40%, 80% { transform: translateX(6px); box-shadow: 0 0 0 4px var(--accent); }
}
.status.fx-flash { animation: fx-flash 1.4s ease-out; border-radius: 8px; }
@keyframes fx-flash { 0%, 40% { background: var(--accent); color: #fff; } }
.eye-badge {
  position: absolute; bottom: -7px; left: 50%; transform: translateX(-50%);
  width: 30px; height: 16px; background: #fff; border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,.4); animation: blink 1.6s ease-in-out infinite;
}
.eye-badge svg { width: 100%; height: 100%; display: block; }
@keyframes blink { 50% { transform: translateX(-50%) scale(1.15); } }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* a color per seat (UI-36): hands, log lines, captions, and flying cards */
.chip { width: 10px; height: 10px; border-radius: 3px; background: var(--seat, #999); display: inline-block; flex: none; }
.hand .who { border-bottom: 3px solid var(--seat, transparent); padding-bottom: 2px; }
.log li.by::marker { color: var(--seat); }
.log li.by { border-left: 3px solid var(--seat); padding-left: 6px; margin-bottom: 2px; }
.caption div { border-left: 6px solid var(--seat, transparent); }
.ghost { border-radius: 7px; box-shadow: 0 0 0 3px var(--seat, transparent); }
.members .chip { margin-right: -2px; }
.bots { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.bots select { padding: 3px 8px; font-size: 13px; }
.total { font-size: 11px; opacity: .8; font-variant-numeric: tabular-nums; }

/* other players around the table on a wide screen, stacked on a narrow one */
.side { display: contents; }
@media (min-width: 900px) {
  .table {
    display: grid; grid-template-columns: auto 1fr auto; align-items: center;
    grid-template-areas: "left top right" "left center right" "left mine right";
  }
  .opponents { display: contents; }
  .side { display: flex; gap: 10px; justify-content: center; align-items: center; }
  .side.left { grid-area: left; flex-direction: column-reverse; }
  .side.top { grid-area: top; flex-wrap: wrap; }
  .side.right { grid-area: right; flex-direction: column; }
  .side:empty { display: none; }
  .table > .center { grid-area: center; }
  .table > .hand.mine { grid-area: mine; justify-self: center; }
}
.center { flex-direction: column; gap: 8px; }
.piles { display: flex; gap: 18px; justify-content: center; align-items: center; }

/* the newest discards beneath the top card (RULE-28) */
.recent { display: flex; gap: 3px; align-items: center; font-size: 11px; opacity: .85; flex-wrap: wrap; justify-content: center; }
.recent > span:first-child { margin-right: 4px; }
.card.mini { width: 22px; height: 31px; }

/* a matchable discard glows, fading as it ages (UI-41) */
#discard.live { animation: glow 6s linear forwards; }
@keyframes glow {
  from { box-shadow: 0 0 0 4px var(--select), 0 0 22px 6px var(--select); }
  to { box-shadow: 0 0 0 0 transparent; }
}

/* memory marks (SET-17) */
.card .mark {
  position: absolute; bottom: -6px; right: -6px; z-index: 2; pointer-events: none;
  background: #fff3c4; color: #1f1d1a; border: 1px solid #c9a227; border-radius: 6px;
  font-size: 11px; font-weight: 700; padding: 0 4px; line-height: 15px;
}
.mark-values { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 0 0 14px; }
.mark-values button { min-height: 44px; font-weight: 700; }

/* first game tips (UI-37) */
.tip {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center;
  margin: 0 0 8px; padding: 8px 10px; border-radius: 10px;
  background: var(--panel); border: 1px dashed var(--select); font-size: 14px; text-align: center;
}
.tip-buttons { display: flex; gap: 6px; }

/* the end of a game (UI-38) */
.summary .match-result { font-weight: 700; margin: 0 0 8px; }
.summary td .chip { margin-right: 6px; vertical-align: middle; }
.chart { margin: 12px 0 0; color: var(--muted); }
.chart svg { width: 100%; max-width: 480px; height: auto; display: block; }
.chart figcaption { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; }
.chart figcaption > span { display: inline-flex; gap: 4px; align-items: center; }
kbd {
  font: 12px ui-monospace, monospace; padding: 0 4px; border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 4px; background: var(--bg);
}

@media (prefers-reduced-motion: reduce) {
  .card[class*="fx-"], .status.fx-flash { animation: none; outline: 3px solid var(--select); outline-offset: 2px; }
  .ghost { display: none; }
  .caption div, .eye-badge, .card.claiming, .card.empty.owed { animation: none; }
  #discard.live { animation: none; box-shadow: 0 0 0 4px var(--select); }
}
