/* The game builder: the /app dashboard, the editor (/app/g/<id>) and the public games page (/games).
   Extends the dark design system from public.css. */

.bar { display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 18px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 10; }
.bar .grow { flex: 1; min-width: 0; }
.bar .hg-brand { text-decoration: none; display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--heading); }
.bar .hg-brand img { width: 22px; height: 22px; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--r); font: 500 13px/1 var(--mono); color: var(--fg); text-decoration: none; background: transparent; cursor: pointer; white-space: nowrap; }
.pill:hover { border-color: var(--fg-2); }
.pill .k { color: var(--fg-3); font-family: var(--sans); }
.plan-chip { font: 500 11px/1 var(--mono); text-transform: uppercase; letter-spacing: .08em; padding: 5px 7px; border: 1px solid var(--accent); border-radius: 4px; color: var(--accent); }
.plan-chip.free { border-color: var(--fg-3); color: var(--fg-3); }

.page { max-width: 1120px; margin: 0 auto; padding: 36px 24px 80px; }
.page h1 { font: 600 42px/1.05 var(--sans); letter-spacing: -.02em; margin: 0 0 6px; }
.page h2 { font: 600 28px/1.1 var(--sans); letter-spacing: -.01em; margin: 0; }
.page .lede { color: var(--fg-2); max-width: 60ch; margin: 0 0 26px; }
.section-row { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 44px 0 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }

.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.game-card { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); display: grid; grid-template-rows: 140px auto; overflow: hidden; text-decoration: none; color: inherit; transition: all .2s; }
.game-card:hover { border-color: var(--accent); }
.game-card .cover { background: var(--surface-2); display: grid; place-items: center; overflow: hidden; border-bottom: 1px solid var(--border); font: 600 34px/1 var(--sans); color: var(--fg-3); }
.game-card .cover img { width: 100%; height: 100%; object-fit: cover; }
.game-card .body { padding: 12px 14px 14px; display: grid; gap: 6px; }
.game-card .title { font-weight: 600; font-size: 15px; color: var(--heading); }
.game-card .meta { font: 12px/1.4 var(--mono); color: var(--fg-3); display: flex; gap: 10px; flex-wrap: wrap; }
.game-card .actions { display: flex; gap: 8px; margin-top: 4px; }

.templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.template { text-align: left; border: 1px solid var(--border-strong); border-radius: var(--r); padding: 12px 14px; background: var(--surface); cursor: pointer; font: inherit; color: inherit; display: grid; gap: 4px; transition: all .15s; }
.template:hover { border-color: var(--fg-2); }
.template.on { border-color: var(--accent); }
.template b { font-size: 14px; color: var(--heading); }
.template span { font-size: 12.5px; color: var(--fg-2); line-height: 1.4; }

