/* RedSAT playground. Light and dark themes follow the system setting; phones get their own
   layout (tabs, a bottom bar, a ⋯ menu) below 760px. */

:root {
  --accent: #e5484d;
  --accent-fill: #e5484d;
  --accent-strong: #cd2b31;
  --accent-soft: #feebec;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --raised: #ffffff;
  --border: #e4e4e7;
  --text: #1c1c1f;
  --muted: #6f6f78;
  --active-line: #f4f4f6;
  --editor-active-line: rgba(0, 0, 0, 0.035);
  --selection: #fbd5d7;
  --ok: #18794e;
  --warn: #ad5700;
  --error: #cd2b31;
  --info: #0b68cb;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
  --syn-keyword: #c2185b;
  --syn-type: #0b68cb;
  --syn-builtin: #6e56cf;
  --syn-function: #7c4a03;
  --syn-number: #0a7d5b;
  --syn-string: #a14f00;
  --syn-interpolation: #c2185b;
  --syn-comment: #8b8b94;
  --syn-operator: #5b5b66;
  --mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --editor-font-size: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #ff6369;
    --accent-strong: #ff8589;
    --accent-soft: #3b1219;
    --bg: #111113;
    --surface: #18181b;
    --raised: #222226;
    --border: #2e2e33;
    --text: #ececef;
    --muted: #9b9ba5;
    --active-line: #1f1f23;
    --editor-active-line: rgba(255, 255, 255, 0.035);
    --selection: #4a1f24;
    --ok: #3dd68c;
    --warn: #ffa057;
    --error: #ff6369;
    --info: #70b8ff;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    --syn-keyword: #ff8dc7;
    --syn-type: #70b8ff;
    --syn-builtin: #b8a6ff;
    --syn-function: #ffc96b;
    --syn-number: #4cc38a;
    --syn-string: #ffb77d;
    --syn-interpolation: #ff8dc7;
    --syn-comment: #7c7c86;
    --syn-operator: #b4b4bd;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-tap-highlight-color: transparent;
}

body.dragging {
  cursor: col-resize;
  user-select: none;
}

.mobile-only {
  display: none !important;
}

/* --- controls ----------------------------------------------------------------------------- */

button,
select,
input,
.links a {
  font: inherit;
  color: inherit;
}

button,
.links a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--raised);
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
}

button:hover,
.links a:hover {
  border-color: var(--muted);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
  flex: none;
}

button.primary {
  background: var(--accent-fill);
  border-color: var(--accent-fill);
  color: white;
  font-weight: 600;
  padding: 0 18px;
}

button.primary:hover {
  background: #cd2b31;
  border-color: #cd2b31;
}

button.danger {
  border-color: var(--error);
  color: var(--error);
}

.danger-text {
  color: var(--error) !important;
}

.ghost {
  background: transparent !important;
  border-color: transparent !important;
}

.ghost:hover {
  background: var(--active-line) !important;
}

button.small {
  height: 28px;
  padding: 0 10px;
  font-size: 13px;
}

button.big {
  height: 44px;
  padding: 0 22px;
  font-size: 15px;
  border-radius: 10px;
}

select {
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--raised);
  cursor: pointer;
}

body.running .run-button,
body:not(.running) .stop-button {
  display: none !important;
}

/* --- top bar ------------------------------------------------------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: inherit;
  text-decoration: none;
  margin-right: 8px;
}

.wordmark {
  font-size: 19px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.wordmark b {
  color: var(--accent);
  font-weight: 800;
}

.badge {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.file-button {
  min-width: 0;
  max-width: 340px;
  gap: 8px;
  font-weight: 600;
}

.file-button span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-button svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linejoin: round;
  stroke-linecap: round;
  color: var(--muted);
}

body[data-view='home'] .run-controls,
body[data-view='loading'] .run-controls {
  visibility: hidden;
}

.file-button[aria-expanded='true'] .chevron {
  transform: rotate(180deg);
}

.spacer {
  flex: 1;
}

.run-controls,
.links {
  display: flex;
  gap: 6px;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

/* --- loading ------------------------------------------------------------------------------ */

