:root {
  --bg: #16141c;
  --panel: #201d29;
  --panel-border: #34303f;
  --text: #e8e4f0;
  --text-dim: #9a92ab;
  --accent: #b18cff;
  --accent-dim: #6d5a94;
  --dm-color: #8cc7ff;
  --player-color: #ffd68c;
  --system-color: #9a92ab;
  --danger: #c0504d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, "Iowan Old Style", serif;
  min-height: 100vh;
}

/* Background art (renderScene in app.js): fixed behind everything,
   dimmed so the solid panels and their text stay easy to read. */
.scene {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity 1.2s ease;
  pointer-events: none;
}

.scene::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(22, 20, 28, 0.55), rgba(22, 20, 28, 0.8));
}

.scene.visible {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .scene {
    transition: none;
  }
}

header {
  text-align: center;
  padding: 2rem 1rem 1rem;
}

header h1 {
  margin: 0;
  font-size: 2.2rem;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.tagline {
  color: var(--text-dim);
  margin: 0.3rem 0 0;
  font-style: italic;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
}

/* Game screen needs room for the story column + character/inventory/
   journal sidebar side by side -- wider than chargen's single-form
   640px. */
#screen-game {
  max-width: 1100px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 1.5rem;
}

.panel h2 {
  margin-top: 0;
  color: var(--accent);
}

label {
  display: block;
  margin: 1rem 0 0.3rem;
  color: var(--text-dim);
  font-size: 0.9rem;
}

input[type="text"],
input[type="email"],
select,
textarea {
  width: 100%;
  padding: 0.6rem;
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}

textarea {
  resize: vertical;
}

.stats-section {
  margin-top: 1.5rem;
}

.stat-block {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-top: 0.8rem;
}

.stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 0.5rem 0.8rem;
}

.stat-name {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.stat-score {
  font-size: 1.1rem;
  font-weight: bold;
}

.stat-mod {
  color: var(--accent);
  font-size: 0.9rem;
}

button {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.6rem 1.2rem;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

button.primary {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: white;
}

button.secondary {
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
}

button:hover {
  filter: brightness(1.15);
}

#create-char-btn {
  margin-top: 1.5rem;
  width: 100%;
}

/* Game screen */

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--panel-border);
  margin-bottom: 1rem;
}

.game-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.location {
  margin: 0.2rem 0 0;
  color: var(--text-dim);
  font-style: italic;
  font-size: 0.9rem;
}

.game-header-right {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}

.hp {
  color: var(--accent);
  font-weight: bold;
}

