:root {
  /* Cold crypt palette: damp slate stone, oxidised-iron seams, cold bone text,
     verdigris / ice accents. */
  --bg: #090c0e;
  --bg-2: #0e151a;
  --panel: #111a1f;
  --panel-2: #18242b;
  --panel-3: #1f2e36;
  --line: #324249;
  --line-soft: #243137;
  --text: #d6dee3;
  --muted: #7e8e98;
  --accent: #5fb3b0;     /* verdigris (primary) */
  --accent-2: #8fd6d2;   /* icy highlight */
  --good: #5fb39a;       /* moss / verdigris green */
  --bad: #c4544e;        /* dried-blood red */
  --warn: #c2a07a;       /* cold bronze */
  /* Role colors — kept cool to match the crypt theme. */
  --role-tank: #6f9bc4;    /* steel blue */
  --role-healer: #5fb39a;  /* verdigris */
  --role-dps: #a784bf;     /* crypt violet */
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Roboto", system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  /* Crisper DOM text, esp. on mobile WebKit. */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  /* Stop the iOS long-press text-selection / copy-lookup callout when playing as
     a home-screen web app. Re-enabled below for the editable text inputs. */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Editable fields still need selection + the callout to type/paste into them. */
input, textarea {
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}

/* ── Menu screen ──────────────────────────────────────────────────── */
#menu {
  position: fixed; inset: 0;
  display: flex;
  /* Cold vignette + a faint spectral glow rising from below. */
  background:
    radial-gradient(ellipse 75% 55% at 50% 16%, rgba(95,179,176,0.08), transparent 62%),
    radial-gradient(ellipse at 50% 120%, var(--bg-2) 0%, var(--bg) 62%),
    var(--bg);
  overflow-y: auto;
  padding: 24px;
}
#menu[hidden] { display: none; }

#menu-card {
  position: relative;
  background:
    linear-gradient(180deg, rgba(143,214,210,0.03), transparent 28%),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 32px 36px 28px;
  width: 100%;
  max-width: 480px;
  /* Centers when it fits, but scrolls (top reachable) when taller than the
     viewport -- margin auto clamps to 0 instead of clipping like flex centering. */
  margin: auto;
  box-shadow:
    0 0 0 1px rgba(0,0,0,0.5),
    inset 0 0 0 1px rgba(95,179,176,0.05),
    inset 0 1px 0 rgba(255,255,255,0.03),
    0 22px 56px rgba(0,0,0,0.65);
}
/* Carved corner flourishes. */
#menu-card::before, #menu-card::after {
  content: ""; position: absolute; width: 16px; height: 16px;
  border: 1px solid var(--accent); opacity: .3; pointer-events: none;
}
#menu-card::before { top: 10px; left: 10px; border-right: 0; border-bottom: 0; }
#menu-card::after  { bottom: 10px; right: 10px; border-left: 0; border-top: 0; }

#menu-card h1 {
  font-family: "Roboto Condensed", "Roboto", sans-serif;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 6px;
  text-transform: uppercase;
  text-align: center;
  margin-bottom: 20px;
  color: var(--accent-2);
  text-shadow: 0 0 16px rgba(95,179,176,0.30), 0 2px 3px rgba(0,0,0,0.8);
}

.card-section {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  margin-top: 16px;
}
.card-section h2 {
  font-family: "Roboto Condensed", "Roboto", sans-serif;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .2em;
  color: var(--accent);
  margin-bottom: 10px;
  font-weight: 700;
}
details.card-section summary { cursor: pointer; list-style: none; display: flex; align-items: baseline; gap: 8px; }
details.card-section summary::-webkit-details-marker { display: none; }

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0;
}
label select, label input {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  font: inherit;
  transition: border-color .15s ease;
}
label select:focus, label input:focus { outline: none; border-color: var(--accent); }

.toggle-label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.toggle-label input { display: inline-block; width: auto; margin: 0; padding: 0; accent-color: var(--accent); }

.hint-inline { font-size: 11px; color: var(--muted); }
.hint { font-size: 11px; color: var(--muted); margin: 6px 0 10px; }

button {
  padding: 10px 18px;
  background: var(--good); color: #0b0d14;
  border: 1px solid var(--good); border-radius: 8px;
  cursor: pointer; font: 600 13px/1 inherit;
  transition: opacity .15s, transform .1s;
}
button:hover { opacity: .85; transform: translateY(-1px); }
button:active { transform: scale(.98); }

