:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #e2e8f0;
  --accent: #38bdf8;
  --accent-dark: #0284c7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

.site-header h1 {
  margin: 0 0 0.25rem;
  color: var(--accent);
}

.tagline {
  margin: 0;
  color: #94a3b8;
}

main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem 1rem;
}

button {
  background: var(--accent-dark);
  color: white;
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.2s ease;
}

button:hover {
  background: var(--accent);
}

footer {
  text-align: center;
  padding: 1rem;
  color: #64748b;
  font-size: 0.85rem;
}

code {
  background: rgba(148, 163, 184, 0.15);
  padding: 0.1rem 0.35rem;
  border-radius: 0.25rem;
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 0.9em;
}

/* --- Problem list --------------------------------------------------- */

.list-wrap {
  width: 100%;
  max-width: 800px;
}

/* The table's box: rounded and shadowed, and scrolling sideways when the
   table is wider than the screen, so the page itself never is. */
.table-scroll {
  overflow-x: auto;
  border-radius: 0.75rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.problem-list {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}

.problem-list th {
  text-align: left;
  padding: 0.9rem 1.25rem;
  color: #94a3b8;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

.problem-list td {
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
}

.problem-row {
  cursor: pointer;
}

.problem-row:hover {
  background: rgba(56, 189, 248, 0.08);
}

.problem-title {
  color: var(--accent);
  font-weight: 600;
}

/* The problem list in queue order (spaced-repetition plan, step 9). */
.next-line {
  margin-bottom: 1rem;
}

.next-line:empty {
  display: none;
}

.queue-position {
  color: #94a3b8;
  text-align: right;
}

.result-new {
  color: var(--accent);
  font-style: italic;
}

/* The question bank (#133): index.html?view=bank. */
.list-wrap.bank-view {
  max-width: 1100px;
}
.view-switch {
  margin: 0 0 1rem;
}
.view-switch:empty {
  display: none;
}
.view-switch a,
.bank-pair a {
  color: var(--accent);
}
.bank-slug {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  color: #94a3b8;
}
.bank-pair {
  white-space: nowrap;
}
/* No underline, which turns "—" into "=": hovering shows it's a link. */
.bank-pair a {
  text-decoration: none;
}
.bank-pair a:hover {
  text-decoration: underline;
}
.bank-neither a {
  color: #94a3b8;
}
/* In a file, but in a language turned off: not on the list. */
.bank-off a {
  opacity: 0.55;
  font-style: italic;
}
.bank-created {
  color: #94a3b8;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}


.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Fundamentals (#93): below Easy, for language features. Violet, outside
   the green-yellow-red scale, so it reads as a different kind of question
   rather than "easier than easy"; not sky blue (--accent, the links) or
   slate (#334155, an uncoloured bubble). Tailwind's violet-500 and -400,
   the pattern of the three below. */
.difficulty-fundamentals {
  background: rgba(139, 92, 246, 0.15);
  color: #a78bfa;
}

.difficulty-easy {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
}

.difficulty-medium {
  background: rgba(234, 179, 8, 0.15);
  color: #facc15;
}

.difficulty-hard {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

/* Topic and source bubbles (bubbles.js). labels.json can override these
   colours per name. Sources are outlined with an inset box-shadow rather
   than a border, so both kinds are exactly the same size. */
.bubbles {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-width: 0;
}

.bubble-topic {
  background: #334155;
  color: #e2e8f0;
}

.bubble-source {
  background: transparent;
  color: #cbd5e1;
  box-shadow: inset 0 0 0 1px currentColor;
}

/* --- Problem page ----------------------------------------------------- */

.problem-body {
  height: 100vh;
  overflow: hidden;
}

.problem-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  text-align: left;
}

.problem-header h1 {
  font-size: 1.25rem;
  margin: 0;
}

.back-link {
  color: #94a3b8;
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}

.back-link:hover {
  color: var(--accent);
}

.header-actions {
  margin-left: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.language-filter {
  position: relative;
}

.language-filter-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 9rem;
  background: var(--surface);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 0.5rem;
  padding: 0.6rem 0.75rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.language-filter-menu[hidden] {
  display: none;
}

.language-filter-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.4rem;
  border-radius: 0.35rem;
  font-size: 0.85rem;
}

/* A language the profile doesn't allow (problem-page.js sets hidden).
   Without this, display: flex above beats the browser's own
   [hidden] { display: none }, and the row shows anyway. */
.language-filter-row[hidden] {
  display: none;
}

.language-filter-row:hover {
  background: rgba(56, 189, 248, 0.1);
}

.language-filter-row input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

.language-filter-row input[type="checkbox"]:disabled {
  cursor: not-allowed;
}

.language-filter-name {
  flex: 1;
  cursor: pointer;
}

.language-filter-name.is-default {
  color: var(--accent);
  font-weight: 600;
}

.icon-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  background: transparent;
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.icon-btn:hover {
  background: rgba(56, 189, 248, 0.12);
  border-color: var(--accent);
}

.icon-btn[hidden] {
  display: none;
}

main.problem-main {
  flex: 1;
  display: flex;
  justify-content: stretch;
  align-items: stretch;
  padding: 0 1.5rem 1.5rem;
  min-height: 0;
  overflow: hidden;
}

.pane {
  background: var(--surface);
  border-radius: 0.75rem;
  overflow-y: auto;
  min-height: 0;
}

.description-pane {
  flex: 0 0 38.2%; /* 1 - 1/φ, rounded to 3 decimals; kept in sync with DEFAULT_PANE_FRACTION in problem-page.js */
  min-width: 20%;
  padding: 1.5rem 1.75rem;
}

.pane-resizer {
  flex: 0 0 6px;
  align-self: stretch;
  /* Inset top/bottom by .pane's own corner radius, so the bar's rounded
     caps start where .description-pane's corners finish curving, instead
     of leaving a little cove where two different radii collide. */
  margin: 0.75rem 0; /* flush against both panes */
  border-radius: 999px;
  background-color: rgba(148, 163, 184, 0.4);
  /* A small, subtle two-ridge knurl mark, centered on the bar. Explicit
     (non-repeating) stops so the pair is symmetric: 1px margin, 1px ridge,
     2px gap, 1px ridge, 1px margin — a *repeating* gradient here would put
     one ridge flush against the edge instead of centering the pair. */
  background-image: linear-gradient(
    to right,
    transparent 0 1px,
    rgba(255, 255, 255, 0.3) 1px 2px,
    transparent 2px 4px,
    rgba(255, 255, 255, 0.3) 4px 5px,
    transparent 5px 6px
  );
  background-size: 6px 60px;
  background-repeat: no-repeat;
  background-position: center;
  cursor: col-resize;
  touch-action: none;
  transition: background-color 0.15s ease;
}

.pane-resizer:hover,
.pane-resizer.dragging {
  background-color: var(--accent);
}

.row-resizer {
  flex: 0 0 6px;
  align-self: stretch;
  /* Inset left/right by #editor-host/.console-panel's own corner radius,
     for the same reason as .pane-resizer's top/bottom inset. */
  margin: 0 0.5rem;
  border-radius: 999px;
  background-color: rgba(148, 163, 184, 0.4);
  /* A small, subtle two-ridge knurl mark, centered on the bar, running
     horizontally — i.e. along this bar's own length, same as the vertical
     bar's ridges run along its length. Explicit (non-repeating) stops so
     the pair is symmetric: 1px margin, 1px ridge, 2px gap, 1px ridge,
     1px margin. */
  background-image: linear-gradient(
    to bottom,
    transparent 0 1px,
    rgba(255, 255, 255, 0.3) 1px 2px,
    transparent 2px 4px,
    rgba(255, 255, 255, 0.3) 4px 5px,
    transparent 5px 6px
  );
  background-size: 60px 6px;
  background-repeat: no-repeat;
  background-position: center;
  cursor: row-resize;
  touch-action: none;
  transition: background-color 0.15s ease;
}

.row-resizer:hover,
.row-resizer.dragging {
  background-color: var(--accent);
}

.description-pane h3 {
  color: var(--accent);
  margin-top: 1.5rem;
}

#problem-constraints li {
  margin-bottom: 0.4rem;
}

.example pre {
  background: rgba(0, 0, 0, 0.25);
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  white-space: pre-wrap;
}

.editor-pane {
  flex: 1;
  min-width: 20%;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  overflow: hidden;
}

.editor-toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.editor-toolbar select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
}

button.primary {
  background: var(--accent);
  color: #0f172a;
}

button.primary:hover {
  background: #7dd3fc;
}

/* Disabled buttons look it: Submit after a saved Submit (issue #18), Run
   while it runs, Log in and Log out while they wait. Hovering one keeps its
   normal background instead of lighting up as if it could be clicked. */
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
button:disabled:hover {
  background: var(--accent-dark);
}
button.primary:disabled:hover {
  background: var(--accent);
}

/* The elapsed-time timer (issue #20): quiet, after Skip. tabular-nums
   gives every digit the same width, so the time doesn't jiggle as it
   counts. Green once frozen by a saved Submit. */
button.elapsed-timer {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
  padding: 0.5rem 0.75rem;
  background: transparent;
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.3);
  font-variant-numeric: tabular-nums;
}
button.elapsed-timer:hover {
  background: rgba(148, 163, 184, 0.15);
}
button.elapsed-timer.frozen {
  color: #4ade80;
  border-color: rgba(74, 222, 128, 0.5);
}

/* The idle timeout's warning (issue #102). No display here: the browser
   hides a closed <dialog> with dialog:not([open]) { display: none }, and a
   display set here would beat it, as .language-filter-row's did [hidden]. */
.idle-dialog {
  max-width: min(28rem, calc(100vw - 2rem));
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 0.75rem;
}
.idle-dialog::backdrop {
  background: rgba(15, 23, 42, 0.7);
}
.idle-dialog h2 {
  margin-top: 0;
}
#idle-dialog-countdown {
  font-variant-numeric: tabular-nums;
}
/* The warning's time left (#102), draining with the countdown. A <progress>
   is styled through non-standard pseudo-elements: the track is the element
   itself in Firefox and ::-webkit-progress-bar in Chromium and Safari; the
   filled part is ::-moz-progress-bar and ::-webkit-progress-value. */
.idle-dialog-progress {
  display: block;
  width: 100%;
  height: 0.5rem;
  margin: 0 0 1rem;
  appearance: none;
  border: none;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(148, 163, 184, 0.25);
}
.idle-dialog-progress::-webkit-progress-bar {
  background: rgba(148, 163, 184, 0.25);
  border-radius: 999px;
}
.idle-dialog-progress::-webkit-progress-value {
  background: var(--accent);
  border-radius: 999px;
}
.idle-dialog-progress::-moz-progress-bar {
  background: var(--accent);
  border-radius: 999px;
}

#editor-host {
  flex: 1;
  min-height: 180px;
  border-radius: 0.5rem;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.2);
}

