/* Turing Circles: paper and ink, one green accent (the rin.games look). */
@font-face { font-family: 'Instrument Sans'; font-weight: 400; font-style: normal; font-display: swap; src: url('./fonts/instrument-sans-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Instrument Sans'; font-weight: 500; font-style: normal; font-display: swap; src: url('./fonts/instrument-sans-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Instrument Sans'; font-weight: 600; font-style: normal; font-display: swap; src: url('./fonts/instrument-sans-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Instrument Serif'; font-weight: 400; font-style: normal; font-display: swap; src: url('./fonts/instrument-serif-latin-400-normal.woff2') format('woff2'); }

:root {
  color-scheme: light dark;
  --paper: #f6f6f3; --card: #ffffff; --ink: #16161a; --muted: #5f6068;
  --line: #e3e2dc; --line-strong: #cfcec7; --accent: #2e6b57; --accent-soft: #e3efe9; --danger: #b42318;
  --on-accent: #ffffff;
  /* six seat colors (orange, sky, green, blue, pink, gray): distinct by hue and by lightness */
  --s0: #d98f00; --s1: #4aa8e0; --s2: #009e73; --s3: #0072b2; --s4: #c26a9b; --s5: #5b6170;
  --t0: #16161a; --t1: #16161a; --t2: #16161a; --t3: #ffffff; --t4: #16161a; --t5: #ffffff;
  --sp1: 4px; --sp2: 8px; --sp3: 12px; --sp4: 16px; --sp5: 24px; --sp6: 32px; --sp7: 48px; --sp8: 64px;
  --r-control: 6px; --r-card: 10px;
  --sans: 'Instrument Sans', 'Segoe UI', Roboto, system-ui, sans-serif;
  --serif: 'Instrument Serif', Georgia, 'Times New Roman', serif;
  --panel-h: 280px; /* a phone; a larger screen sets 320px */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #131316; --card: #1c1c21; --ink: #ecebe6; --muted: #a6a6ae;
    --line: #2e2e35; --line-strong: #3d3d45; --accent: #8fd3b8; --accent-soft: #1e3029; --danger: #ff8b7b;
    --on-accent: #131316;
    --s0: #f0a820; --s1: #6cc3f2; --s2: #1fb98a; --s3: #4a8fe0; --s4: #de8dba; --s5: #b4b8c4;
    --t0: #111114; --t1: #111114; --t2: #111114; --t3: #111114; --t4: #111114; --t5: #111114;
  }
}
:root[data-theme="dark"] {
  --paper: #131316; --card: #1c1c21; --ink: #ecebe6; --muted: #a6a6ae;
  --line: #2e2e35; --line-strong: #3d3d45; --accent: #8fd3b8; --accent-soft: #1e3029; --danger: #ff8b7b;
  --on-accent: #131316;
  --s0: #f0a820; --s1: #6cc3f2; --s2: #1fb98a; --s3: #4a8fe0; --s4: #de8dba; --s5: #b4b8c4;
  --t0: #111114; --t1: #111114; --t2: #111114; --t3: #111114; --t4: #111114; --t5: #111114;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 1.45;
  min-height: 100vh; min-height: 100dvh;
}
.serif, h1, h2 { font-family: var(--serif); font-weight: 400; margin: 0; }
p { margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
button, input { font: inherit; color: inherit; }

/* header */
.header {
  display: flex; align-items: center; gap: var(--sp3);
  max-width: 640px; margin: 0 auto; padding: var(--sp2) var(--sp4); min-height: 52px;
}
.title { font-size: 28px; line-height: 1.1; letter-spacing: -0.01em; }
.spacer { flex: 1; }
.status { font-size: 14px; color: var(--muted); }
.status::before {
  content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); margin-right: var(--sp2); animation: pulse 1.2s ease-in-out infinite;
}

.main { max-width: 640px; margin: 0 auto; padding: 0 var(--sp4) var(--sp4); }
.main > .card { max-width: 640px; margin: 0 auto; }

/* controls */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 var(--sp5); border-radius: var(--r-control);
  border: 1px solid var(--line-strong); background: var(--card); color: var(--ink);
  font-weight: 500; cursor: pointer; text-decoration: none; touch-action: manipulation;
}
.btn:hover:not(:disabled) { border-color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { border-color: var(--accent); filter: brightness(1.08); }
.btn.small { min-height: 36px; padding: 0 var(--sp3); font-size: 14px; }
.btn.icon { min-width: 44px; padding: 0; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.chosen:disabled { opacity: 1; background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.btn:focus-visible, .field:focus-visible, .seat:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.field {
  width: 100%; min-height: 44px; padding: 0 var(--sp3); border-radius: var(--r-control);
  border: 1px solid var(--line-strong); background: var(--card); color: var(--ink);
}
.field:focus { border-color: var(--accent); }
.field.shake, .field.shake:focus { border-color: var(--danger); }
.word-field { font-size: 22px; min-height: 56px; text-align: center; }
.row { display: flex; gap: var(--sp3); flex-wrap: wrap; }
.muted { color: var(--muted); }
.lead { font-size: 18px; }

/* cards and plain screens */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card);
  padding: var(--sp6) var(--sp5); min-height: 280px;
  display: flex; flex-direction: column; gap: var(--sp5);
}
.card.center { align-items: center; justify-content: center; text-align: center; }
.card h2 { font-size: 32px; }
.count { font-family: var(--serif); font-size: 56px; line-height: 1; }
.scores { display: flex; gap: var(--sp6); margin: 0; justify-content: center; }
.scores div { display: flex; flex-direction: column-reverse; align-items: center; gap: var(--sp1); }
.scores dt { font-size: 14px; color: var(--muted); }
.scores dd { margin: 0; font-family: var(--serif); font-size: 48px; line-height: 1; }
.scores.small dd { font-size: 32px; }

/* quiet waiting animation */
.dots { display: inline-flex; gap: var(--sp2); height: 10px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: 0.35; animation: dot 1.2s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@keyframes pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

/* game */
.game { display: flex; flex-direction: column; gap: var(--sp2); }
.role { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp3); min-height: 28px; flex-wrap: wrap; }
.role-line { font-family: var(--serif); font-size: 24px; line-height: 1.2; }
.theme-line { color: var(--muted); font-size: 15px; }
.theme-line strong { color: var(--ink); font-weight: 600; font-size: 17px; }

.stage { display: grid; grid-template-columns: 1fr; gap: var(--sp3); justify-items: center; }
.circle {
  position: relative; width: min(100%, 360px, max(240px, calc(100vh - 500px))); aspect-ratio: 1; container-type: inline-size;
  margin: 0;
}
@supports (height: 100svh) { .circle { width: min(100%, 360px, max(240px, calc(100svh - 500px))); } }
.seat {
  position: absolute; width: 22%; aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 50%; border: 0; padding: 0; cursor: default;
  background: var(--sc); color: var(--st);
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.18);
  transition: opacity 0.15s;
}
.seat:disabled { color: var(--st); opacity: 1; }
.seat.can { cursor: pointer; }
.seat.can:hover { box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.18), 0 0 0 3px var(--line-strong); }
.seat.dim { opacity: 0.4; }
.seat.sel { outline: 4px solid var(--ink); outline-offset: 3px; }
.word {
  max-width: 88%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 600; font-size: clamp(11px, 4cqw, 18px); pointer-events: none;
}
.word.pop { animation: pop 0.35s ease-out; }
@keyframes pop { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: none; } }

