:root {
  color-scheme: light;
  --paper: #fffaf0;
  --stock: #f0e7d2;
  --ink: #211f1a;
  --muted: #6e675b;
  --rule: #2b2822;
  --accent: #e8442e;
  --accent-dark: #ae2d1d;
  --good: #18734b;
  --shadow: 5px 5px 0 var(--rule);
  font-family: "Avenir Next", Avenir, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--stock); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, rgba(255,255,255,.65), transparent 28%),
    linear-gradient(rgba(43,40,34,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(43,40,34,.04) 1px, transparent 1px),
    var(--stock);
  background-size: auto, 24px 24px, 24px 24px, auto;
}
button, input { font: inherit; }
button { touch-action: manipulation; }
.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; }
.playground-chrome { position: sticky; top: 0; z-index: 20; }
.connection {
  margin-left: auto;
  color: var(--muted);
  font-family: var(--pg-font-mono, ui-monospace, monospace);
  font-size: .72rem;
}
.connection::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: #8c8578; }
.connection[data-state="live"]::before { background: var(--good); }
.connection[data-state="connecting"]::before { background: #db8c1e; animation: pulse 1s infinite alternate; }

.app-shell { width: min(920px, calc(100% - 24px)); margin: 0 auto; padding: 18px 0 max(56px, env(safe-area-inset-bottom)); }
.screen { animation: enter .28s cubic-bezier(.2,.7,.2,1) both; }
.mast {
  position: relative;
  overflow: hidden;
  border: 2px solid var(--rule);
  background: var(--paper);
  box-shadow: var(--shadow);
}
.mast::after {
  content: "?";
  position: absolute;
  right: -1.5rem;
  bottom: -3.7rem;
  color: rgba(232,68,46,.1);
  font: 800 clamp(12rem, 65vw, 27rem)/1 Georgia, serif;
  pointer-events: none;
}
.mast-bar, .section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 10px;
  border-bottom: 2px solid var(--rule);
  background: #e9ddc5;
  font: 800 .72rem/1 var(--pg-font-mono, ui-monospace, monospace);
  letter-spacing: .06em;
  text-transform: uppercase;
}
.hero { position: relative; z-index: 1; display: grid; gap: 18px; padding: clamp(28px, 8vw, 64px); }
.kicker, .eyebrow { margin: 0; color: var(--accent-dark); font: 850 .76rem/1.3 var(--pg-font-mono, ui-monospace, monospace); letter-spacing: .08em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 8ch; margin-bottom: 0; font: 800 clamp(3.4rem, 17vw, 8.5rem)/.78 Georgia, serif; letter-spacing: -.075em; }
.hero-copy { max-width: 34rem; margin: 0; color: var(--muted); font-size: clamp(1rem, 3.8vw, 1.28rem); line-height: 1.45; }

.how { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 24px 0; border: 2px solid var(--rule); background: var(--rule); box-shadow: var(--shadow); }
.how article { min-width: 0; padding: 16px 12px; background: var(--paper); }
.how strong { display: block; margin-bottom: 8px; color: var(--accent); font: 900 1.3rem/1 var(--pg-font-mono, ui-monospace, monospace); }
.how span { color: var(--muted); font-size: .86rem; line-height: 1.35; }