/* No theme CDN is loaded (syntax highlighting is intentionally off, so
   there are no tokens to color) — these rules supply the dark-mode base
   colors a CodeMirror theme would otherwise provide. */
#editor-host .CodeMirror {
  height: 100%;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 0.95rem;
}

#editor-host .CodeMirror-gutters {
  background: transparent;
  border-right: 1px solid rgba(148, 163, 184, 0.15);
}

#editor-host .CodeMirror-linenumber {
  color: #64748b;
}

#editor-host .CodeMirror-cursor {
  border-left-color: var(--text);
}

#editor-host .CodeMirror-selected,
#editor-host .CodeMirror-focused .CodeMirror-selected {
  background: rgba(56, 189, 248, 0.25);
}

/* A fill-in-the-blank question (#160): its template as fixed code, in the
   editor's place and looks, with an input box at the blank. */
#editor-host .fill-in-template {
  margin: 0;
  height: 100%;
  box-sizing: border-box;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 0.95rem;
  white-space: pre-wrap;
  overflow: auto;
}

/* Width is set by problem-page.js (fitBlankToText) from the length of the
   box's text, in ch, one at least. content-box, unlike the rest of the
   page (the `*` rule at the top): the width is then the room for text
   alone, that many characters of this monospace font, with the padding
   outside it. As border-box, a box n ch wide lost its padding's 0.3ch and
   scrolled its last character. */
