:root {
  --ink: #eef3f6;
  --dim: #a9b8c2;
  --glass: rgba(10, 20, 28, 0.72);
  --line: rgba(255, 255, 255, 0.14);
  --accent: #f0b429;
  --accent-ink: #231a02;
  --good: #57c98a;
  --bad: #ef6a5a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1a22; color: var(--ink); font: 16px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
.hidden { display: none !important; }
#world { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

h1, h2, h3, p { margin: 0; }
h1 { font-size: 2.6rem; letter-spacing: -0.02em; }
h2 { font-size: 1.5rem; }
h3 { font-size: 0.82rem; margin: 18px 0 8px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.07em; }
.sub { color: var(--dim); }
.error { color: var(--bad); min-height: 1.3em; margin: 8px 0; font-size: 0.95rem; }
.tip { color: var(--dim); font-size: 0.9rem; margin: 10px 0; }
code { background: rgba(255, 255, 255, 0.1); padding: 1px 5px; border-radius: 4px; }

button, .button, input, select, textarea { font: inherit; color: inherit; }
button, .button {
  display: inline-block; text-align: center; cursor: pointer; padding: 11px 16px; border-radius: 9px;
  background: rgba(255, 255, 255, 0.1); border: 1px solid var(--line); transition: background 0.12s, transform 0.06s;
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
}
button:hover, .button:hover { background: rgba(255, 255, 255, 0.18); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .slot:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 650; }
button.primary:hover { background: #ffc94a; }
button.danger { color: #ffb4a8; }
button.ghost { background: transparent; }
button.big { font-size: 1.15rem; padding: 15px 22px; width: 100%; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; background: rgba(0, 0, 0, 0.32); border: 1px solid var(--line);
}
select option { background: #16252e; }
textarea { resize: vertical; }
label { display: block; font-size: 0.9rem; color: var(--dim); }
label input, label select { margin-top: 4px; color: var(--ink); font-size: 1rem; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); }
label.check input { width: auto; margin: 0; }

.screen { position: fixed; inset: 0; overflow-y: auto; display: flex; padding: 20px; }
.screen > .card { margin: auto; }
.card {
  background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 16px; padding: 24px; width: 100%; max-width: 440px;
}
.card.wide { max-width: 860px; }
.home-card > * + * { margin-top: 14px; }
.join-row { display: flex; gap: 8px; }
#code { text-transform: uppercase; letter-spacing: 0.26em; font-weight: 700; font-size: 1.2rem; text-align: center; }
.split { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.split > * { flex: 1 1 130px; }
.bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.tile { text-align: left; padding: 10px 12px; }
.tile b { display: block; }
.tile small { color: var(--dim); display: block; line-height: 1.3; }
.tile.on { border-color: var(--accent); background: rgba(240, 180, 41, 0.17); }
.anglers .tile { display: flex; gap: 10px; align-items: center; }
.anglers .swatch { flex: 0 0 34px; height: 34px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.5); }

.rows > div { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.rows .grow { flex: 1; min-width: 0; }
.rows .pct { font-variant-numeric: tabular-nums; font-weight: 650; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 36px; }
.chip { background: rgba(255, 255, 255, 0.1); border-radius: 999px; padding: 5px 12px; display: inline-flex; gap: 6px; align-items: center; }
.chip button { padding: 0 6px; border: 0; background: none; color: var(--dim); }
.chip.off { opacity: 0.5; }

.room-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.room-code { font-size: 3.4rem; font-weight: 800; letter-spacing: 0.16em; line-height: 1.1; color: var(--accent); }

/* Builder */
.q-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 12px 0; }
.q-card header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; color: var(--dim); }
.q-card header button { padding: 3px 9px; font-size: 0.85rem; }
.q-main { display: grid; grid-template-columns: 1fr 150px; gap: 10px; }
.a-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 8px; margin-top: 10px; }
.a-row { display: grid; grid-template-columns: auto 1fr 72px; gap: 8px; align-items: center; }
.a-row input[type=radio] { width: 20px; height: 20px; accent-color: var(--good); }
.slot {
  position: relative; display: flex; align-items: center; justify-content: center; text-align: center; overflow: hidden;
  border: 1.5px dashed rgba(255, 255, 255, 0.28); border-radius: 8px; font-size: 0.75rem; color: var(--dim);
  min-height: 72px; padding: 4px; cursor: pointer; background: rgba(0, 0, 0, 0.2);
}
.q-main .slot { min-height: 96px; }
.slot.active { border-color: var(--accent); border-style: solid; color: var(--ink); }
.slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; }
.slot .x { position: absolute; top: 2px; right: 2px; padding: 0 6px; font-size: 0.8rem; background: rgba(0, 0, 0, 0.7); border: 0; }