.plans { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.plan { border: 1px solid var(--border); border-radius: var(--r-lg); padding: 20px; display: grid; gap: 10px; align-content: start; background: var(--surface); }
.plan.current { border-color: var(--accent); }
.plan .price { font: 700 40px/1 var(--sans); color: var(--heading); }
.plan .price small { font: 14px var(--sans); color: var(--fg-3); }
.plan ul { margin: 0; padding-left: 18px; color: var(--fg-2); font-size: 13.5px; }
.plan .btn { width: 100%; }
@media (max-width: 820px) { .plans { grid-template-columns: 1fr; } }

.notice { border: 1px solid var(--accent); border-radius: var(--r); padding: 12px 14px; margin: 0 0 18px; display: flex; gap: 12px; align-items: center; justify-content: space-between; background: var(--accent-glow); }
.notice[hidden] { display: none; }
.empty { border: 1px dashed var(--border-strong); border-radius: var(--r); padding: 36px; text-align: center; color: var(--fg-2); }
.auth-box { max-width: 420px; margin: 8vh auto; padding: 28px; border: 1px solid var(--border); border-radius: var(--r-lg); display: grid; gap: 14px; background: var(--surface); }
.auth-box h1 { font: 600 36px/1.05 var(--sans); margin: 0; }

/* ------------------------------------------------------------ immersive editor */
body.editor-page { height: 100vh; overflow: hidden; display: grid; grid-template-rows: 1fr; background: #000; }

/* HUD top bar: glass overlay on game */
.ed-topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  display: flex; align-items: center; gap: 12px; height: 48px; padding: 0 16px;
  background: var(--glass); backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border);
}
.ed-topbar .hg-brand { text-decoration: none; display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 600; font-size: 14px; }
.ed-topbar .hg-brand img { width: 18px; height: 18px; opacity: 0.8; }
.ed-topbar .grow { flex: 1; }
.title-input { font: 500 14px var(--sans); border: 1px solid transparent; background: none; color: #fff; padding: 4px 8px; border-radius: var(--r); width: min(320px, 100%); outline: none; }
.title-input:hover, .title-input:focus { border-color: var(--border-strong); background: var(--surface-2); }
.presence { display: flex; gap: 4px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; color: #fff; font: 600 11px var(--sans); border: 2px solid rgba(255,255,255,0.2); }
.save-state { font: 12px var(--mono); color: var(--fg-3); }

/* Full-screen game canvas */
.ed-game { position: fixed; inset: 0; z-index: 1; }
.ed-game canvas { width: 100%; height: 100%; display: block; outline: none; }

/* Side panel (files, assets) - slides from left */
.ed-panel {
  position: fixed; top: 48px; bottom: 0; left: 0; z-index: 40;
  width: 280px; padding-left: 48px; background: var(--glass); backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--border);
  transform: translateX(-100%); transition: transform 0.25s ease;
  overflow: auto; display: grid; align-content: start;
}
.ed-panel.open { transform: translateX(0); }

/* Code editor panel - slides from right */
.ed-code-panel {
  position: fixed; top: 48px; bottom: 0; right: 0; z-index: 40;
  width: 50%; min-width: 400px; max-width: 800px; padding-right: 48px;
  background: var(--glass); backdrop-filter: var(--glass-blur);
  border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform 0.25s ease;
  display: grid; grid-template-rows: auto auto auto 1fr;
}
.ed-code-panel.open { transform: translateX(0); }

.ed-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 10px 14px 6px; }
.ed-head .label { font-size: 10.5px; }
.ed-list { display: grid; padding: 0 8px 10px; }
.ed-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--r); cursor: pointer; font: 13px/1.3 var(--mono); color: var(--fg-2); border: 0; background: none; text-align: left; width: 100%; transition: all 0.1s; }
.ed-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.ed-item.on { background: var(--accent); color: #fff; }
.ed-item .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-item .who { display: flex; gap: 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.ed-item .thumb { width: 26px; height: 26px; flex: none; border: 1px solid var(--border); border-radius: 4px; background: var(--surface-3) center/cover no-repeat; display: grid; place-items: center; font: 9px var(--mono); color: var(--fg-3); }
.ed-item .x { opacity: 0; border: 0; background: none; color: inherit; cursor: pointer; padding: 0 2px; font-size: 13px; }
.ed-item:hover .x { opacity: .7; }
.gen-row { margin: 2px 8px; padding: 6px 8px; border: 1px dashed var(--border-strong); border-radius: var(--r); font: 12px/1.35 var(--sans); color: var(--fg-2); }
.gen-row.failed { border-color: var(--bad); color: var(--bad); }

.ed-code-head { display: flex; align-items: center; gap: 10px; padding: 0 14px; min-height: 36px; border-bottom: 1px solid var(--border); font: 12.5px var(--mono); color: var(--fg-2); }
.ed-code-head[hidden] { display: none; }
.ed-code-head.entity-head { background: rgba(74,158,255,0.06); border-bottom-color: var(--accent); }
.entity-tag { font: 600 9.5px var(--mono); text-transform: uppercase; letter-spacing: .08em; padding: 3px 7px; background: var(--accent); color: #fff; border-radius: 3px; }
.ed-code-head .grow { flex: 1; }
.ed-code-panel .CodeMirror { height: 100%; font: 13px/1.55 var(--mono); background: transparent; color: var(--fg); }
.ed-code-panel .CodeMirror-gutters { background: transparent; border-right: 1px solid var(--border); }
.ed-code-panel .CodeMirror-linenumber { color: var(--fg-3); }
.ed-code-panel .CodeMirror-cursor { border-left-color: var(--accent); }
.ed-code-panel .CodeMirror-selected { background: rgba(74,158,255,0.15) !important; }
.ed-code-panel .cm-keyword { color: var(--accent-2); }
.ed-code-panel .cm-string, .ed-code-panel .cm-string-2 { color: var(--ok); }
.ed-code-panel .cm-number, .ed-code-panel .cm-atom { color: var(--warn); }
.ed-code-panel .cm-comment { color: var(--fg-3); font-style: italic; }
.ed-code-panel .cm-def, .ed-code-panel .cm-property { color: var(--fg); }
.ed-code-panel .cm-variable-2 { color: var(--fg-2); }
.remote-line { background: rgba(168,85,247,0.08); }
.err-line { background: var(--bad-glow); }
.conflict { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--bad); background: var(--bad-glow); font-size: 13px; }

/* AI HUD overlay - bottom center, the main interaction */
.ed-hud {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center;
  pointer-events: none;
}
.ed-hud > * { pointer-events: auto; }

.ed-hud-chat {
  width: min(680px, calc(100% - 32px));
  max-height: 50vh;
  margin-bottom: 16px;
  display: flex; flex-direction: column;
  background: var(--glass); backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.ed-hud-chat.collapsed .chat-log { display: none; }
.ed-hud-chat.collapsed .thinking { display: none; }

.chat-log {
  overflow: auto; padding: 16px; display: grid; gap: 12px; align-content: start;
  max-height: 35vh; min-height: 0;
}
.msg { display: grid; gap: 4px; font-size: 13.5px; line-height: 1.5; }
.msg .who { font: 500 11px/1 var(--mono); color: var(--fg-3); text-transform: uppercase; letter-spacing: .06em; }
.msg.ai .text { border-left: 2px solid var(--accent); padding-left: 10px; color: var(--fg); }
.msg.system { color: var(--fg-3); font-size: 12.5px; }
.msg .text { white-space: pre-wrap; word-wrap: break-word; }
.msg .changed { font: 12px var(--mono); color: var(--fg-2); }
.msg .sugg { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border-strong); border-radius: var(--r); padding: 6px 8px; font-size: 12.5px; background: var(--surface-2); }
.msg .sugg .grow { flex: 1; min-width: 0; }

.chat-input {
  border-top: 1px solid var(--border); padding: 10px 14px;
  display: flex; gap: 10px; align-items: flex-end;
}
.chat-input textarea {
  flex: 1; min-height: 42px; max-height: 120px; resize: none;
  padding: 10px 14px; border: 1px solid var(--border-strong); border-radius: var(--r);
  background: var(--surface-2); color: var(--fg); font: 14px/1.45 var(--sans); outline: none;
  transition: border-color 0.15s;
}
.chat-input textarea:focus { border-color: var(--accent); }
.chat-input textarea::placeholder { color: var(--fg-3); }
.chat-cost { font-size: 11px; color: var(--fg-3); padding: 4px 0; white-space: nowrap; }
.thinking { color: var(--accent); font-size: 12.5px; font-style: italic; padding: 4px 14px; }

/* Error indicator - sleek red pill, bottom right */
.ed-errors {
  position: fixed; bottom: 16px; right: 16px; z-index: 35;
}
.ed-error-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--r);
  background: var(--bad); color: #fff;
  font: 500 12px var(--mono); cursor: pointer;
  box-shadow: 0 4px 16px rgba(239,68,68,0.3);
  transition: all 0.15s;
}
.ed-error-pill:hover { box-shadow: 0 4px 24px rgba(239,68,68,0.5); }
.ed-error-pill .count { font-weight: 700; }

