:root {
  --bg: #141317;
  --bg-2: #1c1b21;
  --bg-3: #26252d;
  --ink: #f4f1ec;
  --muted: #b7b1a8;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #e8897a;
  --accent-ink: #2a1210;
  --ok: #8fd0b0;
  --danger: #e07a7a;
  --radius: 16px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "PingFang HK", "PingFang TC", "Noto Sans TC", sans-serif;
  -webkit-font-smoothing: antialiased;
}
body {
  min-height: 100dvh;
  min-height: 100vh;
}
button, input, label { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app {
  height: 100dvh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: calc(12px + var(--safe-t)) calc(16px + var(--safe-r)) calc(12px + var(--safe-b)) calc(16px + var(--safe-l));
  max-width: 820px;
  margin: 0 auto;
}

.top { flex: 0 0 auto; }
.title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
}
h1 {
  margin: 2px 0 0;
  font-size: 28px;
  letter-spacing: 0.02em;
  font-weight: 650;
}
.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  flex-shrink: 0;
  padding-top: 4px;
  max-width: none;
}
.header-btn { min-height: 40px; padding: 8px 11px; font-size: 13px; }

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 180px;
  margin-top: 12px;
  background: #0c0b0f;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#view {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#view.hidden, .hidden { display: none !important; }

.empty {
  padding: 28px 22px;
  text-align: center;
  max-width: 420px;
}
.empty-lead {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.65;
  font-size: 15px;
}

.busy {
  position: absolute;
  inset: 0;
  background: rgba(10, 9, 12, 0.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  pointer-events: none;
  color: var(--ink);
  font-size: 14px;
}
.busy.hidden { display: none !important; }
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.status {
  min-height: 1.4em;
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--ok);
  line-height: 1.45;
}
.resized-note { margin-top: 2px; }

.tools {
  flex: 0 0 auto;
  margin-top: 8px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px 12px;
}
.tool-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}
.tool-tab {
  appearance: none;
  border: 0;
  background: var(--bg-3);
  color: var(--muted);
  border-radius: 999px;
  min-height: 42px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.tool-tab.is-active {
  background: var(--ink);
  color: #19181c;
}

.panel { display: block; }
.slider-row {
  display: grid;
  grid-template-columns: 52px 1fr 40px;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  font-size: 14px;
}
.slider-row label { color: var(--ink); }
.slider-row .val {
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 32px;
}
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.footer-row {
  margin-top: 10px;
  display: flex;
  justify-content: center;
}

.btn {
  appearance: none;
  border: 0;
  background: var(--bg-3);
  color: var(--ink);
  border-radius: 999px;
  min-height: 44px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.btn.large { min-height: 52px; padding: 12px 22px; font-size: 17px; }
.btn.ghost {
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.btn:disabled { opacity: 0.4; cursor: default; }
.text-btn {
  appearance: none;
  border: 0;
  background: none;
  color: var(--accent);
  padding: 0 0 0 8px;
  font-size: 13px;
  cursor: pointer;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}
.install-hint { margin-top: 18px; }
.badge {
  display: inline-block;
  margin: 4px 0 0;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(143, 208, 176, 0.15);
  color: var(--ok);
  font-size: 12px;
}

@media (min-width: 720px) {
  h1 { font-size: 32px; }
  .stage { min-height: 360px; }
}