.entry-grid { display: grid; gap: 16px; }
.panel { border: 2px solid var(--rule); background: var(--paper); box-shadow: var(--shadow); }
.panel-body { padding: clamp(18px, 5vw, 30px); }
.panel h2 { margin-bottom: 6px; font: 800 clamp(1.65rem, 7vw, 2.4rem)/1 Georgia, serif; letter-spacing: -.035em; }
.panel-copy { margin-bottom: 20px; color: var(--muted); line-height: 1.45; }
.field { display: grid; gap: 7px; margin-top: 14px; }
.field > span { font: 800 .72rem/1 var(--pg-font-mono, ui-monospace, monospace); letter-spacing: .06em; text-transform: uppercase; }
input {
  width: 100%; min-height: 52px; border: 2px solid var(--rule); border-radius: 0; padding: 10px 12px; color: var(--ink); background: #fffdf7; outline: 0;
}
input:focus { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.signed-input { display: grid; grid-template-columns: minmax(0, 1fr) 52px; min-width: 0; }
.signed-input input { min-width: 0; }
.sign-toggle { min-height: 52px; border: 2px solid var(--rule); border-left: 0; background: #e9ddc5; color: var(--ink); font: 900 1.2rem/1 var(--pg-font-mono, ui-monospace, monospace); cursor: pointer; }
.sign-toggle:focus-visible { position: relative; outline: 3px solid #ad7d25; outline-offset: 2px; }
.sign-toggle:disabled { opacity: .45; }
.sign-hint { margin: 7px 0 0; color: var(--muted); font-size: .78rem; line-height: 1.35; }
.code-input { text-transform: uppercase; letter-spacing: .35em; font: 900 1.25rem/1 var(--pg-font-mono, ui-monospace, monospace); }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.btn { min-height: 50px; border: 2px solid var(--rule); padding: 11px 16px; background: var(--paper); color: var(--ink); font-weight: 850; cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; }
.btn:hover:not(:disabled), .btn:focus-visible:not(:disabled) { transform: translate(-2px,-2px); box-shadow: 3px 3px 0 var(--rule); }
.btn:focus-visible, a:focus-visible { outline: 3px solid #ad7d25; outline-offset: 3px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: #e9ddc5; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-wide { width: 100%; }

.game-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin: 8px 0 20px; }
.game-head h1 { max-width: none; font-size: clamp(2.6rem, 14vw, 6rem); line-height: .88; }
.room-stamp { flex: 0 0 auto; border: 2px solid var(--rule); padding: 9px 12px; background: var(--paper); box-shadow: 3px 3px 0 var(--rule); text-align: center; }
.room-stamp small { display: block; color: var(--muted); font: 750 .63rem/1 var(--pg-font-mono, ui-monospace, monospace); letter-spacing: .08em; text-transform: uppercase; }
.room-stamp strong { display: block; margin-top: 5px; font: 900 1.3rem/1 var(--pg-font-mono, ui-monospace, monospace); letter-spacing: .18em; }

.roster { display: grid; gap: 10px; padding: 0; margin: 0; list-style: none; }
.player-row { display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid #cfc3ad; }
.player-row:last-child { border-bottom: 0; }
.presence { width: 10px; height: 10px; border: 1px solid var(--rule); border-radius: 50%; background: #aaa291; }
.presence.live { background: var(--good); }
.player-row strong { display: block; }
.player-row small { color: var(--muted); }
.host-tag, .solved-tag { padding: 5px 7px; border: 1px solid var(--rule); font: 800 .65rem/1 var(--pg-font-mono, ui-monospace, monospace); text-transform: uppercase; }
.range-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.range-readout { margin: 12px 0 0; color: var(--muted); font-family: var(--pg-font-mono, ui-monospace, monospace); }

.number-board { display: grid; gap: 12px; }
.other-numbers { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.number-card { position: relative; min-height: 154px; border: 2px solid var(--rule); padding: 14px; overflow: hidden; background: var(--paper); box-shadow: 3px 3px 0 var(--rule); }
.number-card.solved { background: #dceadc; }
.number-card .name { position: relative; z-index: 1; display: flex; justify-content: space-between; gap: 8px; font-weight: 850; }
.attempt-count { position: relative; z-index: 1; display: block; margin-top: 5px; color: var(--muted); font: 750 .69rem/1 var(--pg-font-mono, ui-monospace, monospace); }
.number-card .value { position: absolute; right: 10px; bottom: 8px; font: 900 clamp(4.5rem, 21vw, 7rem)/.82 Georgia, serif; letter-spacing: -.08em; }
.your-card { display: grid; place-items: center; min-height: 190px; border: 2px dashed var(--rule); padding: 24px; text-align: center; background: #e9ddc5; }
.your-card .mystery { color: var(--accent); font: 900 clamp(6rem, 36vw, 12rem)/.75 Georgia, serif; }
.your-card h2 { margin: 8px 0 4px; font: 800 1.35rem/1 Georgia, serif; }
.your-card p { margin: 0; color: var(--muted); }
.guess-panel { margin-top: 16px; }
.guess-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.guess-field { margin: 0; }
.guess-form input { min-width: 0; font: 900 1.35rem/1 var(--pg-font-mono, ui-monospace, monospace); }
.feedback { min-height: 1.4em; margin: 12px 0 0; color: var(--accent-dark); font-weight: 800; }
.feedback.good { color: var(--good); }
.guess-history { margin-top: 16px; padding-top: 14px; border-top: 1px solid #cfc3ad; }
.guess-history h3 { margin: 0 0 9px; font: 850 .72rem/1 var(--pg-font-mono, ui-monospace, monospace); letter-spacing: .06em; text-transform: uppercase; }
.guess-history > div { display: flex; flex-wrap: wrap; gap: 7px; }
.guess-chip { border: 1px solid var(--rule); padding: 6px 9px; background: #e9ddc5; font: 800 .8rem/1 var(--pg-font-mono, ui-monospace, monospace); }
.guess-chip.correct { color: var(--good); background: #dceadc; }

.ranking { counter-reset: rank; padding: 0; margin: 0; list-style: none; }
.rank-row { counter-increment: rank; display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 12px; padding: 16px 0; border-bottom: 1px solid #cfc3ad; }
.rank-row::before { content: counter(rank, decimal-leading-zero); color: var(--accent); font: 900 1.1rem/1 var(--pg-font-mono, ui-monospace, monospace); }
.rank-row h3 { margin: 0 0 3px; }
.rank-row p { margin: 0; color: var(--muted); }
.rank-number { font: 900 2.2rem/1 Georgia, serif; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); border: 2px solid var(--rule); padding: 12px 16px; color: #fff; background: var(--ink); box-shadow: 4px 4px 0 var(--accent); font-weight: 750; }
.note { margin: 12px 0 0; color: var(--muted); font-size: .86rem; line-height: 1.4; }

@keyframes enter { from { opacity: 0; transform: translateY(8px); } }
@keyframes pulse { to { opacity: .35; } }
@media (min-width: 720px) {
  .app-shell { padding-top: 32px; }
  .entry-grid { grid-template-columns: 1fr 1fr; }
  .other-numbers { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .number-board { grid-template-columns: minmax(0,1.5fr) minmax(260px,.7fr); align-items: stretch; }
  .your-card { min-height: 100%; }
}
@media (max-width: 430px) {
  .how { grid-template-columns: 1fr; }
  .how article { display: grid; grid-template-columns: 34px 1fr; gap: 8px; align-items: start; }
  .how strong { margin: 0; }
  .game-head { align-items: center; }
  .room-stamp { padding: 7px 9px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