.ed-error-panel {
  position: absolute; bottom: calc(100% + 8px); right: 0;
  width: 400px; max-height: 300px; overflow: auto;
  background: var(--surface); border: 1px solid var(--bad);
  border-radius: var(--r-lg); padding: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.ed-error-panel .err { color: var(--bad); font: 12px/1.5 var(--mono); padding: 4px 0; border-bottom: 1px solid var(--border); }
.ed-error-panel .err:last-child { border: 0; }
.ed-error-panel .ln { cursor: pointer; text-decoration: underline; color: var(--accent); }

/* HUD action buttons */
.hud-actions {
  position: fixed; top: 56px; z-index: 45;
  display: flex; flex-direction: column; gap: 6px;
}
.hud-actions.left { left: 8px; }
.hud-actions.right { right: 8px; }

.hud-btn {
  width: 36px; height: 36px; border-radius: var(--r);
  background: var(--glass); backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border); color: var(--fg-2);
  display: grid; place-items: center; cursor: pointer;
  font-size: 15px; transition: all 0.15s;
  position: relative;
}
.hud-btn:hover { background: var(--surface-2); color: #fff; }
.hud-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Docs panel (shown in side panel) */
.docs { padding: 4px 16px 30px; font-size: 13.5px; }
.docs h1 { font: 600 24px/1.1 var(--sans); margin: 14px 0 8px; }
.docs h2 { font: 600 20px/1.15 var(--sans); margin: 22px 0 8px; }
.docs pre { background: var(--surface-2); border: 1px solid var(--border); padding: 10px; overflow: auto; font-size: 12px; border-radius: var(--r); }
.docs table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.docs td, .docs th { border-bottom: 1px solid var(--border); padding: 5px 6px; text-align: left; vertical-align: top; }
.docs code { background: var(--surface-2); padding: 0 3px; border-radius: 2px; }

.settings { padding: 14px 16px 30px; display: grid; gap: 18px; font-size: 13.5px; }
.settings section { display: grid; gap: 8px; }
.release { display: flex; gap: 10px; align-items: center; border-bottom: 1px solid var(--border); padding: 8px 0; }
.release .grow { flex: 1; min-width: 0; }
.release .v { font: 600 13px var(--mono); color: #fff; }
.release .live { font: 500 10.5px var(--mono); color: var(--ok); border: 1px solid var(--ok); border-radius: 4px; padding: 2px 4px; }

/* Console (in error panel) */
.console { font: 12px/1.5 var(--mono); padding: 8px 12px; display: grid; gap: 2px; }
.console .err { color: var(--bad); }
.console .ln { cursor: pointer; text-decoration: underline; text-decoration-color: var(--border-strong); }

@media (max-width: 900px) {
  body.editor-page { overflow: auto; height: auto; }
  .ed-code-panel { width: 100%; min-width: 0; }
  .ed-panel { width: 100%; }
  .ed-hud-chat { width: calc(100% - 16px); }
}

/* ------------------------------------------------------------ boot sequence overlay */
.boot-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: #050508;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 1s ease;
}
.boot-overlay.fade-out { opacity: 0; pointer-events: none; }

.boot-content { text-align: center; max-width: 520px; width: 100%; padding: 40px; }
.boot-logo {
  font: 700 32px var(--mono); color: var(--accent);
  letter-spacing: 0.25em; opacity: 0;
  transition: opacity 0.4s ease;
}
.boot-logo.visible { opacity: 1; }
.boot-sub {
  font: 500 12px var(--mono); color: var(--fg-3);
  letter-spacing: 0.4em; margin-top: 6px; opacity: 0;
  transition: opacity 0.4s ease 0.2s;
}
.boot-sub.visible { opacity: 1; }

.boot-lines { margin-top: 40px; text-align: left; }
.boot-line {
  font: 13px/1.7 var(--mono); color: var(--fg-3); margin: 0;
  min-height: 22px;
}
.boot-line.accent { color: var(--accent); }
.boot-line.bright { color: #fff; font-weight: 500; }
.boot-line.intro { color: var(--accent); font-size: 14px; }

.boot-cursor {
  display: inline-block; width: 8px; height: 14px;
  background: var(--accent); vertical-align: text-bottom;
  margin-left: 1px; animation: cursor-blink 0.5s step-end infinite;
}
@keyframes cursor-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

.boot-scanline {
  position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.04) 2px, rgba(0,0,0,0.04) 4px);
}
.boot-scanline::after {
  content: ''; position: absolute; left: 0; right: 0; height: 120px;
  background: linear-gradient(rgba(74,158,255,0.04), transparent);
  animation: boot-scan 3.5s linear infinite;
}
@keyframes boot-scan { 0% { top: -120px; } 100% { top: 100%; } }

