/* Colors and sizes shared by the whole page (light theme) */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1c2024;
  --muted: #646b75;
  --border: #dde1e6;
  --field: #ffffff;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --accent-soft: #e3edfd;
  --ok: #1d8049;
  --bad: #c2362f;
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light dark;
}

/* Dark theme, following the system setting */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111316;
    --panel: #1a1d21;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --border: #2e333a;
    --field: #14171a;
    --accent: #5b8ff0;
    --accent-text: #0b0d10;
    --accent-soft: #1f2f4d;
    --ok: #4cc27f;
    --bad: #f06b66;
  }
}

/* Page basics */
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, sans-serif;
}

/* Header: title on the left, status on the right */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
}
.top h1 {
  margin: 0;
  font-size: 1.25rem;
}
.top h1 span {
  color: var(--muted);
  font-weight: 400;
}

/* Status line, colored by message kind */
.status {
  margin: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.status[data-kind="ok"] {
  color: var(--ok);
}
.status[data-kind="error"] {
  color: var(--bad);
}

/* Grid: controls on the left, viewer on the right, runs underneath */
.layout {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 1rem;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.25rem 1.25rem;
}
.runs {
  grid-column: 1 / -1;
}

/* Phones: one column */
@media (max-width: 760px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    padding: 0 1rem 1rem;
  }
  .top {
    padding: 1rem;
  }
}

