/* Poker table theme for Refine-o-matic.
   Green felt, wooden rail header, cream playing cards with corner indices,
   red card backs, poker-chip initials and gold accents. Dark mode = late-night table. */

:root {
  --felt: #1f6b45;
  --felt-light: #2a8457;
  --felt-dark: #154d31;
  --wood: #4a2c17;
  --wood-dark: #2f1b0e;
  --gold: #e8c46b;
  --gold-dark: #c9a248;
  --text: #f7f1e1;
  --text-muted: rgba(247, 241, 225, .78);
  --panel: rgba(0, 0, 0, .2);
  --panel-border: rgba(232, 196, 107, .35);
  --card-bg: #fbf7ec;
  --card-ink: #1b1b1b;
  --card-red: #b8202f;
  --back-a: #b8202f;
  --back-b: #d84a57;
  --ok: #a8f0a0;
  --error: #ffc2b8;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-serif: Georgia, "Times New Roman", "Noto Serif", serif;
  color-scheme: dark; /* felt is dark in both modes: keep native controls readable */
}
:root[data-theme="dark"] {
  --felt: #0f3a26;
  --felt-light: #155034;
  --felt-dark: #08241a;
  --wood: #241309;
  --wood-dark: #160b05;
  --gold: #d4b05a;
  --gold-dark: #a8873c;
  --text: #e9e2cf;
  --text-muted: rgba(233, 226, 207, .7);
  --panel: rgba(0, 0, 0, .32);
  --panel-border: rgba(212, 176, 90, .28);
  --card-bg: #e6dfcc;
  --back-a: #8e1824;
  --back-b: #a83542;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--felt-dark); }
body {
  margin: 0; min-height: 100dvh;
  font: 400 1.0625rem/1.5 var(--font);
  color: var(--text);
  background: radial-gradient(ellipse 120% 80% at 50% 25%, var(--felt-light), var(--felt) 55%, var(--felt-dark));
  background-attachment: fixed;
}
button, input { font: inherit; color: inherit; }
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px dashed var(--gold); outline-offset: 3px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.container {
  max-width: 60rem; margin: 0 auto;
  padding: 0 max(1.5rem, env(safe-area-inset-right)) 2rem max(1.5rem, env(safe-area-inset-left));
}

/* ---------- Header: the wooden rail ---------- */
.site-header {
  position: sticky; top: 0; z-index: 10;
  padding-top: env(safe-area-inset-top);
  background: linear-gradient(var(--wood), var(--wood-dark));
  border-bottom: 3px solid var(--gold-dark);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .35);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 3.5rem; }
.brand {
  font: 700 1.25rem/1.2 var(--font-serif); color: var(--gold);
  text-decoration: none; white-space: nowrap;
}
.brand::before { content: "\2660"; margin-right: .4rem; } /* ♠ */
.header-actions { display: flex; align-items: center; gap: .125rem; min-width: 0; }

.nav-session {
  display: flex; flex-direction: column; min-width: 0; line-height: 1.2;
  padding-right: .75rem; margin-right: .375rem; border-right: 1px solid rgba(232, 196, 107, .3);
}
.nav-session-label { font-size: .6875rem; color: var(--gold); text-transform: uppercase; letter-spacing: .08em; }
.nav-session-name {
  font-weight: 700; font-size: .9375rem; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 16rem;
}

.icon-button {
  display: inline-grid; place-items: center; flex: none;
  width: 2.75rem; height: 2.75rem; padding: 0;
  background: transparent; color: var(--text); border: 0; border-radius: 50%;
  transition: color .2s ease, background-color .2s ease, transform .15s ease;
}
.icon-button svg {
  width: 1.375rem; height: 1.375rem;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.icon-button svg .dot { fill: currentColor; stroke: none; }
@media (hover: hover) { .icon-button:hover { color: var(--gold); background: rgba(232, 196, 107, .12); } }
.icon-button:active { transform: scale(.92); }
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }

