@font-face {
  font-family: 'Departure Mono';
  src: url('/fonts/DepartureMono-Regular.woff2') format('woff2');
  font-display: swap;
}

/* Codedex-inspired: a pixel display face used *sparingly* — the wordmark, the
   level number, milestone headlines. Everything else stays mono, exactly as
   Codedex pairs PixelGrid with Noto Sans Mono rather than setting body text in it. */
/* ── Rustlings Web Design System & Theme ────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:ital,wght@0,400;0,700;1,400&display=swap');

:root {
  /* Fonts */
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-code: "JetBrains Mono", "Fira Code", ui-monospace, "SF Mono", monospace;

  /* Theme: Futuristic Cyber-Crab (Dark) with Stark Sharp Borders */
  --bg:          #0a0c10;
  --inset:       #010409;
  --panel:       #151b23;
  --panel-hi:    #1e252e;
  
  --edge:        #7a828e;             /* High contrast borders */
  --edge-soft:   #3d444d;             /* Secondary borders */
  
  --fg:          #f0f3f6;
  --muted:       #9198a1;
  
  --rust:        #ff7b45;             /* Neon Oxide Orange */
  --rust-deep:   #b84a1e;             /* Core Rust orange */
  --ember:       #ffab7b;             /* Warm glow highlight */
  --gold:        #f0b72f;             /* Gold warnings */
  --green:       #26cd4d;             /* Emerald success */
  --red:         #ff6a69;             /* Cyber crimson error */
  --info:        #8ccfff;             /* Neon light blue info */
  --on-rust:     #000000;             /* High-contrast dark on orange */
  --mark-bg:     rgba(255, 123, 69, 0.15); /* Error caret marker highlight */
  --shadow:      #010409;
  --gutter:      #3d444d;             /* Code gutter numbers */

  /* Syntax Highlighting Styles */
  --t-com:       #9198a1;
  --t-num:       #ffc98c;
  --t-fnc:       #e6d5c0;
  --t-att:       #c297ff;
  
  --mono:        var(--font-code);
  --code:        13px/1.6 var(--font-code);
  color-scheme:  dark;
}

:root[data-theme="light"] {
  /* High contrast, stark, beautiful light theme */
  --bg:          #ffffff;
  --inset:       #f6f8fa;
  --panel:       #ffffff;
  --panel-hi:    #eaeef2;
  
  --edge:        #1f2328;             /* Dark, very visible boundaries */
  --edge-soft:   #d0d7de;
  
  --fg:          #1f2328;
  --muted:       #57606a;
  
  --rust:        #bc4c00;
  --rust-deep:   #953800;
  --ember:       #d15200;
  --gold:        #9a6700;
  --green:       #1a7f37;
  --red:         #cf222e;
  --info:        #0969da;
  --on-rust:     #ffffff;
  --mark-bg:     rgba(188, 76, 0, 0.12);
  --shadow:      rgba(31, 35, 40, 0.15);
  --gutter:      #8c959f;
  
  --t-com:       #57606a;             /* Dark, readable comments */
  --t-num:       #0550ae;
  --t-fnc:       #1f2328;
  --t-att:       #8250df;
  color-scheme:  light;
}

/* ── Base & Scrollbars ───────────────────────────────────── */
* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 var(--font-ui);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.workspace {
  position: relative;
  display: grid;
  min-height: 0;
}