#start-btn {
  width: 100%; margin-top: 14px; padding: 13px;
  font-family: "Roboto Condensed", "Roboto", sans-serif;
  font-size: 15px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: #06100f;
  background: linear-gradient(180deg, var(--accent-2), var(--accent) 55%, #3c7f7c);
  border: 1px solid #2c5d5a; border-radius: 7px;
  box-shadow: 0 0 20px rgba(95,179,176,0.25), inset 0 1px 0 rgba(255,255,255,0.35), inset 0 -2px 6px rgba(0,0,0,0.3);
  text-shadow: 0 1px 0 rgba(255,255,255,0.2);
}
#start-btn:hover { opacity: 1; filter: brightness(1.08); box-shadow: 0 0 28px rgba(95,179,176,0.4), inset 0 1px 0 rgba(255,255,255,0.35); }

/* Secondary action button (menu) — outlined, less loud than the green Start. */
.secondary-btn {
  width: 100%; margin-top: 8px; padding: 10px;
  background: transparent; color: var(--accent);
  border: 1px solid var(--line); border-radius: 8px;
  font-weight: 600;
}
.secondary-btn:hover { border-color: var(--accent); }
.secondary-btn .hint-inline { font-weight: 400; }

/* Two-step class picker: role tabs + class cards */
.picker-label { font-size: 12px; color: var(--muted); margin: 10px 0 6px; }
.role-tabs { display: flex; gap: 6px; }
.role-tab {
  flex: 1; padding: 9px 6px;
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); border-radius: 8px;
  font: 600 12px/1 inherit;
}
.role-tab:hover { border-color: currentColor; transform: none; opacity: 1; }
.role-tab.active { background: rgba(255,255,255,0.04); border-color: currentColor; }
/* The role color tints the tab text only when active (muted otherwise). */
.role-tab.active.role-tank   { color: var(--role-tank); }
.role-tab.active.role-healer { color: var(--role-healer); }
.role-tab.active.role-dps    { color: var(--role-dps); }

.class-cards { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.class-card {
  padding: 9px 12px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  font: 600 12px/1 inherit; width: auto;
}
.class-card:hover { border-color: currentColor; transform: none; opacity: 1; }
.class-card.active { background: rgba(255,255,255,0.05); }
.class-card.active.role-tank   { border-color: var(--role-tank); color: var(--role-tank); }
.class-card.active.role-healer { border-color: var(--role-healer); color: var(--role-healer); }
.class-card.active.role-dps    { border-color: var(--role-dps); color: var(--role-dps); }

/* Class preview: an animated depiction of the selected class casting (left) next
   to its description (right). */
.class-preview {
  display: flex; gap: 12px; align-items: stretch;
  margin: 12px 0 4px;
}
.class-anim {
  flex: 0 0 auto; width: 156px; height: 184px;
  background: radial-gradient(120% 90% at 50% 30%, var(--panel-3), var(--panel) 75%);
  border: 1px solid var(--line); border-radius: 10px;
}
.class-desc {
  flex: 1 1 auto; display: flex; flex-direction: column;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; min-width: 0;
}
.class-desc h3 { margin: 0 0 2px; font-size: 15px; color: var(--text); }
.class-desc .cd-role {
  font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 8px;
}
.class-desc .cd-role.role-tank   { color: var(--role-tank); }
.class-desc .cd-role.role-healer { color: var(--role-healer); }
.class-desc .cd-role.role-dps    { color: var(--role-dps); }
.class-desc p { margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--text); opacity: .9; }

.menu-status { font-size: 11px; color: var(--bad); margin-top: 8px; min-height: 16px; }
.menu-status.ok { color: var(--good); }

.menu-footer { margin-top: 20px; display: flex; justify-content: space-between; align-items: center; }
.build-label { font-size: 10px; color: var(--muted); opacity: .6; letter-spacing: .3px; }
.menu-footer a { font-size: 11px; color: var(--muted); text-decoration: none; transition: color .15s; }
.menu-footer a:hover { color: var(--accent); }

/* Priority editor */
#priority-editor { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.priority-block {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
.priority-block h3 { margin: 0 0 6px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.priority-list { list-style: none; padding: 0; margin: 0; }
.priority-list li {
  background: var(--panel); border: 1px solid var(--line);
  padding: 5px 8px; margin: 3px 0; border-radius: 6px;
  font-size: 11px; cursor: grab; display: flex; justify-content: space-between;
  transition: border-color .15s;
}
.priority-list li:hover { border-color: var(--accent); }
.priority-list li.dragging { opacity: .4; }
.role-tank   { color: var(--role-tank); }
.role-healer { color: var(--role-healer); }
.role-dps    { color: var(--role-dps); }

/* ── Game screen ──────────────────────────────────────────────────── */
#game {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
}
#game[hidden] { display: none; }

#canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#game-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  background: #060810;
  /* Let the browser smoothly resample the HiDPI backing store to the screen.
     In-canvas crispness (blocky minimap, smooth fog/sprites) is controlled
     per-draw via ctx.imageSmoothingEnabled, so nearest-neighbor here would only
     re-alias text/sprites when DPR is fractional or clamped. */
  image-rendering: auto;
}

