:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #16191d;
  --muted: #5b636e;
  --line: #dfe2e7;
  --field: #f7f8fa;
  --accent: #0b6bcb;
  --accent-ink: #ffffff;
  --stage: #e9ecf0;
  --danger: #b42318;
  --scrim: rgba(244, 245, 247, 0.86);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111317;
    --surface: #181b20;
    --ink: #e8eaed;
    --muted: #9aa2ad;
    --line: #2a2f37;
    --field: #1f2329;
    --accent: #4ea1f3;
    --accent-ink: #0b1220;
    --stage: #0c0d10;
    --danger: #f97066;
    --scrim: rgba(17, 19, 23, 0.86);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111317;
  --surface: #181b20;
  --ink: #e8eaed;
  --muted: #9aa2ad;
  --line: #2a2f37;
  --field: #1f2329;
  --accent: #4ea1f3;
  --accent-ink: #0b1220;
  --stage: #0c0d10;
  --danger: #f97066;
  --scrim: rgba(17, 19, 23, 0.86);
}

* { box-sizing: border-box; }

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

body {
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  min-height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.bar h1 { margin: 0; font-size: 16px; font-weight: 600; white-space: nowrap; }

.filename {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn {
  font: inherit;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 12px;
  min-height: 34px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

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

.panel-toggle { display: none; }

.stage {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 300px;
  min-height: 0;
}

#view {
  grid-column: 1;
  grid-row: 1;
  width: 100%;
  height: 100%;
  display: block;
  background: var(--stage);
  touch-action: none;
  cursor: grab;
}
#view:active { cursor: grabbing; }
#view:focus-visible { outline-offset: -3px; }

.empty, .progress, .error, .hud { grid-column: 1; grid-row: 1; }

.empty {
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--stage);
  z-index: 1;
}
.empty[hidden] { display: none; }

.drop {
  max-width: 420px;
  width: 100%;
  text-align: center;
  padding: 40px 24px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.drop svg { width: 40px; height: 40px; fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.drop h2 { margin: 8px 0 4px; font-size: 18px; }
.drop p { margin: 0 0 16px; color: var(--muted); }
.drop-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.drop .fine { margin: 16px 0 0; font-size: 13px; }
.stage.dragging .drop { border-color: var(--accent); }
.stage.dragging .empty { display: grid; }

.progress {
  align-self: center;
  justify-self: center;
  width: min(360px, calc(100% - 32px));
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  z-index: 2;
}
.progress[hidden] { display: none; }
.progress p { margin: 0 0 8px; }
.track { height: 6px; background: var(--field); border-radius: 3px; overflow: hidden; }
.fill { height: 100%; width: 0; background: var(--accent); transition: width 0.1s linear; }

.error {
  align-self: start;
  justify-self: center;
  margin: 16px;
  padding: 10px 14px;
  max-width: 560px;
  background: var(--surface);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 8px;
  z-index: 3;
}
.error[hidden] { display: none; }

.hud {
  align-self: end;
  justify-self: start;
  margin: 0;
  padding: 6px 16px 10px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  text-shadow: 0 0 3px var(--stage), 0 0 3px var(--stage);
}

.scalebar {
  grid-column: 1;
  grid-row: 1;
  align-self: end;
  justify-self: end;
  margin: 0 16px 12px;
  display: grid;
  justify-items: center;
  gap: 2px;
  pointer-events: none;
  color: var(--ink);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 3px var(--stage), 0 0 3px var(--stage);
}
.scalebar[hidden] { display: none; }
.scalebar-bar {
  display: block;
  height: 6px;
  border: 2px solid var(--ink);
  border-top: 0;
}

.panel {
  grid-column: 2;
  grid-row: 1;
  overflow-y: auto;
  background: var(--surface);
  border-left: 1px solid var(--line);
  padding: 4px 16px 24px;
}

.panel section { padding: 12px 0; border-bottom: 1px solid var(--line); }
.panel section:last-child { border-bottom: 0; }
.panel h2 { margin: 0 0 10px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.facts, .keys { margin: 0; display: grid; gap: 6px; }
.keys div { display: flex; justify-content: space-between; gap: 12px; }
.facts dt { color: var(--muted); font-size: 12px; }
.facts dd, .keys dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.facts dd { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
.keys dd { color: var(--muted); text-align: right; }

.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field > span { display: flex; justify-content: space-between; }
.field output { color: var(--muted); font-variant-numeric: tabular-nums; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }

select, .xyz input {
  font: inherit;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  min-height: 34px;
  width: 100%;
}

.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }

.buttons { display: grid; gap: 6px; margin-top: 8px; }
.buttons.four { grid-template-columns: repeat(4, 1fr); }
.buttons.two { grid-template-columns: 1fr 1fr; }
.buttons .btn { padding: 6px 4px; }

.hint { margin: 0 0 10px; color: var(--muted); }
.hint:empty { display: none; }
#share-busy .track { margin-bottom: 10px; }

.copyrow { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center; margin-bottom: 10px; }
.copyrow code {
  font: 12px/1.35 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  overflow-wrap: anywhere;
  user-select: all;
}

.xyz { display: grid; gap: 6px; }
.xyz label { display: grid; grid-template-columns: 16px 1fr; align-items: center; gap: 8px; color: var(--muted); }
.xyz input { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; min-width: 0; }
.xyz .btn { margin-left: 24px; }

@media (max-width: 760px) {
  .bar { gap: 8px; padding: 8px 12px; }
  .bar h1 { font-size: 15px; }
  .filename { display: none; }
  .panel-toggle { display: inline-block; margin-left: auto; }
  .stage { grid-template-columns: 1fr; }
  .panel {
    grid-column: 1;
    align-self: end;
    max-height: 60%;
    border-left: 0;
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.18);
    z-index: 4;
    display: none;
  }
  .panel.open { display: block; }
}

@media (max-width: 420px) {
  .bar h1 { font-size: 14px; }
  .bar .btn { padding: 6px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .fill { transition: none; }
}