::selection {
  background: var(--rust);
  color: var(--on-rust);
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Custom Scrollbar Styles */
nav::-webkit-scrollbar,
#out::-webkit-scrollbar,
#code::-webkit-scrollbar,
.body::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
nav::-webkit-scrollbar-track,
#out::-webkit-scrollbar-track,
#code::-webkit-scrollbar-track,
.body::-webkit-scrollbar-track {
  background: transparent;
}
nav::-webkit-scrollbar-thumb,
#out::-webkit-scrollbar-thumb,
#code::-webkit-scrollbar-thumb,
.body::-webkit-scrollbar-thumb {
  background: var(--edge-soft);
}
nav::-webkit-scrollbar-thumb:hover,
#out::-webkit-scrollbar-thumb:hover,
#code::-webkit-scrollbar-thumb:hover,
.body::-webkit-scrollbar-thumb:hover {
  background: var(--rust);
}

/* ── Button Hierarchy ────────────────────────────────────── */
/*  Tier 1 – .btn           Ghost / outline (most buttons)
    Tier 2 – .btn.primary   Loud CTA (Run, Next)
    Tier 3 – .btn.ghost     Minimal / toolbar (Raw, ⤢, Tab) */

button {
  font: inherit;
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: 0.25rem 0.6rem;
  font-size: .8rem;
  font-weight: 600;
  font-family: var(--font-ui);
  color: var(--fg);
  background: transparent;
  border: 1.5px solid var(--edge-soft);
  border-radius: 0;
  box-shadow: none;
  transition: background 0.1s ease, border-color 0.1s ease, color 0.1s ease;
}
.btn:hover:not(:disabled) {
  background: var(--panel-hi);
  border-color: var(--edge);
}
.btn:active:not(:disabled) {
  background: var(--edge-soft);
}
.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}
.btn:focus-visible {
  outline: 2px solid var(--rust);
  outline-offset: 1px;
}

/* Pressed / toggled state */
.btn[aria-pressed="true"] {
  background: var(--rust);
  border-color: var(--rust);
  color: var(--on-rust);
}

.skip {
  position: absolute;
  left: -100vw;
  top: .4rem;
  z-index: 40;
  padding: .4rem .8rem;
  color: var(--fg);
  background: var(--panel);
  border: 2px solid var(--rust);
  border-radius: 0;
}
.skip:focus {
  left: .4rem;
}
.spacer {
  margin-left: auto;
}

/* Tier 3 – Ghost: minimal toolbar buttons (Raw, ⤢, Tab) */
.btn.ghost {
  border-color: transparent;
  background: transparent;
  padding: 0.2rem 0.5rem;
  font-size: .78rem;
  color: var(--muted);
}
.btn.ghost:hover:not(:disabled) {
  color: var(--fg);
  background: var(--panel-hi);
  border-color: var(--edge-soft);
}
.btn.ghost[aria-pressed="true"] {
  color: var(--rust);
  background: var(--panel-hi);
  border-color: var(--edge-soft);
}

/* Revert code action button (highlighted gold accent) */
.btn.revert {
  border-color: var(--gold);
  color: var(--gold);
  background: transparent;
}
.btn.revert:hover:not(:disabled) {
  background: var(--gold);
  color: var(--on-rust);
}
.btn.revert[hidden] {
  display: none;
}

/* ── Header UI ────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: .9rem;
  flex-wrap: wrap;
  padding: 0.45rem 0.9rem;
  background: var(--panel);
  border-bottom: 2px solid var(--edge);
  z-index: 10;
}
.brand {
  margin: 0;
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: -.02em;
  white-space: nowrap;
}
.brand em {
  font-style: normal;
  color: var(--rust);
}

/* Compiling Pulse Animation (Idea 4) */
@keyframes crabPulse {
  0% { filter: drop-shadow(0 0 0 rgba(255, 123, 69, 0)); transform: scale(1); }
  50% { filter: drop-shadow(0 0 8px rgba(255, 123, 69, 0.85)); transform: scale(1.15); }
  100% { filter: drop-shadow(0 0 0 rgba(255, 123, 69, 0)); transform: scale(1); }
}
#logo-crab {
  display: inline-block;
  transition: transform 0.2s ease;
}
#logo-crab.compiling {
  animation: crabPulse 1.2s infinite ease-in-out;
}


/* XP progressions with badges (Idea 3) */
.chip {
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: 0.25rem 0.6rem;
  border: 2px solid var(--edge-soft);
  background: var(--inset);
  border-radius: 0;
  font-size: .78rem;
  white-space: nowrap;
}
.chip b {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.xp .level-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 700;
}
.xp .level-symbol {
  font-size: 0.82rem;
  color: var(--rust);
  text-shadow: 0 0 6px var(--rust);
}
.xp #level {
  color: var(--rust);
}
.xp .milestone {
  color: var(--ember);
  border-left: 1px solid var(--edge-soft);
  padding-left: .45rem;
}
.xp .track {
  width: 74px;
  height: 9px;
  background: var(--bg);
  border: 1px solid var(--edge-soft);
  padding: 1px;
  border-radius: 0;
}
.xp .fill {
  display: block;
  height: 100%;
  background: var(--rust);
  transition: width .35s steps(12);
}