/* ---------- Headings ---------- */
h1 {
  font: 700 2rem/1.2 var(--font-serif); letter-spacing: -.01em;
  margin: 2rem 0 .75rem; overflow-wrap: anywhere;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .3);
}
h2 {
  font: 700 .875rem/1.3 var(--font); color: var(--gold);
  text-transform: uppercase; letter-spacing: .1em;
  margin: 1.5rem 0 .5rem;
}
.lead { font-size: 1.125rem; color: var(--text-muted); margin: 0 0 1.5rem; max-width: 40rem; }
.progress { color: var(--text-muted); margin: 0; font-size: 1rem; }

/* ---------- Join form ---------- */
.panel {
  max-width: 32rem; padding: 1.5rem;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px;
}
.field { margin: 0 0 1.25rem; }
label { display: block; font-weight: 700; margin-bottom: .375rem; }
input {
  display: block; width: 100%; padding: .75rem 1rem;
  background: var(--card-bg); color: var(--card-ink);
  border: 0; border-radius: 8px; box-shadow: inset 0 2px 4px rgba(0, 0, 0, .15);
  font-size: 1.0625rem; /* >= 16px: no iOS zoom */
}
input:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- Buttons: gold chips ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 2.875rem; padding: .625rem 1.5rem;
  border: 2px solid var(--gold); border-radius: 999px;
  font-weight: 700; letter-spacing: .02em;
  transition: transform .15s ease, filter .2s ease, background-color .2s ease;
}
.btn-primary {
  background: linear-gradient(var(--gold), var(--gold-dark)); color: #2b1a08;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .3);
}
.btn-secondary { background: transparent; color: var(--gold); }
@media (hover: hover) {
  .btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
  .btn-secondary:hover:not(:disabled) { background: rgba(232, 196, 107, .12); }
}
.btn:active:not(:disabled) { transform: translateY(1px) scale(.98); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-top: 1rem; max-width: 32rem; }

.error { color: var(--error); font-weight: 700; margin: 0; }
.error:not(:empty) { margin: .5rem 0; }

/* ---------- Team: seats around the table ---------- */
.people {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: .5rem;
}
.person {
  display: flex; align-items: center; gap: .625rem;
  min-height: 3rem; padding: .375rem .5rem;
  background: var(--panel); border: 1px solid transparent; border-radius: 10px;
  transition: border-color .2s ease, opacity .2s ease;
}
.person.voted { border-color: var(--panel-border); }
.person.offline { opacity: .5; }
.person .status { display: none; }

