:root {
  --bg: #f6f4ee;
  --card: #ffffff;
  --ink: #1d2327;
  --muted: #5d6870;
  --line: #e3dfd3;
  --accent: #1f7a6b;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1ed;
  --warn-bg: #fff4dc;
  --warn-line: #e8c97a;
  --warn-ink: #5b4300;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(30 35 39 / 6%), 0 8px 24px rgb(30 35 39 / 6%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --card: #1d2226;
    --ink: #eceff1;
    --muted: #9aa5ad;
    --line: #2d353b;
    --accent: #4fc3ae;
    --accent-ink: #0c2a25;
    --accent-soft: #1b3832;
    --warn-bg: #3a2f12;
    --warn-line: #6e5a1f;
    --warn-ink: #f3dfa6;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

[hidden] { display: none !important; }

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) 16px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
  max-width: 760px;
  margin: 0 auto 8px;
}

.tabs {
  display: flex;
  gap: 4px;
  max-width: 760px;
  margin: 0 auto;
  overflow-x: auto;
  scrollbar-width: none;
}

.tab {
  flex: 1 0 auto;
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 10px 12px;
  cursor: pointer;
}

.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

main { max-width: 760px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-ink); }

h1 { font-size: 1.45rem; line-height: 1.25; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; line-height: 1.3; margin: 18px 0 6px; }
.card > h2:first-child, .result-head h2 { margin-top: 0; }
p { margin: 0 0 12px; }

.muted { color: var(--muted); }
.small, small { font-size: 0.86rem; }

.banner, .note {
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.95rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.95rem;
  z-index: 10;
  max-width: calc(100vw - 32px);
  text-align: center;
}

/* ------------------------------------------------------------ file picker */

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 28px 16px;
  margin: 16px 0;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.drop:hover, .drop.is-over, .drop:focus-within { border-color: var(--accent); background: var(--accent-soft); }
.drop.has-file { border-style: solid; border-color: var(--accent); }
.drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.drop-icon { color: var(--accent); }
.drop-title { font-weight: 700; font-size: 1.1rem; overflow-wrap: anywhere; }
.drop-sub { color: var(--muted); font-size: 0.92rem; }

/* ------------------------------------------------------------ switch */

.switch {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  padding: 12px 0 16px;
  cursor: pointer;
}

.switch input { position: absolute; opacity: 0; }
.switch small { display: block; color: var(--muted); }

.switch-track {
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  margin-top: 2px;
  transition: background 0.15s;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 30%);
  transition: transform 0.15s;
}

.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------ buttons */

button { font: inherit; }

.primary, .secondary, .ghost {
  border-radius: 12px;
  padding: 13px 18px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
  min-height: 48px;
}

.primary { background: var(--accent); color: var(--accent-ink); width: 100%; }
.primary:disabled { opacity: 0.45; cursor: not-allowed; }
.secondary { background: var(--accent-soft); color: var(--accent); }
.ghost { background: none; color: var(--muted); border-color: var(--line); }
.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font-weight: 600; }

.row { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.row > * { flex: 1 1 140px; width: auto; }

/* ------------------------------------------------------------ progress */

.steps { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 10px; }
.steps li { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.steps .step-count { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 0.92rem; }

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--line);
  flex: none;
}

.steps li.is-active { color: var(--ink); font-weight: 600; }
.steps li.is-active .dot { border-color: var(--accent); border-top-color: transparent; animation: spin 0.9s linear infinite; }
.steps li.is-done { color: var(--ink); }
.steps li.is-done .dot { background: var(--accent); border-color: var(--accent); }

@keyframes spin { to { transform: rotate(360deg); } }

.bar { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 6px 0 12px; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width 0.4s; }

.status { font-weight: 600; min-height: 1.5em; }
.wait { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); border-radius: 12px; padding: 10px 14px; }

/* ------------------------------------------------------------ result */

.result-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.result-head h2 { overflow-wrap: anywhere; }
.result-head .ghost { flex: none; min-height: 40px; padding: 8px 14px; }

.sticky { position: sticky; top: 96px; z-index: 2; background: var(--card); padding: 8px 0; margin: 4px 0; }

.text { border-top: 1px solid var(--line); padding-top: 14px; font-size: 1.02rem; line-height: 1.7; overflow-wrap: anywhere; }
.text h3 { font-size: 1.08rem; margin: 22px 0 6px; color: var(--accent); }
.text p { margin: 0 0 14px; }
.text p.is-raw { color: var(--muted); }

/* ------------------------------------------------------------ forms and lists */

textarea, input[type="password"], input[type="text"], select {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

textarea { resize: vertical; line-height: 1.5; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.field { display: block; font-weight: 600; margin: 12px 0; }
.field input, .field select, .field textarea { margin-top: 6px; font-weight: 400; }

.list { list-style: none; margin: 12px 0 0; padding: 0; }
.list li { display: flex; gap: 10px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.list .item-main { flex: 1; min-width: 0; background: none; border: 0; text-align: left; color: inherit; cursor: pointer; padding: 0; }
.list .item-name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .item-meta { display: block; color: var(--muted); font-size: 0.86rem; }
.list .item-delete { flex: none; min-height: 40px; padding: 6px 12px; }

.plain { padding-left: 1.2em; margin: 0 0 12px; }
.plain li { margin-bottom: 8px; }

details > summary { font-weight: 700; cursor: pointer; }
details[open] > summary { margin-bottom: 10px; }

@media (min-width: 620px) {
  main { padding: 24px 16px; }
  .card { padding: 28px; }
  .tab { flex: 0 0 auto; }
}

/* ------------------------------------------------------------ audio editor */

.wide { width: 100%; margin: 0 0 8px; }

.editor { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 8px 0 12px; }
.editor h2 { margin-top: 0; }

.wave-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  touch-action: pan-x;
}

.wave-scroll canvas { display: block; cursor: pointer; }

.wave-bar { display: flex; align-items: center; gap: 8px; margin: 10px 0 4px; }
.wave-bar .secondary { min-height: 44px; padding: 8px 16px; }
.clock { flex: 1; font-variant-numeric: tabular-nums; font-size: 0.85rem; color: var(--muted); white-space: nowrap; }

.mini {
  min-width: 44px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: none;
  color: inherit;
  font-size: 1.2rem;
  cursor: pointer;
}

.editor .row .ghost { font-size: 0.92rem; padding: 10px 12px; }
.editor .list li:first-child { border-top: 0; }
.editor .list .item-main { cursor: default; font-size: 0.95rem; }