.ring-svg { position: absolute; inset: -9%; width: 118%; height: 118%; pointer-events: none; overflow: visible; display: none; }
.seat.active .ring-svg { display: block; }
.ring-track, .ring { fill: none; stroke-width: 4; }
.ring-track { stroke: var(--line-strong); }
.ring { stroke: var(--ink); stroke-linecap: round; }

.pill {
  position: absolute; left: 50%; transform: translateX(-50%);
  padding: 1px var(--sp2); border-radius: 999px; font-size: 11px; font-weight: 600; line-height: 1.5;
  white-space: nowrap; pointer-events: none;
  background: var(--ink); color: var(--paper);
}
.you-pill { top: -9px; }
.tag-pill { bottom: -9px; background: var(--card); color: var(--ink); border: 1px solid var(--ink); }

.mark { position: absolute; pointer-events: none; }
.m-ally { top: -5px; left: -5px; width: 22px; height: 22px; border-radius: 50%; background: var(--card); border: 2px solid var(--ink); }
.m-ally::before, .m-ally::after { content: ''; position: absolute; top: 5px; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--ink); }
.m-ally::before { left: 2px; }
.m-ally::after { left: 7px; }
.m-pick { bottom: 0; left: -4px; width: 14px; height: 14px; border-radius: 50%; background: var(--ac); border: 2px solid var(--ink); }
.m-lock { top: -5px; right: -5px; width: 22px; height: 22px; border-radius: 50%; background: var(--card); border: 2px solid var(--ink); }
.m-lock::before { content: ''; position: absolute; left: 4px; top: 9px; width: 10px; height: 7px; background: var(--ink); border-radius: 1px; }
.m-lock::after { content: ''; position: absolute; left: 6px; top: 3px; width: 6px; height: 6px; border: 2px solid var(--ink); border-bottom: 0; border-radius: 4px 4px 0 0; }

