:root {
  --bg: #070b16; --bg2: #0d1426; --panel: #111a31; --panel2: #18233f; --line: #26345a;
  --text: #e6ebf7; --muted: #8b97b5; --amber: #ffb547; --teal: #3fe0c5; --red: #ff5d6c; --violet: #a68bff;
  --radius: 14px; --serif: Georgia, 'Times New Roman', serif; --mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
a { color: var(--teal); }
#stars { position: fixed; inset: 0; z-index: -1; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-family: var(--serif); font-weight: 400; letter-spacing: .02em; }
.wrap { max-width: 1060px; margin: 0 auto; padding: 24px 16px 60px; }
.center { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.card { background: color-mix(in srgb, var(--panel) 92%, transparent); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: 0 20px 60px #0008; backdrop-filter: blur(6px); }
.narrow { width: 100%; max-width: 420px; }
.logo { font-family: var(--serif); font-size: 34px; text-align: center; margin-bottom: 4px; }
.logo span { color: var(--amber); }
.tag { color: var(--muted); text-align: center; font-size: 14px; margin: 0 0 18px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
input, select, textarea { width: 100%; background: var(--bg2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 11px 12px; font: inherit; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px #3fe0c533; }
button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 10px; padding: 11px 16px; font: 600 14px/1 system-ui, sans-serif; cursor: pointer; background: var(--amber); color: #1b1200; text-decoration: none; transition: transform .08s, filter .15s; touch-action: manipulation; }
button:hover, .btn:hover { filter: brightness(1.08); }
button:active, .btn:active { transform: scale(.97); }
button:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn-teal { background: var(--teal); color: #00201a; }
.btn-red { background: var(--red); color: #fff; }
.btn-sm { padding: 7px 10px; font-size: 12px; border-radius: 8px; }
.full { width: 100%; margin-top: 16px; }
.err { color: var(--red); min-height: 1.2em; font-size: 13px; margin-top: 8px; }
.ok { color: var(--teal); }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; border: 1px solid var(--line); color: var(--muted); }
.pill.on { color: var(--teal); border-color: #3fe0c566; }
.pill.warn { color: var(--amber); border-color: #ffb54766; }
.pill.bad { color: var(--red); border-color: #ff5d6c66; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: #070b16cc; backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20; }
.brand { font-family: var(--serif); font-size: 20px; text-decoration: none; color: var(--text); }
.brand span { color: var(--amber); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs button { background: var(--panel2); color: var(--text); }
.tabs button.active { background: var(--amber); color: #1b1200; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); }
.big-code { font: 700 30px/1 var(--mono); letter-spacing: .25em; color: var(--amber); }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice button { flex-direction: column; padding: 22px 12px; height: auto; background: var(--panel2); color: var(--text); border: 1px solid var(--line); gap: 8px; line-height: 1.3; }
.choice button b { font-size: 16px; }
.choice button small { color: var(--muted); font-weight: 400; }
.choice button .ico { font-size: 30px; }

/* toasts */
#toasts { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); align-items: center; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100vw - 24px)); pointer-events: none; }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 4px solid var(--teal); padding: 10px 12px; border-radius: 10px; font-size: 13px; animation: tin .25s ease-out; box-shadow: 0 8px 30px #0009; }
.toast.hint { border-left-color: var(--violet); } .toast.warn { border-left-color: var(--red); } .toast.muted { border-left-color: var(--line); color: var(--muted); } .toast.good { border-left-color: var(--amber); }
@keyframes tin { from { transform: translateX(30px); opacity: 0; } }

/* modal */
.modal-bg { position: fixed; inset: 0; background: #000b; z-index: 100; display: grid; place-items: center; padding: 12px; animation: fade .2s; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); max-width: min(920px, 100%); max-height: calc(100dvh - 24px); width: 100%; overflow: auto; position: relative; box-shadow: 0 30px 80px #000; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 14px; }
.x { background: transparent; color: var(--text); font-size: 22px; padding: 4px 10px; }
@keyframes fade { from { opacity: 0; } }

/* ---------- play page ---------- */
body.play { overflow: hidden; }
.hud { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: #070b16ee; height: 54px; position: relative; z-index: 10; }
.hud .title { font-family: var(--serif); font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.hud .title small { color: var(--muted); font-family: system-ui; font-size: 12px; display: block; }
.timer { font: 700 18px var(--mono); color: var(--amber); }
.progress { position: absolute; left: 0; bottom: -1px; height: 3px; background: linear-gradient(90deg, var(--teal), var(--amber)); transition: width .8s; }
.icon-btn { background: var(--panel2); color: var(--text); width: 40px; height: 40px; padding: 0; border-radius: 10px; font-size: 18px; position: relative; flex: none; }
.icon-btn .badge { position: absolute; top: -4px; right: -4px; background: var(--red); color: #fff; font-size: 10px; border-radius: 99px; min-width: 16px; height: 16px; display: grid; place-items: center; padding: 0 4px; }
.stage { display: grid; grid-template-columns: 1fr 330px; height: calc(100dvh - 54px); }
.scene-wrap { position: relative; overflow: hidden; display: grid; place-items: center; background: radial-gradient(ellipse at center, #121c38, #05080f); }
.scene { width: 100%; height: 100%; max-height: 100%; touch-action: manipulation; user-select: none; }
.scene .hot { cursor: pointer; fill: transparent; stroke: transparent; stroke-width: 3; transition: stroke .2s, fill .2s; }
.scene .hot:hover, body.show-spots .scene .hot { stroke: var(--amber); fill: #ffb5471a; stroke-dasharray: 8 5; }
.scene .hot.found { }
.side { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.side section { padding: 12px; border-bottom: 1px solid var(--line); }
.side h4 { margin: 0 0 8px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.lock { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; }
.lock.done { border-color: #3fe0c566; }
.lock .lab { font-size: 13px; margin-bottom: 6px; display: flex; justify-content: space-between; }
.lock .fields { display: flex; gap: 6px; }
.lock input { font: 700 16px var(--mono); text-transform: uppercase; letter-spacing: .1em; padding: 9px; min-width: 0; }
.lock input::placeholder { text-transform: none; letter-spacing: 0; font: 400 13px system-ui, sans-serif; }
.lock .acts { display: flex; gap: 6px; margin-top: 8px; }
.lock .acts button { flex: 1; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.players { display: flex; flex-wrap: wrap; gap: 6px; }
.player { font-size: 12px; padding: 3px 8px 3px 6px; border-radius: 99px; background: var(--bg2); border: 1px solid var(--line); display: inline-flex; gap: 5px; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #555; display: inline-block; }
.dot.on { background: var(--teal); box-shadow: 0 0 6px var(--teal); }
.chat { flex: 1; display: flex; flex-direction: column; min-height: 140px; padding: 0 !important; }
.chat-log { flex: 1; overflow-y: auto; padding: 10px 12px; font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
.chat-log .m b { color: var(--amber); font-weight: 600; }
.chat-log .m.ai b { color: var(--violet); } .chat-log .m.gm b { color: var(--red); } .chat-log .m.sys { color: var(--muted); font-style: italic; }
.chat-in { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.chat-in input { padding: 9px; font-size: 13px; }
.reacts { display: flex; gap: 4px; padding: 0 8px 8px; }
.reacts button { background: var(--bg2); padding: 6px 8px; font-size: 15px; }
.inv { display: flex; gap: 8px; flex-wrap: wrap; min-height: 44px; }
.inv .item { width: 52px; height: 52px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line); display: grid; place-items: center; cursor: pointer; font-size: 26px; }
.inv .item:hover { border-color: var(--amber); }

/* story overlay */
.story { position: fixed; inset: 0; z-index: 90; background: radial-gradient(ellipse at 50% 30%, #13204acc, #030510f5); display: flex; align-items: safe center; justify-content: center; padding: 24px 20px; overflow-y: auto; animation: fade .4s; }
.story-box { max-width: 640px; width: 100%; }
.story-kicker { color: var(--amber); letter-spacing: .25em; text-transform: uppercase; font-size: 12px; margin-bottom: 10px; }
.story h2 { font-family: var(--serif); font-weight: 400; font-size: clamp(26px, 5vw, 40px); }
.story p { font-family: var(--serif); font-size: clamp(16px, 2.4vw, 19px); line-height: 1.7; color: #d7def0; opacity: 0; animation: rise .7s forwards; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ping marker */
.ping { position: absolute; pointer-events: none; width: 40px; height: 40px; margin: -20px 0 0 -20px; border-radius: 50%; border: 3px solid var(--teal); animation: pingA 1.6s ease-out forwards; z-index: 5; }
.ping::after { content: attr(data-name); position: absolute; top: 42px; left: 50%; transform: translateX(-50%); white-space: nowrap; font-size: 11px; color: var(--teal); background: #000a; padding: 1px 5px; border-radius: 4px; }
@keyframes pingA { 0% { transform: scale(.3); opacity: 1; } 70% { opacity: 1; } 100% { transform: scale(1.6); opacity: 0; } }
.float-react { position: absolute; font-size: 34px; pointer-events: none; animation: floatUp 2s ease-out forwards; z-index: 6; }
@keyframes floatUp { to { transform: translateY(-160px) scale(1.4); opacity: 0; } }

/* terminal */
.term { background: #021006; color: #5dff8a; font: 14px/1.45 var(--mono); padding: 14px; border-radius: 10px; height: min(62vh, 520px); overflow-y: auto; text-shadow: 0 0 6px #2bff6a88; border: 2px solid #0e3a1c; box-shadow: inset 0 0 60px #00ff4415; }
.term .who { color: #2e9a52; }
.term-in { display: flex; gap: 8px; margin-top: 8px; }
.term-in input { background: #021006; color: #5dff8a; font-family: var(--mono); border-color: #0e3a1c; }

/* hints */
.hint-item { background: var(--bg2); border-left: 3px solid var(--violet); padding: 10px 12px; border-radius: 8px; margin-bottom: 8px; }
.hint-item.sol { border-left-color: var(--red); }

/* lobby */
.member-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.member { display: flex; justify-content: space-between; padding: 10px 12px; background: var(--bg2); border-radius: 10px; }

@media (max-width: 860px) {
  .stage { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .side { border-left: 0; border-top: 1px solid var(--line); max-height: 46dvh; overflow-y: auto; }
  .side.collapsed .collapsible { display: none; }
  .hud .title { font-size: 15px; }
  .choice { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01s !important; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 860px) and (orientation: landscape) {
  .stage { grid-template-columns: 1fr 250px; grid-template-rows: 1fr; }
  .side { border-top: 0; border-left: 1px solid var(--line); max-height: none; }
  .side.collapsed { display: none; }
  .stage:has(.side.collapsed) { grid-template-columns: 1fr; }
  .hud { height: 46px; } .stage { height: calc(100dvh - 46px); }
  .icon-btn { width: 36px; height: 36px; }
}
@media (max-width: 520px) { .brand { font-size: 17px; white-space: nowrap; } .topbar .btn-sm { padding: 6px 8px; } }
