/* SPDX-FileCopyrightText: The flint contributors */
/* SPDX-License-Identifier: MIT OR Apache-2.0 */

:root {
  color-scheme: light dark;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --border: #dedbd3;
  --text: #1f1d1a;
  --muted: #6b665d;
  --accent: #d9480f;
  --accent-soft: #fdebe1;
  --selected: #fde3d3;
  --error: #c92a2a;
  --error-soft: #fdecec;
  --warn: #a35f00;
  --warn-soft: #fff4dc;
  --ok: #2b8a3e;
  --ok-soft: #e6f4e9;
  --ghost: #8a8478;
  --code-bg: #fbfaf8;
  --tok-comment: #8a8478;
  --tok-required: #c92a2a;
  --tok-placeholder: #7048e8;
  --tok-format: #ae3ec9;
  --tok-wildcard: #0c8599;
  --tok-slash: #a35f00;
  --terminal-bg: #1d1b19;
  --terminal-text: #e9e6df;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 2px 8px rgb(0 0 0 / 4%);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --line: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514;
    --surface: #1f1e1c;
    --surface-2: #282624;
    --border: #3a3734;
    --text: #ece9e3;
    --muted: #a39d92;
    --accent: #ff8a4c;
    --accent-soft: #3a2519;
    --selected: #4a2b1a;
    --error: #ff8787;
    --error-soft: #3d1f1f;
    --warn: #ffc069;
    --warn-soft: #3a2e17;
    --ok: #8ce99a;
    --ok-soft: #1f3324;
    --ghost: #8f897e;
    --code-bg: #1a1918;
    --tok-comment: #8f897e;
    --tok-required: #ff8787;
    --tok-placeholder: #b197fc;
    --tok-format: #e599f7;
    --tok-wildcard: #66d9e8;
    --tok-slash: #ffc069;
    --terminal-bg: #0f0e0d;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  /* biome-ignore lint/complexity/noImportantStyles: the hidden attribute must win over any class's display, or hidden things show */
  display: none !important;
}

