:root {
  --bg: #111318;
  --surface: #1b1f27;
  --surface-alt: #252a35;
  --border: #384050;
  --text: #e6e8ee;
  --muted: #98a2b3;
  --accent: #e0a94f;
  --danger: #e05a5a;
  --success: #58c97a;
  --info: #78b7f2;
  --mana: #5da9ff;
  --font-mono: "JetBrains Mono", "Fira Code", Consolas, monospace;
  --font-sans: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  min-height: 100vh;
}

.screen {
  display: none;
  min-height: 100vh;
  padding: 1rem;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#screen-game.active {
  justify-content: flex-start;
  align-items: stretch;
  height: 100vh;
  overflow: hidden;
  padding: 0.75rem;
  gap: 0.75rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  width: 100%;
  max-width: 720px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.menu-card {
  max-width: 400px;
  text-align: center;
}

.title {
  margin: 0 0 0.25rem;
  font-size: 2.2rem;
  color: var(--accent);
}

.subtitle {
  margin: 0 0 1.5rem;
  color: var(--muted);
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.row-actions {
  flex-direction: row;
  justify-content: flex-end;
  margin-top: 1rem;
}

.btn {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  color: #141414;
  font-weight: 600;
  border-color: var(--accent);
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

input[type="text"],
select {
  width: 100%;
  padding: 0.5rem 0.65rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
}

.form-row {
  margin-bottom: 1rem;
}

.checkbox-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.checkbox-row label {
  margin: 0;
}

.creator-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0.35rem 0 0;
}

.creator-section {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.badge {
  font-size: 0.78rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  color: var(--accent);
}

.attr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.attr-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  text-align: center;
}

.attr-controls-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.skill-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.skill-item {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  font-size: 0.84rem;
  cursor: pointer;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
}

.hud-stats,
.hud-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.hud-pill {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.25rem 0.55rem;
  font-size: 0.85rem;
  font-family: var(--font-mono);
}

.hud-pill.hp { color: var(--danger); }
.hud-pill.stam { color: var(--success); }
.hud-pill.mana { color: var(--mana); }

.game-layout {
  display: grid;
  grid-template-columns: minmax(280px, 500px) 1fr;
  gap: 0.75rem;
  flex: 1;
  min-height: 0;
}

.game-layout.no-map {
  grid-template-columns: 1fr;
}

.map-panel[hidden],
.map-container[hidden] {
  display: none;
}

@media (max-width: 820px) {
  #screen-game.active {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  .game-layout {
    grid-template-columns: 1fr;
  }
}

.map-panel,
.log-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.map-container {
  display: flex;
  justify-content: safe center;
  align-items: safe center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem;
  max-width: 100%;
  overflow: auto;
}

.map-grid {
  display: grid;
  gap: 1px;
  font-family: var(--font-mono);
  user-select: none;
}

.map-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 1.35rem;
  font-size: 0.95rem;
}

.map-glyph .map-cell {
  height: 1.7rem;
  font-size: 1.05rem;
}

.map-svg-canvas {
  width: 100%;
  max-width: 416px;
  height: auto;
}

.cell-player { color: #7cf29c; font-weight: 700; }
.cell-hostile { color: var(--danger); font-weight: 700; }
.cell-friendly { color: var(--info); font-weight: 700; }
.cell-npc { color: var(--accent); }
.cell-wall { color: #70788a; }
.cell-tree { color: #4ba85c; }
.cell-water { color: #4d90d6; }
.cell-door { color: #d89b52; font-weight: 700; }
.cell-chair, .cell-wardrobe { color: #b5885a; }
.cell-item { color: #f5d15b; font-weight: 700; }
.cell-portal { color: #b68cff; font-weight: 700; }
.cell-skull { color: #e8e8e8; font-weight: 700; }
.cell-void { background: #000000; }
.cell-lit { background: rgba(255, 224, 102, 0.14); border-radius: 2px; }

.hud-level-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.xp-bar {
  width: 68px;
  height: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.xp-bar-lg {
  width: 100%;
  height: 10px;
  margin: 0.35rem 0 0.75rem;
}

.xp-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}

.stat-attr-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.cell-banner {
  background: var(--bg);
  border-left: 3px solid var(--accent);
  padding: 0.85rem 1rem;
  font-size: 0.98rem;
  line-height: 1.55;
  min-height: 15rem;
  max-height: 45vh;
  overflow-y: auto;
  border-radius: 4px;
  white-space: pre-wrap;
}

.last-output {
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.94rem;
  line-height: 1.5;
  max-height: 140px;
  overflow-y: auto;
  flex-shrink: 0;
}

.last-output-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.log-output {
  flex: 1;
  min-height: 150px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.94rem;
  line-height: 1.55;
}

.log-entry {
  margin-bottom: 0.45rem;
  white-space: pre-wrap;
}

.log-info { color: var(--text); }
.log-success { color: var(--success); }
.log-warn { color: var(--accent); }
.log-danger { color: var(--danger); }
.log-system { color: var(--muted); }
.log-cmd { color: var(--info); }

.hl-object { color: var(--color-object, #f5d15b); font-weight: 600; }
.hl-character { color: var(--color-character, #78b7f2); font-weight: 600; }
.hl-hostile { color: var(--color-hostile, #e05a5a); font-weight: 600; }
.hl-item { color: var(--color-item, #58c97a); font-weight: 600; }
.hl-location { color: var(--color-location, #e0a94f); font-weight: 600; }

.command-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
}

.command-suggestions[hidden] {
  display: none;
}

.suggestion-item {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  cursor: pointer;
}

.suggestion-item:hover,
.suggestion-item.active {
  border-color: var(--accent);
  color: var(--accent);
}

.command-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.55rem;
}

.prompt {
  color: var(--accent);
  font-family: var(--font-mono);
  font-weight: 700;
}

.command-form input {
  border: none;
  background: transparent;
  padding: 0.25rem;
  outline: none;
  font-family: var(--font-mono);
}

.mobile-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.mobile-controls[hidden] {
  display: none;
}

.dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.dpad-mid {
  display: flex;
  gap: 0.25rem;
}

.quick-verbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-window {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  color: var(--accent);
}

.modal-body {
  padding: 1rem;
  overflow-y: auto;
  font-size: 0.92rem;
}

.dialog-choices {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.85rem;
}

.inline-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  font-size: 0.92rem;
}

.inline-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.inline-dialog-header strong {
  color: var(--accent);
}

.inline-dialog-actions {
  display: flex;
  gap: 0.35rem;
}

.inline-dialog-text {
  margin: 0;
  line-height: 1.5;
}

.inline-dialog-hint {
  margin-top: 0.5rem;
  font-size: 0.84rem;
  color: var(--warn, #e0a94f);
}

.dialog-graph {
  margin-top: 1rem;
  padding: 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  white-space: pre-wrap;
}