/* Unified HUD Dock Toolbar (Idea 1) */
.hud-dock {
  display: inline-flex !important;
  align-items: center !important;
  background: var(--inset) !important;
  border: 2px solid var(--edge) !important;
  box-shadow: 2px 2px 0 var(--shadow) !important;
  padding: 0 !important;
  height: 28px !important;
  border-radius: 0 !important;
}
.hud-dock > *:not([hidden]) {
  border-left: 2px solid var(--edge-soft) !important;
}
.hud-dock > *:not([hidden]):first-child,
.hud-dock > [hidden] + *:not([hidden]) {
  border-left: none !important;
}
.dock-item, .dock-btn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  height: 100% !important;
  padding: 0 0.65rem !important;
  background: transparent !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  color: var(--fg) !important;
  font-size: 0.82rem !important;
  font-family: var(--font-ui) !important;
  cursor: pointer !important;
  box-sizing: border-box !important;
  transform: none !important;
}
.dock-btn {
  transition: background 0.1s ease, color 0.1s ease !important;
}
.dock-btn:hover {
  background: var(--panel-hi) !important;
  color: var(--rust) !important;
}
.dock-btn:active {
  background: var(--edge-soft) !important;
}

/* Streak Heat Glow Breathing (Idea 5) */
@keyframes streakHeat {
  0% { text-shadow: none; box-shadow: inset 0 0 0 rgba(255, 123, 69, 0); }
  50% { text-shadow: 0 0 6px var(--ember); box-shadow: inset 0 0 6px rgba(255, 123, 69, 0.15); }
  100% { text-shadow: none; box-shadow: inset 0 0 0 rgba(255, 123, 69, 0); }
}
.dock-item.streak {
  font-weight: 700 !important;
  color: var(--ember) !important;
  animation: streakHeat 2.5s infinite ease-in-out !important;
}

.taskbar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  padding: 0.5rem 0.9rem;
  background: var(--panel);
  border-bottom: 2px solid var(--edge);
}
.taskbar .badge {
  font-size: 1.15rem;
  line-height: 1;
  padding-right: 0.75rem;
  border-right: 1px solid var(--edge-soft);
  margin-right: 0.25rem;
}
.taskbar .who {
  display: none; /* Hide redundant exercise name */
}
.taskbar .place {
  display: none; /* Removed progress track completely */
}
.taskbar .mode {
  display: none; /* Hide redundant cargo run mode tag */
}

/* Prev/Next nav arrows - compact ghost style */
.taskbar #prev, .taskbar #next {
  border-color: transparent;
  background: transparent;
  padding: 0.15rem 0.45rem;
  font-size: .9rem;
  line-height: 1;
  color: var(--muted);
  box-shadow: none;
  transition: color 0.1s ease, background 0.1s ease;
}
.taskbar #prev:hover:not(:disabled), .taskbar #next:hover:not(:disabled) {
  color: var(--fg);
  background: var(--panel-hi);
}
.taskbar #prev:active:not(:disabled), .taskbar #next:active:not(:disabled) {
  color: var(--rust);
  background: var(--edge-soft);
}

/* File path breadcrumb with inline solved/unsolved dots */
.file-path-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.taskbar .file {
  display: inline-flex;
  align-items: center;
  font-size: 0.82rem;
  white-space: nowrap;
}
/* Solved/unsolved indicator preceding path */
.taskbar .file::before {
  content: "○";
  color: var(--edge-soft);
  margin-right: 0.5rem;
  font-weight: bold;
  font-family: var(--font-code);
  font-size: 0.85rem;
}
.taskbar .file.solved::before {
  content: "●";
  color: var(--green);
  text-shadow: 0 0 6px var(--green);
}

.dir-name {
  color: var(--muted);
  font-family: var(--font-ui);
  font-weight: 500;
  padding: 0.1rem 0.35rem;
}
.path-sep {
  color: var(--edge-soft);
  margin: 0 0.15rem;
  font-weight: bold;
}
.file-name {
  color: var(--fg);
  font-family: var(--font-code);
  font-weight: 600;
  padding: 0.1rem 0.35rem;
}
.taskbar .aid {
  display: flex;
  gap: .4rem;
  margin-left: auto;
}