#bottom-bar {
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 6px 12px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));   /* clear the home indicator */
  display: flex;
  justify-content: center;
}
#hotbar { display: flex; gap: 6px; touch-action: manipulation; }
.hotbar-slot {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px; font-size: 11px; min-width: 70px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .1s;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.hotbar-slot:hover { border-color: var(--accent); }
.hotbar-slot:active { background: var(--panel); border-color: var(--accent); }
/* Dim cooldown via colour only — NOT opacity, which would also fade the border
   and make the outline pulse as the spell ticks on/off cooldown. */
.hotbar-slot.cooldown { color: var(--muted); background: var(--panel); }
.hotbar-slot kbd { display: block; color: var(--accent); font-size: 9px; }
/* Tabular figures keep the countdown a constant width as it ticks. */
.cd { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Floating overlays */
#status-log {
  position: absolute;
  bottom: calc(48px + env(safe-area-inset-bottom));
  left: calc(8px + env(safe-area-inset-left));   /* bottom-left, clear of the minimap (top-right) */
  font-size: 10px; color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(11,13,20,0.85);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  max-width: 260px;
  max-height: 90px;
  overflow-y: auto;
  pointer-events: none;
}
/* No message → don't show the empty dark box (read as a stray black blob in the
   bottom-left corner, mirroring the fps readout opposite it). */
#status-log:empty {
  display: none;
}
#fps {
  position: absolute;
  bottom: calc(48px + env(safe-area-inset-bottom));
  right: calc(8px + env(safe-area-inset-right));
  font-size: 10px; color: var(--muted);
  pointer-events: none;
}
#top-controls {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  left: calc(8px + env(safe-area-inset-left));
  display: flex; gap: 6px;
}
#menu-btn, #pause-btn {
  position: static;
  background: rgba(11,13,20,0.85);
  border: 1px solid var(--line);
  color: var(--muted); font-size: 11px;
  padding: 4px 10px; border-radius: 6px;
  width: auto;
  transition: color .15s, border-color .15s, background .15s;
}
#menu-btn:hover, #pause-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(86,224,255,0.08);
  transform: none;
  opacity: 1;
}

/* Pause overlay */
#pause-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6,8,16,0.85);
  z-index: 5;
}
#pause-overlay[hidden] { display: none; }
#pause-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 24px 32px;
  display: flex; flex-direction: column;
  align-items: center; gap: 16px;
  min-width: 220px;
}
#pause-card h2 {
  margin: 0; letter-spacing: .04em;
}
#pause-stats {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; color: var(--muted);
  text-align: center; line-height: 1.7;
}
#resume-btn { width: auto; font-size: 14px; }

/* In-combat indicator (top-center) */
#combat-indicator {
  position: absolute; top: 8px; left: 50%;
  transform: translateX(-50%);
  font-size: 11px; font-weight: 700; letter-spacing: 1px;
  color: var(--bad);
  background: rgba(11,13,20,0.85);
  border: 1px solid var(--bad);
  border-radius: 6px;
  padding: 4px 12px;
  pointer-events: none;
  animation: combat-pulse 1s ease-in-out infinite;
}
/* While the top-center boss banner (canvas, y 8–42) is up, drop the indicator
   below it so the two don't overlap. Toggled from main.js via RENDER.bossBannerShown. */
#combat-indicator.below-boss { top: 46px; }
#combat-indicator[hidden] { display: none; }
@keyframes combat-pulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}

/* Damage meter (top-left, below the menu button) — compact, roughly the
   footprint of the minimap + level badge cluster in the top-right. */
#meter {
  position: absolute; top: 44px; left: 8px;
  width: 150px;
  font-size: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(11,13,20,0.85);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 4px 5px;
  pointer-events: auto;   /* allow hover for the cast-breakdown tooltip */
}
#meter:empty { display: none; }
.meter-title {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-size: 7px;
  margin-bottom: 3px;
}
.meter-row {
  margin-bottom: 3px;
}
.meter-row.dead { opacity: .45; }
.meter-name { font-weight: 600; }
.meter-bars {
  position: relative;
  height: 5px;
  margin: 1px 0;
  background: rgba(255,255,255,0.04);
  border-radius: 2px;
  overflow: hidden;
}
.meter-bar {
  position: absolute; left: 0;
  height: 2px;
  border-radius: 1px;
  min-width: 0;
}
.meter-bar.dmg  { top: 0;    background: var(--warn); }
.meter-bar.heal { bottom: 0; background: var(--good); }
.meter-nums {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
}
.meter-nums .dmg  { color: var(--warn); }
.meter-nums .heal { color: var(--good); }
.meter-nums small { color: var(--muted); font-size: 7px; }

