:root {
  --bg: #0b0d10;
  --panel: #12161b;
  --panel-line: #232a32;
  --deep: #0a0c0e;
  --accent: #5b7a95;
  --accent-dim: #2c3b47;
  --accent-bright: #8ab4d6;
  --flesh: #c1425a;
  --flesh-dim: #4a1f28;
  --warn: #e0a13c;
  --text: #d7e0e6;
  --text-dim: #7c8892;
  --mono: 'Courier New', ui-monospace, monospace;
  --serif: Georgia, 'Times New Roman', serif;
  --radius: 2px;
  --transition: 0.3s;
  --panel-shadow: 0 0 40px rgba(0,0,0,0.5);
  --text-glow: none;
  --action: #c1425a;
  --surface: var(--bg);
  --font-size: 12px;
  --font-size-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--mono);
  overflow: hidden;
  text-shadow: var(--text-glow);
}

/* pixel theme: no font smoothing */
body[data-theme="pixel"] { -webkit-font-smoothing: none; }

/* terminal theme: CRT scanline overlay */
body[data-theme="terminal"] #app::before {
  content: '';
  position: fixed; inset: 0; z-index: 9999;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px, transparent 2px,
    rgba(0,0,0,0.18) 2px, rgba(0,0,0,0.18) 4px
  );
  pointer-events: none;
}

/* --- Layout --- */
#app {
  display: flex; flex-direction: column;
  height: 100vh; width: 100vw;
  position: relative;
}

#status-bar {
  display: flex; gap: 40px; align-items: center;
  padding: 10px 24px;
  font-size: var(--font-size); letter-spacing: 1px; color: var(--text-dim);
  text-transform: uppercase;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-line);
  flex-shrink: 0;
}
#status-bar .val { color: var(--text); font-weight: bold; }

.status-bar-hp {
  display: inline-block; width: 80px; height: 8px;
  background: var(--deep); border: 1px solid var(--panel-line);
  vertical-align: middle; margin-left: 6px; overflow: hidden;
}
.status-bar-hp-fill {
  display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  transition: width var(--transition);
}

#main {
  display: flex; flex: 1; min-height: 0;
}

/* --- Left: Canvas Area --- */
#left {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; flex: 1;
  background:
    radial-gradient(ellipse at center, rgba(255,255,255,0.02), transparent 70%),
    var(--surface);
  position: relative;
}

#game-container {
  flex: 1;
  width: 100%; height: 100%;
  overflow: hidden;
}
#game-container canvas {
  display: block;
  width: 100% !important; height: 100% !important;
  image-rendering: pixelated;
}

/* --- Hotbar --- */
#hotbar {
  position: absolute; bottom: 16px;
  display: flex; gap: 4px;
}
.hotbar-slot {
  width: 68px; height: 56px;
  background: var(--panel); border: 1px solid var(--panel-line);
  color: var(--text); font-family: var(--mono);
  font-size: 11px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px;
  position: relative;
  text-transform: uppercase; letter-spacing: 1px;
  border-radius: var(--radius);
  text-shadow: var(--text-glow);
}
.hotbar-slot .hotkey {
  position: absolute; top: 2px; left: 4px;
  font-size: 9px; color: var(--text-dim);
}
.hotbar-slot .slot-name { font-size: 11px; font-weight: bold; }
.hotbar-slot .slot-cost { font-size: 9px; color: var(--text-dim); }
.hotbar-slot.selected { border-color: var(--accent); background: var(--panel); outline: 1px solid var(--accent); }
.hotbar-slot:hover:not(:disabled) { border-color: var(--accent-dim); }
.hotbar-slot:disabled { opacity: 0.35; cursor: not-allowed; }

/* --- Right: Sidebar --- */
#right {
  width: 340px; min-width: 340px;
  background: var(--panel);
  border-left: 1px solid var(--panel-line);
  display: flex; flex-direction: column;
}

.sidebar-section { padding: 12px 14px; }

#sidebar-vitals {
  border-bottom: 1px solid var(--panel-line);
  display: flex; flex-direction: column; gap: 10px;
}

.vitals {
  background: var(--deep); border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  padding: 8px 10px;
}
.vitals-label { font-size: var(--font-size-sm); color: var(--text-dim); letter-spacing: 2px; margin-bottom: 4px; }
#ekg { width: 100%; height: 44px; display: block; }

.stat-row { display: flex; justify-content: space-between; font-size: var(--font-size); margin-top: 4px; }
.bar-bg {
  width: 100%; height: 10px; background: var(--deep); border: 1px solid var(--panel-line);
  margin-top: 6px; overflow: hidden;
  border-radius: var(--radius);
}
.bar-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--flesh-dim), var(--flesh));
  transition: width var(--transition);
}
.bar-fill.core {
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
}

#controls { display: flex; gap: 8px; }
button.ctrl {
  flex: 1; background: var(--deep); border: 1px solid var(--panel-line); color: var(--text);
  font-family: var(--mono); font-size: var(--font-size); padding: 9px 4px; cursor: pointer;
  letter-spacing: 1px; text-transform: uppercase;
  border-radius: var(--radius);
  text-shadow: var(--text-glow);
}
button.ctrl:hover { border-color: var(--action); }

/* --- Log --- */
#sidebar-log {
  flex: 2; min-height: 0; overflow: hidden;
  padding: 0;
}
#log {
  height: 100%; overflow-y: auto;
  background: var(--deep);
  padding: 10px 12px; font-size: var(--font-size); line-height: 1.55;
}
#log .entry { margin-bottom: 9px; color: var(--text-dim); }
#log .entry.reveal {
  color: var(--flesh); font-size: 13px; border-left: 2px solid var(--flesh); padding-left: 8px;
}
#log .entry.sys { color: var(--accent); font-style: italic; }
#log .entry.elara { color: var(--text); }
#log .entry.tactical { color: var(--warn); }
#log::-webkit-scrollbar { width: 6px; }
#log::-webkit-scrollbar-thumb { background: var(--panel-line); }