.loading {
  display: none;
  grid-row: 2;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

body[data-view='loading'] .loading {
  display: flex;
}

.loading.failed {
  color: var(--error);
}

.loading.failed .spinner {
  display: none;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --- workspace ---------------------------------------------------------------------------- */

.workspace {
  --split: 56%;
  display: grid;
  grid-template-columns: minmax(0, var(--split)) 6px minmax(0, 1fr);
  min-height: 0;
  padding: 12px;
}

body[data-view='home'] .workspace,
body[data-view='loading'] .workspace {
  display: none;
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.divider {
  cursor: col-resize;
  border-radius: 3px;
  margin: 0 1px;
}

.divider:hover,
body.dragging .divider {
  background: var(--selection);
}

.pane-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px 8px;
  border-bottom: 1px solid var(--border);
}

.about {
  min-width: 0;
  flex: 1;
}

.doc-title {
  width: 100%;
  padding: 1px 4px;
  margin-left: -5px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  font-size: 15px;
  font-weight: 650;
}

.doc-title:not([readonly]):hover {
  border-color: var(--border);
}

.doc-title:not([readonly]):focus {
  border-color: var(--accent);
  outline: none;
}

.doc-title[readonly] {
  cursor: default;
  outline: none;
}

.about p,
.pane-head h2 {
  margin: 0;
}

.about p {
  color: var(--muted);
  font-size: 13px;
}

.pane-head h2 {
  font-size: 15px;
  font-weight: 650;
  padding-top: 2px;
}

.doc-actions {
  display: flex;
  gap: 4px;
}

.note {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 7px 16px;
  background: var(--accent-soft);
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.note span {
  flex: 1;
}

.editor {
  flex: 1;
  min-height: 0;
}

.options {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
  font-size: 13px;
  color: var(--muted);
}

.options label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.options input {
  accent-color: var(--accent-fill);
  width: 15px;
  height: 15px;
}

.options .solver {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.output-pane .pane-head {
  flex-wrap: wrap;
  row-gap: 6px;
}

.output-pane .pane-head > * {
  min-width: 0;
}

/* --- output ------------------------------------------------------------------------------- */

/* The members of a race, one chip each; the selected one's output is shown below. */
.race-bar {
  display: flex;
  flex: none;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.race-bar[hidden] {
  display: none;
}

.race-bar::-webkit-scrollbar {
  display: none;
}

.race-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
}

.race-chip::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.race-chip[aria-selected='true'] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.race-chip[data-state='running']::before {
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

.race-chip[data-state='won']::before {
  background: var(--ok);
}

.race-chip[data-state='failed']::before {
  background: var(--warn);
}

.output {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 12px 16px;
  overflow: auto;
  font: 13.5px/1.55 var(--mono);
  font-variant-ligatures: none;
  /* Lines keep their layout (aligned tables, grids) and scroll sideways rather than wrap. */
  white-space: pre;
}

.output .trace {
  color: var(--muted);
  font-size: 12.5px;
}

.output .system {
  color: var(--muted);
  font-style: italic;
}

.output .crash {
  color: var(--error);
  font-weight: 600;
}

.output .diagnostic {
  display: block;
  width: 100%;
  height: auto;
  margin: 8px 0;
  padding: 8px 12px;
  border: none;
  border-left: 3px solid var(--info);
  border-radius: 0 6px 6px 0;
  background: var(--active-line);
  font: 12.5px/1.5 var(--mono);
  text-align: left;
  white-space: pre;
  overflow-x: auto;
}

.output .diagnostic.error {
  border-left-color: var(--error);
}

.output .diagnostic.warning {
  border-left-color: var(--warn);
}

.output .diagnostic:hover {
  background: var(--selection);
}

.placeholder {
  max-width: 460px;
  margin: 40px auto;
  padding: 0 12px;
  color: var(--muted);
  font-family: var(--sans);
  white-space: normal;
  text-align: center;
}

kbd {
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--raised);
  font: 12px var(--mono);
}

/* The status, then the figures: on one line when they fit, else the figures go below. */
.statusbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 2px 16px;
  padding: 7px 16px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--muted);
}

.status-text.ok {
  color: var(--ok);
  font-weight: 600;
}

.status-text.error {
  color: var(--error);
  font-weight: 600;
}

.status-text.running::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}

.status-text {
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats {
  display: flex;
  flex: 0 1 auto;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 2px 12px;
  min-width: 0;
  font-variant-numeric: tabular-nums;
}

.stat {
  white-space: nowrap;
  cursor: help;
}

.stat b {
  color: var(--text);
  font-weight: 600;
}

/* --- editor tooltips ---------------------------------------------------------------------- */

.hover,
.signature {
  max-width: 460px;
  padding: 8px 11px;
  font-size: 13px;
  line-height: 1.45;
}

.hover {
  max-height: min(26em, 60vh);
  overflow-y: auto;
}

/* Docs, rendered from the compiler's light Markdown (see renderDoc in intelligence.js). */
.doc p,
.doc ul {
  margin: 0 0 6px;
}

.doc > :last-child {
  margin-bottom: 0;
}

.doc ul {
  padding-left: 18px;
}

.doc li + li {
  margin-top: 3px;
}

.doc code,
.doc-syntax {
  font-family: var(--mono);
  font-size: 12px;
}

.doc code {
  padding: 0 3px;
  border-radius: 4px;
  background: var(--active-line);
}

.doc-syntax {
  margin-bottom: 6px;
  font-weight: 600;
  white-space: pre-wrap;
}

.hover-head,
.signature-head {
  font: 600 13px var(--mono);
  margin-bottom: 2px;
}

.hover-kind {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.signature-head {
  font-weight: 500;
}

.active-param {
  color: var(--accent);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.signature-doc {
  color: var(--muted);
  margin-top: 3px;
}

/* --- home --------------------------------------------------------------------------------- */

.home {
  grid-row: 2;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.home-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 24px 48px;
}

.home-close {
  margin: -8px 0 8px -10px;
}

/* The examples page's header, on phones only. */
.home-page-head {
  display: none;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  align-items: center;
  gap: 32px;
  padding: 32px;
  margin-bottom: 28px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background:
    radial-gradient(1200px 300px at -10% -40%, var(--accent-soft), transparent 70%),
    var(--surface);
}

.hero h1 {
  text-wrap: balance;
  margin: 0 0 12px;
  font-size: 34px;
  line-height: 1.15;
  letter-spacing: -0.025em;
}

.hero h1 span {
  color: var(--accent);
}

.hero p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 15.5px;
  max-width: 560px;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.hero .hero-note {
  margin: 0;
  font-size: 13px;
}

.hero a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.hero.compact {
  padding: 22px 28px;
}

.hero.compact h1 {
  font-size: 26px;
}

.teaser {
  margin: 0;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  font: 14px/1.7 var(--mono);
  overflow-x: auto;
  box-shadow: var(--shadow);
}

.teaser .k {
  color: var(--syn-keyword);
  font-weight: 600;
}

.teaser .n {
  color: var(--syn-number);
}

.teaser .t {
  color: var(--syn-type);
}

.teaser .c {
  color: var(--ok);
  font-style: italic;
}

.shelf {
  margin-bottom: 26px;
}

.shelf h2,
.examples-title h2 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.examples-title h2 {
  margin: 8px 0 16px;
  font-size: 20px;
  text-transform: none;
  letter-spacing: -0.01em;
  color: var(--text);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.card {
  position: relative;
  display: flex;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s;
}

.card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.card.current {
  border-color: var(--accent);
}

.card.new {
  border-style: dashed;
}

.card-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 4px;
  width: 100%;
  height: auto;
  padding: 14px 16px;
  border: none;
  background: none;
  text-align: left;
  white-space: normal;
}

.card-main:hover {
  border: none;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  font-size: 14.5px;
}

.card.file .card-title {
  font-family: var(--mono);
  font-size: 13.5px;
}

.card-text {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card .tag {
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 600;
}

/* An example no solver finishes. */
.card .tag.hard {
  background: var(--accent-fill);
  color: white;
}

.card-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  opacity: 0;
}

.card:hover .card-delete,
.card-delete:focus-visible {
  opacity: 1;
}

.card-delete:hover {
  color: var(--error);
  border-color: var(--border);
}

/* --- dropdown buttons (the solver picker; the file button is their big sibling) ------------ */

.dropdown-button {
  min-width: 0;
  max-width: 220px;
  height: 30px;
  gap: 6px;
  padding: 0 8px 0 10px;
  font-size: 13px;
  font-weight: 600;
}

.dropdown-button span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-button .chevron {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--muted);
  transition: transform 0.12s;
}

.dropdown-button[aria-expanded='true'] .chevron,
.file-button .chevron {
  transition: transform 0.12s;
}

.dropdown-button[aria-expanded='true'] .chevron {
  transform: rotate(180deg);
}

.dropdown-panel .switcher-list {
  padding: 6px;
}

/* --- file switcher ------------------------------------------------------------------------ */

.switcher {
  position: fixed;
  inset: auto;
  width: min(460px, calc(100vw - 16px));
  max-height: min(70vh, 640px);
  margin: 0;
  padding: 0;
  display: none;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--raised);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.switcher:popover-open {
  display: flex;
}

.switcher-search {
  flex: none;
  margin: 10px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  outline: none;
  font-size: 14px;
}

.switcher-search:focus {
  border-color: var(--accent);
}

.switcher-list {
  overflow-y: auto;
  padding: 0 6px 6px;
  overscroll-behavior: contain;
}

.switcher-section + .switcher-section {
  margin-top: 6px;
  border-top: 1px solid var(--border);
}

/* Section headers stay in view while their rows scroll past. */
.switcher-section h3 {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -6px 2px;
  padding: 9px 16px 6px;
  background: var(--raised);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.switcher-count {
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--active-line);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  text-align: center;
}

.switcher-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  height: auto;
  min-height: 36px;
  padding: 6px 10px;
  border: none;
  border-radius: 8px;
  background: none;
  text-align: left;
  white-space: normal;
}

/* A row that is a link (e.g. Guide in the ⋯ menu). */
a.switcher-row {
  box-sizing: border-box;
  color: inherit;
  text-decoration: none;
}

.switcher-row:hover {
  border: none;
}

.switcher-row.active {
  background: var(--active-line);
}

.switcher-row.current .switcher-title::after {
  content: ' ✓';
  color: var(--accent);
}

.switcher-row.file .switcher-title {
  font-family: var(--mono);
  font-size: 13px;
}

.switcher-row.command .switcher-title {
  color: var(--accent);
}

.switcher-title {
  font-weight: 600;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.switcher-detail {
  max-width: 100%;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.switcher-empty {
  margin: 12px;
  color: var(--muted);
}

.switcher-footer {
  margin: 6px -6px 0;
  padding: 6px 6px 0;
  border-top: 1px solid var(--border);
}

/* --- page footer, toast, menu sheet ------------------------------------------------------- */

.pagefoot {
  padding: 0 18px 10px;
  color: var(--muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 10;
  padding: 9px 16px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-weight: 500;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* --- medium screens ----------------------------------------------------------------------- */

@media (max-width: 1100px) {
  .badge {
    display: none;
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .teaser {
    display: none;
  }
}

/* --- phones ------------------------------------------------------------------------------- */

@media (max-width: 760px) {
  :root {
    --editor-font-size: 15px;
  }

  .mobile-only {
    display: revert !important;
  }

  .desktop-only {
    display: none !important;
  }

  html,
  body {
    overflow: hidden;
    overscroll-behavior: none;
  }

  body {
    position: fixed;
    top: var(--app-top, 0);
    left: 0;
    right: 0;
    height: var(--app-height, 100dvh);
    grid-template-rows: auto auto 1fr auto;
  }

  body[data-view='home'] {
    grid-template-rows: auto 1fr;
  }

  .topbar {
    gap: 8px;
    padding: 8px 10px;
    padding-top: max(8px, env(safe-area-inset-top));
  }

  .brand {
    margin-right: 0;
  }

  .wordmark {
    display: none;
  }

  .file-button {
    flex: 1;
    max-width: none;
    height: 40px;
    justify-content: flex-start;
  }

  .file-button .chevron {
    margin-left: auto;
  }

  .spacer {
    display: none;
  }

  .tabs {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 6px 10px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }

  body[data-view='home'] .tabs,
  body[data-view='home'] .mobilebar {
    display: none !important;
  }

  .tabs button {
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-weight: 600;
  }

  .tabs button[aria-selected='true'] {
    background: var(--active-line);
    color: var(--text);
  }

  .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
  }

  .workspace {
    display: block;
    padding: 0;
    min-height: 0;
  }

  .pane {
    height: 100%;
    border: none;
    border-radius: 0;
  }

  .divider {
    display: none;
  }

  body[data-tab='code'] .output-pane,
  body[data-tab='output'] .editor-pane {
    display: none;
  }

  .pane-head {
    padding: 8px 12px 6px;
  }

  .output-pane .pane-head {
    display: none;
  }

  .note {
    padding: 8px 12px;
    flex-wrap: wrap;
  }

  .doc-actions button.small {
    height: 34px;
  }

  .output {
    padding: 12px;
    font-size: 13px;
  }

  .statusbar {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 6px 12px;
  }

  .stats {
    justify-content: flex-start;
  }

  .mobilebar {
    display: flex !important;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
  }

  body.keyboard-open .mobilebar {
    padding-bottom: 8px;
  }

  .mobilebar .run-button,
  .mobilebar .stop-button {
    height: 42px;
    flex: none;
    padding: 0 18px;
    border-radius: 10px;
  }

  /* The run options, beside Run (the label "Solver" is left out: the choice says it). */
  .mobile-options {
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .mobile-options::-webkit-scrollbar {
    display: none;
  }

  .mobile-options .options {
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 12px;
    font-size: 14px;
    color: var(--text);
  }

  .mobile-options .options label {
    flex: none;
    min-height: 42px;
  }

  .mobile-options .options input {
    width: 18px;
    height: 18px;
  }

  .mobile-options .solver > span:first-child {
    display: none;
  }

  .mobile-options .dropdown-button {
    height: 42px;
    max-width: 170px;
  }

  .home-inner {
    padding: 14px 12px 32px;
  }

  .hero {
    padding: 22px 18px;
    margin-bottom: 20px;
    border-radius: 14px;
  }

  .hero h1,
  .hero.compact h1 {
    font-size: 25px;
  }

  .hero p {
    font-size: 15px;
  }

  .hero-actions {
    flex-direction: column;
  }

  .hero-actions button {
    width: 100%;
  }

  /* Two pages: the landing (introduction, a short example, the ways to start), and the
     examples, which "Start with an example" opens. */
  .home-inner[data-page='landing'] .shelf,
  .home-inner[data-page='landing'] .examples-title,
  .home-inner[data-page='examples'] .hero,
  .home-inner[data-page='examples'] .home-close,
  .home-inner[data-page='examples'] .shelf.files,
  .home-inner[data-page='examples'] .examples-title {
    display: none;
  }

  .home-inner[data-page='examples'] .home-page-head {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: -4px 0 10px -8px;
  }

  .home-page-head h2 {
    margin: 0;
    font-size: 18px;
  }

  /* The landing's order: title, introduction, the short example, then the buttons. */
  .hero {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
  }

  .hero-text {
    display: contents;
  }

  .hero h1 {
    order: 1;
  }

  .hero .hero-lead {
    order: 2;
  }

  .hero .teaser {
    display: block;
    order: 3;
    margin-bottom: 20px;
    font-size: 13px;
    overflow-x: auto;
  }

  .hero-actions {
    order: 4;
  }

  .hero .hero-note {
    order: 5;
  }

  .cards {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .card:hover {
    transform: none;
    box-shadow: none;
  }

  .card-delete {
    opacity: 1;
  }

  .card-main {
    padding: 12px 14px;
  }

  .toast {
    bottom: calc(80px + env(safe-area-inset-bottom));
  }
}
