:root {
  color-scheme: light dark;
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #1c1d1f;
  --muted: #6b6f76;
  --faint: #9a9ea6;
  --line: #e3e3df;
  --accent: #2f6fec;
  --accent-soft: #e8effd;
  --error: #c4352b;
  --error-soft: #fcefed;
  --ok: #1d7a4a;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", "DejaVu Sans Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121315;
    --panel: #1b1c1f;
    --text: #e8e9eb;
    --muted: #a0a4ab;
    --faint: #6f737a;
    --line: #2c2e33;
    --accent: #7aa5ff;
    --accent-soft: #1e2a44;
    --error: #ff8a80;
    --error-soft: #3a1f1d;
    --ok: #6fd39c;
  }
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }
code, kbd { font-family: var(--mono); font-size: 0.9em; }
kbd {
  padding: 0 0.35em;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--panel);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 820px;
  margin: 0 auto;
}

/* Header */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 10px;
}
.brand { font-weight: 650; letter-spacing: -0.01em; }
.status { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 13px;
  font-family: var(--mono);
  cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--faint); }

/* History */
.log {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px 16px;
  overscroll-behavior: contain;
}

.welcome { margin-top: 12vh; }
.lead { font-size: 20px; margin: 0 0 6px; }
.muted, .note { color: var(--muted); }
.welcome .muted { max-width: 60ch; }

.examples, .defs {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.example {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 6px;
  padding: 3px 9px;
  font-family: var(--mono);
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
}
.example:hover { border-color: var(--accent); color: var(--accent); }

.entry { padding: 10px 0; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }

.entry .input {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  padding: 0;
  text-align: left;
  font-family: var(--mono);
  font-size: 15px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  cursor: pointer;
}
.entry .input::before { content: "› "; color: var(--faint); }
.entry .input:hover { color: var(--accent); }

.output {
  margin-top: 2px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  word-break: break-word;
}
.output.note, .output.error { display: block; font-size: 15px; }
.output.error { color: var(--error); }
.pending { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

.eq { color: var(--faint); font-family: var(--mono); font-size: 20px; }
.value {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 500;
  cursor: copy;
  min-width: 0;
  overflow-wrap: anywhere;
}
.more {
  border: 0;
  background: none;
  padding: 0;
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
}
.copied { font-size: 13px; color: var(--ok); }

.help { display: block; }
.help dl { margin: 6px 0 10px; display: grid; gap: 4px; }
.help dl > div { display: grid; grid-template-columns: minmax(9.5em, max-content) 1fr; gap: 12px; }
.help dt code { color: var(--accent); }
.help dd { margin: 0; color: var(--muted); }
.help p { margin: 8px 0 0; }

/* Composer */
.composer {
  position: relative;
  padding: 8px 16px calc(12px + env(safe-area-inset-bottom));
}
.field {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  transition: border-color 0.15s;
}
.field:focus-within { border-color: var(--accent); }
.field.busy { border-color: var(--faint); }
.prompt { font-family: var(--mono); font-size: 20px; line-height: 26px; color: var(--accent); }
textarea {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  resize: none;
  font: 18px/26px var(--mono);
  padding: 0;
  height: 26px;
}
textarea::placeholder { color: var(--faint); }

.hint {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 22px;
  padding: 4px 4px 0;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
}
.preview { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.preview.error { color: var(--muted); font-family: var(--sans); font-style: italic; }
.sighint { margin-left: auto; color: var(--faint); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.suggest {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(100% - 4px);
  max-height: 50vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.12);
  padding: 4px;
  z-index: 10;
}
.option {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  gap: 12px;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.option.active { background: var(--accent-soft); }
.option .name { font-family: var(--mono); font-weight: 600; }
.option .sig { font-family: var(--mono); font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.option .desc { font-size: 13px; color: var(--faint); white-space: nowrap; }

@media (max-width: 560px) {
  .bar { padding-top: 10px; }
  .value { font-size: 20px; }
  .option { grid-template-columns: auto 1fr; }
  .option .desc { display: none; }
  .help dl > div { grid-template-columns: 1fr; gap: 0; }
  .welcome { margin-top: 4vh; }
}
