:root {
  --bg: #05061a;
  --panel: #0d1033;
  --line: #262b6b;
  --text: #e6e8ff;
  --muted: #9aa0d6;
  --red: #e0453a;
  --green: #46c46a;
  --orange: #f08a24;
  --blue: #4f7dff;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 0%, #111556 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}
.beam {
  width: 26px; height: 3px; border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--red) 40%, #ffd1cc);
  box-shadow: 0 0 8px var(--red);
}
#turn {
  flex: 1;
  text-align: center;
  font-weight: 600;
  letter-spacing: 0.04em;
  min-height: 1.5em;
}
#turn.red, #turn.mine.red { color: var(--red); }
#turn.green, #turn.mine.green { color: var(--green); }
#turn.theirs { color: var(--muted); }
#turn.wait { color: var(--orange); }
.actions { display: flex; gap: 14px; }
.link {
  background: none; border: 0; padding: 4px 0;
  color: var(--muted); text-decoration: underline; text-underline-offset: 3px;
}
.link:hover { color: var(--text); }
body[data-screen="menu"] #new-game, body[data-screen="menu"] header [data-rules] { visibility: hidden; }

#stage {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  min-height: 0;
}
#view {
  display: block;
  border-radius: 10px;
  background: #000;
  box-shadow: 0 0 0 1px var(--line), 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 80px rgba(79, 125, 255, 0.12);
  touch-action: none;
  cursor: crosshair;
}
body[data-screen="menu"] #view, body[data-screen="loading"] #view { visibility: hidden; }

.panel {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(560px, calc(100% - 32px));
  height: fit-content;
  max-height: calc(100% - 24px);
  overflow: auto;
  background: rgba(13, 16, 51, 0.96);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
.panel h2 { margin: 0 0 8px; font-size: 26px; letter-spacing: 0.12em; text-transform: uppercase; }
.lede { color: var(--muted); margin: 0 auto 22px; max-width: 42ch; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.choices button, .share-row button {
  border: 1px solid var(--line);
  background: #161a4a;
  border-radius: 10px;
  padding: 14px 12px;
  font-weight: 600;
  font-size: 16px;
}
.choices button small { display: block; font-weight: 400; font-size: 13px; color: var(--muted); margin-top: 4px; }
.primary { background: linear-gradient(180deg, #e0453a, #b52f27) !important; border-color: #ff7a6e !important; }
.primary small { color: #ffd9d4 !important; }
.choices button:hover, .share-row button:hover { filter: brightness(1.15); }

.share-row { display: flex; gap: 8px; margin: 14px 0; }
.share-row input {
  flex: 1; min-width: 0;
  background: #070920; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font: 14px ui-monospace, Consolas, monospace;
}
.share-row button { padding: 10px 16px; white-space: nowrap; }
.code { color: var(--muted); }
.code strong { color: var(--text); letter-spacing: 0.2em; font-family: ui-monospace, Consolas, monospace; }
#seat { font-weight: 600; }

.spinner {
  width: 42px; height: 42px; margin: 0 auto 12px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--red);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#banner {
  position: absolute;
  left: 50%; bottom: 18px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: #2b2f6e;
  border: 1px solid #4b51a8;
  border-radius: 10px;
  padding: 8px 14px;
  text-align: center;
}
#banner.bad { background: #5a1d1d; border-color: #a33; }

#touchbar { display: none; justify-content: center; padding: 0 16px 10px; }
body.touch:not([data-screen="menu"]) #touchbar { display: flex; }
#touchbar button {
  border: 1px solid var(--line);
  background: #161a4a;
  border-radius: 999px;
  padding: 12px 28px;
  font-weight: 600;
  font-size: 16px;
}

#rules {
  position: fixed; inset: 0;
  background: rgba(3, 4, 16, 0.75);
  display: flex; justify-content: center; align-items: flex-start;
  overflow: auto;
  padding: 24px 16px;
  z-index: 10;
}
#rules[hidden] { display: none; }
.rules-inner {
  position: relative;
  max-width: 680px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px 28px;
}
.rules-inner h2 { margin-top: 0; letter-spacing: 0.1em; text-transform: uppercase; }
.rules-inner h3 { margin: 20px 0 6px; color: var(--orange); font-size: 15px; letter-spacing: 0.08em; text-transform: uppercase; }
.rules-inner ul { padding-left: 20px; }
.rules-inner li { margin: 4px 0; }
.rules-inner dt { font-weight: 700; margin-top: 8px; }
.rules-inner dd { margin: 0 0 0 0; color: #c8cbf2; }
.close { position: absolute; top: 18px; right: 22px; }

footer {
  padding: 8px 16px 14px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
footer p { margin: 2px 0; }
footer a { color: var(--muted); }

@media (max-width: 560px) {
  header { gap: 8px; }
  h1 { font-size: 16px; }
  #turn { order: 3; flex-basis: 100%; }
  .choices { grid-template-columns: 1fr; }
  .panel { padding: 20px; }
  #stage { padding: 8px; }
}
