:root {
  --shell: #171914;
  --shell-2: #22251e;
  --paper: #eee7d8;
  --paper-hi: #f8f2e7;
  --paper-ink: #28271f;
  --ink: #171914;
  --muted: #746f62;
  --brass: #a97932;
  --brass-hi: #d1a653;
  --line: rgba(40, 39, 31, 0.22);
  --red: #bd4038;
  --blue: #2c68a1;
  --green: #4d774c;
  --yellow: #c99326;
  --danger: #a23f37;
  --ok: #587c55;
  --shadow: 0 22px 60px rgba(8, 10, 7, 0.24);
  --font-sans: Inter, "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  --font-serif: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  --font-mono: "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { min-width: 320px; background: var(--shell); }

body {
  margin: 0;
  min-height: 100vh;
  color: #f0eadc;
  background: var(--shell);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }

button { color: inherit; }

button:focus-visible, input:focus-visible {
  outline: 2px solid var(--brass-hi);
  outline-offset: 3px;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .11;
  z-index: 20;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.28'/%3E%3C/svg%3E");
}

.site-head {
  height: 78px;
  padding: 0 clamp(20px, 4vw, 58px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(238, 231, 216, .13);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand svg { width: 36px; height: 36px; }
.brand-hex { fill: none; stroke: var(--brass-hi); stroke-width: 1.5; }
.brand-plane { fill: var(--brass-hi); }
.brand span { display: grid; gap: 2px; }
.brand strong { font-family: var(--font-serif); font-size: 15px; letter-spacing: .08em; }
.brand small { color: #9b9589; font: 9px/1 var(--font-mono); letter-spacing: .14em; }

.network-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #a8a296;
  font: 11px/1 var(--font-mono);
  letter-spacing: .06em;
}

.network-state i { width: 7px; height: 7px; border-radius: 50%; background: #77756e; }
.network-state[data-state="online"] i { background: #78a271; box-shadow: 0 0 0 4px rgba(120, 162, 113, .12); }
.network-state[data-state="connecting"] i { background: var(--brass-hi); animation: pulse 1.2s infinite; }
.network-state[data-state="error"] i { background: var(--danger); }

main { width: min(1500px, 100%); margin: 0 auto; }

.entry-screen {
  min-height: calc(100vh - 78px);
  padding: clamp(44px, 8vh, 96px) clamp(20px, 6vw, 88px);
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(390px, .75fr);
  align-items: center;
  gap: clamp(48px, 8vw, 120px);
}

.eyebrow {
  color: var(--brass-hi);
  font: 10px/1.4 var(--font-mono);
  letter-spacing: .16em;
  text-transform: uppercase;
}

.entry-copy h1 {
  margin: 22px 0;
  max-width: 760px;
  font: 500 clamp(38px, 5.5vw, 72px)/1.12 var(--font-serif);
  letter-spacing: -.035em;
}

.entry-copy > p {
  max-width: 610px;
  margin: 0;
  color: #aaa497;
  font-size: 15px;
  line-height: 1.9;
}

.entry-facts {
  display: flex;
  gap: clamp(26px, 5vw, 64px);
  margin: 46px 0 0;
}

.entry-facts div { display: grid; gap: 8px; }
.entry-facts dt { color: var(--paper); font: 26px/1 var(--font-mono); }
.entry-facts dd { margin: 0; color: #7f7b71; font-size: 11px; letter-spacing: .08em; }

.entry-panel {
  color: var(--ink);
  background: var(--paper);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, .3);
}

.panel-tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); }
.tab { min-height: 58px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.tab + .tab { border-left: 1px solid var(--line); }
.tab.active { color: var(--ink); background: var(--paper-hi); box-shadow: inset 0 -3px var(--brass); }

.entry-form { padding: clamp(26px, 4vw, 42px); }
.form-heading { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 28px; }
.form-heading span { font: 600 20px/1.2 var(--font-serif); }
.form-heading small { color: var(--muted); font-size: 11px; }

.entry-form > label { display: grid; gap: 9px; margin-bottom: 20px; }
.entry-form label > span, .entry-form legend { color: #5f5b50; font-size: 11px; letter-spacing: .08em; }
.entry-form input {
  width: 100%;
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, .32);
  padding: 0 14px;
}
.entry-form input::placeholder { color: #aaa496; }
.entry-form .code-input { font: 600 20px/1 var(--font-mono); letter-spacing: .22em; text-transform: uppercase; }
.entry-form fieldset { border: 0; margin: 0 0 26px; padding: 0; }
.entry-form legend { margin-bottom: 10px; }

.count-options { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); }
.count-options label { position: relative; cursor: pointer; }
.count-options label + label { border-left: 1px solid var(--line); }
.count-options input { position: absolute; opacity: 0; pointer-events: none; }
.count-options span { min-height: 44px; display: grid; place-items: center; color: var(--muted); }
.count-options input:checked + span { color: var(--paper-hi); background: var(--ink); }

.primary-button, .secondary-button, .copy-button, .roll-button {
  border: 0;
  cursor: pointer;
}

.primary-button {
  width: 100%;
  min-height: 58px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 18px;
  color: var(--paper-hi);
  background: var(--ink);
}
.primary-button span { font-weight: 650; letter-spacing: .04em; }
.primary-button small { color: #aaa497; font-size: 10px; }
.primary-button:hover:not(:disabled) { background: #2b2e26; }
.primary-button:disabled, .secondary-button:disabled, .roll-button:disabled { cursor: not-allowed; opacity: .42; }
.primary-button.compact { width: auto; min-width: 150px; justify-content: center; }

.form-error { margin: -14px 42px 30px; color: var(--danger); font-size: 12px; line-height: 1.5; }

.lobby-screen { padding: clamp(38px, 6vw, 82px) clamp(20px, 6vw, 88px); }
.room-brief { display: flex; align-items: end; justify-content: space-between; gap: 28px; }
.room-brief h1 { margin: 12px 0 8px; font: 500 clamp(36px, 5vw, 62px)/1.1 var(--font-serif); }
.room-brief p { margin: 0; color: #9b9589; }
.room-code-block { min-width: 250px; padding: 18px 20px; color: var(--ink); background: var(--paper); border-left: 5px solid var(--brass); }
.room-code-block small { display: block; color: var(--muted); font-size: 10px; letter-spacing: .12em; }
.room-code-block strong { display: block; margin: 6px 0 12px; font: 700 28px/1 var(--font-mono); letter-spacing: .18em; }
.copy-button { padding: 0; color: #72501e; background: none; font-size: 11px; text-decoration: underline; text-underline-offset: 4px; }

.lobby-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(280px, .7fr); margin-top: 44px; border: 1px solid rgba(238,231,216,.18); }
.seat-manifest { background: var(--paper); color: var(--ink); }
.seat-manifest > header, .module-strip header, .event-panel header {
  min-height: 52px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.seat-manifest > header span { font-family: var(--font-serif); font-weight: 600; }
.seat-manifest > header small { color: var(--muted); font: 11px/1 var(--font-mono); }
.seat-list { display: grid; grid-template-columns: 1fr 1fr; }
.seat-card {
  min-height: 116px;
  padding: 20px;
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 14px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.seat-card:nth-child(2n) { border-right: 0; }
.seat-number { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid var(--line); font: 12px/1 var(--font-mono); }
.seat-card strong { display: block; font-size: 14px; }
.seat-card small { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; }
.seat-badge { padding: 6px 8px; color: #8a8579; border: 1px solid var(--line); font-size: 9px; letter-spacing: .08em; }
.seat-badge.ready { color: #41633e; border-color: rgba(65,99,62,.4); }
.seat-card.empty { color: #8d877a; background: rgba(255,255,255,.18); }

.flight-notes { padding: 30px; background: var(--shell-2); }
.stamp { display: inline-block; padding: 6px 9px; color: var(--brass-hi); border: 1px solid rgba(209,166,83,.5); font: 9px/1 var(--font-mono); letter-spacing: .12em; transform: rotate(-1deg); }
.flight-notes h2 { margin: 26px 0 20px; font: 500 24px/1.2 var(--font-serif); }
.flight-notes ol { list-style: none; padding: 0; margin: 0; }
.flight-notes li { min-height: 48px; display: flex; align-items: center; gap: 14px; border-top: 1px solid rgba(238,231,216,.12); }
.flight-notes li i { color: var(--brass-hi); font: normal 9px/1 var(--font-mono); }
.flight-notes li span { color: #c7c0b2; font-size: 12px; }
.flight-notes p { margin: 24px 0 0; color: #827e74; font-size: 11px; line-height: 1.7; }

.lobby-actions {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid rgba(238,231,216,.14);
}
.lobby-actions > span { color: #a49e92; font-size: 12px; }
.lobby-actions > div { display: flex; gap: 10px; }
.secondary-button { min-width: 120px; min-height: 58px; color: var(--paper); background: transparent; border: 1px solid rgba(238,231,216,.28); }
.secondary-button.active { color: var(--ink); background: var(--paper); }

.game-screen { padding: 18px clamp(14px, 3vw, 44px) 38px; }
.game-meta { min-height: 56px; display: flex; justify-content: space-between; align-items: center; }
.game-meta > div { display: grid; gap: 5px; }
.game-meta strong { font-family: var(--font-serif); font-size: 17px; }
.room-chip { border: 1px solid rgba(238,231,216,.2); padding: 9px 12px; color: #b5afa2; background: transparent; font: 10px/1 var(--font-mono); cursor: pointer; }

.player-rail { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid rgba(238,231,216,.14); }
.player-status { min-height: 58px; padding: 9px 13px; display: grid; grid-template-columns: 8px 1fr auto; align-items: center; gap: 10px; }
.player-status + .player-status { border-left: 1px solid rgba(238,231,216,.14); }
.player-status > i { width: 8px; height: 22px; background: var(--player-color); }
.player-status strong { display: block; font-size: 11px; }
.player-status small { display: block; margin-top: 3px; color: #817d73; font-size: 9px; }
.player-status span { color: #9c968a; font: 9px/1 var(--font-mono); }
.player-status.current { background: rgba(209,166,83,.08); box-shadow: inset 0 -2px var(--brass-hi); }

.game-layout { display: grid; grid-template-columns: minmax(520px, 1fr) 330px; gap: 16px; margin-top: 16px; }
.board-stage { position: relative; min-width: 0; display: grid; place-items: center; background: #26291f; border: 1px solid rgba(238,231,216,.12); overflow: hidden; }
.board-wrap { width: min(100%, calc(100vh - 210px)); aspect-ratio: 1; }
.board-wrap svg { display: block; width: 100%; height: 100%; }
.svg-board-title { fill: var(--paper-ink); opacity: .6; font: 16px var(--font-mono); letter-spacing: 3px; }
.flight-arc-case { fill: none; stroke: var(--paper-hi); stroke-width: 10; opacity: .65; }
.flight-arc { fill: none; stroke-width: 4; stroke-dasharray: 14 10; opacity: .9; }
.piece { cursor: default; transition: transform 360ms cubic-bezier(.2,.7,.2,1), opacity 180ms ease; }
.piece.clickable { cursor: pointer; }
.piece .pawn-shadow { fill: #171914; opacity: .25; }
.piece .pawn-num { fill: var(--pc); font: 700 10px var(--font-mono); text-anchor: middle; }
.piece .legal-ring { fill: none; stroke: var(--brass-hi); stroke-width: 3; stroke-dasharray: 5 4; opacity: 0; }
.piece.clickable .legal-ring { opacity: 1; animation: ring 1.5s linear infinite; }
.piece.clickable:hover .sel-lift { transform: translateY(-7px); }

.sync-veil { position: absolute; inset: 0; z-index: 4; display: grid; place-content: center; justify-items: center; gap: 8px; color: var(--ink); background: rgba(238,231,216,.86); text-align: center; }
.sync-veil small { color: var(--muted); font-size: 10px; }
.signal-loader { display: flex; gap: 4px; margin-bottom: 8px; }
.signal-loader i { width: 5px; height: 18px; background: var(--brass); animation: signal .9s ease-in-out infinite alternate; }
.signal-loader i:nth-child(2) { animation-delay: .15s; }
.signal-loader i:nth-child(3) { animation-delay: .3s; }

.control-desk { min-width: 0; color: var(--ink); background: var(--paper); border-top: 4px solid var(--brass); }
.desk-head { min-height: 58px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.desk-head span { font: 600 15px/1 var(--font-serif); }
.desk-head small { color: var(--muted); font-size: 9px; }
.dice-readout { padding: 18px 16px; display: flex; align-items: center; gap: 14px; }
.die-face { width: 54px; height: 54px; flex: 0 0 auto; display: grid; place-items: center; color: var(--paper-hi); background: var(--ink); font: 700 24px/1 var(--font-mono); }
.dice-readout strong, .dice-readout small { display: block; }
.dice-readout strong { font-size: 12px; }
.dice-readout small { max-width: 190px; margin-top: 5px; color: var(--muted); font-size: 9px; line-height: 1.4; }
.roll-button { width: calc(100% - 32px); min-height: 58px; margin: 0 16px 14px; padding: 0 15px; display: flex; align-items: center; justify-content: space-between; color: var(--paper); background: var(--ink); }
.roll-button span { font-weight: 650; }
.roll-button small { color: #aaa497; font-size: 9px; }
.piece-choices { min-height: 46px; padding: 0 16px 14px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.piece-choice { min-height: 42px; border: 1px solid var(--line); color: var(--muted); background: rgba(255,255,255,.2); font: 700 10px/1 var(--font-mono); }
.piece-choice.available { cursor: pointer; color: var(--ink); border-color: var(--brass); background: var(--paper-hi); }
.module-strip, .event-panel { border-top: 1px solid var(--line); }
.module-strip header, .event-panel header { min-height: 40px; padding: 0 16px; }
.module-strip header span, .event-panel header span { font-size: 10px; letter-spacing: .06em; }
.module-strip header small, .event-panel header small { color: var(--muted); font: 9px/1 var(--font-mono); }
#ownedModules { min-height: 54px; padding: 10px 16px; display: flex; flex-wrap: wrap; gap: 6px; }
.owned-module { padding: 7px 8px; border: 1px solid var(--line); color: #4c493f; background: var(--paper-hi); font-size: 9px; }
.empty-copy { align-self: center; color: #969083; font-size: 9px; }
.event-panel ol { max-height: 170px; overflow: auto; list-style: none; padding: 6px 16px 14px; margin: 0; }
.event-panel li { padding: 7px 0; display: grid; grid-template-columns: 30px 1fr; gap: 8px; color: #5c584e; border-bottom: 1px solid rgba(40,39,31,.1); font-size: 9px; line-height: 1.4; }
.event-panel li time { color: var(--brass); font-family: var(--font-mono); }

.module-overlay, .result-overlay { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 24px; background: rgba(13,15,12,.88); }
.module-dialog { width: min(1120px, 100%); color: var(--ink); background: var(--paper); box-shadow: var(--shadow); }
.module-dialog > header { min-height: 94px; padding: 22px clamp(20px,4vw,40px); display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.module-dialog h2 { margin: 6px 0 0; font: 500 27px/1.2 var(--font-serif); }
.lock-status { display: flex; gap: 6px; }
.lock-chip { padding: 7px 9px; color: var(--muted); border: 1px solid var(--line); font: 9px/1 var(--font-mono); }
.lock-chip.locked { color: #42643f; border-color: rgba(66,100,63,.4); }
.module-grid { padding: clamp(20px,4vw,42px); display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.module-card { position: relative; min-height: 260px; padding: 24px; display: flex; flex-direction: column; text-align: left; color: var(--ink); background: var(--paper-hi); border: 1px solid var(--line); cursor: pointer; }
.module-card::before { content: ""; position: absolute; inset: 0 0 auto; height: 4px; background: var(--card-color, var(--brass)); }
.module-card:hover:not(:disabled) { transform: translateY(-5px); box-shadow: 0 15px 28px rgba(40,39,31,.16); }
.module-card:disabled { cursor: default; opacity: .55; }
.module-card .rarity { color: var(--card-color, var(--brass)); font: 9px/1 var(--font-mono); letter-spacing: .12em; }
.module-card h3 { margin: 22px 0 12px; font: 600 22px/1.2 var(--font-serif); }
.module-card p { margin: 0; color: #666156; font-size: 12px; line-height: 1.7; }
.module-card .tags { margin-top: auto; padding-top: 20px; display: flex; gap: 6px; }
.module-card .tags span { padding: 5px 7px; border: 1px solid var(--line); font-size: 9px; }
.refresh-card { min-height: 38px; border: 1px solid var(--line); border-top: 0; color: #6e552c; background: transparent; cursor: pointer; font-size: 10px; }
.refresh-card:disabled { cursor: default; color: #9e988c; }
.module-choice { display: grid; }
.module-dialog > p { margin: 0; padding: 0 40px 26px; color: var(--muted); font-size: 10px; }

.result-sheet { width: min(480px, 100%); padding: 42px; color: var(--ink); background: var(--paper); text-align: center; box-shadow: var(--shadow); }
.result-sheet h2 { margin: 28px 0 10px; font: 500 34px/1.2 var(--font-serif); }
.result-sheet p { margin: 0 0 28px; color: var(--muted); font-size: 12px; }
.result-sheet .primary-button { margin: 0 auto; }

.toast { position: fixed; z-index: 50; left: 50%; bottom: 26px; transform: translateX(-50%); max-width: min(420px, calc(100vw - 32px)); padding: 12px 16px; color: var(--paper); background: #2a2c25; border: 1px solid rgba(238,231,216,.18); box-shadow: var(--shadow); font-size: 11px; }

@keyframes pulse { 50% { opacity: .35; } }
@keyframes signal { from { transform: scaleY(.35); opacity: .45; } to { transform: scaleY(1); opacity: 1; } }
@keyframes ring { to { stroke-dashoffset: -18; } }

@media (max-width: 920px) {
  .entry-screen { grid-template-columns: 1fr; align-content: start; }
  .entry-copy h1 { font-size: clamp(38px, 9vw, 62px); }
  .entry-panel { width: min(560px, 100%); }
  .lobby-grid { grid-template-columns: 1fr; }
  .game-layout { grid-template-columns: 1fr; }
  .board-wrap { width: 100%; }
  .control-desk { display: grid; grid-template-columns: 1fr 1fr; }
  .desk-head, .module-strip, .event-panel { grid-column: 1 / -1; }
  .dice-readout { border-right: 1px solid var(--line); }
  .roll-button { width: auto; margin: 12px 16px; }
  .piece-choices { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  .site-head { height: 64px; padding: 0 16px; }
  .brand svg { width: 30px; height: 30px; }
  .brand strong { font-size: 13px; }
  .network-state span { display: none; }
  .entry-screen { min-height: calc(100vh - 64px); padding: 34px 16px 48px; gap: 34px; }
  .entry-copy h1 { margin: 16px 0; font-size: 38px; }
  .entry-copy > p { font-size: 13px; line-height: 1.75; }
  .entry-facts { margin-top: 28px; justify-content: space-between; gap: 12px; }
  .entry-facts dt { font-size: 20px; }
  .entry-facts dd { font-size: 9px; }
  .entry-form { padding: 24px 18px; }
  .form-heading { align-items: start; flex-direction: column; gap: 6px; }
  .form-error { margin-left: 18px; margin-right: 18px; }
  .lobby-screen { padding: 32px 16px 48px; }
  .room-brief { align-items: stretch; flex-direction: column; }
  .room-brief h1 { font-size: 40px; }
  .room-code-block { min-width: 0; }
  .seat-list { grid-template-columns: 1fr; }
  .seat-card, .seat-card:nth-child(2n) { border-right: 0; }
  .lobby-actions { align-items: stretch; flex-direction: column; padding: 20px 0; }
  .lobby-actions > div { display: grid; grid-template-columns: 1fr 1fr; }
  .lobby-actions .primary-button, .secondary-button { min-width: 0; }
  .game-screen { padding: 10px 8px calc(20px + env(safe-area-inset-bottom)); }
  .game-meta { padding: 0 4px; }
  .player-rail { grid-template-columns: 1fr 1fr; }
  .player-status:nth-child(3) { border-left: 0; border-top: 1px solid rgba(238,231,216,.14); }
  .player-status:nth-child(4) { border-top: 1px solid rgba(238,231,216,.14); }
  .game-layout { margin-top: 8px; gap: 8px; }
  .control-desk { display: block; position: relative; }
  .dice-readout { border-right: 0; }
  .roll-button { width: calc(100% - 32px); margin: 0 16px 14px; }
  .event-panel ol { max-height: 130px; }
  .module-overlay { padding: 8px; align-items: end; }
  .module-dialog { max-height: 92vh; overflow: auto; }
  .module-dialog > header { align-items: start; flex-direction: column; gap: 16px; }
  .module-grid { grid-template-columns: 1fr; padding: 16px; }
  .module-card { min-height: 190px; }
  .module-dialog > p { padding: 0 16px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