.encounter-status {
  margin: 0.8rem 0;
  padding: 0.6rem 0.9rem;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.log {
  height: 55vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.log-entry {
  line-height: 1.5;
}

.log-dm {
  color: var(--dm-color);
}

/* Report this AI text: a small flag after each story line (app.js renderLogEntry) */
.log-flag {
  background: none;
  border: none;
  padding: 0 0.3rem;
  margin-left: 0.3rem;
  font-size: 0.8rem;
  color: var(--text);
  opacity: 0.45;
  cursor: pointer;
  vertical-align: baseline;
}
.log-flag:hover, .log-flag:focus-visible { opacity: 1; }
.log-flag:disabled { opacity: 0.35; cursor: default; }
.ai-report-quote {
  margin: 0 0 0.8rem;
  padding: 0.5rem 0.8rem;
  border-left: 3px solid var(--accent);
  max-height: 8rem;
  overflow-y: auto;
  font-size: 0.9rem;
  opacity: 0.85;
}
.ai-report-reasons {
  border: none;
  padding: 0;
  margin: 0 0 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.ai-report-reasons legend { margin-bottom: 0.4rem; }

.log-player {
  color: var(--player-color);
  text-align: right;
}

.log-player::before {
  content: "> ";
  color: var(--text-dim);
}

.log-system {
  color: var(--system-color);
  font-style: italic;
  text-align: center;
  font-size: 0.9rem;
}

.input-row {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
}

.input-row input {
  flex: 1;
}

footer {
  max-width: 640px;
  margin: 2rem auto 1rem;
  padding: 0 1rem;
  text-align: center;
}

footer p {
  color: var(--text-dim);
  font-size: 0.75rem;
  line-height: 1.4;
}

footer a {
  color: var(--accent-dim);
}

/* Class details (spell/feature picker) */

.class-details {
  margin-top: 1.5rem;
  border-top: 1px solid var(--panel-border);
  padding-top: 1rem;
}

.class-details-empty {
  color: var(--text-dim);
  font-style: italic;
  font-size: 0.9rem;
}

.feature-item {
  margin-bottom: 0.8rem;
}

.feature-item strong {
  color: var(--accent);
}

.feature-item p {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.class-details h4 {
  margin: 1rem 0 0.3rem;
  color: var(--accent);
  font-size: 0.95rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.pick-count {
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: normal;
}

.pick-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.pick-item {
  font-size: 0.9rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  cursor: pointer;
}

.pick-item input {
  width: auto;
}

.spell-meta {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.stat-method-hint {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0.4rem 0;
}

.stat-assign-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.9rem;
  padding: 0.2rem 0;
}

.point-buy-row .point-buy-score {
  min-width: 1.5rem;
  text-align: center;
  font-weight: bold;
}

.point-buy-row button {
  padding: 0.2rem 0.6rem;
  font-size: 0.9rem;
}

/* ---------- Game screen layout: story column + tabbed sidebar ---------- */
/* See BACKEND.md's "Dedicated UI" section -- the story column (log +
   input) is unchanged from before; Character/Inventory/Journal were
   previously only reachable as typed commands and are now persistent
   panels reading the same real gameState/character data. */

.game-layout {
  display: flex;
  gap: 1.2rem;
  align-items: flex-start;
}

.game-story {
  flex: 1 1 60%;
  min-width: 0; /* lets .log's overflow-y actually constrain width in a flex child */
}

.game-sidebar {
  flex: 1 1 40%;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  max-height: calc(55vh + 3.6rem); /* matches .log's 55vh + its input-row's real height, so the sidebar and story column bottom out together */
  overflow: hidden;
}

@media (max-width: 860px) {
  .game-layout {
    flex-direction: column;
  }
  .game-sidebar {
    max-height: 60vh;
  }
}

.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0.7rem 0.5rem;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  font-weight: bold;
}

.tab-btn:hover {
  filter: none;
  color: var(--text);
}

.tab-panel {
  padding: 1rem;
  overflow-y: auto;
}

.tab-panel[hidden] {
  display: none;
}

/* Character sheet */

.sheet-section {
  margin-bottom: 1.1rem;
}

.sheet-section h4 {
  margin: 0 0 0.5rem;
  color: var(--accent);
  font-size: 0.95rem;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 0.3rem;
}

.sheet-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  padding: 0.2rem 0;
  color: var(--text-dim);
}

.sheet-row strong {
  color: var(--text);
  font-weight: normal;
}

.sheet-skill-list {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.sheet-skill {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  padding: 0.15rem 0;
}

.sheet-skill-name {
  color: var(--text-dim);
}

.sheet-skill.proficient .sheet-skill-name {
  color: var(--text);
}

.sheet-skill-mod {
  color: var(--accent);
  min-width: 2.2rem;
  text-align: right;
}

.sheet-tag {
  font-size: 0.7rem;
  color: var(--accent-dim);
  margin-left: 0.4rem;
}

/* Inventory */

.inv-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--panel-border);
  font-size: 0.85rem;
}

.inv-item:last-child {
  border-bottom: none;
}

.inv-item-name {
  flex: 1;
}

.inv-item-tag {
  font-size: 0.72rem;
  color: var(--accent);
  margin-left: 0.4rem;
}

.inv-action-btn {
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
}

.inv-empty {
  color: var(--text-dim);
  font-style: italic;
  font-size: 0.85rem;
}

/* Journal */

.journal-entry {
  font-size: 0.85rem;
  padding: 0.3rem 0;
  color: var(--text-dim);
  line-height: 1.4;
}

.journal-entry strong {
  color: var(--text);
}

/* ---------- Battle map (read-only visual aid, see renderBattleMap() in
   app.js for what this is and deliberately isn't) ---------- */

.battle-map {
  margin: 0.8rem 0;
  padding: 0.7rem;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
}

.battle-map-grid {
  display: grid;
  gap: 3px;
  aspect-ratio: auto;
}

.battle-cell {
  aspect-ratio: 1;
  min-height: 28px;
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.battle-token {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: bold;
  cursor: default;
}

.battle-token-party {
  background: var(--accent-dim);
  border: 2px solid var(--accent);
  color: white;
}

.battle-token-monster-cover-none {
  background: #3a2430;
  border: 2px solid #d4708a;
  color: var(--text);
}

.battle-token-monster-cover-half {
  background: #3a2430;
  border: 2px dashed #d4708a;
  color: var(--text);
}

.battle-token-monster-cover-three-quarters {
  background: #3a2430;
  border: 2px double #d4708a;
  color: var(--text);
}

.battle-token-monster-dead {
  background: transparent;
  border: 1px solid var(--text-dim);
  color: var(--text-dim);
  opacity: 0.5;
}

.battle-map-note {
  margin: 0.5rem 0 0;
  font-size: 0.72rem;
  color: var(--text-dim);
  font-style: italic;
}

/* Tap-to-act buttons (renderActionBar in app.js) */
.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0;
}
.action-bar:empty {
  display: none;
}
.action-bar button {
  font-size: 0.9rem;
  padding: 0.45rem 0.8rem;
  min-height: 2.5rem; /* comfortable tap target on a phone */
}
.action-bar .action-group-label {
  width: 100%;
  font-size: 0.75rem;
  color: var(--accent);
  margin-top: 0.2rem;
}

/* How-to-play choice and the Dungeon Crawl hero cards */
.mode-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 0.75rem;
}
.mode-card, .premade-card {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1rem;
}
.mode-card strong, .premade-card strong {
  color: var(--accent);
  font-size: 1.1rem;
}
.mode-card span, .premade-card span {
  font-size: 0.9rem;
}
.premade-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}
.premade-card .premade-role {
  font-size: 0.8rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.mode-back {
  margin-bottom: 0.75rem;
}

.premade-card {
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: var(--bg);
}
.premade-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.4rem;
}
.premade-actions button {
  flex: 1;
  min-height: 2.5rem;
}

