:root {
  --bg: #0A0C10;
  --surface: #12151C;
  --surface-2: #1A1F29;
  --border: #262C3A;
  --text: #E6E9F0;
  --muted: #9AA3B2;
  --accent: #5B8CFF;
  --success: #34D399;
  --warning: #FBBF24;
  --danger: #EF4444;
  --neutral: #6B7280;
  --r: 14px;
  --r-lg: 16px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 12px) 16px calc(var(--safe-b) + 16px);
}

h1, h2, h3 { margin: 0; font-weight: 600; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace; }

button, input, textarea, select {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

button {
  -webkit-user-select: none;
  user-select: none;
  cursor: pointer;
  border: none;
  background: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--r);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
  transition: background .15s, opacity .15s, transform .05s;
}
.btn:active { transform: scale(.98); background: #222836; }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:active { background: #4a7ae6; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:active { background: #d63c3c; }
.btn.warn { background: var(--warning); border-color: var(--warning); color: #1a1405; }
.btn.gray { background: var(--surface-2); }
.btn.ghost { background: transparent; }
.btn.big { min-height: 64px; font-size: 19px; border-radius: var(--r-lg); width: 100%; }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 14px; border-radius: 10px; }

input[type="text"], input[type="password"] {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--border);
  outline: none;
}
input:focus { border-color: var(--accent); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.badge.rec { color: var(--danger); border-color: rgba(239,68,68,.4); }
.badge.proc { color: var(--warning); border-color: rgba(251,191,36,.4); }
.badge.ok { color: var(--success); border-color: rgba(52,211,153,.4); }
.badge.share { color: var(--accent); border-color: rgba(91,140,255,.4); }
.badge.off { color: var(--muted); }

.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

header.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0 12px;
}
header.top h1 { font-size: 20px; }

/* history */
.new-rec { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.new-rec label { font-size: 13px; color: var(--muted); }
.sess-list { display: flex; flex-direction: column; gap: 10px; }
.sess-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  cursor: pointer;
}
.sess-card:active { background: var(--surface-2); }
.sess-card .name { font-weight: 600; font-size: 16px; }
.sess-card .meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }

/* recording */
.rec-view { background: var(--bg); }
.rec-top { display: flex; flex-direction: column; align-items: center; gap: 6px; padding-top: 8px; }
.timer {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  font-size: 64px;
  font-weight: 600;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.timer.paused { animation: blink 1s steps(2, start) infinite; color: var(--warning); }
@media (prefers-reduced-motion: reduce) {
  .timer.paused { animation: none; color: var(--warning); }
}
@keyframes blink { 0% { opacity: 1; } 50% { opacity: .35; } 100% { opacity: 1; } }

.meter {
  width: 100%;
  max-width: 320px;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}
.meter > div { height: 100%; width: 0%; background: var(--accent); border-radius: 3px; }

.rec-stats { display: flex; gap: 18px; font-size: 13px; color: var(--muted); }

.feed {
  flex: 1;
  overflow-y: auto;
  margin: 14px 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  min-height: 120px;
  max-height: 40dvh;
  font-size: 15px;
  -webkit-overflow-scrolling: touch;
}
.feed .line { margin-bottom: 8px; }
.feed .line .ts { color: var(--muted); font-size: 12px; font-family: ui-monospace, Menlo, monospace; margin-right: 6px; }
.feed .gap { color: var(--warning); font-size: 13px; }
.feed .cur { color: var(--muted); }

.rec-controls {
  display: flex;
  gap: 10px;
  padding-bottom: 8px;
}
.rec-controls .btn { flex: 1; min-height: 56px; font-size: 17px; }

/* session view */
.player { display: flex; flex-direction: column; gap: 8px; }
.player .prow { display: flex; align-items: center; gap: 8px; }
.player .ptime { font-family: ui-monospace, Menlo, monospace; font-size: 13px; color: var(--muted); min-width: 96px; text-align: center; }
.pbar { position: relative; height: 28px; display: flex; align-items: center; cursor: pointer; }
.pbar .track { width: 100%; height: 4px; border-radius: 2px; background: var(--surface-2); position: relative; }
.pbar .fill { height: 100%; border-radius: 2px; background: var(--accent); width: 0%; }

.seg {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 3px;
  gap: 3px;
  overflow-x: auto;
}
.seg button {
  flex: 1;
  min-height: 38px;
  padding: 4px 8px;
  border-radius: 10px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.seg button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 14px 0 0; }
.tabs button {
  min-height: 40px;
  padding: 0 14px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  font-weight: 500;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }

.md {
  padding: 14px 4px;
  font-size: 15.5px;
  overflow-wrap: break-word;
}
.md h1 { font-size: 22px; margin: 10px 0 12px; }
.md h2 { font-size: 18px; margin: 18px 0 8px; }
.md h3 { font-size: 16px; margin: 14px 0 6px; }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 8px 0; padding-left: 22px; }
.md li { margin: 4px 0; }
.md code { background: var(--surface-2); border-radius: 6px; padding: 1px 5px; font-family: ui-monospace, Menlo, monospace; font-size: 13.5px; }
.md pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; width: 100%; margin: 10px 0; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 8px; font-size: 14px; }
.md blockquote { border-left: 3px solid var(--accent); margin: 10px 0; padding: 2px 12px; color: var(--muted); }
.md .katex-display { overflow-x: auto; padding: 4px 0; }

.toc { display: flex; flex-direction: column; gap: 2px; margin: 8px 0; }
.toc a { color: var(--accent); text-decoration: none; font-size: 14px; padding: 3px 0; }
.toc a.l3 { padding-left: 16px; color: var(--muted); }

.share-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  flex-wrap: wrap;
}
.share-item:last-child { border-bottom: none; }
.share-item .url { color: var(--accent); word-break: break-all; flex: 1; min-width: 180px; font-size: 13px; }

/* sheet / modal */
#sheet-root .backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
#sheet-root .sheet {
  width: 100%;
  max-width: 760px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(var(--safe-b) + 18px);
  max-height: 82dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#sheet-root .sheet h2 { font-size: 17px; }

#toast-root {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--safe-b) + 84px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 60;
  pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  max-width: 90vw;
  animation: tin .2s ease-out;
}
.toast.warn { border-color: rgba(251,191,36,.5); color: var(--warning); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.banner {
  background: rgba(251,191,36,.12);
  border: 1px solid rgba(251,191,36,.4);
  color: var(--warning);
  border-radius: var(--r);
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 10px;
}

.spin {
  width: 22px; height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: rot .8s linear infinite;
  margin: 24px auto;
}
@keyframes rot { to { transform: rotate(360deg); } }

.center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; flex: 1; text-align: center; }
.login-box { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; }

.menu-pop {
  position: fixed;
  z-index: 50;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  min-width: 170px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.menu-pop button { text-align: left; padding: 10px 12px; border-radius: 8px; font-size: 15px; }
.menu-pop button:active { background: var(--surface); }
.menu-pop button.danger { color: var(--danger); background: none; border: none; }

.help details { font-size: 14px; color: var(--muted); }
.help summary { cursor: pointer; padding: 6px 0; color: var(--text); }
.help ul { padding-left: 20px; }

@media (min-width: 760px) {
  .timer { font-size: 72px; }
}