/* HUD */
#hud { position: fixed; top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px; display: flex; gap: 6px; align-items: stretch; z-index: 4; pointer-events: none; }
.hud-box { background: var(--glass); border-radius: 10px; padding: 5px 12px; line-height: 1.2; }
.hud-box span { display: block; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1.1rem; white-space: nowrap; }
.hud-box small { color: var(--dim); white-space: nowrap; }
#hud-tools { margin-left: auto; display: flex; gap: 4px; pointer-events: auto; }
#hud-tools button { background: var(--glass); padding: 6px 10px; }

#board { position: fixed; top: 72px; left: 10px; margin: 0; padding: 6px 10px; list-style: none; width: 200px; background: var(--glass); border-radius: 10px; font-size: 0.86rem; z-index: 2; }
#board li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
#board li.me { color: var(--accent); font-weight: 650; }
#board span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board small { font-variant-numeric: tabular-nums; }
#feed { position: fixed; top: 72px; right: 10px; width: 250px; font-size: 0.85rem; z-index: 2; text-align: right; }
#feed div { background: var(--glass); border-radius: 8px; padding: 4px 9px; margin-bottom: 4px; animation: fade 6s forwards; }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

#event-banner { position: fixed; top: 76px; left: 50%; transform: translateX(-50%); width: min(460px, calc(100vw - 20px)); background: rgba(160, 80, 0, 0.88); padding: 8px 14px; border-radius: 10px; text-align: center; z-index: 5; }
#event-banner b { display: block; }
#toast { position: fixed; left: 50%; bottom: 42%; transform: translateX(-50%); background: var(--glass); border-radius: 10px; padding: 10px 16px; z-index: 8; }

.panel {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(660px, calc(100vw - 20px));
  max-height: calc(100dvh - 80px); overflow-y: auto; background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: 14px; padding: 18px; z-index: 3; text-align: center;
}
.panel.low { top: auto; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(520px, calc(100vw - 20px)); padding: 12px 14px; }
.panel > * + * { margin-top: 10px; }

#q-text { font-size: 1.3rem; font-weight: 600; }
#q-image { max-width: 100%; max-height: 34vh; border-radius: 8px; background: #fff; display: block; margin: 0 auto 10px; }
#q-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#q-choices button { min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 8px; font-size: 1.05rem; color: #fff; border: 0; }
#q-choices button img { max-width: 100%; max-height: 110px; border-radius: 5px; background: #fff; }
#q-choices button:nth-child(1) { background: #a93f3a; }
#q-choices button:nth-child(2) { background: #2c6fa6; }
#q-choices button:nth-child(3) { background: #a87a1e; }
#q-choices button:nth-child(4) { background: #3b8058; }
#q-choices button:hover { filter: brightness(1.12); }
#q-choices kbd { font: inherit; font-size: 0.72rem; opacity: 0.65; }
#q-choices .picked-right { outline: 3px solid var(--good); }
#q-timer { height: 6px; background: rgba(255, 255, 255, 0.15); border-radius: 3px; overflow: hidden; margin-bottom: 10px; }
#q-timer i { display: block; height: 100%; background: var(--accent); }
.answer { font-size: 1.25rem; font-weight: 650; color: var(--good); }
.answer img { display: block; margin: 6px auto; max-height: 150px; max-width: 100%; background: #fff; border-radius: 6px; }

#baits { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
#baits button { padding: 6px 2px; font-size: 0.72rem; line-height: 1.15; }
#baits button span { display: block; font-size: 1.35rem; }
#baits button.on { border-color: var(--accent); background: rgba(240, 180, 41, 0.2); }
#cast-meter { position: relative; height: 26px; display: grid; grid-template-columns: 40% 35% 25%; background: rgba(0, 0, 0, 0.4); border-radius: 7px; overflow: hidden; font-size: 0.72rem; }
#cast-meter span { position: relative; z-index: 1; line-height: 26px; border-left: 1px solid rgba(255, 255, 255, 0.3); color: var(--ink); }
#cast-meter i { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #4aa3c8, #2c6fa6 60%, #18406e); }

#strike { background: rgba(255, 255, 255, 0.1); }
#panel-wait.biting { border-color: var(--bad); }
#panel-wait.biting #strike { background: var(--bad); color: #fff; animation: pulse 0.3s infinite alternate; }
@keyframes pulse { to { transform: scale(1.04); } }

.gauge { text-align: left; font-size: 0.8rem; color: var(--dim); }
.gauge > div { position: relative; height: 18px; background: rgba(0, 0, 0, 0.42); border-radius: 6px; overflow: hidden; margin-top: 2px; }
.gauge i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--good); }
.gauge b { position: absolute; top: 0; bottom: 0; background: rgba(87, 201, 138, 0.2); border-left: 1px solid var(--good); border-right: 1px solid var(--good); }
#tension.hot i { background: var(--bad); }
#tension.slack i { background: #6fb4ff; }
#lineout i { background: #dfe6ea; }