/* Cyberpunk Decoder Hint Box (Idea 1 & 5) */
@keyframes slideFadeIn {
  0% { opacity: 0; transform: translateY(-4px); }
  100% { opacity: 1; transform: translateY(0); }
}
.hint-box {
  width: 100%;
  margin-top: 0.4rem;
  border: 2px solid var(--edge);
  box-shadow: 4px 4px 0 var(--shadow);
  background: var(--inset);
  animation: slideFadeIn 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: flex;
  flex-direction: column;
}
.hint-box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel-hi);
  border-bottom: 2px solid var(--edge);
  padding: 0.35rem 0.7rem;
}
.hint-box-header .title {
  font-family: var(--font-code);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--rust);
  letter-spacing: 0.05em;
}
.hint-box-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.1rem 0.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.1s ease;
}
.hint-box-close:hover {
  color: var(--fg);
}
.hint-box-body {
  padding: 0.4rem 0.2rem;
  max-height: 200px;
  overflow-y: auto;
}
.hint-step {
  width: 100%;
  margin: 0.2rem 0;
  padding: 0.35rem 0.65rem;
  font-size: .8rem;
  color: var(--fg);
  white-space: pre-wrap;
  font-family: var(--font-ui);
}
.hint-box-footer {
  background: var(--panel);
  border-top: 1px solid var(--edge-soft);
  padding: 0.3rem 0.7rem;
  font-size: 0.68rem;
  color: var(--muted);
  font-family: var(--font-ui);
}
.hint-box-footer kbd {
  background: var(--bg);
  border: 1px solid var(--edge);
  box-shadow: 1px 1px 0 var(--shadow);
  padding: 0 0.2rem;
  font-size: 0.68rem;
}

/* Neon Orange Highlighted inline code tags in hints (Idea 2) */
.hint-step code {
  background: var(--bg);
  border: 1px solid var(--edge-soft);
  color: var(--rust);
  font-weight: 600;
  padding: 0.05rem 0.25rem;
  font-family: var(--font-code);
}
.welcome {
  width: 100%;
  margin: .3rem 0 0;
  padding: .5rem .7rem;
  background: var(--inset);
  border-left: 3px solid var(--rust);
}
.welcome p {
  margin: 0 0 .5rem;
  font-size: .82rem;
  color: var(--fg);
}
.welcome[hidden] {
  display: none;
}

/* ── Navigation drawer (aside) ─────────────────────────── */
aside {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 15;
  width: min(300px, 82vw);
  display: none;
  background: var(--panel);
  border-right: 2px solid var(--edge);
  box-shadow: 6px 0 0 #0006;
}
body.browsing aside {
  display: grid;
  /* two rows: the progress header, then the list that scrolls */
  grid-template-rows: auto minmax(0, 1fr);
}

nav {
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
}
nav details {
  border-bottom: 1px solid var(--edge-soft);
}
summary {
  display: flex;
  align-items: center;
  gap: .5rem;
  list-style: none;
  cursor: pointer;
  font-size: .8rem;
}
summary::-webkit-details-marker {
  display: none;
}
nav summary {
  padding: .5rem .75rem;
}
nav summary:hover, nav details[open] > summary {
  background: var(--panel-hi);
}
nav .badge {
  font-size: 1rem;
  filter: grayscale(1) opacity(.4);
  line-height: 1;
}
nav .cleared .badge {
  filter: none;
}
nav summary .title {
  flex: 1;
  text-transform: lowercase;
  color: var(--muted);
}
nav .cleared summary .title {
  color: var(--fg);
}
nav summary .score {
  color: var(--edge);
  font-size: .72rem;
  font-variant-numeric: tabular-nums;
}
nav .cleared summary .score {
  color: var(--green);
}
nav ol {
  list-style: none;
  margin: 0;
  padding: 0 0 .35rem;
}
nav li button {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: .8rem;
  padding: .2rem .75rem .2rem 1.5rem;
  border-left: 3px solid transparent;
}
nav li button:hover:not(:disabled) {
  background: var(--panel-hi);
  color: var(--fg);
}
nav li button::before {
  content: "○";
  color: var(--edge-soft);
}
nav li button.solved {
  color: var(--fg);
}
nav li button.solved::before {
  content: "●";
  color: var(--green);
}
nav li button[aria-current="true"] {
  border-left-color: var(--rust);
  background: var(--inset);
  color: var(--fg);
}