/* the story: under the circle on a phone */
.story {
  width: 100%; height: 64px; overflow-y: auto; padding: var(--sp2) var(--sp3);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card);
  font-family: var(--serif); font-size: 18px; line-height: 1.3;
}
.story .w, .story .w-lead { text-decoration: underline; text-decoration-color: var(--sc); text-decoration-thickness: 3px; text-underline-offset: 4px; }
.story .w.fresh, .story .w-lead.fresh { animation: fade 0.5s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* the panel: one fixed height, so nothing moves when it changes */
.panel {
  height: var(--panel-h); background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card);
  padding: var(--sp4); overflow: hidden;
}
.pane { height: 100%; display: flex; flex-direction: column; gap: var(--sp2); overflow: hidden; }
#p-quiet { align-items: center; justify-content: center; }
#p-turn { justify-content: center; }
#p-break, #p-resume { align-items: flex-start; }
#p-break .row { margin-top: var(--sp2); }
#p-break .dots { margin-top: var(--sp3); }
#p-resume { justify-content: center; }
#p-final h2, #p-break h2 { font-size: 26px; line-height: 1.1; }
#p-final { gap: 6px; }
#p-final h2 { font-size: 22px; }
#p-final .lead { font-size: 16px; line-height: 1.4; }
#fin-wait { min-height: 1.45em; font-size: 14px; }
#p-final .row { margin-top: auto; }
.chat-list {
  flex: 1; min-height: 56px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--r-control);
  padding: var(--sp2) var(--sp3); display: flex; flex-direction: column; gap: var(--sp1);
}
.msg { display: flex; gap: var(--sp2); align-items: baseline; font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
.msg-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--sc); transform: translateY(1px); }
.chat-row { display: flex; gap: var(--sp2); }
#p-over { align-items: flex-start; }
.result { font-family: var(--serif); font-size: 26px; line-height: 1.2; padding-left: var(--sp3); border-left: 4px solid var(--line-strong); }
.result.win { border-left-color: var(--accent); }
.result.defeat { border-left-color: var(--danger); }
#p-over .scores { margin-top: var(--sp2); justify-content: flex-start; }
#p-over .row { margin-top: auto; }

/* motion */
.shake { animation: shake 0.4s; border-color: var(--danger); }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition: none !important; }
  .dots i { opacity: 0.7; }
  .status::before { opacity: 1; }
}

/* a tablet or desktop: the story sits inside the circle, kept inside the seats' inner ring and out of the seats' way */
@media (min-width: 720px) {
  :root { --panel-h: 320px; --c: min(520px, max(340px, calc(100vh - 500px))); }
  .game { gap: var(--sp3); }
  .stage { grid-template-areas: 'stack'; }
  .circle, .story { grid-area: stack; }
  .circle { width: var(--c); margin: var(--sp3) 0; }
  .story {
    align-self: center; width: calc(0.4 * var(--c)); height: auto; max-height: calc(0.3 * var(--c)); min-height: 0;
    background: transparent; border: 0; padding: 0; text-align: center; z-index: 1; pointer-events: none;
    font-size: clamp(15px, calc(0.05 * var(--c)), 22px); line-height: 1.35;
  }
}
/* a wide desktop: the circle on the left, the panel beside it, so a laptop screen holds both */
@media (min-width: 900px) {
  :root { --c: min(520px, max(300px, calc(100vh - 190px))); }
  .header, .main { max-width: 960px; }
  .game { display: grid; grid-template-columns: minmax(0, 1fr) 340px; column-gap: var(--sp5); row-gap: var(--sp2); align-items: start; }
  .role { grid-column: 1 / -1; }
  .stage { grid-column: 1; grid-row: 2; }
  .panel { grid-column: 2; grid-row: 2; }
  .circle { margin: 0; }
}
@media (max-width: 400px) {
  .card { padding: var(--sp5) var(--sp4); }
  .count { font-size: 48px; }
  .title { font-size: 24px; }
}