html,
body {
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px / 1.5 var(--sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

code {
  font-family: var(--mono);
  font-size: 0.92em;
}

a {
  color: var(--accent);
}

h2 {
  font-size: 13px;
  margin: 0;
  font-weight: 600;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

button {
  font: inherit;
  color: inherit;
}

.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
.button:hover {
  border-color: var(--accent);
}
.button.small {
  padding: 2px 8px;
  font-size: 12px;
}

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

/* Header */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
}
/* The bolt is narrow, so it's drawn a little larger than crank's round
   logo to carry the same weight beside the name. */
.logo {
  width: 24px;
  height: 24px;
  fill: var(--accent);
}
.tagline {
  margin: 0;
  color: var(--muted);
  flex: 1;
  min-width: 200px;
}
.topbar-actions {
  display: flex;
  gap: 8px;
}

/* Examples */

.examples {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.example-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.example-chip {
  flex: none;
  display: inline-flex;
  gap: 6px;
  align-items: baseline;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
  white-space: nowrap;
}
.example-chip .number {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.example-chip:hover {
  border-color: var(--accent);
}
.example-chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.explanation {
  grid-area: explanation;
}
.explanation-head {
  justify-content: flex-start;
  flex-wrap: wrap;
}
.explanation-head h2 {
  margin-right: auto;
}
.explanation-body {
  overflow: auto;
  flex: 1;
  padding: 4px 14px 12px;
}
.explanation-body p {
  margin: 6px 0 0;
}
.explanation-body ul {
  margin: 6px 0 0;
  padding-left: 20px;
}
.explanation-body code {
  background: var(--surface-2);
  padding: 1px 4px;
  border-radius: 4px;
}
.modified {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0 6px;
  border-radius: 999px;
}

/* Workspace */

.workspace {
  flex: 1;
  display: grid;
  padding: 16px 20px;
  /* The gaps between the panels are tracks of their own, each holding a
     splitter; dragging one sets the custom property beside it (see
     "splitters" in app.js). */
  --gap: 16px;
  --explanation-width: 280px;
  --files-width: 320px;
  --editor-height: minmax(280px, 1fr);
  --output-height: minmax(160px, auto);
  grid-template-columns: min(var(--files-width), 60%) var(--gap) minmax(0, 1fr);
  grid-template-rows: var(--editor-height) var(--gap) var(--output-height);
  grid-template-areas: "files split-files editor" "files split-files split-output" "files split-files output";
  min-height: 560px;
}
/* An example's description, when there is one, is a column of its own
   before the files. */
.workspace:has(> .explanation:not([hidden])) {
  grid-template-columns:
    min(var(--explanation-width), 40%) var(--gap) min(var(--files-width), 40%) var(--gap)
    minmax(0, 1fr);
  grid-template-areas:
    "explanation split-explanation files split-files editor"
    "explanation split-explanation files split-files split-output"
    "explanation split-explanation files split-files output";
}
.files {
  grid-area: files;
}
.editor-panel {
  grid-area: editor;
}
.output-panel {
  grid-area: output;
}

.splitter {
  position: relative;
  margin: 0;
  border: 0;
  border-radius: 4px;
  /* A touch drag resizes, rather than scrolling the page. */
  touch-action: none;
}
#split-explanation {
  grid-area: split-explanation;
  cursor: col-resize;
}
#split-files {
  grid-area: split-files;
  cursor: col-resize;
}
#split-output {
  grid-area: split-output;
  cursor: row-resize;
}
/* A line down the middle of the gap, while it's hovered or dragged. */
.splitter::before {
  content: "";
  position: absolute;
  border-radius: 1px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.1s;
}
#split-explanation::before,
#split-files::before {
  inset: 0 7px;
}
#split-output::before {
  inset: 7px 0;
}
.splitter:hover::before,
.splitter.dragging::before {
  opacity: 1;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  min-height: 40px;
}
.panel-head h2 {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.flint-icon-inline {
  display: inline-grid;
  place-items: center;
  color: var(--accent);
}
/* A touch larger than the same icon in the file list. */
.flint-icon-inline svg {
  width: 18px;
  height: 18px;
}
#editor-path {
  font-family: var(--mono);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.error-note {
  font-size: 11px;
  color: var(--error);
  background: var(--error-soft);
  padding: 0 8px;
  border-radius: 999px;
  white-space: nowrap;
  flex: none;
}
.panel-note {
  margin: 0;
  padding: 8px 12px 4px;
  color: var(--muted);
  font-size: 12px;
}
/* The lozenge sits beside the filename; the hint's own margin pushes it right. */
.editor-panel .panel-head {
  justify-content: flex-start;
}
#editor-heading {
  flex: 0 1 auto;
  min-width: 4em;
}
.hint {
  flex: 0 10 auto;
  min-width: 0;
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar {
  display: flex;
  gap: 2px;
}
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 5px;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
}
.icon-button:hover {
  background: var(--surface);
  color: var(--text);
}
.icon-button svg,
.row svg {
  width: 16px;
  height: 16px;
}

/* File tree */

.tree {
  overflow: auto;
  padding: 4px 0 12px;
  flex: 1;
  font-size: 13px;
}