.journal-premise {
  margin: 0 0 0.6rem;
  color: var(--text-dim);
  font-style: italic;
  line-height: 1.5;
}

.journal-place {
  display: block;
  font-size: 0.85em;
  color: var(--text-dim);
}

.companion-kind {
  margin: -0.3rem 0 0.6rem;
  color: var(--text-dim);
  font-size: 0.85em;
  font-style: italic;
}

.companion-actions {
  margin-top: 0.6rem;
}

/* Level-up screen banner (2026-11-03) */
.level-up-banner {
  border: 2px solid var(--accent, #c9a227);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
}
.level-up-banner h2 { margin: 0 0 6px; }
.level-up-banner p { margin: 0; }
.level-up-banner button { margin-left: 8px; }

/* Spell cards and ability notes (2026-11-03) */
.spell-pick { display: block; }
.spell-pick label { cursor: pointer; }
.spell-details summary, .sheet-details summary { cursor: pointer; color: var(--accent); font-size: 0.9em; }
.spell-details { margin: 2px 0 6px 26px; }
.sheet-details { margin: 2px 0; }
.sheet-details > summary { font-weight: 600; color: inherit; }
.spell-card { border-left: 3px solid var(--accent-dim, #6d5a94); padding: 6px 10px; margin: 6px 0; }
.spell-card-meta { font-style: italic; opacity: 0.85; }
.spell-card-stats { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.9em; margin: 4px 0; }
.tag-conc { font-style: normal; font-size: 0.8em; border: 1px solid var(--accent, #b18cff); border-radius: 4px; padding: 0 4px; margin-left: 6px; }
.play-note { font-size: 0.92em; opacity: 0.95; }

/* Landing page (before the mode picker) */
.dev-notice {
  border: 1px solid var(--player-color);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin: 0 0 1.25rem;
  color: var(--player-color);
  background: rgba(255, 214, 140, 0.08);
}
#landing h2 {
  margin-top: 1.5rem;
}
.landing-art {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  margin-bottom: 1.25rem;
}
#landing h2:first-of-type {
  margin-top: 0;
}
.landing-list {
  padding-left: 1.2rem;
  line-height: 1.5;
}
.landing-list li {
  margin-bottom: 0.5rem;
}
#landing-start-btn {
  margin-top: 0.5rem;
  width: 100%;
}

/* Bug reports */
.bug-report-btn {
  margin-top: 0.75rem;
}
.hint {
  color: var(--text-dim);
  font-size: 0.9rem;
}
.bug-dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 1.5rem;
  width: min(32rem, calc(100vw - 2rem));
  box-sizing: border-box;
}
.bug-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}
.bug-dialog h2 {
  margin-top: 0;
  color: var(--accent);
}
.bug-dialog textarea {
  width: 100%;
  box-sizing: border-box;
}
.bug-dialog input[type="text"] {
  width: 100%;
  box-sizing: border-box;
  margin: 0.3rem 0 0.8rem;
  padding: 0.5rem;
  font: inherit;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
}
button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none;
}
.bug-dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Game over screen */
.gameover {
  text-align: center;
}
.gameover-line {
  font-size: 1.25rem;
  font-style: italic;
  color: var(--player-color);
}
.gameover-final {
  text-align: left;
  margin: 1rem 0 1.5rem;
}
#gameover-new-btn {
  width: 100%;
}

