:root {
  color-scheme: light;

  --radius: 0.625rem;
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);

  --background: oklch(0.985 0.003 90);
  --foreground: oklch(0.16 0.005 90);
  --card: oklch(0.995 0.002 90);
  --primary: oklch(0.22 0.005 90);
  --primary-foreground: oklch(0.985 0.003 90);
  --muted: oklch(0.962 0.004 90);
  --muted-foreground: oklch(0.52 0.008 90);
  --destructive: oklch(0.577 0.245 27.325);
  --border: oklch(0.915 0.005 90);
  --input: oklch(0.915 0.005 90);
  --ring: oklch(0.62 0.006 90);

  --shadow-xs: 0 1px 2px 0 rgb(28 27 24 / 0.05);
  --shadow-sm: 0 1px 3px 0 rgb(28 27 24 / 0.07), 0 1px 2px -1px rgb(28 27 24 / 0.07);

  --font-sans: 'Geist', ui-sans-serif, -apple-system, 'Segoe UI', Inter, system-ui, sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--background);
  color: var(--foreground);
}

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

::selection {
  background: color-mix(in oklch, var(--primary) 16%, transparent);
}

#app {
  min-height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 18px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

#bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  font-size: 13px;
  letter-spacing: 0.01em;
  color: var(--muted-foreground);
}

#back {
  font: inherit;
  font-size: 16px;
  line-height: 1;
  color: var(--foreground);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  width: 32px;
  height: 32px;
  padding: 0;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition:
    background-color 0.15s,
    border-color 0.15s,
    box-shadow 0.15s,
    transform 0.05s;
}

#back:hover {
  background: var(--muted);
}

#back:focus-visible {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 50%, transparent);
}

#back:active {
  transform: translateY(1px);
}

#brand {
  flex: none;
  display: inline-flex;
  color: var(--foreground);
}

#brand svg {
  display: block;
  width: 26px;
  height: 26px;
}

#crumb {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#home {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
}

#home[hidden] {
  display: none;
}

#composer {
  margin: auto 0;
}

#home.has-hits #composer {
  margin: 4px 0 0;
}

#home.has-hits {
  padding-bottom: 34px;
}

#home.has-hits #searchwrap {
  position: sticky;
  top: 0;
  z-index: 3;
  padding: 6px 0;
  background: var(--background);
}

#searchwrap {
  position: relative;
}

#q {
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: var(--foreground);
  background: var(--card);
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  height: 44px;
  padding: 0 14px;
  outline: none;
  appearance: none;
  box-shadow: var(--shadow-xs);
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

#q::placeholder {
  color: var(--muted-foreground);
}

#q:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 50%, transparent);
}

#q::-webkit-search-cancel-button {
  appearance: none;
}

#hits {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}

#hits:empty {
  display: none;
}

#hits li + li {
  border-top: 1px solid var(--border);
}

#hits button {
  display: flex;
  gap: 10px;
  align-items: baseline;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 12px;
  cursor: pointer;
  transition: background-color 0.15s;
}

#hits button:hover,
#hits button[aria-selected='true'] {
  background: var(--muted);
}

#hits button:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: -2px;
}

#hits .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#hits .cat {
  color: var(--muted-foreground);
  font-size: 12px;
  white-space: nowrap;
}

#hits .empty {
  color: var(--muted-foreground);
  padding: 14px 12px;
}

#hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  text-align: center;
  color: var(--muted-foreground);
  font-size: 12px;
}

#tool {
  padding-top: 18px;
}

#tool h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

#tool .desc {
  margin: 6px 0 20px;
  color: var(--muted-foreground);
  font-size: 15px;
}

#tool .engine {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--muted-foreground);
  vertical-align: middle;
}

label.field {
  display: block;
  margin: 0 0 14px;
}

label.field > span.lab {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--foreground);
}