.row {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 6px 0 calc(8px + var(--depth, 0) * 16px);
  cursor: default;
  position: relative;
  white-space: nowrap;
  border-left: 2px solid transparent;
}
.row:hover {
  background: var(--surface-2);
}
.row:focus-visible {
  outline-offset: -2px;
}
.row .actions svg {
  width: 14px;
  height: 14px;
}
.row .twisty {
  width: 14px;
  flex: none;
  color: var(--muted);
  display: inline-grid;
  place-items: center;
}
.row .twisty svg {
  width: 10px;
  height: 10px;
  transition: transform 0.1s;
}
.row[aria-expanded="true"] .twisty svg {
  transform: rotate(90deg);
}
.row .icon {
  flex: none;
  display: inline-grid;
  place-items: center;
  color: var(--muted);
}
.row .name {
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--mono);
  font-size: 12.5px;
}
.row .badge {
  margin-left: 6px;
  font-size: 11px;
  padding: 0 6px;
  border-radius: 999px;
  flex: none;
  line-height: 16px;
}
.row .actions {
  margin-left: auto;
  display: none;
  gap: 1px;
  padding-left: 6px;
}
.row:hover .actions,
.row:focus-within .actions {
  display: flex;
}
.row .actions button {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
}
.row .actions button:hover {
  background: var(--surface);
  color: var(--text);
}

.row.directory,
.row.flint {
  cursor: pointer;
}

/* A .flint file: the only kind that opens, so it looks clickable. */
.row.flint .icon {
  color: var(--accent);
}
.row.flint .name {
  color: var(--accent);
  font-weight: 600;
}

/* The .flint file open in the editor. */
.row.open {
  background: var(--selected);
  border-left-color: var(--accent);
}
.row.open:hover {
  background: var(--selected);
}

/* Selected (target for "new file" etc.). */
.row.selected:not(.open) {
  background: var(--surface-2);
}

/* Something flint reported: an entry no rule allows, or one of a group's disagreeing files. */
.row.problem .name {
  color: var(--error);
}
.row.problem .icon {
  color: var(--error);
}
.row.problem .badge {
  background: var(--error-soft);
  color: var(--error);
}

/* A .flint file that doesn't parse. */
.row.broken .name {
  text-decoration: underline wavy var(--error);
  text-underline-offset: 3px;
}
.row.broken .badge {
  background: var(--error-soft);
  color: var(--error);
}

/* Something required that's missing: shown where flint expects it. */
.row.ghost .name {
  color: var(--ghost);
  font-style: italic;
}
.row.ghost .icon {
  color: var(--ghost);
  opacity: 0.7;
}
.row.ghost::before {
  content: "";
  position: absolute;
  inset: 3px 6px 3px calc(26px + var(--depth, 0) * 16px);
  border: 1px dashed var(--warn);
  border-radius: 4px;
  pointer-events: none;
}
.row.ghost .badge {
  background: var(--warn-soft);
  color: var(--warn);
}

/* Last, as the most specific; only the line, so a broken .flint file's
   underline stays wavy and red. */
.row.flint:hover .name {
  text-decoration-line: underline;
}

/* A collapsed folder with a problem somewhere inside. */
.row .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--error);
  margin-left: 6px;
  flex: none;
}

.row.flash {
  animation: flash 1.2s ease-out;
}
@keyframes flash {
  0%,
  30% {
    background: var(--accent-soft);
  }
  100% {
    background: transparent;
  }
}

.row input {
  font: 12.5px var(--mono);
  padding: 1px 4px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  min-width: 0;
  height: 22px;
}
.row input:invalid {
  border-color: var(--error);
}

.tree-empty {
  color: var(--muted);
  padding: 8px 14px;
  margin: 0;
}

/* Editor: a textarea over a highlighted copy of its own text. */

.editor {
  flex: 1;
  min-height: 0;
  position: relative;
  background: var(--code-bg);
}
.editor-scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
  display: flex;
  align-items: flex-start;
}
.gutter {
  flex: none;
  position: sticky;
  left: 0;
  z-index: 2;
  padding: 10px 0;
  min-width: 44px;
  min-height: 100%;
  background: var(--code-bg);
  border-right: 1px solid var(--border);
  font: 12.5px / var(--line) var(--mono);
  color: var(--muted);
  text-align: right;
  user-select: none;
}
.gutter div {
  padding: 0 10px 0 16px;
  height: var(--line);
  position: relative;
}
.gutter .error,
.gutter .warn {
  color: var(--text);
  font-weight: 600;
}
.gutter .error::before,
.gutter .warn::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 7px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.gutter .error::before {
  background: var(--error);
}
.gutter .warn::before {
  background: var(--warn);
}

