/* play.pigface.io: the same tokens as pigface.io, one working screen:
   a lake tree on the left, the editor above the grid on the right. */

@font-face {
  font-family: "Instrument Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/fonts/instrument-sans.woff2") format("woff2");
}
@font-face {
  font-family: "Fragment Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/fragment-mono.woff2") format("woff2");
}

:root {
  --bg: #f4f7f5;
  --fg: #0f221d;
  --mute: #44544f;
  --line: #d5ddd9;
  --card: #ffffff;
  --card-2: #eef2f0;
  --petal: #a6209f;
  --centre: #ffc233;
  --accent: #a6209f;
  --accent-ink: #ffffff;
  --ok: #1f7a4d;
  --bad: #b3261e;
  /* SQL */
  --kw: #a6209f;
  --fn: #0f221d;
  --str: #b07a00;
  --num: #1f6f8b;
  --id: #5a3d8a;
  --cm: #6e7d78;
  --op: #44544f;
  /* data kinds */
  --k-num: #1f6f8b;
  --k-date: #a6209f;
  --k-str: #1f7a4d;
  --k-bool: #b07a00;
  --k-any: #6e7d78;
  --sans: "Instrument Sans", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Fragment Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f221d;
    --fg: #f4f7f5;
    --mute: #b9c7c1;
    --line: #2a3d37;
    --card: #15302a;
    --card-2: #112a24;
    --petal: #c843c1;
    --accent: #c843c1;
    --accent-ink: #0f221d;
    --ok: #6fd3a0;
    --bad: #ff8a80;
    --kw: #e46bdc;
    --fn: #f4f7f5;
    --str: #ffc233;
    --num: #7fd0e8;
    --id: #c9b3ff;
    --cm: #7f9088;
    --op: #b9c7c1;
    --k-num: #7fd0e8;
    --k-date: #e46bdc;
    --k-str: #6fd3a0;
    --k-bool: #ffc233;
    --k-any: #7f9088;
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html {
  height: 100%;
}
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding-left: max(10px, env(safe-area-inset-left, 0px));
  padding-right: max(10px, env(safe-area-inset-right, 0px));
}
a {
  color: inherit;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--mute);
}

/* ── top bar ── */
.bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-block: 9px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.lock {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  text-decoration: none;
  font-size: 18px;
  line-height: 1;
}
.flower {
  width: 1.1em;
  height: 1.1em;
}
.petals {
  fill: var(--petal);
}
.centre {
  fill: var(--centre);
}
.lock .word {
  font-weight: 600;
  letter-spacing: -0.045em;
  padding-bottom: 0.08em;
}
.engine {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--mute);
  white-space: nowrap;
}
.engine i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mute);
}
.engine[data-state="ok"] i {
  background: var(--ok);
}
.engine[data-state="bad"] i {
  background: var(--bad);
}
.full {
  font-size: 12px;
  font-weight: 500;
  color: var(--mute);
  white-space: nowrap;
}
@media (max-width: 720px) {
  .bar .eyebrow {
    display: none;
  }
}

/* ── layout ── */
.work {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 0 18px;
  padding-block: 10px 8px;
  min-height: 0;
}
@media (max-width: 720px) {
  .work {
    grid-template-columns: 1fr;
    gap: 14px;
  }
}