/* ------------------------------------------------------------ voice toggle */
.hud-btn.voice-on { background: rgba(168,85,247,0.2); border-color: var(--accent-2); color: var(--accent-2); }
.hud-btn.voice-on:hover { background: rgba(168,85,247,0.3); }
.hud-btn.voice-off { color: var(--fg-3); }

/* ------------------------------------------------------------ chat message animation */
.msg.new { animation: msg-in 0.35s ease both; }
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.msg.ai.typing .text { border-left-color: var(--accent-2); }
.msg.ai.typing .text::after {
  content: ''; display: inline-block; width: 7px; height: 13px;
  background: var(--accent); vertical-align: text-bottom; margin-left: 2px;
  animation: cursor-blink 0.5s step-end infinite;
}

/* ------------------------------------------------------------ profile dropdown */
.profile-btn { background: none; border: 0; cursor: pointer; padding: 2px; border-radius: 50%; transition: all 0.15s; }
.profile-btn:hover { background: var(--surface-2); }
.profile-avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; font: 600 12px var(--sans); }
.profile-dropdown {
  position: fixed; top: 58px; right: 16px; z-index: 200;
  width: 260px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 8px 0;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.profile-dropdown[hidden] { display: none; }
.profile-info { padding: 12px 16px; }
.profile-info .name { font: 600 14px var(--sans); color: var(--heading); }
.profile-info .email { font: 12px var(--sans); color: var(--fg-3); margin-top: 2px; }
.profile-info .plan { font: 11px var(--mono); color: var(--accent); margin-top: 6px; }
.profile-sep { height: 1px; background: var(--border); margin: 4px 0; }
.profile-friends { padding: 8px 16px; }
.profile-friends .profile-friends-head { font: 500 11px var(--sans); text-transform: uppercase; letter-spacing: .06em; color: var(--fg-3); margin-bottom: 6px; }
.profile-friends .friend-mini { display: flex; align-items: center; gap: 8px; padding: 4px 0; font: 13px var(--sans); color: var(--fg-2); }
.profile-friends .friend-mini .dot { width: 8px; height: 8px; border-radius: 50%; }
.profile-friends .none { font: 12px var(--sans); color: var(--fg-3); }
.profile-link {
  display: block; width: 100%; padding: 8px 16px; font: 14px var(--sans); color: var(--fg-2);
  text-decoration: none; text-align: left; border: 0; background: none; cursor: pointer;
  transition: all 0.1s;
}
.profile-link:hover { background: var(--surface-2); color: var(--heading); }

/* ------------------------------------------------------------ friends */
.friends-list { display: grid; gap: 6px; }
.friend-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); }
.friend-row .friend-avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: #fff; font: 600 13px var(--sans); flex: none; }
.friend-row .friend-name { flex: 1; font: 500 14px var(--sans); color: var(--heading); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.friend-row .friend-since { font: 12px var(--mono); color: var(--fg-3); }
.friend-row .btn { opacity: 0; transition: opacity .15s; }
.friend-row:hover .btn { opacity: 1; }
.friends-empty { color: var(--fg-3); font-size: 14px; padding: 12px 0; }

/* ------------------------------------------------------------ overseer games */
.overseer-card { border-color: rgba(74,158,255,0.2); }
.overseer-card:hover { border-color: var(--accent); box-shadow: 0 4px 20px rgba(74,158,255,0.1); }
.overseer-card .cover { border-bottom-color: rgba(74,158,255,0.15); }

/* ------------------------------------------------------------ public games */
.gallery-head { display: flex; gap: 12px; align-items: end; justify-content: space-between; margin-bottom: 18px; }

/* The signed-out header must not show the account bits (an inline display or .btn beat the hidden attribute), and phones get a header that fits 390px. */
.bar #who[hidden], .bar #studioLink[hidden] { display: none !important; }
.gallery-head > * { min-width: 0; }
@media (max-width: 560px) {
  .bar { padding: 0 12px; gap: 8px; }
  .bar #studioLink, .bar .plan-chip { display: none !important; }
  .gallery-head { flex-wrap: wrap; align-items: stretch; }
  .gallery-head .segmented { flex: 1 1 100%; }
  .gallery-head .segmented button { padding: 8px 6px; white-space: nowrap; }
  .auth-box { margin: 4vh 16px; max-width: none; padding: 22px; }
}
