:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #17201d;
  --muted: #5d6b66;
  --border: #dde3e0;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e0f2ef;
  --danger: #c2410c;
  --danger-soft: #fdebe1;
  --ok: #15803d;
  --warn: #b45309;
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412;
    --surface: #18201d;
    --text: #e8eeeb;
    --muted: #97a7a0;
    --border: #2a3532;
    --accent: #2dd4bf;
    --accent-ink: #062320;
    --accent-soft: #123430;
    --danger: #fb923c;
    --danger-soft: #3a2116;
    --ok: #4ade80;
    --warn: #fbbf24;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.brand { flex: 1; min-width: 0; }
.brand h1 { font-size: 18px; margin: 0; }
.sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn, .sync {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; min-height: 40px; padding: 0 12px; font: inherit; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
}
.icon-btn { width: 40px; padding: 0; justify-content: center; }
.sync.pending { color: var(--warn); }
.sync.offline { color: var(--danger); }
.sync.ok { color: var(--ok); }

main { max-width: 560px; margin: 0 auto; padding: 16px; }
.tab { display: none; }
.tab.active { display: block; }
h2 { font-size: 15px; color: var(--muted); margin: 24px 4px 8px; font-weight: 600; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.big-btn {
  display: inline-flex; align-items: center; justify-content: center; text-align: center;
  min-height: 56px; padding: 0 18px; border-radius: 14px; border: 0;
  background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 600; font-size: 17px;
  cursor: pointer; user-select: none;
}
.big-btn:active { transform: scale(.98); }
.big-btn:disabled { opacity: .45; }
.big-btn.secondary { background: var(--accent-soft); color: var(--text); }
.big-btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.big-btn.danger { background: var(--danger); color: #fff; }

.status-card { align-items: stretch; text-align: center; padding: 24px 16px; }
.status { font-size: 15px; color: var(--muted); }
.status.on { color: var(--ok); font-weight: 600; }
.timer { font-size: 44px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -1px; text-align: center; }
.status-card .big-btn { min-height: 72px; font-size: 20px; }

textarea, input, select {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 12px; padding: 12px;
}
textarea { resize: vertical; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; font-size: 15px; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.center { text-align: center; }

.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button {
  flex: 1 1 auto; min-height: 44px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; font-size: 14px;
}
.seg button[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.thumbs:empty { display: none; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--bg); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 16px; line-height: 1;
}

.voice-card { align-items: center; padding: 28px 16px; }
.voice-card > * { width: 100%; }
.rec-btn {
  width: 132px !important; height: 132px; border-radius: 50%; border: 6px solid var(--danger-soft);
  background: var(--danger); display: grid; place-items: center; cursor: pointer;
}
.rec-dot { width: 40px; height: 40px; border-radius: 50%; background: #fff; transition: border-radius .15s, width .15s, height .15s; }
.rec-btn[aria-pressed="true"] { animation: pulse 1.4s infinite; }
.rec-btn[aria-pressed="true"] .rec-dot { border-radius: 8px; width: 36px; height: 36px; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(194,65,12,.45); } 50% { box-shadow: 0 0 0 18px rgba(194,65,12,0); } }
#voiceReview { display: flex; flex-direction: column; gap: 12px; }
#voiceReview[hidden] { display: none; }
audio { width: 100%; }

.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history li {
  display: flex; gap: 12px; align-items: center; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
}
.history .h-ico { font-size: 20px; width: 28px; text-align: center; }
.history .h-body { flex: 1; min-width: 0; }
.history .h-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history .h-time { color: var(--muted); font-size: 12px; }
.history .h-st { font-size: 12px; white-space: nowrap; }
.h-st.pending { color: var(--warn); }
.h-st.sent { color: var(--ok); }
.h-st.error { color: var(--danger); }
.history .empty { color: var(--muted); justify-content: center; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; height: var(--tabbar-h); border: 0; background: none; color: var(--muted);
  font: inherit; font-size: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.tabbar .ico { font-size: 22px; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--accent); font-weight: 600; }
.tabbar button.active .ico { filter: none; opacity: 1; }

dialog {
  width: min(520px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); padding: 20px;
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { display: flex; flex-direction: column; gap: 14px; }
dialog h2 { margin: 0; color: var(--text); font-size: 18px; }
details { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
details[open] { display: flex; flex-direction: column; gap: 12px; }
summary { cursor: pointer; color: var(--muted); font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  max-width: calc(100vw - 32px); transition: opacity .2s, transform .2s; z-index: 10;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