/* ── tree ── */
.tree {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  align-content: start;
  border-right: 1px solid var(--line);
  padding-right: 10px;
}
@media (max-width: 720px) {
  .tree {
    border-right: 0;
    padding-right: 0;
  }
}
.tree-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  padding-bottom: 6px;
}
.tree-note {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--mute);
  text-align: right;
}
.tree-body {
  font-family: var(--mono);
  font-size: 12px;
  overflow: auto;
  max-height: 70vh;
}
.tree details details {
  padding-left: 12px;
  border-left: 1px solid var(--line);
  margin-left: 5px;
}
.tree summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  color: var(--fg);
  white-space: nowrap;
}
.tree summary::-webkit-details-marker {
  display: none;
}
.tree summary::before {
  content: "";
  width: 0;
  height: 0;
  border: 4px solid transparent;
  border-left: 5px solid var(--mute);
  margin-left: 2px;
  transition: transform 0.12s;
}
.tree details[open] > summary::before {
  transform: rotate(90deg) translateX(-1px);
}
@media (prefers-reduced-motion: reduce) {
  .tree summary::before {
    transition: none;
  }
}
.tree .table > summary .label {
  color: var(--accent);
}
.tree .count {
  color: var(--mute);
  font-size: 10px;
}
.tree .kids {
  display: grid;
}
.tree .desc {
  margin: 0 0 4px 12px;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--mute);
  white-space: normal;
}
.tree .row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 2px 0 2px 12px;
  white-space: nowrap;
  min-width: 0;
}
.tree .row .label {
  all: unset;
  cursor: default;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree .row button.label {
  cursor: pointer;
}
.tree .row button.label:hover {
  color: var(--accent);
  text-decoration: underline;
}
.tree .row.action .label {
  color: var(--mute);
  font-size: 11px;
}
.tree .glyph {
  flex: none;
  font-size: 9px;
  letter-spacing: 0.02em;
  width: 30px;
  text-align: center;
  padding: 1px 0;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--k-any);
}
.tree .k-num .glyph {
  color: var(--k-num);
}
.tree .k-date .glyph {
  color: var(--k-date);
}
.tree .k-str .glyph {
  color: var(--k-str);
}
.tree .k-bool .glyph {
  color: var(--k-bool);
}
.tree .file .glyph {
  color: var(--mute);
  font-size: 10px;
}
.tree .type {
  margin-left: auto;
  color: var(--mute);
  font-size: 10px;
  padding-left: 8px;
}

/* ── editor ── */
.pane {
  display: grid;
  grid-template-rows: auto auto auto auto;
  align-content: start;
  gap: 8px;
  min-width: 0;
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.sep {
  width: 1px;
  height: 18px;
  background: var(--line);
  margin-inline: 4px;
}
.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chip {
  font: 500 12px/1 var(--sans);
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
}
.chip:hover {
  border-color: var(--accent);
}
.btn {
  background: var(--accent);
  color: var(--accent-ink);
  font: 600 13px/1 var(--sans);
  padding: 9px 13px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn[disabled] {
  opacity: 0.6;
  cursor: default;
}
.btn.ghost {
  background: transparent;
  color: var(--fg);
  border-color: var(--line);
}
.btn.small {
  font-size: 11px;
  padding: 6px 9px;
}

/* the editor is a textarea with transparent text over a painted copy */
.ed {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  min-height: 170px;
  height: 220px;
  resize: vertical;
  overflow: hidden;
}
.ed pre,
.ed textarea {
  margin: 0;
  position: absolute;
  inset: 0;
  padding: 12px 14px;
  font: 13.5px/1.55 var(--mono);
  font-variant-ligatures: none;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  border: 0;
  background: transparent;
}
.ed pre {
  pointer-events: none;
  color: var(--fg);
  overflow: hidden;
}
/* The painted copy must measure exactly as the textarea: the same face
   and weight for every token (a synthetic bold or italic widens glyphs),
   no kerning, and <code> must not fall back to the UA's monospace. */
.ed code {
  font: inherit;
  font-variant-ligatures: none;
}
.ed pre,
.ed textarea,
.ed code {
  font-kerning: none;
  letter-spacing: 0;
  word-spacing: 0;
  text-rendering: optimizeSpeed;
}
.ed textarea {
  color: transparent;
  caret-color: var(--fg);
  resize: none;
  outline: none;
  width: 100%;
  height: 100%;
}
.ed textarea::selection {
  background: color-mix(in srgb, var(--accent) 25%, transparent);
}
.hints {
  position: absolute;
  z-index: 3;
  margin: 0;
  padding: 4px;
  list-style: none;
  min-width: 220px;
  max-width: 360px;
  max-height: 220px;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 34, 29, 0.18);
  font-family: var(--mono);
  font-size: 12px;
}
.hints li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}
.hints li[aria-selected="true"] {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
.hints .glyph {
  flex: none;
  font-size: 9px;
  width: 30px;
  text-align: center;
  padding: 1px 0;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--k-any);
}
.hints .k-kw .glyph {
  color: var(--kw);
}
.hints .k-fn .glyph {
  color: var(--fn);
}
.hints .k-tbl .glyph {
  color: var(--accent);
}
.hints .k-num .glyph {
  color: var(--k-num);
}
.hints .k-date .glyph {
  color: var(--k-date);
}
.hints .k-str .glyph {
  color: var(--k-str);
}
.hints .k-bool .glyph {
  color: var(--k-bool);
}
.hints .from {
  margin-left: auto;
  color: var(--mute);
  font-size: 10px;
  padding-left: 10px;
}
.hints b {
  font-weight: 600;
  color: var(--accent);
}
.lint {
  margin: -4px 0 0;
  min-height: 1.2em;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--mute);
  white-space: pre-wrap;
}
.lint[data-state="bad"] {
  color: var(--bad);
}
.lint[data-state="ok"] {
  color: var(--ok);
}
.t-kw {
  color: var(--kw);
}
.t-fn {
  color: var(--fn);
}
.t-ty {
  color: var(--k-date);
}
.t-str {
  color: var(--str);
}
.t-num {
  color: var(--num);
}
.t-id {
  color: var(--id);
}
.t-cm {
  color: var(--cm);
}
.t-op {
  color: var(--op);
}