label.field textarea,
label.field input[type='text'],
label.field input[type='number'],
label.field input[type='color'],
label.field select {
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: var(--foreground);
  background: var(--card);
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  outline: none;
  appearance: none;
  box-shadow: var(--shadow-xs);
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

label.field select {
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236e6a61' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
}

label.field input[type='color'] {
  height: 40px;
  padding: 4px;
}

label.field textarea {
  min-height: 130px;
  resize: vertical;
  line-height: 1.5;
  font-family: var(--font-mono);
  font-size: 16px;
  padding: 10px 12px;
}

@media (min-width: 768px) {
  label.field textarea,
  label.field input[type='text'],
  label.field input[type='number'],
  label.field input[type='color'],
  label.field select {
    font-size: 14px;
  }
}

label.field input:focus,
label.field textarea:focus,
label.field select:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 50%, transparent);
}

label.field.check {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

label.field.check input {
  appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  border: 1px solid var(--input);
  border-radius: 4px;
  background: var(--card);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  position: relative;
  transition:
    background-color 0.15s,
    border-color 0.15s,
    box-shadow 0.15s;
}

label.field.check input:checked {
  background: var(--primary);
  border-color: var(--primary);
}

label.field.check input:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid var(--primary-foreground);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

label.field.check input:focus-visible {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 50%, transparent);
}

label.field.check > span.lab {
  margin: 0;
  font-size: 14px;
  font-weight: 400;
  color: var(--foreground);
}

label.field .row {
  display: flex;
  gap: 12px;
  align-items: center;
}

label.field input[type='range'] {
  flex: 1;
  accent-color: var(--primary);
  background: none;
  border: 0;
  padding: 0;
}

label.field .numval {
  min-width: 3.5ch;
  text-align: right;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

.drop {
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 16px;
  text-align: center;
  color: var(--muted-foreground);
  font-size: 14px;
  background: var(--card);
  cursor: pointer;
  transition:
    background-color 0.15s,
    border-color 0.15s;
}

.drop:hover {
  background: var(--muted);
}

.drop.over,
.drop.has {
  border-style: solid;
  border-color: var(--ring);
  color: var(--foreground);
}

.drop .files {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
  color: var(--foreground);
  text-align: left;
}

.drop .files li {
  padding: 2px 0;
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 22px 0 0;
}

button.run {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--primary-foreground);
  background: var(--primary);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 0 18px;
  min-height: 40px;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition:
    background-color 0.15s,
    box-shadow 0.15s,
    transform 0.05s;
}

button.run:hover {
  background: color-mix(in oklch, var(--primary) 85%, var(--background));
}

button.run:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 50%, transparent);
}

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

button.run[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

button.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--foreground);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 14px;
  min-height: 40px;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition:
    background-color 0.15s,
    box-shadow 0.15s,
    transform 0.05s;
}

button.ghost:hover {
  background: var(--muted);
}

button.ghost:focus-visible {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 50%, transparent);
}

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

button.ghost[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

#results {
  padding-top: 22px;
}

#results h3 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted-foreground);
}

pre.out {
  margin: 0;
  padding: 12px 14px;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  max-height: 62vh;
  cursor: copy;
}

table.out {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  display: block;
  overflow-x: auto;
  white-space: nowrap;
}

table.out th,
table.out td {
  text-align: left;
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.out th {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted-foreground);
}

table.out tbody tr:last-child td {
  border-bottom: 0;
}

dl.out {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(7rem, 34%) 1fr;
  gap: 0;
  font-size: 15px;
}

dl.out dt {
  color: var(--muted-foreground);
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--border);
}

dl.out dd {
  margin: 0;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

dl.out dt:last-of-type,
dl.out dd:last-of-type {
  border-bottom: 0;
}

.files {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.files a {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  color: var(--foreground);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  background: var(--card);
  box-shadow: var(--shadow-xs);
  transition: background-color 0.15s;
}

.files a:hover {
  background: var(--muted);
}

.files .size {
  color: var(--muted-foreground);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.note {
  color: var(--muted-foreground);
  font-size: 14px;
  margin: 10px 0 0;
}

.err {
  color: var(--destructive);
  background: color-mix(in oklch, var(--destructive) 8%, var(--card));
  border: 1px solid color-mix(in oklch, var(--destructive) 25%, transparent);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin: 0;
  font-size: 14px;
}

figure.preview {
  margin: 0 0 16px;
}

figure.preview img {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: block;
}

.bench {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--muted-foreground);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.bench b {
  color: var(--foreground);
  font-weight: 600;
}

iframe.htm {
  width: 100%;
  min-height: 320px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
}

@media (min-width: 720px) {
  #app {
    padding-top: 28px;
  }
}

.doc {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 24px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
}

.doc-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.doc-head h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
}

.doc-meta {
  margin: 4px 0 0;
  color: var(--muted-foreground);
  font-size: 13px;
}

.doc-meta-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 18px;
  margin: 16px 0;
}

