:root {
  --bg: #0b1020;
  --surface: #151b2e;
  --surface-2: #1d2540;
  --text: #eef2ff;
  --muted: #93a0c4;
  --primary: #3b82f6;
  --primary-press: #2563eb;
  --danger: #ef4444;
  --accent: #22c55e;
  --warn: #f59e0b;
  --border: #28324f;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #eef2fb;
    --text: #0e1426;
    --muted: #5b6a8c;
    --primary: #2563eb;
    --primary-press: #1d4ed8;
    --border: #dde3f0;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior-y: contain;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.warn-text { color: var(--warn); }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }

/* App shell */
.app { display: flex; flex-direction: column; height: 100dvh; }
.appbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.appbar-title { font-weight: 700; font-size: 18px; }
.badge {
  font-size: 11px; color: var(--muted); padding: 3px 8px;
  border: 1px solid var(--border); border-radius: 999px;
}
#main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px; padding-bottom: 96px; }
.screen { animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Tab bar */
.tabbar {
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom); position: sticky; bottom: 0; z-index: 5;
}
.tab {
  flex: 1; background: none; border: none; color: var(--muted);
  font-size: 22px; padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab span { font-size: 11px; }
.tab.active { color: var(--primary); }

/* Buttons */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 12px 16px; border-radius: var(--radius); font-size: 15px; font-weight: 600;
  cursor: pointer; transition: transform .05s, background .15s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-press); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; }
.btn-block { display: block; width: 100%; margin-top: 10px; }
.btn-small { padding: 7px 12px; font-size: 13px; }
.btn-lg { padding: 16px 28px; font-size: 17px; }

/* Lists / cards */
.list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.card .meta { min-width: 0; }
.card .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { font-size: 12px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.section-head h2 { margin: 0; font-size: 20px; }

/* FAB */
.fab-wrap { position: fixed; left: 0; right: 0; bottom: calc(var(--safe-bottom) + 70px); text-align: center; pointer-events: none; }
.fab {
  pointer-events: auto;
  width: 72px; height: 72px; border-radius: 50%; border: none;
  background: var(--danger); color: #fff; font-size: 28px;
  box-shadow: 0 8px 24px rgba(239, 68, 68, .4);
}
.fab:active { transform: scale(0.94); }
.fab-hint { pointer-events: none; margin-top: 6px; font-size: 12px; }

/* Recording */
.rec-head { display: flex; justify-content: space-between; align-items: center; }
.chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; font-size: 13px; }
.rec-timer { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rec-warn { background: rgba(245, 158, 11, .12); color: var(--warn); border: 1px solid rgba(245,158,11,.3); border-radius: 10px; padding: 8px 12px; font-size: 13px; margin: 12px 0; }
.rec-pulse { display: flex; justify-content: center; margin: 24px 0; }
.pulse-dot { width: 22px; height: 22px; border-radius: 50%; background: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(239,68,68,.5);} 70% { box-shadow: 0 0 0 22px rgba(239,68,68,0);} 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0);} }
.rec-live { min-height: 80px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; white-space: pre-wrap; }
.rec-speakers { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.spk-btn { border: 2px solid transparent; border-radius: 999px; padding: 6px 12px; background: var(--surface-2); color: var(--text); font-size: 13px; }
.spk-btn.active { border-color: currentColor; }
.rec-controls { display: flex; gap: 12px; justify-content: center; margin-top: 24px; }

/* Progress */
.progress-wrap { text-align: center; padding: 50px 16px; }
.spinner { width: 48px; height: 48px; border: 4px solid var(--border); border-top-color: var(--primary); border-radius: 50%; margin: 0 auto 20px; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress-bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 18px auto; max-width: 320px; }
.progress-fill { height: 100%; width: 0%; background: var(--primary); transition: width .3s; }

/* Result */
.result-head { margin-bottom: 12px; }
.title-input { width: 100%; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 17px; font-weight: 600; }
.segments { display: flex; flex-direction: column; gap: 10px; }
.seg {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px;
}
.seg-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.seg-speaker { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); }
.seg-time { font-size: 11px; color: var(--muted); }
.seg-text { white-space: pre-wrap; }
.seg-text .fixed { color: var(--accent); border-bottom: 1px dotted var(--accent); }
.result-actions { position: sticky; bottom: 0; padding-top: 12px; }

/* Settings */
.settings { display: flex; flex-direction: column; gap: 4px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 2px; border-bottom: 1px solid var(--border); }
.set-row.col { flex-direction: column; align-items: stretch; gap: 8px; }
.set-row.switch span { flex: 1; }
.set-row select, .set-row input[type="text"], .set-row textarea, .lock-input {
  background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 15px; font-family: inherit;
}
.set-row textarea { width: 100%; resize: vertical; }
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--primary); }
.danger-zone { border: 1px solid rgba(239,68,68,.3); border-radius: 10px; padding: 12px; margin-top: 16px; }

/* Sheets */
.sheet { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; background: rgba(0,0,0,.5); animation: fade .15s; }
.sheet-card { width: 100%; background: var(--surface); border-radius: 20px 20px 0 0; padding: 8px 18px calc(var(--safe-bottom) + 20px); max-height: 88vh; overflow-y: auto; animation: slideup .2s ease; }
@keyframes slideup { from { transform: translateY(30px); } to { transform: none; } }
.sheet-handle { width: 40px; height: 4px; background: var(--border); border-radius: 999px; margin: 6px auto 12px; }
.sheet-card h3 { margin: 4px 0 12px; }
.sheet-section { margin: 12px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip-toggle { border: 1px solid var(--border); border-radius: 999px; padding: 7px 14px; background: var(--surface-2); color: var(--text); font-size: 14px; }
.chip-toggle.on { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Lock overlay */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 24px; }
.lock-card { width: 100%; max-width: 340px; text-align: center; }
.lock-icon { font-size: 44px; }
.lock-card h2 { margin: 8px 0 4px; }
.lock-input { width: 100%; text-align: center; font-size: 20px; letter-spacing: 4px; margin-top: 12px; }
.lock-error { color: var(--danger); min-height: 20px; font-size: 13px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 90px); transform: translateX(-50%);
  background: #000c; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 60;
  animation: fade .15s;
}

/* Text correction */
.text-area {
  width: 100%; background: var(--surface); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 12px; font-size: 15px; font-family: inherit; resize: vertical; line-height: 1.6;
}
.text-output {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; margin: 8px 0 12px; min-height: 120px; line-height: 1.7;
}

/* Home import actions */
.home-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.home-actions .btn { flex: 1; min-width: 140px; }
.vm-steps { margin: 8px 0 14px; padding-left: 20px; }
.vm-steps li { margin: 8px 0; line-height: 1.5; }

/* Diagnostics */
.diag-out {
  text-align: left; white-space: pre-wrap; word-break: break-all;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; font-size: 12px; line-height: 1.5; margin-top: 10px; max-height: 320px; overflow: auto;
}
#progress-error { margin-top: 18px; }

/* Dictionary entry rows */
.dict-row .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.tag { font-size: 11px; color: var(--muted); background: var(--surface-2); padding: 2px 8px; border-radius: 999px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