/* ── Editor Workspace ───────────────────────────────────── */
main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  min-height: 0;
  background: var(--bg);
}

.editor {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
  background: var(--inset);
}
.gutter {
  font: var(--code);
  color: var(--gutter);
  text-align: right;
  padding: .8rem .55rem .8rem .9rem;
  user-select: none;
  overflow: hidden;
  white-space: pre;
  border-right: 1px solid var(--edge-soft);
}
.gutter b {
  color: var(--rust);
  font-weight: 700;
}
.gutter i {
  color: var(--muted);
  font-style: normal;
}
.stack {
  position: relative;
  min-height: 0;
}
.stack > * {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: .8rem .9rem;
  border: 0;
  font: var(--code);
  white-space: pre;
  overflow: auto;
}
#paint {
  pointer-events: none;
  color: var(--fg);
}
#code {
  background: transparent;
  color: transparent;
  caret-color: var(--rust);
  resize: none;
  outline: 0;
}
#code::selection {
  background: var(--mark-bg);
  color: transparent;
}
#mark {
  position: absolute;
  pointer-events: none;
  background: var(--mark-bg);
  border-bottom: 2px solid var(--rust);
}

/* Code Syntax Painting */
.t-kw { color: var(--rust) }
.t-mac { color: var(--gold) }
.t-typ { color: var(--info) }
.t-str { color: var(--green) }
.t-com { color: var(--t-com); font-style: italic }
.t-num { color: var(--t-num) }
.t-fnc { color: var(--t-fnc) }
.t-att { color: var(--t-att) }

/* ── Runbar & Terminal ──────────────────────────────────── */
.runbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .45rem .9rem;
  background: var(--panel);
  border-top: 1px solid var(--edge-soft);
}

/* The one loud CTA */
.runbar .primary {
  padding: .35rem 1.2rem;
  font-size: .82rem;
  font-weight: 700;
  background: var(--rust);
  border: 2px solid var(--rust-deep);
  color: var(--on-rust);
  box-shadow: 2px 2px 0 var(--shadow);
  border-radius: 0;
}
.runbar .primary:hover:not(:disabled) {
  background: var(--ember);
}
.runbar .primary:active:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: none;
}

/* Runbar secondary buttons auto-ghost */
.runbar .btn:not(.primary) {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  font-size: .78rem;
}
.runbar .btn:not(.primary):hover:not(:disabled) {
  color: var(--fg);
  background: var(--panel-hi);
  border-color: var(--edge-soft);
}
.runbar .btn:not(.primary)[aria-pressed="true"] {
  color: var(--rust);
  background: var(--panel-hi);
  border-color: var(--edge-soft);
}

.verdict {
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
}
.verdict.pass {
  color: var(--green);
}
.verdict.fail {
  color: var(--red);
}

#out {
  margin: 0;
  padding: 0;
  overflow: auto;
  background: var(--inset);
  color: var(--muted);
  font: var(--code);
  min-height: 0;
  max-height: 45vh;
  resize: vertical;
  border-top: 1px solid var(--edge-soft);
}
#out[hidden] {
  display: none;
}
#out .raw {
  margin: 0;
  padding: .7rem .9rem;
  white-space: pre;
  font: var(--code);
}
#out .note {
  margin: 0;
  padding: .7rem .9rem;
  white-space: pre-wrap;
  color: var(--fg);
}

#out {
  animation: errorSlideIn 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes errorSlideIn {
  0% { opacity: 0; transform: translateY(6px); }
  100% { opacity: 1; transform: translateY(0); }
}


