:root {
  --bg: #17171a; --panel: #1e1e22; --panel-2: #27272c; --line: #3a3a41;
  --text: #ecebe6; --muted: #a3a2a9; --accent: #ecb03d; --accent-ink: #1a1408;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
body {
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh; height: 100dvh; overflow: hidden; overscroll-behavior: none;
}
[hidden] { display: none !important; }

button, .file-btn {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; min-height: 42px; padding: 0 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
button:disabled { opacity: .45; cursor: default; }
.primary, button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font-size: 0; }

.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) 10px 6px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.bar h1 { font-size: 17px; margin: 0; font-weight: 650; }

#stageWrap { position: relative; overflow: hidden; background: #0d0d0f; }
#stage {
  position: absolute; left: 0; top: 0; display: block; touch-action: none;
  -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
}

.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.card { width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; display: grid; gap: 12px; }
.card h2 { font-size: 18px; margin: 0; }
.card ol { margin: 0; padding-left: 1.3em; color: var(--muted); display: grid; gap: 4px; }

.tools { display: flex; gap: 6px; }
.tools button { min-height: 36px; padding: 0 11px; font-size: 14px; }
#btnSave { min-height: 36px; }
#btnSave { margin-left: auto; }

.toast {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 3;
  max-width: calc(100% - 24px); padding: 8px 14px; border-radius: 20px;
  background: rgba(20, 20, 23, .94); border: 1px solid var(--line);
  font-size: 14px; text-align: center; pointer-events: none;
}

.tool-panel {
  position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 2;
  display: grid; gap: 10px; padding: 12px; max-height: 60%; overflow: auto;
  background: rgba(30, 30, 34, .94); border: 1px solid var(--line); border-radius: 12px;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}

.toolbar {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.toolbar button {
  flex-direction: column; gap: 2px; min-height: 54px; border: 0; border-radius: 0;
  background: none; color: var(--muted); font-size: 11px; font-weight: 500; padding: 4px 2px;
}
.toolbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.toolbar button[aria-pressed="true"] { background: none; color: var(--accent); border: 0; font-weight: 600; }
.toolbar button[data-tool][aria-pressed="true"] { box-shadow: inset 0 2px 0 var(--accent); }
.group { display: grid; gap: 8px; }

.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1 1 0; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1 1 0; border: 0; border-radius: 0; background: none; min-height: 40px; padding: 0 4px; font-size: 14px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); }

.slider { display: grid; grid-template-columns: 6.5em 1fr 3em; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.slider output { text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; height: 32px; margin: 0; accent-color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; margin: 0; }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sw { width: 34px; height: 34px; min-height: 0; padding: 0; border-radius: 50%; border: 2px solid var(--line); }
.sw[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 2px; border-color: var(--line); }
.sw-custom { position: relative; overflow: hidden; display: inline-block; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); }
.sw-custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; padding: 0; cursor: pointer; }

.sheet { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .72); display: flex; align-items: flex-end; justify-content: center; }
.sheet .card { border-radius: 14px 14px 0 0; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
.sheet img { width: 100%; max-height: 45vh; object-fit: contain; background: #000; border-radius: 8px; }

.sheet .card h2 { font-size: 18px; margin: 0; }

.match { position: fixed; inset: 0; z-index: 20; background: #000; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.match video { position: absolute; width: 2px; height: 2px; opacity: 0; pointer-events: none; }
.match canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.match-top {
  position: absolute; left: 0; right: 0; top: 0; display: flex; gap: 12px; align-items: center;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; background: rgba(0, 0, 0, .55);
}
.match-top .slider { flex: 1; grid-template-columns: 5.5em 1fr 3em; color: #ddd; }
.match-hint {
  position: absolute; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 104px);
  margin: 0; text-align: center; font-size: 14px; color: #fff; text-shadow: 0 1px 3px #000; pointer-events: none;
}
.match-bottom { position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 18px); display: flex; justify-content: center; }
.shutter { width: 74px; height: 74px; min-height: 0; padding: 0; border-radius: 50%; background: #fff; border: 5px solid rgba(255, 255, 255, .45); background-clip: padding-box; }
.shutter:active { transform: scale(.94); }

@media (min-width: 700px) {
  .tool-panel { left: auto; width: 380px; }
}