/* ── grid ── */
.grid-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.status {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--mute);
  margin-right: auto;
}
.modes {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}
.mode {
  font: 500 11px/1 var(--sans);
  color: var(--mute);
  background: transparent;
  border: 0;
  padding: 6px 9px;
  cursor: pointer;
}
.mode[aria-pressed="true"] {
  background: var(--card-2);
  color: var(--fg);
}
.grid .text {
  margin: 0;
  padding: 12px 14px;
  font: 12px/1.5 var(--mono);
  font-variant-ligatures: none;
  color: var(--fg);
  white-space: pre;
}
.grid {
  min-height: 140px;
  max-height: 62vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}
.grid .error {
  margin: 0;
  padding: 14px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--bad);
  white-space: pre-wrap;
}
.tbl table {
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-variant-ligatures: none;
  white-space: nowrap;
}
.tbl th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--card-2);
  text-align: left;
  font-weight: 400;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
}
.tbl th span + span {
  margin-left: 7px;
}
.badge {
  font-size: 9px;
  letter-spacing: 0.02em;
  padding: 1px 4px;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--k-any);
  vertical-align: 1px;
}
.tbl th.k-num .badge {
  color: var(--k-num);
}
.tbl th.k-date .badge {
  color: var(--k-date);
}
.tbl th.k-str .badge {
  color: var(--k-str);
}
.tbl th.k-bool .badge {
  color: var(--k-bool);
}
.tbl td {
  padding: 4px 10px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
}
.tbl tr:nth-child(even) td {
  background: color-mix(in srgb, var(--card-2) 55%, var(--card));
}
.tbl td.n {
  text-align: right;
}
.tbl td.null {
  color: var(--mute);
  font-style: italic;
}
.tbl td.k-num {
  color: var(--k-num);
}
.tbl td.k-date {
  color: var(--k-date);
}
.tbl td.k-bool {
  color: var(--k-bool);
}
.tbl td.k-str {
  color: var(--fg);
}
.tbl td.k-list,
.tbl td.k-any {
  color: var(--k-any);
}
.tbl .rn {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--card-2);
  color: var(--mute);
  text-align: right;
  font-size: 10px;
  min-width: 36px;
}
.tbl th.rn {
  z-index: 2;
}

/* ── footer ── */
.foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-block: 7px 9px;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--mute);
}