.fill-in-template .fill-in-blank {
  box-sizing: content-box;
  font: inherit;
  color: var(--text);
  background: rgba(56, 189, 248, 0.1);
  border: none;
  border-bottom: 2px solid var(--accent);
  padding: 0 0.15ch;
  margin: 0 0.1ch;
}

.fill-in-template .fill-in-blank:focus {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

/* A fill-in-the-blank judge's message and hints, in the Results tab. */
.judge-message {
  margin: 0.5rem 0;
}

.judge-hints {
  margin: 0.25rem 0 0;
  padding-left: 1.25rem;
}

/* In a Submissions row: what was typed, and the judge's message. */
.submission-answer,
.submission-message {
  margin-top: 0.2rem;
  font-size: 0.85em;
  color: #94a3b8;
}

.submission-answer code {
  color: var(--text);
}

.console-panel {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  max-height: 35%;
  overflow-y: auto;
}

.console-toolbar {
  display: flex;
  align-items: center;
  margin-top: 0.75rem;
}

#console-status {
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.console-tabs,
.description-tabs {
  display: flex;
  gap: 1rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  margin-bottom: 0.5rem;
}

.description-tabs {
  margin-bottom: 1.25rem;
}

.tab-button {
  background: transparent;
  color: #94a3b8;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0.35rem 0.1rem;
  margin-bottom: -1px;
  font-size: 0.85rem;
}

.tab-button:hover {
  background: transparent;
  color: var(--text);
}

.tab-button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

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

.coming-soon {
  color: #94a3b8;
  font-style: italic;
}

/* Links inside question text (Learning and Applying tabs). The browser's
   default blue is nearly invisible on the dark background. */
.tab-panel a,
.tab-panel a:visited {
  color: var(--accent);
}

/* Submissions tab (problem-page.js, refreshSubmissions) */
.submissions-heading {
  margin: 0 0 0.5rem;
  color: #94a3b8;
  font-size: 0.85rem;
}

.submissions-scroll {
  overflow-x: auto;
}

.submissions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.submissions-table th {
  text-align: left;
  color: #94a3b8;
  font-weight: 600;
  padding: 0.4rem 0.45rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

.submissions-table td {
  padding: 0.4rem 0.45rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
}

/* Only "When" may wrap; the short columns read badly split over two lines. */
.submissions-table td:not(:first-child) {
  white-space: nowrap;
}

.submissions-table button {
  padding: 0.2rem 0.7rem;
  font-size: 0.8rem;
}

.learning-cta {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(148, 163, 184, 0.15);
  color: var(--accent);
}

.tab-ref-link {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: text-decoration-color 0.15s;
}

.tab-ref-link:hover,
.tab-ref-link:focus-visible {
  text-decoration-color: currentColor;
}

#console-stdout,
#console-stderr {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 0.85rem;
  color: var(--text);
}

#console-stdout:empty::before,
#console-stderr:empty::before {
  content: '(empty)';
  color: #64748b;
  font-style: italic;
}