/* Initials as a poker chip */
.avatar {
  width: 2rem; height: 2rem; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  font: 700 .75rem var(--font); color: #fff; letter-spacing: 0;
  border: 3px dashed rgba(255, 255, 255, .85);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .25), 0 2px 3px rgba(0, 0, 0, .3);
}
.avatar-0 { background: #b8202f; } .avatar-1 { background: #1f4e9c; } .avatar-2 { background: #222; }
.avatar-3 { background: #2e7d32; } .avatar-4 { background: #6a3d9a; } .avatar-5 { background: #c76a12; }

.who { flex: 1; min-width: 0; }
.person-name {
  display: block; font-weight: 700; font-size: 1rem; line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.person-name .you { font-weight: 400; color: var(--text-muted); }

/* Mini card flips over on reveal */
.mini { width: 1.75rem; height: 2.375rem; flex: none; perspective: 300px; }
.mini-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d; transition: transform .5s cubic-bezier(.2, .9, .25, 1);
}
.mini.revealed .mini-inner { transform: rotateY(180deg); }
.mini-face {
  position: absolute; inset: 0; border-radius: 4px;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: grid; place-items: center;
  font: 700 .9375rem var(--font-serif);
}
.mini-back { border: 1.5px dashed rgba(247, 241, 225, .45); }
.mini.voted .mini-back {
  border: 2px solid var(--card-bg);
  background: repeating-linear-gradient(45deg, var(--back-a) 0 3px, var(--back-b) 3px 6px);
  background-size: 8.485px 8.485px; /* one stripe period, so the drift loops seamlessly */
  animation: back-drift 1.4s linear infinite;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
}
.mini-front {
  transform: rotateY(180deg);
  background: var(--card-bg); color: var(--card-ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
}

/* ---------- Result: "the pot" ---------- */
.summary {
  display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.5rem;
  margin: .75rem 0 0; padding: 1rem 1.25rem;
  background: rgba(0, 0, 0, .45);
  border: 2px solid var(--gold); border-radius: 14px;
  box-shadow: inset 0 0 0 4px rgba(0, 0, 0, .25), 0 0 0 1px rgba(0, 0, 0, .3), 0 10px 24px rgba(0, 0, 0, .35);
  animation: pot-in .4s cubic-bezier(.2, .9, .25, 1);
}
.summary:not(.shown) { display: none; }
@keyframes pot-in { from { opacity: 0; transform: scale(.96); } }
.summary-main { display: flex; flex-direction: column; }
.summary-label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; color: var(--gold); }
.summary .big {
  font: 700 3.5rem/1 var(--font-serif); color: var(--gold);
  text-shadow: 0 2px 8px rgba(0, 0, 0, .4); font-variant-numeric: tabular-nums;
}
.summary-side { display: flex; flex-direction: column; gap: .5rem; flex: 1 1 12rem; min-width: 0; }
.summary .meta { color: var(--text); font-weight: 700; }

/* Votes per card: bars (motion.css), the most-voted one in gold */
.summary { --bar-top: var(--gold); }
.bar-v { font: 700 1.0625rem var(--font-serif); color: var(--gold); }

/* Consensus: a gold plaque */
.summary.is-consensus {
  background: linear-gradient(var(--gold), var(--gold-dark)); color: #2b1a08; border-color: #fff3c4;
  --bar-top: currentColor;
}
.summary.is-consensus .bar-v { color: #2b1a08; }
.summary.is-consensus .summary-label,
.summary.is-consensus .big,
.summary.is-consensus .meta { color: #2b1a08; text-shadow: none; }

/* Lowest / highest estimate in the team list */
.person .tag:empty { display: none; }
.person .tag {
  display: block; margin-top: .125rem;
  font-size: .6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--gold);
}
.person.extreme { border-color: var(--gold); background: rgba(0, 0, 0, .32); }

/* Cards can't be picked after reveal: hide the hand so the result gets the space */
#room-view.is-revealed .tray { display: none; }

/* ---------- Your hand: playing cards ---------- */
.deck {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem;
  max-width: 32rem; padding-top: 8px;
}
.card {
  position: relative; aspect-ratio: 5 / 7; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--card-bg); color: var(--card-ink);
  border: 0; border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .35), inset 0 0 0 1px rgba(0, 0, 0, .08);
  font: 700 1.625rem var(--font-serif);
  user-select: none; -webkit-user-select: none;
  transition: transform .2s cubic-bezier(.2, .9, .25, 1), box-shadow .2s ease, rotate .3s ease-out;
}
@keyframes back-drift { to { background-position: 8.485px 0; } }
/* Corner indices, like a real card */
.card::before, .card::after {
  content: attr(data-value);
  position: absolute; font: 700 .6875rem/1 var(--font-serif);
}
.card::before { top: .3rem; left: .35rem; }
.card::after { bottom: .3rem; right: .35rem; transform: rotate(180deg); }
.card[data-value="1"], .card[data-value="3"], .card[data-value="8"], .card[data-value="21"] { color: var(--card-red); }

@media (hover: hover) {
  .card:hover:not(:disabled) { transform: translateY(-3px); box-shadow: 0 6px 12px rgba(0, 0, 0, .35); }
}
.card:active:not(:disabled) { transform: scale(.95); transition-duration: .06s; }
.card[aria-pressed="true"] {
  transform: translateY(-8px);
  box-shadow: 0 0 0 3px var(--gold), 0 10px 18px rgba(0, 0, 0, .45);
}
.card:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ---------- Wide screens: seats left, hand right ---------- */
@media (min-width: 56rem) {
  #room-view:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(20rem, 26rem);
    /* right column ("side") holds the hand, or the result once revealed */
    grid-template-areas:
      "title    title"
      "progress side"
      "meter    side"
      "label    side"
      "team     side"
      "actions  side"
      "error    side"
      "note     side";
    grid-template-rows: auto auto auto auto auto auto auto 1fr;
    column-gap: 2rem; align-items: start;
  }
  #room-title { grid-area: title; }
  #room-view .progress { grid-area: progress; }
  #room-view .meter { grid-area: meter; }
  #room-view .section-title { grid-area: label; }
  #room-view .people { grid-area: team; }
  #room-view .actions { grid-area: actions; }
  #room-error { grid-area: error; }
  #observer-note { grid-area: note; }
  #room-view .tray, #room-view .summary { grid-area: side; }
  #room-view .summary { margin-top: 1.5rem; flex-direction: column; align-items: flex-start; }
  #room-view .summary-side { flex: none; width: 100%; }
}

