:root {
  --bg: #0e1116;
  --panel: #171b22;
  --panel2: #1f2530;
  --line: #2a313d;
  --text: #e8ecf2;
  --muted: #8a94a6;
  --accent: #4fd1a5;
  --rec: #ff4757;
  --warn: #ffb020;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .3px; }
.brand svg { color: var(--accent); }
.tabs { display: flex; gap: 4px; background: var(--panel); padding: 4px; border-radius: 12px; }
.tab { background: none; border: 0; padding: 7px 12px; border-radius: 9px; color: var(--muted); cursor: pointer; display: flex; align-items: center; }
.tab.icon { padding: 7px 9px; }
.tab.active { background: var(--panel2); color: var(--text); }
.tab:disabled { opacity: .35; }

main { max-width: 640px; margin: 0 auto; padding: 16px; }
.view { display: none; }
.view.active { display: block; }

/* ---- record ---- */
#view-rec.active { display: flex; flex-direction: column; align-items: center; min-height: calc(100dvh - 90px); }
.format { color: var(--muted); font-size: 13px; text-align: center; margin: 4px 0 20px; font-variant-numeric: tabular-nums; }
.meter-wrap { width: 100%; }
.meter { position: relative; height: 22px; background: var(--panel); border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.meter-fill {
  position: absolute; inset: 0 auto 0 0; width: 0%;
  background: linear-gradient(90deg, #2bb37f 0%, #4fd1a5 66%, #ffd166 80%, #ffb020 90%, #ff4757 100%);
  background-size: calc(100vw - 32px) 100%;
}
@media (min-width: 672px) { .meter-fill { background-size: 608px 100%; } }
.meter-hold { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; left: 0; opacity: .8; }
.meter-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; position: relative; height: 14px; }
.meter-scale span { position: absolute; transform: translateX(-50%); }
.meter-scale span:first-child { transform: none; }
.meter-scale span:last-child { transform: translateX(-100%); }
.meter-info { display: flex; justify-content: space-between; margin-top: 10px; font-size: 14px; font-variant-numeric: tabular-nums; }
.clip { padding: 1px 8px; border-radius: 5px; background: var(--panel); color: var(--muted); font-size: 12px; font-weight: 700; }
.clip.on { background: var(--rec); color: #fff; }

.timer { font-size: 54px; font-weight: 300; margin: auto 0 24px; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.rec-btn {
  width: 128px; height: 128px; border-radius: 50%; border: 6px solid #fff3; background: var(--panel);
  display: grid; place-items: center; cursor: pointer; transition: transform .1s;
}
.rec-btn:active { transform: scale(.96); }
.rec-btn .dot { width: 72px; height: 72px; border-radius: 50%; background: var(--rec); transition: all .2s; }
.rec-btn.recording { border-color: #ff475766; animation: pulse 1.4s infinite; }
.rec-btn.recording .dot { width: 46px; height: 46px; border-radius: 10px; }
.rec-btn:disabled { opacity: .4; }
@keyframes pulse { 50% { box-shadow: 0 0 0 14px #ff475722; } }
.hint { color: var(--muted); margin: 14px 0 auto; font-size: 14px; }
.mic-off { text-align: center; margin-top: 12px; }

/* ---- editor ---- */
.wave-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; touch-action: none; }
#wave { display: block; width: 100%; height: 200px; }
.stats { color: var(--muted); font-size: 13px; margin: 8px 2px 14px; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.row > * { flex: 1 1 0; }
.btn {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 11px;
  padding: 12px 10px; cursor: pointer; white-space: nowrap; min-height: 46px;
}
.btn:active { filter: brightness(1.2); }
.btn:disabled { opacity: .45; }
.btn.primary { background: var(--accent); color: #062b1e; border-color: transparent; font-weight: 700; }
.btn.danger { color: #ff8a95; }
.toggles { display: grid; gap: 8px; margin: 4px 0 16px; }
.tgl { display: flex; gap: 10px; align-items: center; background: var(--panel); padding: 12px; border-radius: 11px; border: 1px solid var(--line); }
.tgl input { width: 20px; height: 20px; accent-color: var(--accent); }
.actions { margin-top: 16px; }
.progress { height: 6px; background: var(--panel); border-radius: 3px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .15s; }

/* ---- forms ---- */
.fields { display: grid; gap: 14px; }
.fields label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input, select {
  width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 11px;
  padding: 12px; color: var(--text); font-size: 16px; min-height: 46px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }
small { font-size: 12px; }
small.ok { color: var(--accent); }
small.bad { color: var(--rec); }
.diag { margin-top: 20px; padding: 12px; background: var(--panel); border-radius: 11px; font-size: 13px; color: var(--muted); white-space: pre-line; border: 1px solid var(--line); }
.legal { display: flex; gap: 16px; justify-content: center; margin: 28px 0 8px; font-size: 13px; }
.legal a { color: var(--muted); }

/* ---- server ---- */
.files { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.files li { background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
.files .meta { flex: 1; min-width: 0; }
.files .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files .sub { color: var(--muted); font-size: 12px; }
.files button { background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; width: 40px; height: 40px; cursor: pointer; display: grid; place-items: center; flex: none; }
.files button.del { color: #ff8a95; }
.empty { color: var(--muted); text-align: center; margin-top: 30px; }

/* ---- overlays ---- */
.countdown { position: fixed; inset: 0; background: #0e1116e6; display: grid; place-items: center; font-size: 120px; font-weight: 200; z-index: 20; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--line); padding: 12px 18px; border-radius: 12px; z-index: 30;
  max-width: calc(100vw - 32px); box-shadow: 0 8px 30px #0008;
}
.toast.err { border-color: var(--rec); }
.toast.ok { border-color: var(--accent); }
[hidden] { display: none !important; }