.code {
  position: relative;
  flex: 1;
  min-width: max-content;
  min-height: 100%;
}
.highlight,
#source {
  margin: 0;
  padding: 10px 16px 10px 12px;
  border: 0;
  font: 13px / var(--line) var(--mono);
  tab-size: 4;
  white-space: pre;
  overflow-wrap: normal;
  letter-spacing: 0;
}
.highlight {
  color: var(--text);
  min-height: 100%;
  pointer-events: none;
}
#source {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
  outline: none;
}
#source::selection {
  background: rgb(217 72 15 / 25%);
  color: transparent;
}
.highlight .line {
  display: block;
  min-height: var(--line);
}
.highlight .line.error {
  background: var(--error-soft);
}
.highlight .line.warn {
  background: var(--warn-soft);
}
.highlight .note {
  margin-left: 2.5em;
  font-family: var(--sans);
  font-size: 12px;
  font-style: italic;
}
.highlight .error .note {
  color: var(--error);
}
.highlight .warn .note {
  color: var(--warn);
}
.tok-comment {
  color: var(--tok-comment);
  font-style: italic;
}
.tok-required {
  color: var(--tok-required);
  font-weight: 700;
}
.tok-placeholder {
  color: var(--tok-placeholder);
}
.tok-format {
  color: var(--tok-format);
}
.tok-wildcard {
  color: var(--tok-wildcard);
  font-weight: 700;
}
.tok-slash {
  color: var(--tok-slash);
  font-weight: 700;
}
.tok-escape {
  color: var(--muted);
}

.editor-empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

/* Output */

.status {
  font-size: 12px;
  font-weight: 600;
  padding: 1px 10px;
  border-radius: 999px;
}
.status.passed {
  background: var(--ok-soft);
  color: var(--ok);
}
.status.failed {
  background: var(--error-soft);
  color: var(--error);
}

.terminal {
  margin: 0;
  flex: 1;
  overflow: auto;
  padding: 12px 14px;
  background: var(--terminal-bg);
  color: var(--terminal-text);
  font: 12.5px / 1.6 var(--mono);
  white-space: pre;
}
.terminal .prompt {
  color: #8f897e;
}
.terminal .exit {
  color: #8f897e;
}
.terminal .link {
  cursor: pointer;
  background: none;
  border: 0;
  /* A border, not a text-decoration: an offset dotted underline is drawn
     outside the button's box, and browsers sometimes leave it on screen
     after the link is gone. The margin keeps the line's height the same. */
  border-bottom: 1px dotted currentColor;
  margin-bottom: -1px;
  padding: 0;
  font: inherit;
  line-height: 1.2;
  color: inherit;
}
.terminal .link:hover {
  border-bottom-style: solid;
}

/* Footer */

.footer {
  padding: 4px 20px 20px;
  color: var(--muted);
  font-size: 12px;
}
.footer p {
  margin: 4px 0;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 10;
}

.noscript {
  padding: 20px;
}

/* Narrow screens: stack everything. */

@media (max-width: 820px) {
  .topbar {
    padding: 10px 16px;
  }
  .examples {
    padding: 8px 16px;
  }
  .workspace {
    padding: 12px 16px;
    gap: 12px;
    /* Stacked, the panels size themselves: nothing to drag. */
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 340px auto;
    grid-template-areas: "files" "editor" "output";
  }
  .workspace:has(> .explanation:not([hidden])) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto 340px auto;
    grid-template-areas: "explanation" "files" "editor" "output";
  }
  .splitter {
    display: none;
  }
  .files .tree {
    max-height: 320px;
  }
  .row .actions {
    display: flex;
  }
  .hint {
    display: none;
  }
  .footer {
    padding: 4px 16px 16px;
  }
}
