:root {
  --bg: #0f1020; --panel: rgba(18, 19, 36, .92); --panel2: #1c1e36; --line: rgba(255,255,255,.1);
  --text: #f1f2f8; --muted: #9aa0c0; --accent: #ff4d8d; --accent2: #3fd0ff; --ok: #39d98a; --warn: #ffd23f; --err: #ff6b6b;
  --radius: 12px; font-family: "Segoe UI", Inter, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--err); min-height: 1.2em; font-size: 13px; margin: 6px 0 0; }

.screen { position: fixed; inset: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; background: #0d0e1c; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent2); box-shadow: 0 0 0 2px rgba(63,208,255,.2); }
input[type=color] { padding: 2px; height: 36px; cursor: pointer; }
label { display: block; font-size: 13px; color: var(--muted); margin: 8px 0; }
label > input, label > select { margin-top: 4px; color: var(--text); }

.btn {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 14px; cursor: pointer;
  transition: transform .08s, background .15s, border-color .15s; white-space: nowrap;
}
.btn:hover { border-color: rgba(255,255,255,.3); background: #262848; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, #ff4d8d, #ff8a3d); border: none; font-weight: 700; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { padding: 11px 20px; font-size: 15px; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn.audio { background: linear-gradient(135deg, #2b2d6e, #3a2b6e); border-color: rgba(167,139,250,.5); font-weight: 600; }
.btn.danger { border-color: rgba(255,107,107,.5); color: #ffb3b3; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- auth ---------- */
#auth-bg { position: absolute; inset: 0; width: 100%; height: 100%; }
.auth-card {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(420px, 92vw);
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px; backdrop-filter: blur(8px);
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.logo { margin: 0; font-size: 30px; letter-spacing: .5px; background: linear-gradient(90deg, #ff4d8d, #ffd23f, #3fd0ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tagline { color: var(--muted); margin: 6px 0 18px; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab { flex: 1; background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 8px; cursor: pointer; color: var(--muted); }
.tab.active { background: var(--panel2); color: var(--text); border-color: rgba(255,255,255,.3); }
#auth-form .btn { width: 100%; margin-top: 10px; }
.bridge-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 99px; font-size: 12.5px; font-weight: 600;
  background: rgba(124,131,255,.15); border: 1px solid rgba(124,131,255,.45); color: #c9ccff; white-space: nowrap;
}
.bridge-pill.online { background: rgba(57,217,138,.15); border-color: rgba(57,217,138,.5); color: #a8ffd0; }
.auth-card .bridge-pill { margin-top: 16px; }

/* ---------- creator ---------- */
#creator-screen { overflow: auto; background: radial-gradient(ellipse at top, #24204a, #0f1020 60%); }
.creator { display: grid; grid-template-columns: minmax(340px, 560px) 360px; gap: 28px; max-width: 980px; margin: 28px auto; padding: 0 16px; }
.creator-form { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 22px; }
.creator-form h2 { margin: 0 0 4px; }
.field-title { margin: 16px 0 6px; font-weight: 700; font-size: 14px; }
.field-title.small { margin: 10px 0 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.role-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.role-card { background: #0d0e1c; border: 1px solid var(--line); border-radius: 10px; padding: 8px 4px; cursor: pointer; text-align: center; font-size: 12px; }
.role-card .em { font-size: 22px; display: block; }
.role-card.sel { border-color: var(--accent); background: rgba(255,77,141,.12); box-shadow: 0 0 0 1px var(--accent) inset; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.sw { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; box-shadow: 0 0 0 1px rgba(255,255,255,.15); }
.sw.sel { border-color: #fff; transform: scale(1.1); }
.check { display: flex; gap: 8px; align-items: center; color: var(--text); }
.check input { width: auto; }
.creator-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.creator-preview { position: sticky; top: 20px; align-self: start; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; text-align: center; }
#cc-avatar { background: radial-gradient(circle at 50% 70%, #3a3f6e, #15162a 70%); border-radius: 14px; width: 100%; max-width: 320px; }
#cc-lot { background: #4f8a3c; border-radius: 12px; width: 100%; max-width: 300px; }
.preview-name { font-size: 18px; font-weight: 800; margin: 8px 0 2px; }

/* ---------- game ---------- */
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: auto; }
.topbar {
  position: absolute; top: 0; left: 0; right: 0; display: flex; gap: 8px; align-items: center; padding: 8px 12px;
  background: linear-gradient(180deg, rgba(10,11,24,.92), rgba(10,11,24,.65)); border-bottom: 1px solid var(--line); z-index: 5;
}
.brand { font-weight: 800; font-size: 16px; margin-right: 6px; }
.spacer { flex: 1; }
.where { font-size: 13px; color: var(--muted); margin-right: 4px; }
#minimap { position: absolute; right: 12px; top: 60px; border-radius: 10px; border: 1px solid var(--line); background: rgba(10,11,24,.8); z-index: 4; }
.hint {
  position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); background: rgba(10,11,24,.88); border: 1px solid rgba(255,210,63,.6);
  color: #ffe9a8; padding: 8px 14px; border-radius: 10px; font-weight: 600; font-size: 14px; pointer-events: none; z-index: 4;
}
.hint:empty { display: none; }
.controls-help { position: absolute; right: 12px; bottom: 10px; font-size: 11.5px; color: rgba(255,255,255,.55); z-index: 3; }

.panel { position: absolute; right: 12px; top: 210px; width: 260px; max-height: calc(100% - 280px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; z-index: 4; }
.panel h3 { margin: 0 0 8px; font-size: 15px; }
#members-list { list-style: none; margin: 0; padding: 0; }
#members-list li { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-bottom: 1px solid var(--line); font-size: 13px; }
#members-list li canvas { flex: none; }
#members-list .m-info { flex: 1; min-width: 0; }
#members-list .m-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#members-list .m-where { color: var(--muted); font-size: 11.5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #555; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }

.chat { position: absolute; left: 12px; bottom: 12px; width: min(420px, 60vw); z-index: 4; }
.chat-log { max-height: 190px; overflow: auto; display: flex; flex-direction: column; gap: 3px; margin-bottom: 6px; mask-image: linear-gradient(transparent, #000 25%); padding-top: 20px; }
.chat-line { background: rgba(10,11,24,.72); padding: 4px 9px; border-radius: 8px; font-size: 13px; width: fit-content; max-width: 100%; word-wrap: break-word; }
.chat-line .who { font-weight: 700; }
.chat-line.sys { color: #ffe9a8; font-style: italic; }
.chat-line .scope { font-size: 10.5px; color: var(--muted); margin-right: 4px; }
#chat-form { display: flex; gap: 6px; }
#chat-scope { width: 140px; flex: none; }
#chat-input { background: rgba(13,14,28,.88); }

.interior { position: absolute; inset: 0; background: rgba(5,5,12,.7); display: flex; align-items: center; justify-content: center; z-index: 8; backdrop-filter: blur(3px); }
.interior-box { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 16px; width: min(1180px, 96vw); max-height: 94vh; overflow: auto; box-shadow: 0 20px 70px rgba(0,0,0,.6); }
.interior-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.interior-head h2 { margin: 0; font-size: 20px; }
.interior-body { display: grid; grid-template-columns: minmax(0, 760px) 1fr; gap: 14px; align-items: start; }
#int-canvas { width: 100%; border-radius: 12px; background: #000; display: block; }
.interior-side { font-size: 13.5px; }
.interior-side h4 { margin: 12px 0 6px; font-size: 14px; }
.interior-side ul { margin: 0; padding-left: 18px; }
.interior-side li { margin: 3px 0; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 700; background: rgba(255,255,255,.08); border: 1px solid var(--line); }
.badge.step { background: rgba(255,210,63,.15); border-color: rgba(255,210,63,.5); color: #ffe9a8; }
.badge.ok { background: rgba(57,217,138,.15); border-color: rgba(57,217,138,.5); color: #a8ffd0; }
.badge.work { background: rgba(63,208,255,.15); border-color: rgba(63,208,255,.5); color: #bdefff; }
.badge.err { background: rgba(255,107,107,.15); border-color: rgba(255,107,107,.5); color: #ffc2c2; }
.box { background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 8px 0; }
.box textarea { margin: 6px 0; }
pre.json { background: #0b0c18; border: 1px solid var(--line); border-radius: 8px; padding: 8px; max-height: 180px; overflow: auto; font-size: 11px; }

.modal { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(5,5,12,.65); z-index: 9; }
.modal-box { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: min(640px, 94vw); max-height: 88vh; overflow: auto; }
.modal-box h2 { margin-top: 0; }
.modal-close { position: absolute; top: 10px; right: 10px; background: transparent; border: none; font-size: 18px; cursor: pointer; color: var(--muted); }
.notes { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-top: 12px; }
.note { color: #222; padding: 10px; border-radius: 4px; box-shadow: 0 4px 10px rgba(0,0,0,.35); font-size: 13.5px; position: relative; min-height: 90px; word-wrap: break-word; }
.note .meta { font-size: 11px; color: rgba(0,0,0,.55); margin-top: 8px; }
.note .del { position: absolute; top: 4px; right: 6px; border: none; background: transparent; cursor: pointer; color: rgba(0,0,0,.45); }
.qtable { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.qtable th, .qtable td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); }
.qtable th { color: var(--muted); font-weight: 600; }

.toasts { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 10; align-items: center; }
.toast { background: var(--panel); border: 1px solid rgba(255,210,63,.5); padding: 10px 16px; border-radius: 10px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: pop .25s ease-out; }
@keyframes pop { from { transform: translateY(-8px); opacity: 0; } }

@media (max-width: 900px) {
  .creator { grid-template-columns: 1fr; }
  .creator-preview { position: static; }
  .interior-body { grid-template-columns: 1fr; }
  .controls-help, .where { display: none; }
}