/* Desktop: scale the damage meter up (~1.8x) so it isn't tiny on a big screen.
   Matches render.js isMobileView() — mobile is a coarse pointer OR a narrow
   viewport, so desktop is a fine pointer AND a wide viewport. The mobile size
   above stays the default. */
@media (min-width: 768px) and (pointer: fine) {
  #meter {
    top: 48px;
    width: 270px;
    font-size: 14px;
    border-radius: 7px;
    padding: 7px 9px;
  }
  .meter-title { font-size: 12px; margin-bottom: 5px; }
  .meter-row { margin-bottom: 5px; }
  .meter-bars { height: 9px; margin: 2px 0; border-radius: 3px; }
  .meter-bar { height: 4px; border-radius: 2px; }
  .meter-nums small { font-size: 12px; }
}

/* Game-over overlay */
/* Floor-cleared / descend overlay (mirrors pause-card styling) */
#floor-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6,8,16,0.85);
  z-index: 6;
}
#floor-overlay[hidden] { display: none; }
#floor-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 24px 32px;
  display: flex; flex-direction: column;
  align-items: center; gap: 16px;
  min-width: 240px;
}
#floor-title {
  margin: 0; font-size: 22px; font-weight: 700;
  letter-spacing: .06em; color: var(--good);
}
#floor-sub {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; color: var(--muted);
  text-align: center; line-height: 1.7;
}
#descend-btn { width: auto; font-size: 14px; }
#descend-btn:disabled { opacity: .5; cursor: default; }

/* Boon picker: a row of choosable cards on the floor-cleared overlay */
#boon-cards {
  display: flex; gap: 12px; flex-wrap: wrap;
  justify-content: center; max-width: 560px;
}
.boon-card {
  flex: 1 1 150px; max-width: 180px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  text-align: left;
  transition: border-color .12s, transform .12s, background .12s;
}
.boon-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.boon-card.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--panel-2));
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.boon-card .boon-name {
  font-weight: 700; font-size: 14px; color: var(--accent);
  margin-bottom: 4px;
}
.boon-card .boon-desc {
  font-size: 12px; color: var(--text); line-height: 1.4;
}

#gameover-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: rgba(6,8,16,0.85);
  gap: 20px;
}
#gameover-overlay[hidden] { display: none; }
#gameover-text {
  font-size: 48px; font-weight: 800; letter-spacing: .04em;
  text-shadow: 0 0 20px currentColor;
}
#gameover-text.victory { color: var(--good); }
#gameover-text.defeat  { color: var(--bad); }
.go-buttons { display: flex; gap: 12px; }
.go-buttons button { width: auto; font-size: 14px; }
#back-btn {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line);
}
#back-btn:hover { border-color: var(--accent); background: var(--panel); }

/* ── Touch spell circles ───────────────────────────────────────────
   A full-screen, click-through overlay holding the positioned ability tokens;
   only the circles themselves capture taps so movement/world taps pass through. */
#spell-circles {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 3;
}
#spell-circles:empty { display: none; }

.spell-circle {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 64px; height: 64px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 1px;
  border-radius: 50%;
  background: rgba(20, 24, 38, 0.82);
  border: 2px solid var(--accent);
  color: var(--text);
  font: 600 10px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.spell-circle:active { background: rgba(40, 48, 74, 0.92); transform: translate(-50%, -50%) scale(0.94); }
.spell-circle.cooldown { border-color: var(--line); color: var(--muted); opacity: 0.7; }
.spell-circle .sc-key { color: var(--accent); font-size: 9px; }
.spell-circle.cooldown .sc-key { color: var(--muted); }
.spell-circle .sc-name { font-size: 9px; max-width: 58px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spell-circle .sc-cd { font-size: 9px; color: var(--warn); min-height: 9px; }

/* ── Spell-circle layout editor ──────────────────────────────────── */
#circle-editor {
  position: fixed; inset: 0;
  z-index: 20;
  background:
    radial-gradient(circle at 50% 40%, rgba(86, 224, 255, 0.06), transparent 60%),
    var(--bg);
}
#circle-editor[hidden] { display: none; }
#circle-editor-field { position: absolute; inset: 0; }
#circle-editor .spell-circle.editor {
  cursor: grab; border-style: dashed;
}
#circle-editor .spell-circle.editor.dragging { cursor: grabbing; border-style: solid; box-shadow: 0 0 0 3px rgba(86, 224, 255, 0.3); }

#circle-editor-bar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px;
  background: rgba(11, 13, 20, 0.9);
  border-bottom: 1px solid var(--line);
}
.circle-editor-hint { font-size: 12px; color: var(--muted); }
.circle-editor-actions { display: flex; gap: 8px; }
.circle-editor-actions button { padding: 8px 14px; font-size: 12px; }
#circle-cancel { background: var(--panel-2); color: var(--text); border-color: var(--line); }
#circle-clear { background: transparent; color: var(--muted); border-color: var(--line); }
