:root {
  --brass: #d9a441;
  --brass-soft: rgba(217, 164, 65, 0.18);
  --panel: rgba(14, 12, 10, 0.72);
  --panel-border: rgba(217, 164, 65, 0.22);
  --ink: #f3ece0;
}

html, body.game { height: 100%; margin: 0; overflow: hidden; background: #050505; color: var(--ink); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#viewport { position: fixed; inset: 0; }
#viewport canvas { display: block; }

.hud-panel { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.kbd { display: inline-block; min-width: 1.6em; padding: 0 .4em; border: 1px solid rgba(255,255,255,.35); border-bottom-width: 2px; border-radius: 5px; font-size: .78em; font-weight: 600; text-align: center; background: rgba(255,255,255,.06); line-height: 1.6; }

/* crosshair & prompt */
#crosshair { position: fixed; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: rgba(255,255,255,.75); box-shadow: 0 0 4px rgba(0,0,0,.8); pointer-events: none; transition: all .12s; z-index: 5; }
#crosshair.active { width: 18px; height: 18px; margin: -9px 0 0 -9px; background: transparent; border: 2px solid var(--brass); box-shadow: 0 0 10px rgba(217,164,65,.5); }
.hud-prompt { position: fixed; left: 50%; top: calc(50% + 28px); transform: translateX(-50%); padding: .35rem .8rem; border-radius: 10px; background: var(--panel); border: 1px solid var(--panel-border); font-size: .95rem; white-space: nowrap; pointer-events: none; z-index: 5; }

#hudTop { position: fixed; left: 16px; top: 16px; padding: .55rem .9rem; z-index: 6; min-width: 220px; }
.hud-room { font-family: Georgia, "Times New Roman", serif; font-size: 1.1rem; color: var(--brass); letter-spacing: .02em; }
.hud-meta { font-size: .85rem; opacity: .85; }
#hudTimer { font-variant-numeric: tabular-nums; }

#hudRight { position: fixed; right: 16px; top: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; z-index: 6; }
.hud-buttons { display: flex; gap: 6px; }
.hud-btn { position: relative; width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--panel-border); background: var(--panel); color: var(--ink); font-size: 1.1rem; display: grid; place-items: center; backdrop-filter: blur(6px); transition: background .15s, border-color .15s; }
.hud-btn:hover { border-color: var(--brass); }
.hud-btn.active { background: rgba(217,164,65,.28); border-color: var(--brass); color: #fff; }
#lookHint { position: fixed; left: 50%; top: 16px; transform: translateX(-50%); padding: .4rem .9rem; border-radius: 999px; background: var(--panel); border: 1px solid var(--panel-border); backdrop-filter: blur(6px); font-size: .88rem; white-space: nowrap; pointer-events: none; z-index: 6; }
#lookHint[hidden] { display: none; }
body.mouse-free #viewport canvas { cursor: pointer; }
body.mouse-free #crosshair { opacity: .45; }
.hud-btn .badge { position: absolute; top: -6px; right: -6px; font-size: .65rem; }

#videoTiles { display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 140px); overflow-y: auto; }
.video-tile { position: relative; width: 200px; aspect-ratio: 4/3; border-radius: 12px; overflow: hidden; background: #111; border: 1px solid var(--panel-border); }
.video-tile video { width: 100%; height: 100%; object-fit: cover; }
.video-tile.self video { transform: scaleX(-1); }
.video-tile.audio-only { aspect-ratio: auto; height: 34px; }
.video-tile.audio-only video { display: none; }
.video-name { position: absolute; left: 6px; bottom: 6px; padding: 1px 8px; border-radius: 8px; background: rgba(0,0,0,.6); font-size: .78rem; }
.video-mic { position: absolute; right: 8px; bottom: 6px; color: #ff6b6b; }

#pendingPanel { position: fixed; right: 16px; bottom: 16px; width: 290px; display: flex; flex-direction: column; gap: 8px; z-index: 6; }
.pending-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--brass); padding-left: 2px; }
.pending-row { background: var(--panel); border: 1px solid rgba(240,196,25,.45); border-radius: 12px; padding: .6rem .7rem; backdrop-filter: blur(6px); animation: pop .3s ease-out; }
.pending-row.gate { border-color: rgba(120,180,255,.35); }

#heldBar { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); padding: .45rem 1rem; font-size: .9rem; z-index: 6; }

#netStatus { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); background: #7a1d1d; padding: .4rem 1rem; border-radius: 10px; z-index: 30; }

#toasts { position: fixed; top: 78px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 20; pointer-events: none; width: min(560px, calc(100vw - 32px)); }
.game-toast { pointer-events: auto; display: flex; align-items: center; gap: .6rem; width: 100%; padding: .55rem .8rem; border-radius: 12px; background: rgba(14,12,10,.88); border: 1px solid var(--panel-border); box-shadow: 0 8px 24px rgba(0,0,0,.35); animation: pop .25s ease-out; transition: opacity .4s; }
.game-toast.success i:first-child { color: #49d17a; }
.game-toast.warning i:first-child { color: #f0c419; }
.game-toast.solved { border-color: rgba(240,196,25,.6); }
.game-toast.solved i:first-child { color: #f0c419; }
.game-toast.info i:first-child { color: #7cc4ff; }
.game-toast.fade-out { opacity: 0; }
@keyframes pop { from { transform: translateY(-6px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }

/* chat */
#chat { position: fixed; left: 16px; bottom: 16px; width: min(380px, calc(100vw - 340px)); padding: .5rem; z-index: 6; transition: opacity .2s; }
#chat.collapsed #chatLog { display: none; }
#chatLog { max-height: 220px; overflow-y: auto; font-size: .86rem; margin-bottom: .4rem; padding-right: 4px; }
.chat-line { padding: 1px 2px; line-height: 1.35; word-wrap: break-word; }
.chat-line.system { color: #b9b1a3; font-style: italic; }
.chat-line.system.success { color: #8de0a7; }
.chat-time { color: #7d7466; font-size: .75em; }
.chat-name { font-weight: 600; }
#chatInput { background: rgba(0,0,0,.4); border-color: rgba(255,255,255,.12); color: var(--ink); }
#chatInput:focus { border-color: var(--brass); box-shadow: 0 0 0 .15rem var(--brass-soft); }

/* overlays */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(5,4,3,.62); backdrop-filter: blur(3px); z-index: 15; padding: 16px; }
.overlay[hidden] { display: none; }
.overlay.clickable { cursor: pointer; }
#overlayLoading { background: #050505; z-index: 40; }
.lobby-card { background: rgba(18,15,12,.92); border: 1px solid var(--panel-border); border-radius: 18px; padding: 1.6rem 1.8rem; max-width: 640px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.controls-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem 1.2rem; text-align: left; font-size: .92rem; }
.lobby-card h2 { font-family: Georgia, serif; }
.share-code { padding: .6rem .8rem; border: 1px dashed var(--panel-border); border-radius: 10px; }
.share-code strong { color: var(--brass); letter-spacing: .12em; font-size: 1.15rem; }
.lobby-players { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .6rem; }
.lobby-player { display: flex; align-items: center; gap: .6rem; padding: .5rem; border-radius: 12px; background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.08); }
.lobby-player img, .lobby-player > span { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; display: grid; place-items: center; font-size: 1.6rem; flex-shrink: 0; }
.player-dot { width: 30px; height: 30px; border-radius: 8px; display: inline-grid; place-items: center; }

/* modals */
.modal-content { background: #16130f; border: 1px solid var(--panel-border); }
.modal-title { font-family: Georgia, serif; color: var(--brass); }
.read-body { font-size: 1.05rem; line-height: 1.6; }
.read-body.style-note, .read-body.style-card { background: #efe3c4; color: #2d2433; padding: 1.4rem 1.6rem; border-radius: 6px; font-family: Georgia, "Times New Roman", serif; font-style: italic; box-shadow: inset 0 0 40px rgba(120,90,40,.25); }
.read-body.style-book { font-family: Georgia, serif; }
.read-body.style-plaque { background: linear-gradient(135deg,#b8893b,#e2c27a 45%,#9b7230); color: #2a1d08; padding: 1.2rem; border-radius: 6px; text-align: center; font-family: Georgia, serif; letter-spacing: .03em; }
.read-body.style-chalk { background: #23302a; color: #f2f2ea; padding: 1.4rem; border-radius: 6px; text-align: center; font-family: Georgia, serif; }
.chalk-circles { display: flex; justify-content: center; gap: 1.2rem; flex-wrap: wrap; }
.chalk-circle { width: 70px; height: 70px; border-radius: 50%; border: 5px solid; display: grid; place-items: end center; }
.chalk-circle span { transform: translateY(34px); font-weight: 700; font-size: 1.2rem; }
.read-body.style-chalk .chalk-circles { margin-bottom: 2.2rem; }

/* lock UIs */
.lock-modal .modal-body { padding: 1.6rem 1rem; }
.lock-ui { display: inline-block; }
.lock-ui.shake { animation: shake .45s; }
.lock-ui.ok { filter: drop-shadow(0 0 14px rgba(73,209,122,.7)); }
.lock-solved .lock-ui { opacity: .55; pointer-events: none; }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(5px); } 30%, 50%, 70% { transform: translateX(-9px); } 40%, 60% { transform: translateX(9px); } }

.keypad { background: linear-gradient(160deg,#9aa0a6,#5d6369); padding: 16px; border-radius: 14px; box-shadow: inset 0 1px 0 rgba(255,255,255,.4), 0 10px 30px rgba(0,0,0,.4); }
.keypad-screen { background: #031c0e; color: #3dff8f; font-family: "Courier New", monospace; font-size: 1.9rem; padding: .3rem .8rem; border-radius: 8px; margin-bottom: 12px; text-shadow: 0 0 8px rgba(61,255,143,.7); letter-spacing: .1em; box-shadow: inset 0 2px 8px rgba(0,0,0,.8); }
.keypad-grid { display: grid; grid-template-columns: repeat(3, 64px); gap: 9px; }
.keypad-key { height: 54px; border-radius: 10px; border: 0; background: linear-gradient(#2a2d31,#15171a); color: #eee; font-size: 1.35rem; font-weight: 600; box-shadow: 0 3px 0 #000, inset 0 1px 0 rgba(255,255,255,.15); }
.keypad-key:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; }
.keypad-key.clear { color: #ff8a8a; font-size: 1rem; }
.keypad-key.ok { color: #7dffad; font-size: 1rem; }

.wheels { background: linear-gradient(160deg,#c99a45,#7d5a1e); padding: 18px 22px; border-radius: 18px 18px 26px 26px; box-shadow: inset 0 2px 0 rgba(255,255,255,.35), 0 12px 30px rgba(0,0,0,.45); }
.wheels.letters { background: linear-gradient(160deg,#5e6266,#2e3134); }
.wheel-row { display: flex; gap: 10px; justify-content: center; }
.wheel { display: flex; flex-direction: column; align-items: center; gap: 4px; border-radius: 10px; padding: 2px; }
.wheel.selected .wheel-window { box-shadow: 0 0 0 2px #ffd36b, inset 0 6px 10px rgba(0,0,0,.85); }
.wheel-btn { border: 0; background: rgba(0,0,0,.25); color: #fff; width: 48px; border-radius: 8px; line-height: 1.4; }
.wheel-window { width: 52px; height: 104px; border-radius: 8px; overflow: hidden; background: linear-gradient(#0a0a0a, #2b2b2b 30%, #3a3a3a 50%, #2b2b2b 70%, #0a0a0a); box-shadow: inset 0 6px 10px rgba(0,0,0,.85); display: flex; flex-direction: column; justify-content: center; align-items: center; user-select: none; cursor: ns-resize; }
.wheel-cur { font-size: 2rem; font-weight: 700; color: #fff; line-height: 1.2; font-family: "Courier New", monospace; }
.wheel-prev, .wheel-next { font-size: 1.1rem; color: rgba(255,255,255,.3); font-family: "Courier New", monospace; }

.directional { background: linear-gradient(160deg,#8e959b,#454b51); padding: 18px; border-radius: 22px; box-shadow: 0 12px 30px rgba(0,0,0,.45); }
.dir-seq { min-height: 44px; background: #111; border-radius: 10px; padding: .45rem; margin-bottom: 12px; font-size: 1.4rem; color: #ffd36b; display: flex; gap: .3rem; justify-content: center; flex-wrap: wrap; }
.dir-seq .text-secondary { font-size: .85rem; align-self: center; }
.dir-pad { display: grid; grid-template-columns: repeat(3, 62px); grid-template-rows: repeat(3, 62px); gap: 6px; justify-content: center; }
.dir-pad button { border: 0; border-radius: 14px; background: linear-gradient(#2a2d31,#15171a); color: #fff; font-size: 1.5rem; box-shadow: 0 3px 0 #000; }
.dir-pad button:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; }
.dir-pad .dir-center { border-radius: 50%; background: radial-gradient(#d9a441,#7d5a1e); font-size: 1.2rem; }

.colors { background: linear-gradient(160deg,#3a3d42,#1d1f22); padding: 20px 24px; border-radius: 16px; box-shadow: 0 12px 30px rgba(0,0,0,.45); }
.color-leds { display: flex; gap: 10px; justify-content: center; margin-bottom: 16px; }
.color-led { width: 18px; height: 18px; border-radius: 50%; background: #2a2a2a; box-shadow: inset 0 2px 4px rgba(0,0,0,.8); }
.color-led.on { box-shadow: 0 0 10px currentColor, inset 0 -2px 4px rgba(0,0,0,.3); }
.color-buttons { display: flex; gap: 14px; justify-content: center; }
.color-btn { width: 66px; height: 66px; border-radius: 50%; border: 4px solid #111; background: radial-gradient(circle at 35% 30%, #fff8 0, var(--c) 30%, color-mix(in srgb, var(--c) 60%, #000) 100%); box-shadow: 0 5px 0 #000, 0 0 18px color-mix(in srgb, var(--c) 50%, transparent); }
.color-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #000; }

@media (max-width: 760px) {
  #chat { width: calc(100vw - 32px); bottom: 70px; }
  #pendingPanel { width: calc(100vw - 32px); bottom: 200px; }
  .video-tile { width: 120px; }
  .controls-grid { grid-template-columns: 1fr; }
}

.invite-box summary { cursor: pointer; color: var(--brass); }
.invite-box summary:hover { text-decoration: underline; }

@media (max-width: 900px) { #lookHint { top: auto; bottom: 64px; } }