.problem {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-left: 5px solid var(--red);
  background: none;
  color: var(--muted);
  padding: .65rem .9rem;
  font: var(--code);
  box-sizing: border-box;
}
.problem:hover {
  background: var(--panel-hi);
}
.problem.warning {
  border-left-color: var(--gold);
}
.problem.test {
  border-left-color: var(--rust);
}
.problem .head {
  display: flex;
  align-items: baseline;
  gap: .55rem;
  flex-wrap: wrap;
}
.problem .code {
  display: inline-flex;
  align-items: center;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--red);
  color: var(--red);
  font-weight: 700;
  font-size: 0.72rem;
  padding: 0.05rem 0.35rem;
  border-radius: 0;
  font-family: var(--font-code);
}
.problem.warning .code {
  background: rgba(234, 179, 8, 0.12);
  border-color: var(--gold);
  color: var(--gold);
}
.problem.test .code {
  background: rgba(255, 123, 69, 0.12);
  border-color: var(--rust);
  color: var(--rust);
}
.problem .where {
  color: var(--edge);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.problem .what {
  color: var(--fg);
  font-weight: 700;
}
.problem .label {
  display: block;
  margin-top: .2rem;
  color: var(--ember);
  white-space: pre-wrap;
}
.problem .help {
  display: block;
  margin-top: .25rem;
  color: var(--info);
}

/* Neon highlighted inline code tags in compiler errors (Idea 3) */
.problem code {
  background: var(--bg);
  border: 1px solid var(--edge-soft);
  color: var(--rust);
  font-weight: 600;
  padding: 0.05rem 0.25rem;
  font-family: var(--font-code);
}

.clean {
  margin: 0;
  padding: .7rem .9rem;
  color: var(--green);
  font-weight: 700;
}
.clean span {
  display: block;
  margin-top: .35rem;
  color: var(--muted);
  font-weight: 400;
  white-space: pre-wrap;
}
.clean .advance {
  margin-top: .8rem;
  padding: .38rem 1.1rem;
  font-size: .82rem;
  font-weight: 700;
  background: var(--rust);
  border: 2px solid var(--rust-deep);
  color: var(--on-rust);
  box-shadow: 2px 2px 0 var(--shadow);
}
.clean .advance:hover:not(:disabled) {
  background: var(--ember);
  border-color: var(--rust);
  color: var(--on-rust);
}
.clean .advance:active:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: none;
}

/* ── Dialog Modals ──────────────────────────────────────── */
a {
  color: var(--info);
}
a:hover {
  color: var(--rust);
}
code, .block {
  font: var(--code);
  background: var(--panel-hi);
  border: 1px solid var(--edge-soft);
  padding: 0 .25em;
  color: var(--fg);
}
.block {
  display: block;
  padding: .6rem .7rem;
  margin: .6rem 0;
  overflow-x: auto;
  white-space: pre;
}

dialog {
  width: min(46rem, 92vw);
  max-height: 80vh;
  padding: 0;
  color: var(--fg);
  background: var(--bg);
  border: 2px solid var(--edge);
  box-shadow: 6px 6px 0 var(--rust-deep);
  border-radius: 0; /* Fully sharp corners */
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
dialog .top {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .45rem .9rem;
  background: var(--panel);
  border-bottom: 2px solid var(--edge);
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--edge);
}
dialog h2 {
  margin: 0;
  font-size: .8rem;
  letter-spacing: .06em;
  text-transform: uppercase;
}
dialog .body {
  padding: .9rem;
  overflow: auto;
  max-height: 66vh;
  font-size: 0.85rem;
}
dialog .para {
  white-space: pre-wrap;
  margin: 0;
}
dialog dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .35rem .9rem;
  margin: 0;
}
dialog dt {
  color: var(--rust);
  font-weight: 700;
  white-space: nowrap;
}
dialog dd {
  margin: 0;
  color: var(--muted);
}

.progress-bar-container {
  width: 100%;
  height: 8px;
  background: var(--inset);
  border: 2px solid var(--edge); /* High contrast dark border */
  margin-top: 0.4rem;
  padding: 0;
  position: relative;
}
.progress-bar-fill {
  height: 100%;
  background: var(--rust);
  box-shadow: 0 0 6px var(--rust);
  transition: width 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.overall-progress {
  margin-bottom: 1.2rem;
}
.overall-progress .progress-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 0.35rem;
}
.overall-progress .progress-bar-container {
  height: 12px;
}
.overall-progress .progress-bar-fill {
  background: linear-gradient(90deg, var(--rust-deep) 0%, var(--rust) 100%);
  box-shadow: 0 0 8px var(--rust);
}