#panel-catch h2 { font-size: 1.7rem; }
.rarity { text-transform: uppercase; letter-spacing: 0.14em; font-weight: 750; font-size: 0.8rem; }
.sci { font-style: italic; color: var(--dim); }
#c-art { width: 100%; max-width: 560px; height: auto; display: block; margin: 8px auto; background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.13), transparent 70%); }
#c-icon { font-size: 5rem; line-height: 1.2; }
#c-stats { display: flex; justify-content: center; gap: 22px; flex-wrap: wrap; }
#c-stats div b { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
#c-stats div { color: var(--dim); font-size: 0.8rem; }
#c-stats .score b { color: var(--accent); }
#c-fact { color: var(--dim); font-size: 0.95rem; }

#tokens { position: fixed; right: 10px; bottom: 16px; z-index: 6; display: flex; flex-direction: column; gap: 6px; width: 200px; }
#tokens select { font-size: 0.86rem; padding: 6px; background: rgba(0, 0, 0, 0.72); }
#tokens button { background: rgba(120, 50, 140, 0.88); font-size: 0.86rem; padding: 8px; }

#panel-spectate { width: min(760px, calc(100vw - 20px)); }
#sp-board, #over-board { list-style: none; margin: 10px 0 0; padding: 0; text-align: left; }
#sp-board li, #over-board li { display: flex; gap: 12px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
#sp-board li span:nth-child(2), #over-board li span:nth-child(2) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#paused { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 3rem; font-weight: 800; background: rgba(0, 0, 0, 0.5); z-index: 9; }
#gulls { position: fixed; inset: 0; z-index: 7; pointer-events: none; overflow: hidden; }
#gulls span { position: absolute; font-size: 5.5rem; animation: flap 0.34s infinite alternate; }
@keyframes flap { to { transform: translateY(-16px) scale(1.08) rotate(5deg); } }
body.rocking #game .panel { animation: rock 1.6s ease-in-out infinite; }
@keyframes rock { 25% { margin-left: -14px; rotate: -2deg; } 75% { margin-left: 14px; rotate: 2deg; } }

#podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; margin: 16px 0; }
#podium > div { flex: 0 1 180px; text-align: center; background: rgba(255, 255, 255, 0.08); border-radius: 10px 10px 0 0; padding: 10px; }
#podium .p1 { min-height: 170px; background: rgba(240, 180, 41, 0.26); }
#podium .p2 { min-height: 134px; }
#podium .p3 { min-height: 108px; }
#podium b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#podium .place { font-size: 1.6rem; font-weight: 800; }
#podium small { color: var(--dim); display: block; }
#reconnecting { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); background: var(--bad); color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 20; }

@media (max-width: 760px) {
  h1 { font-size: 2.1rem; }
  #board { width: 142px; font-size: 0.75rem; top: 66px; }
  #feed { display: none; }
  .hud-box { padding: 3px 8px; }
  .hud-box span { font-size: 0.95rem; }
  .hud-box small { font-size: 0.68rem; }
  #q-text { font-size: 1.1rem; }
  #q-choices { gap: 6px; }
  #q-choices button { font-size: 0.95rem; min-height: 54px; }
  .q-main { grid-template-columns: 1fr; }
  .room-code { font-size: 2.6rem; }
  #gulls span { font-size: 4rem; }
  #tokens { width: 150px; bottom: auto; top: 66px; right: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  #gulls span, #panel-wait.biting #strike, body.rocking #game .panel { animation: none; }
}