/* ---------- Phones: everything on one screen ---------- */
@media (max-width: 40rem) {
  .container { padding-left: max(.75rem, env(safe-area-inset-left)); padding-right: max(.75rem, env(safe-area-inset-right)); padding-bottom: 1rem; }
  .header-inner { gap: .5rem; min-height: 3.25rem; }
  .brand { font-size: 1.0625rem; }
  .header-actions { gap: 0; }
  .nav-session { padding-right: .5rem; margin-right: .25rem; }
  .nav-session-name { max-width: 7rem; }
  h1 { font-size: 1.625rem; margin-top: 1.25rem; }
  #room-title { display: none; } /* the session name is in the header */
  .progress { margin-top: .75rem; }
  h2 { margin: 1rem 0 .375rem; }
  .panel { padding: 1rem; }
  .people { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .375rem; }
  .person { min-height: 2.75rem; padding: .25rem .375rem; gap: .5rem; }
  .avatar { width: 1.75rem; height: 1.75rem; font-size: .6875rem; border-width: 2px; }
  .person-name { font-size: .9375rem; }
  .actions { max-width: none; }
  .deck { max-width: none; gap: .375rem; }
  .card { aspect-ratio: 4 / 5; font-size: 1.5rem; }
}

/* Clock (shared.css): gold serif digits on the wooden rail */
:root .clock { font-family: var(--font-serif); font-size: 1.125rem; color: var(--gold); }

/* Motion colours (motion.css) */
:root {
  --motion-accent: var(--gold);
  --motion-ok: #3fbf5a;
  --motion-track: rgba(0, 0, 0, .3);
  --motion-muted: var(--text-muted);
  --motion-confetti: var(--back-a);
  --motion-radius: 999px;
  --switch-off: rgba(0, 0, 0, .35);
}
.meter { margin-top: .5rem; }

/* Theme menu (menu.css): a wooden tray */
:root {
  --menu-bg: var(--wood-dark);
  --menu-fg: var(--text);
  --menu-border: var(--gold-dark);
  --menu-hover: rgba(232, 196, 107, .15);
  --menu-accent: var(--gold);
  --menu-radius: 12px;
  --menu-item-radius: 8px;
  --menu-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; transition-delay: 0ms !important; }
  .mini-inner, .mini.revealed .mini-inner { transform: none; }
  .mini-front { transform: none; opacity: 0; }
  .mini.revealed .mini-back { opacity: 0; }
  .mini.revealed .mini-front { opacity: 1; }
  .card[aria-pressed="true"] { transform: none; }
  .summary { animation: none; }
}
@media (prefers-contrast: more) {
  :root { --text-muted: var(--text); --panel: rgba(0, 0, 0, .45); }
  .person, .panel, .summary { border: 1px solid var(--gold); }
}