/* Stats Cards Layout (Idea 1) */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.2rem;
}
.stats-card {
  background: var(--inset);
  border: 2px solid var(--edge);
  box-shadow: 4px 4px 0 var(--shadow);
  padding: 0.75rem 0.9rem;
}
.stats-card h3 {
  margin: 0 0 0.6rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--rust);
  font-weight: 700;
  border-bottom: 1px solid var(--edge-soft);
  padding-bottom: 0.3rem;
}
.stats-card .progress-facts {
  margin: 0;
  grid-template-columns: auto 1fr;
}
.stats-card .progress-facts dt {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
}
.stats-card .progress-facts dd {
  color: var(--fg);
  font-size: 0.82rem;
  font-weight: 700;
  text-align: right;
}
.stats-card .progress-facts dd .progress-bar-container {
  text-align: left;
}

/* Rank Badge alignment (Idea 4) */
#rank-badge-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  justify-content: flex-end;
  width: 100%;
}
#rank-badge {
  font-size: 1.1rem;
  line-height: 1;
}

/* Next Milestone Tip styling (Idea 5) */
.next-milestone-tip {
  font-size: 0.8rem;
  color: var(--fg);
  background: rgba(255, 123, 69, 0.08);
  border-left: 3px solid var(--rust);
  padding: 0.55rem 0.75rem;
  margin-bottom: 1.2rem;
}
:root[data-theme="light"] .next-milestone-tip {
  background: rgba(188, 76, 0, 0.05);
  border-left-color: var(--rust);
}

.progress-facts {
  margin: 0 0 1rem;
}
.progress-facts dt {
  color: var(--edge);
  font-weight: 400;
  font-size: .72rem;
  text-transform: uppercase;
}

.trophies {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: .6rem;
}
.trophy {
  display: flex;
  gap: .55rem;
  padding: .5rem;
  border: 2px solid var(--edge-soft);
  background: var(--inset);
  border-radius: 0;
  transition: none;
}
.trophy:hover {
  border-color: var(--rust);
}
.trophy .icon {
  font-size: 1.4rem;
}
.trophy b {
  display: block;
  font-size: .8rem;
  color: var(--muted);
}
.trophy.won b {
  color: var(--fg);
}
.trophy small {
  color: var(--muted);
  font-size: .72rem;
}

.trophy.won {
  background: rgba(255, 123, 69, 0.05);
  border: 2px solid var(--rust);
  box-shadow: 2px 2px 0 var(--shadow);
}
:root[data-theme="light"] .trophy.won {
  background: rgba(188, 76, 0, 0.04);
  border-color: var(--rust);
}

.trophy.locked {
  opacity: 0.55;
  background: rgba(122, 130, 142, 0.04);
  border: 2px dashed var(--edge-soft);
}
.trophy.locked .icon {
  filter: grayscale(1) opacity(0.3);
}

#milestonedlg {
  width: min(30rem, 92vw);
  box-shadow: 6px 6px 0 var(--rust-deep);
}
.milestone-body {
  text-align: center;
}
.mile-icon {
  margin: .4rem 0;
  font-size: 3.4rem;
  line-height: 1;
}
.mile-head {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--rust);
}
.mile-sub {
  margin: .3rem 0 1rem;
  font-size: .84rem;
  color: var(--muted);
}
.milestone-body .progress-facts {
  text-align: left;
}
.milestone-body .primary {
  background: var(--rust);
  border-color: var(--rust-deep);
  color: var(--on-rust);
  font-weight: 700;
}

.danger {
  color: var(--red);
  border-color: var(--red);
}
.danger:hover:not(:disabled) {
  background: var(--red);
  color: var(--on-rust);
}

#wipedlg {
  width: min(28rem, 92vw);
  box-shadow: 6px 6px 0 var(--red);
}
#wipedlg .top {
  border-bottom-color: var(--red);
}
#wipedlg h2 {
  color: var(--red);
}
.wipe-lead {
  margin: 0 0 .7rem;
  font-size: .84rem;
  color: var(--fg);
}
.wipe-list {
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
  display: grid;
  gap: .3rem;
}
.wipe-list li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: .3rem .5rem;
  font-size: .8rem;
  color: var(--muted);
  background: var(--inset);
  border-left: 3px solid var(--red);
}
.wipe-list b {
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
.wipe-actions {
  display: flex;
  gap: .5rem;
  justify-content: flex-end;
}

/* ── Rewards & Toasting ────────────────────────────────── */
#toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  display: grid;
  gap: .5rem;
  justify-items: end;
  z-index: 99;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  padding: .55rem .8rem;
  font-size: .82rem;
  max-width: 24rem;
  background: var(--panel);
  border: 2px solid var(--rust);
  box-shadow: 4px 4px 0 var(--rust-deep);
  border-radius: 0;
  animation: pop .18s steps(3);
}
.toast .icon {
  font-size: 1.2rem;
  line-height: 1.2;
}
.toast b {
  color: var(--rust);
}
.toast em {
  display: block;
  font-style: normal;
  color: var(--muted);
  font-size: .78rem;
}
@keyframes pop {
  from { transform: translateY(6px) scale(.96); opacity: 0; }
}

.flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
  overflow: hidden;
}
.flash span {
  position: absolute;
  top: -2rem;
  font-size: 1.6rem;
  animation: fall 1.6s linear forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(360deg); opacity: .2; }
}

.particle {
  position: absolute;
  pointer-events: none;
  font-size: 1.5rem;
  transform: translate(-50%, -50%);
  animation: particleBlow 1.5s cubic-bezier(0.1, 0.8, 0.3, 1) forwards;
  z-index: 210;
}
@keyframes particleBlow {
  0% { transform: translate(-50%, -50%) scale(0.6) rotate(0deg); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.3) rotate(var(--rot)); opacity: 0; }
}

@keyframes streakPulse {
  0% { box-shadow: 0 0 0 rgba(255, 123, 69, 0); }
  50% { box-shadow: 0 0 12px rgba(255, 123, 69, 0.35); }
  100% { box-shadow: 0 0 0 rgba(255, 123, 69, 0); }
}
.chip.streak:not([hidden]) {
  animation: streakPulse 2s infinite ease-in-out;
}

.tabkey {
  display: none;
}
@media (max-width: 860px) {
  .tabkey {
    display: inline-flex;
  }
  #out {
    max-height: 32vh;
  }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}


/* ── pixel display, used in four places only ─────────────────────────── */
.brand {
  font-family: var(--pixel);
  font-size: .62rem;          /* Press Start 2P runs large; this matches the row */
  letter-spacing: .04em;
  line-height: 1.8;
}
.brand em { font-style: normal; color: var(--rust) }

.xp #level, .level-badge {
  font-family: var(--pixel);
  font-size: .56rem;
  letter-spacing: 0;
}

.mile-head, #milehead {
  font-family: var(--pixel);
  font-size: .78rem;
  line-height: 1.7;
}

.trophy b { font-family: var(--pixel); font-size: .5rem; line-height: 1.9 }

/* ── the xp bar reads as a game meter: discrete blocks, not a smooth fill ── */
.xp .track {
  position: relative;
  background:
    repeating-linear-gradient(90deg,
      transparent 0 6px,
      var(--panel) 6px 8px);
  background-color: var(--bg);
}
.xp .fill { position: relative; z-index: -1 }

/* ── a multi-hue accent set, the way Codedex colours its chapters ─────── */
:root {
  --hue-1: #8beb46; --hue-2: #5ceee1; --hue-3: #ebe527;
  --hue-4: #f59f54; --hue-5: #c297ff;
}
:root[data-theme="light"] {
  --hue-1: #2f7d16; --hue-2: #0f7d74; --hue-3: #7a6a00;
  --hue-4: #9a5510; --hue-5: #5b3a9e;
}
nav details:nth-child(5n+1) .cleared-mark { color: var(--hue-1) }
nav details:nth-child(5n+2) .cleared-mark { color: var(--hue-2) }
nav details:nth-child(5n+3) .cleared-mark { color: var(--hue-3) }
nav details:nth-child(5n+4) .cleared-mark { color: var(--hue-4) }
nav details:nth-child(5n+5) .cleared-mark { color: var(--hue-5) }

/* ── one pill, on the single most important action, as Codedex does ──── */


/* ── divider between the code and the results ──────────────────────────── */
.grip {
  height: 8px;
  cursor: ns-resize;
  background: var(--panel);
  border-top: 2px solid var(--edge);
  border-bottom: 1px solid var(--edge-soft);
  position: relative;
  touch-action: none;
}
.grip::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 2px;
  transform: translate(-50%, -50%);
  background: var(--edge);
}
.grip:hover::after, .grip:focus-visible::after { background: var(--rust); width: 54px }
.grip[hidden] { display: none }
#out { resize: none }


/* Only the TUI stylesheet gives the bottom line to a status bar. */
.statusline { display: none }