.status-pass {
  color: #4ade80;
}

.status-fail {
  color: #f87171;
}

.test-case {
  padding: 0.5rem 0;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
  font-size: 0.9rem;
}

.test-case:first-child {
  border-top: none;
}

.test-case.fail strong {
  color: #f87171;
}

.test-case.pass strong {
  color: #4ade80;
}

.test-case-error,
.test-case-error code {
  color: #f87171;
}

.error-block {
  white-space: pre-wrap;
  color: #f87171;
}

/* --- Sign-in page (login.html) and the header's account control ------------- */

.auth-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
}

.auth-card {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  width: 100%;
  max-width: 22rem;
  background: var(--surface);
  padding: 1.5rem;
  border-radius: 0.75rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.auth-card[hidden] {
  display: none;
}

.auth-card h2 {
  margin: 0;
  color: var(--accent);
  font-size: 1.2rem;
}

.auth-card label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: #94a3b8;
}

.auth-card input {
  padding: 0.55rem 0.7rem;
  border-radius: 0.4rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.auth-hint,
.auth-switch {
  margin: 0;
  font-size: 0.85rem;
  color: #94a3b8;
}

.auth-switch a {
  color: var(--accent);
}

.auth-error {
  color: #f87171;
  min-height: 1.2rem;
  margin: 0.8rem 0 0;
}

.account {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: #94a3b8;
}

.problem-header .account {
  margin: 0;
}

.account button {
  padding: 0.25rem 0.7rem;
  font-size: 0.8rem;
}

.account-trusted {
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  color: #fcd34d;
  box-shadow: inset 0 0 0 1px currentColor;
  font-size: 0.75rem;
}