/* --- Elara --- */
#sidebar-elara {
  flex: 3; min-height: 280px;
  padding: 0; position: relative;
  overflow: hidden;
  border-top: 1px solid var(--panel-line);
  background: var(--deep);
}
#elara-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 30% 60%, rgba(91,122,149,0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 40%, rgba(91,122,149,0.05) 0%, transparent 50%),
    linear-gradient(to bottom, #0c0f14, #0a0d12 40%, #080a0e);
  background-size: cover;
  z-index: 0;
  transition: filter var(--transition);
}
#elara-portrait-wrap {
  width: 100%; height: 100%;
  display: flex; align-items: flex-end; justify-content: center;
  overflow: hidden;
  position: relative; z-index: 1;
}
#elara-portrait-wrap::after {
  content: '';
  position: absolute; bottom: 0; left: 0; right: 0; height: 80px;
  background: linear-gradient(to top, var(--surface), transparent);
  z-index: 2; pointer-events: none;
}
#elara-portrait {
  width: 100%; height: 100%;
  object-fit: cover; object-position: top center;
  display: block;
  mix-blend-mode: lighten;
}
#elara-portrait:not([src]), #elara-portrait[src=""] {
  display: none;
}
#elara-dialogue {
  position: absolute; top: 12px; left: 8px; right: 8px;
  z-index: 4;
  background: rgba(10, 12, 14, 0.92);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-height: 52px;
  font-size: var(--font-size); line-height: 1.5;
  color: var(--text);
  display: none;
  text-shadow: var(--text-glow);
}
#elara-dialogue.visible { display: block; }
#elara-dialogue.dialogue-revelation {
  color: var(--flesh);
  font-family: var(--serif); font-style: italic;
  border-color: var(--flesh);
}
#elara-dialogue.dialogue-tactical {
  color: var(--warn);
  border-color: var(--warn);
}

/* --- Dev Shortcuts --- */
#dev-shortcuts-btn {
  position: absolute; bottom: 12px; left: 12px;
  width: 28px; height: 28px; z-index: 5;
  background: rgba(18,22,27,0.85); border: 1px solid var(--panel-line);
  color: var(--text-dim); font-family: var(--mono); font-size: 14px;
  cursor: pointer; line-height: 1;
  border-radius: var(--radius);
}
#dev-shortcuts-btn:hover { border-color: var(--accent); color: var(--text); }
#dev-shortcuts-panel {
  display: none;
  position: absolute; bottom: 48px; left: 12px; z-index: 5;
  background: rgba(10,12,14,0.95); border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  padding: 12px 16px; font-size: 11px; line-height: 1.8;
  color: var(--text-dim); min-width: 200px;
}
#dev-shortcuts-panel.visible { display: block; }
#dev-shortcuts-panel .dev-title {
  font-size: 10px; letter-spacing: 2px; color: var(--accent);
  margin-bottom: 6px; text-transform: uppercase;
}
#dev-shortcuts-panel kbd {
  display: inline-block; background: var(--deep); border: 1px solid var(--panel-line);
  padding: 1px 5px; font-family: var(--mono); font-size: 10px;
  color: var(--text); margin-right: 4px;
  border-radius: var(--radius);
}
#dev-shortcuts-panel .dev-current {
  margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--panel-line);
  font-size: 10px; color: var(--text-dim);
}

/* --- Overlay --- */
#overlay {
  position: absolute; inset: 0;
  background: rgba(6,7,9,0.92);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; text-align: center; gap: 16px;
  z-index: 10;
}
#overlay h1 {
  font-family: var(--serif); font-weight: normal; font-style: italic;
  font-size: 34px; color: var(--flesh); letter-spacing: 1px; margin: 0;
  text-shadow: var(--text-glow);
}
#overlay p { color: var(--text-dim); max-width: 480px; font-size: var(--font-size); line-height: 1.6; margin: 0; }
#overlay button {
  margin-top: 10px; background: transparent; border: 1px solid var(--action); color: var(--action);
  padding: 12px 26px; font-family: var(--mono); letter-spacing: 2px; text-transform: uppercase;
  cursor: pointer; font-size: var(--font-size);
  border-radius: var(--radius);
  text-shadow: var(--text-glow);
}
#overlay button:hover { background: var(--action); color: var(--bg); text-shadow: none; }
.hint { font-size: var(--font-size-sm); color: var(--text-dim); letter-spacing: 1px; }

/* --- Loading Screen --- */
#loading-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 10000;
  opacity: 1;
  transition: opacity 0.4s ease;
}
#loading-screen.fade-out { opacity: 0; pointer-events: none; }
.loading-content { text-align: center; }
.loading-title {
  font-family: 'Silkscreen', var(--mono);
  font-size: 1.8rem; letter-spacing: 0.3em; color: var(--text);
  margin-bottom: 0.4rem;
}
.loading-sub {
  font-size: var(--font-size-sm); color: var(--text-dim);
  letter-spacing: 0.15em; margin-bottom: 2rem;
}
.loading-track {
  width: 280px; height: 3px;
  background: var(--panel-line); margin: 0 auto 1rem;
}
.loading-fill {
  height: 100%; width: 0%;
  background: var(--accent);
  transition: width 0.1s ease;
}
.loading-status {
  font-size: var(--font-size-sm); color: var(--accent-dim);
  letter-spacing: 0.25em;
}