.doc-meta-list dt {
  color: var(--muted-foreground);
  font-size: 12px;
}

.doc-meta-list dd {
  margin: 0 0 6px;
  font-size: 13px;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.doc-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted-foreground);
  border-bottom: 1px solid var(--border);
  padding: 6px 8px 6px 0;
}

.doc-table td {
  border-bottom: 1px solid var(--border);
  padding: 7px 8px 7px 0;
}

.doc-table tbody tr:last-child td {
  border-bottom: 0;
}

.doc-totals {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 24px;
  margin: 16px 0 0;
  font-size: 14px;
}

.doc-totals dt {
  color: var(--muted-foreground);
}

.doc-totals dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.doc-notes {
  margin: 14px 0 0;
  color: var(--muted-foreground);
  font-size: 13px;
}

@media print {
  body {
    background: #fff;
    color: #000;
  }

  #bar,
  #tool,
  #results .note,
  #results h3,
  #print-doc {
    display: none;
  }

  .doc {
    border: 0;
    padding: 0;
    box-shadow: none;
  }
}

.live {
  margin: 14px 0;
  display: grid;
  gap: 10px;
}

.live .big {
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.live .big-small {
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.live .zone {
  color: var(--muted-foreground);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.clock-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
}

.clock-row:last-child {
  border-bottom: 0;
}

.shots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.shots img,
img.shot {
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--muted);
}

.sounds {
  display: grid;
  gap: 8px;
}

.sounds audio {
  width: 100%;
}

.sheet {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
}

.sheet table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.sheet th,
.sheet td {
  border-bottom: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
}

.sheet th {
  font-weight: 600;
  background: var(--muted);
}

.sheet tbody tr:last-child td {
  border-bottom: 0;
}

.tree {
  font-family: var(--font-mono);
  font-size: 13px;
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  background: var(--card);
}

.tree-row {
  padding: 1px 0;
}

.tree .key {
  color: #8a5a2b;
}

.tree .type {
  color: var(--muted-foreground);
  font-style: italic;
}

.tree .null {
  color: #8a5a8a;
}

.tree .num {
  color: #1f5a7a;
}

.tree .val {
  color: var(--foreground);
}

.md {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  background: var(--card);
  line-height: 1.65;
}

.md h1,
.md h2,
.md h3 {
  margin: 0.8em 0 0.3em;
}

.md h1:first-child,
.md p:first-child {
  margin-top: 0;
}

.md a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.md code {
  background: var(--muted);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  font-size: 0.9em;
}

.md pre {
  background: var(--muted);
  padding: 12px;
  border-radius: var(--radius-md);
  overflow-x: auto;
}

.md blockquote {
  margin: 0.6em 0;
  padding-left: 12px;
  border-left: 2px solid var(--border);
  color: var(--muted-foreground);
}

.md table {
  border-collapse: collapse;
}

.md td {
  border: 1px solid var(--border);
  padding: 6px 10px;
}

.specimen {
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}

.specimen:last-child {
  border-bottom: 0;
}

textarea.play-src {
  width: 100%;
  min-height: 120px;
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--card);
  color: var(--foreground);
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  padding: 10px;
  outline: none;
  box-shadow: var(--shadow-xs);
}

textarea.play-src:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 50%, transparent);
}

iframe.play {
  width: 100%;
  min-height: 260px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
}

video.preview-video {
  width: 100%;
  max-height: 320px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #000;
}

a.dl {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
  box-shadow: var(--shadow-xs);
  text-decoration: none;
  color: var(--foreground);
  font-size: 14px;
  transition: background-color 0.15s;
}

a.dl:hover {
  background: var(--muted);
}

iframe.pdf-view {
  width: 100%;
  height: 70vh;
  min-height: 420px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