/* Card look shared by the three sections */
.panel {
  min-width: 0;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Control column: stacked groups */
.controls {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}
.group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.group:disabled {
  opacity: 0.45;
}

/* Small caption above each field */
.label {
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.label small {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

/* Text fields */
textarea,
input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}
textarea,
#done-input,
#pieces-input {
  resize: vertical;
}
textarea:focus,
input:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* Inline error under a field (takes no space when empty) */
.error {
  margin: 0;
  color: var(--bad);
  font-size: 0.85rem;
}
.error:empty {
  display: none;
}

/* Buttons */
button {
  padding: 0.45rem 0.9rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}
button:hover:not(:disabled) {
  border-color: var(--accent);
}
button:disabled {
  cursor: default;
  opacity: 0.5;
}
button.quiet {
  border-color: transparent;
  color: var(--muted);
}
button.primary {
  padding: 0.65rem;
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

/* Row of buttons */
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Step / Full cube switch */
.segmented {
  display: flex;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.segmented label {
  flex: 1;
  padding: 0.35rem;
  border-radius: 6px;
  text-align: center;
  cursor: pointer;
}
.segmented input {
  position: absolute;
  opacity: 0;
}
.segmented label:has(input:checked) {
  background: var(--panel);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.15);
  font-weight: 600;
}
.segmented label:has(input:focus-visible) {
  outline: 2px solid var(--accent);
}

/* Piece toggle chips: one box per piece type, stacked like the group's other fields */
.chip-boxes {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
/* A long box (a puzzle with many pieces of a type) scrolls; the padding keeps focus rings in view, the margin keeps the box where it was */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  max-height: 9.5rem;
  overflow-y: auto;
  padding: 2px;
  margin: -2px;
}
/* Chips the puzzle lays out as grids (the Clock's front and back dials): the grids side by side, each its name over a fixed number of columns */
.chip-grids {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
}
.chip-grid-name {
  display: block;
  margin-bottom: 0.2rem;
  color: var(--muted);
  font-size: 0.8rem;
}
.chips.chip-grid {
  display: grid;
  grid-template-columns: repeat(var(--columns), auto);
  justify-content: start;
}
/* The filter over the chips spans the column, its text in the chips' font */
.chip-filter {
  width: 100%;
  box-sizing: border-box;
  font-family: var(--mono);
}
/* Boxes and buttons made from the puzzle sit in their row as if written there */
.box-group {
  display: contents;
}
.chip {
  min-width: 3.1rem;
  padding: 0.2rem 0.4rem;
  font-family: var(--mono);
  font-size: 0.85rem;
}
.chip[aria-pressed="true"] {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
  font-weight: 600;
}
/* Chips with a role other than solved: dashed border plus their role tag (:o, :p, :s2, :r…) */
.chip[aria-pressed="true"]:not([data-tag=""]) {
  border-style: dashed;
}
.chip[aria-pressed="true"]:not([data-tag=""])::after {
  content: attr(data-tag);
}

/* Anything the picked puzzle doesn't have (move boxes, rows, quick picks) stays hidden, whatever its own display */
[hidden] {
  display: none !important;
}

/* Allowed-move checkboxes */
.moves {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.9rem;
  font-family: var(--mono);
}
.moves label {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
}
/* Move box rows (outer, wide, slices…), one under the other */
.move-rows {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
/* The half-turn boxes' fold: its title quiet, its rows a little below it */
.half-turns summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85em;
}
.half-turns .move-rows {
  margin-top: 0.3rem;
}
/* A row keeps its name on the left and wraps only its boxes */
.moves.move-row {
  flex-wrap: nowrap;
}
.move-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.9rem;
}
/* Hand turn rows and move box rows: each row's name in a column of its own, so the boxes line up */
.moves.hand-turns .axis-name,
.moves.move-row .axis-name {
  min-width: 5.5rem;
  color: var(--muted);
}

/* Offsets and solvable-with fields with their quick-pick buttons on one line (buttons wrap below on narrow screens) */
.offsets input {
  flex: 1 1 9rem;
  width: auto;
  min-width: 0;
}
.offsets button {
  padding: 0.45rem 0.6rem;
}

/* Blindfolded fields: buffer and parity pieces fill their row, the targets number stays small */
.bld .check-label:has(input[type="text"]) {
  flex: 1 1 10rem;
  min-width: 0;
}
.bld input[type="text"] {
  flex: 1 1 4rem;
  width: auto;
  min-width: 0;
}

/* Move quick picks: small buttons under the move boxes (the row wraps them on narrow screens) */
.picks button {
  padding: 0.3rem 0.6rem;
}

/* Pieces box (one alternative per line) with its add button beside it, at the top */
.pieces {
  align-items: flex-start;
}
.pieces textarea {
  flex: 1 1 12rem;
  width: auto;
  min-width: 0;
}

/* Small note under a field */
.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Viewer column: cube on top, result below */
.viewer {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.player-slot twisty-player {
  width: 100%;
  height: 340px;
}
.result {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* Solution text */
.solution {
  margin: 0;
  font-family: var(--mono);
  font-size: 1.1rem;
  overflow-wrap: anywhere;
}

/* Moves / time / check numbers */
.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  margin: 0.25rem 0 0.5rem;
}
.stats dt {
  color: var(--muted);
  font-size: 0.8rem;
}
.stats dd {
  margin: 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
#check-stat[data-kind="ok"] {
  color: var(--ok);
}
#check-stat[data-kind="error"] {
  color: var(--bad);
}

/* Runs table */
.runs h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th,
td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
th {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}
td:last-child {
  font-family: var(--mono);
  white-space: normal;
}
tbody tr {
  cursor: pointer;
}
tbody tr:hover {
  background: var(--bg);
}
tbody tr.selected {
  background: var(--accent-soft);
}
tbody tr.bad td[data-col="check"] {
  color: var(--bad);
}
.empty {
  margin: 0.5rem 0 0;
  color: var(--muted);
}

/* Fingering table and answers list under the result: stacked under their captions, scrolling when long */
.fingering,
.candidates {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.5rem;
}
.scroll {
  max-height: 16rem;
  overflow-y: auto;
}
/* Fingering rows aren't clickable; the move is in the mono font, the last column in the text font; regrips are muted */
.fingering tbody tr {
  cursor: default;
}
.fingering td:first-child {
  font-family: var(--mono);
}
.fingering td:last-child {
  font-family: inherit;
  white-space: nowrap;
}
.fingering tr.regrip td {
  color: var(--muted);
}


/* Right column: viewer and method panels stacked */
.side {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

/* Method panel: editor on top, results under it */
.method {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.method h2 {
  margin: 0;
  font-size: 1rem;
}
.method-editor {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

/* Rows whose fields share the width (they wrap on narrow screens) */
.row.grow > select,
.row.grow > input[type="text"] {
  flex: 1 1 10rem;
  width: auto;
  min-width: 0;
}

/* Checkbox with its text */
.check-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
}

/* Small number field inside its text (lookahead steps, extra moves, search time) */
.number-label input[type="number"] {
  width: 4rem;
  padding: 0.3rem 0.4rem;
}

/* Method search button and its time budget on one line, the button taking the room left */
.search-row {
  align-items: center;
}
.search-row > button {
  flex: 1 1 auto;
}

/* Numbered step list */
.step-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}
.step-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  counter-increment: step;
}
.step-list li::before {
  content: counter(step);
  min-width: 1.2em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.step-list li.editing {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* Step name over its settings */
.step-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}
.step-text small {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

/* Edit / up / down / remove buttons */
.step-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.25rem;
}
.step-actions button {
  padding: 0.2rem 0.5rem;
}

/* Total row of the method results */
tbody tr.total td {
  font-weight: 600;
}
