:root {
  --bg: #1b1712;
  --panel: #2b2620;
  --panel-light: #3a342b;
  --border: #5a4f3f;
  --gold: #d9b65a;
  --text: #e8e0d0;
  --muted: #a89e88;
  --good: #7bd47b;
  --bad: #e08a7b;
  --right-w: 300px;
  --bottom-h: 230px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: 1fr var(--right-w);
  grid-template-rows: 1fr var(--bottom-h);
  grid-template-areas:
    "game   right"
    "bottom right";
  height: 100vh;
  width: 100vw;
  gap: 4px;
  padding: 4px;
}

#game { grid-area: game; background: #000; border: 2px solid var(--border); overflow: hidden; }
#right-panel { grid-area: right; }
#bottom-panel { grid-area: bottom; }

/* ---- Right panel ---- */
#right-panel {
  background: var(--panel);
  border: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#minimap {
  height: 150px;
  background: #0c0a08;
  border-bottom: 2px solid var(--border);
}
#minimap canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }

#right-tabs { display: flex; border-bottom: 2px solid var(--border); }
.tab {
  flex: 1;
  padding: 8px 4px;
  background: var(--panel-light);
  color: var(--muted);
  border: none;
  border-right: 1px solid var(--border);
  cursor: pointer;
  font-weight: bold;
}
.tab:last-child { border-right: none; }
.tab.active { background: var(--panel); color: var(--gold); }

.tab-body { padding: 10px; overflow-y: auto; flex: 1; min-height: 0; }
.tab-body h3 { margin: 6px 0; color: var(--gold); font-size: 13px; text-transform: uppercase; letter-spacing: 1px; }
.tab-body ul { list-style: none; margin: 0 0 12px; padding: 0; }
.tab-body li { padding: 4px 0; font-size: 14px; border-bottom: 1px solid rgba(255,255,255,0.05); }

.action-row { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.action-row .charges { color: var(--muted); font-size: 12px; }
.action-row .keybind {
  background: var(--panel-light); border: 1px solid var(--border); border-radius: 3px;
  padding: 1px 6px; font-size: 12px; color: var(--gold); min-width: 20px; text-align: center;
}
.action-row.locked .charges { color: var(--bad); }

.score-table { width: 100%; font-size: 13px; margin-bottom: 14px; border-collapse: collapse; }
.score-table caption { color: var(--gold); text-align: left; font-weight: bold; padding-bottom: 4px; }
.score-table td { padding: 2px 4px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.score-table td:last-child { text-align: right; color: var(--gold); }

/* ---- Bottom panel ---- */
#bottom-panel {
  background: var(--panel);
  border: 2px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#dialogue-mode, #code-mode { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.hidden { display: none !important; }

#speaker { color: var(--gold); font-weight: bold; margin-bottom: 6px; }
#dialogue-text { flex: 1; font-size: 16px; line-height: 1.5; overflow-y: auto; }
#dialogue-actions { margin-top: 8px; display: flex; gap: 8px; }

button {
  background: var(--gold); color: #2b2620; border: none; border-radius: 4px;
  padding: 8px 16px; font-weight: bold; cursor: pointer; font-size: 14px;
}
button:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.5; cursor: default; }
button.secondary { background: var(--panel-light); color: var(--text); border: 1px solid var(--border); }

/* ---- Code mode ---- */
#code-header { display: flex; justify-content: space-between; margin-bottom: 4px; }
#code-title { color: var(--gold); font-weight: bold; }
#code-tier { color: var(--muted); font-size: 13px; }
#code-prompt { font-size: 14px; margin-bottom: 6px; color: var(--text); }
#code-editor-wrap { flex: 1; min-height: 0; display: flex; }
#code-input {
  flex: 1;
  background: #14110d;
  color: #e8e0d0;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 15px;
  padding: 8px;
  resize: none;
  line-height: 1.4;
  tab-size: 4;
}
#code-input:focus { outline: 1px solid var(--gold); }
#code-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 12px; }
#code-feedback { flex: 1; font-size: 14px; }
#code-feedback.good { color: var(--good); }
#code-feedback.bad { color: var(--bad); }

/* ---- Auth overlay ---- */
#auth-overlay {
  position: fixed; inset: 0; background: rgba(10,8,6,0.96);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.auth-box { text-align: center; }
.auth-box h1 { color: var(--gold); font-size: 48px; margin-bottom: 8px; }
.auth-box p { color: var(--muted); }
