:root {
  --bg: #f9f8f6;
  --panel: #f9f8f6;
  --card: #ffffff;
  --text: #1c2026;
  --muted: #6b7177;
  --line: #e4e2de;
  --hover: #f0eeeb;
  --active: #e9e7e4;
  --accent: #1f4e79;
  --accent-hover: #183f63;
  --accent-text: #ffffff;
  --rec: #d92d20;
  --warn-bg: #fff6e0;
  --warn-line: #f0c36d;
  --err: #b42318;
  --ok: #2e7d4f;
  --radius: 12px;
  --side-w: 300px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121518;
    --panel: #16191d;
    --card: #1c2025;
    --text: #e7eaee;
    --muted: #949ca5;
    --line: #2b3138;
    --hover: #22272d;
    --active: #2a3037;
    --accent: #4f8fc8;
    --accent-hover: #63a0d6;
    --accent-text: #0b1620;
    --rec: #f04438;
    --warn-bg: #2b2412;
    --warn-line: #7a5f1c;
    --err: #ff8a80;
    --ok: #6fcf97;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--err); }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- controls */
button {
  font: inherit; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 9px 14px; min-height: 40px; cursor: pointer;
}
button:disabled { opacity: .5; cursor: default; }
button.small { font-size: 14px; padding: 6px 12px; min-height: 34px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button.primary.copied { background: var(--ok); border-color: var(--ok); }
button.ghost { background: transparent; }
button.ghost:hover { background: var(--hover); }
button.danger { color: var(--err); border-color: transparent; }
button.link { border: 0; background: none; color: var(--muted); text-decoration: underline; padding: 4px; min-height: 0; }
input[type=password], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px;
}
select { padding: 8px 10px; }
textarea { resize: vertical; line-height: 1.45; }
textarea.out { font-size: 14px; min-height: 200px; white-space: pre-wrap; background: var(--card); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------ login */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.login-card input { margin: 12px 0; }
.login-card button { width: 100%; }

/* ----------------------------------------------------------------- layout */
.layout { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: var(--side-w); flex: 0 0 var(--side-w);
  display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line);
  padding-top: env(safe-area-inset-top); padding-left: env(safe-area-inset-left);
}
.editor { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

/* ---------------------------------------------------------------- sidebar */
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px 18px; }
.side-title { font-size: 17px; font-weight: 600; color: var(--muted); }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
  border-radius: 999px; padding: 8px 20px; font-weight: 600; font-size: 16px;
}
.pill span { font-size: 22px; line-height: 1; font-weight: 400; }
.pill:hover { background: var(--accent-hover); }
.note-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; -webkit-overflow-scrolling: touch; }
.group { font-size: 13px; font-weight: 600; color: var(--muted); padding: 14px 10px 4px; }
.note-item {
  display: flex; width: 100%; align-items: baseline; justify-content: space-between; gap: 10px;
  border: 0; background: transparent; text-align: left; border-radius: 8px;
  padding: 8px 10px; min-height: 0; font-size: 16px;
}
.note-item:hover { background: var(--hover); }
.note-item.active { background: var(--active); }
.note-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item .time { flex: none; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.empty { padding: 14px 10px; }
.side-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border-top: 1px solid var(--line); padding: 8px 14px calc(8px + env(safe-area-inset-bottom)) 18px;
}

/* ----------------------------------------------------------------- editor */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 10px 16px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.back { display: none; align-items: center; gap: 2px; border: 0; background: var(--hover); padding: 6px 12px 6px 6px; min-height: 36px; }
.title-input {
  flex: 1; min-width: 0; font: inherit; font-size: 20px; font-weight: 600; color: var(--text);
  border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 4px 8px;
}
.title-input::placeholder { color: var(--text); opacity: 1; }
.title-input:hover { border-color: var(--line); }
.title-input:focus { border-color: var(--accent); background: var(--card); outline: none; }
.title-input:focus::placeholder { color: var(--muted); }
.save-state { flex: none; min-width: 60px; text-align: right; }
.content {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 8px calc(20px + env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) 20px;
}
.content > * { max-width: 860px; margin-left: auto; margin-right: auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px auto; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.actions { display: flex; gap: 8px; }

.recorder { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.rec-info { flex: 1; min-width: 120px; }
.rec-options { display: flex; flex-direction: column; gap: 6px; flex: 0 1 300px; min-width: 220px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.rec {
  width: 76px; height: 76px; flex: none; border-radius: 50%; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 4px solid var(--line); background: var(--card);
}
.rec .dot { width: 44px; height: 44px; border-radius: 50%; background: var(--rec); transition: all .15s ease; }
.rec.recording { border-color: var(--rec); animation: pulse 1.4s ease-in-out infinite; }
.rec.recording .dot { width: 28px; height: 28px; border-radius: 7px; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(217,45,32,.35); } 50% { box-shadow: 0 0 0 12px rgba(217,45,32,0); } }
@media (prefers-reduced-motion: reduce) { .rec.recording { animation: none; } }
.timer { font-variant-numeric: tabular-nums; font-size: 22px; }
.check { font-size: 14px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.check input { width: 18px; height: 18px; margin: 0; }

.warn { background: var(--warn-bg); border-color: var(--warn-line); }
.warn ul { margin: 8px 0 0; padding-left: 20px; }
.banner { padding: 10px 14px; border: 1px solid var(--err); border-radius: 10px; margin: 12px auto; }

/* ----------------------------------------------------------------- mobile */
@media (max-width: 799px) {
  .sidebar { width: 100%; flex-basis: 100%; border-right: 0; padding-right: env(safe-area-inset-right); }
  .editor { display: none; }
  body.show-editor .sidebar { display: none; }
  body.show-editor .editor { display: flex; }
  .back { display: inline-flex; }
  .content { padding-left: 12px; padding-right: calc(12px + env(safe-area-inset-right)); }
  .recorder { flex-direction: column; text-align: center; }
  .rec { width: 92px; height: 92px; }
  .rec .dot { width: 54px; height: 54px; }
  .rec.recording .dot { width: 34px; height: 34px; border-radius: 8px; }
  .rec-options { width: 100%; flex-basis: auto; text-align: left; }
  .title-input { font-size: 18px; }
  .note-item { padding: 10px; font-size: 17px; }
}