/* Retirement screen */
.retired h2 {
  text-align: center;
}
.retired .gameover-line {
  text-align: center;
}
.retired h3 {
  color: var(--accent);
  margin: 1.5rem 0 0.5rem;
}
.retired-tale p {
  line-height: 1.6;
  font-style: italic;
}
#retired-new-btn {
  width: 100%;
  margin-top: 1rem;
}

/* Account box on the landing page (account.js, 2026-11-06) */
.account-box {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin: 1.5rem 0 1rem;
}
.account-box p { margin: 0.25rem 0 0.5rem; }
.account-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.account-row[hidden] { display: none; }
.account-row input { flex: 1 1 12rem; min-width: 0; width: auto; }
#account-age-form select { flex: 1 1 8rem; min-width: 0; width: auto; }
#account-age-form input { flex: 0 1 6rem; }
.account-message { color: var(--text-dim); font-size: 0.9rem; min-height: 1.2em; }
.account-notice { color: var(--text-dim); font-size: 0.85rem; margin: 0 0 0.5rem; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Sign-in gate: Start stays locked until signed in (account.js). */
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Account menu + My characters (characters.js, 2026-11-07) */
header { position: relative; }
.menu-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: 1.3rem;
  line-height: 1;
  padding: 0.4rem 0.6rem;
}
.menu-btn[hidden] { display: none; }
.menu-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 1rem 0;
}
.menu-heading {
  color: var(--accent);
  font-size: 1rem;
  margin: 1rem 0 0.4rem;
}
.menu-legal {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.menu-legal a { color: var(--dm-color); }
.landing-legal { text-align: center; font-size: 0.9rem; }
.landing-legal a { color: var(--dm-color); }
.characters-dialog h3 {
  color: var(--accent);
  margin: 1.25rem 0 0.5rem;
}
.characters-note {
  border-left: 3px solid var(--accent);
  padding-left: 0.75rem;
}
.hero-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.hero-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--panel-border);
}
.hero-name { font-weight: bold; }
.hero-tag {
  font-size: 0.8rem;
  color: var(--text-dim);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
}
.hero-actions { margin-left: auto; }
.hero-row label { display: flex; align-items: center; gap: 0.5rem; }

/* Difficulty guide + Plans & prices (guides.js, 2026-11-07) */
.guide-links { display: flex; gap: 8px; flex-wrap: wrap; }
.guide-dialog { max-width: 720px; }
.scroll-x { overflow-x: auto; }
.guide-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.guide-table th, .guide-table td { text-align: left; vertical-align: top; padding: 6px; border-bottom: 1px solid var(--panel-border); }

/* Contact support (support.js, 2026-11-07). The address is plain text so
   anyone can copy it into their own email; one click selects all of it. */
.support-address { user-select: all; -webkit-user-select: all; overflow-wrap: anywhere; }
.support-copy { padding: 2px 10px; font-size: 0.85em; margin-left: 4px; }
#support-dialog select, #support-dialog input[type="email"] { width: 100%; box-sizing: border-box; margin-bottom: 8px; }
/* Support conversations (Menu > Support). */
#support-dialog { max-height: calc(100vh - 2rem); overflow-y: auto; }
.support-thread { border: 1px solid var(--panel-border); border-radius: 8px; padding: 6px 10px; margin: 6px 0; }
.support-thread summary { cursor: pointer; }
.support-new { color: var(--accent); font-weight: bold; }
.support-msg { margin: 8px 0; padding: 6px 8px; border-radius: 6px; background: rgba(255, 255, 255, 0.04); }
.support-msg-support { border-left: 3px solid var(--accent); }
.support-msg-who { font-size: 0.8em; color: var(--text-dim); }
.support-msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.support-reply { margin-top: 6px; }
