:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1d1c1a;
  --muted: #77736b;
  --line: #e4e0d7;
  --accent: #ec3a78;
  --accent-ink: #c2185b;
  --accent-text: #ffffff;
  --grad: linear-gradient(135deg, #ff8a4c 0%, #ff3d7f 52%, #7b4dff 100%);
  --glow: rgba(255, 61, 127, .32);
  --chip: #efebe2;
  --chip-on: #1d1c1a;
  --chip-on-text: #ffffff;
  --danger: #c0392b;
  --rec: #d6282e;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --surface: #212127;
    --text: #efede8;
    --muted: #9b978f;
    --line: #313139;
    --accent: #ff5c8f;
    --accent-ink: #ff8fb1;
    --glow: rgba(255, 92, 143, .25);
    --chip: #2c2c33;
    --chip-on: #efede8;
    --chip-on-text: #16161a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  background-image:
    radial-gradient(520px 260px at 0% 0%, rgba(255, 138, 76, .14), transparent 70%),
    radial-gradient(520px 300px at 100% 0%, rgba(123, 77, 255, .13), transparent 70%);
  background-repeat: no-repeat;
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px 16px;
  background: var(--bg);
}
.topbar h1 { font-size: 26px; margin: 0; letter-spacing: -.02em; }
#scriptView .topbar h1 { font-size: 18px; }

.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: transparent; font-size: 26px; line-height: 1; cursor: pointer;
}
.icon-btn:active { background: var(--chip); }
.icon-btn.danger { font-size: 20px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- toolbar ---------- */
.toolbar { padding: 0 16px 8px; display: grid; gap: 10px; }
input[type="search"], input[type="text"], select {
  width: 100%; padding: 11px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips.scroll-x { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips.scroll-x::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; border-radius: 999px;
  padding: 6px 12px; font-size: 14px;
  background: var(--chip); cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--chip-on); color: var(--chip-on-text); }
.chip .x { margin-left: 6px; opacity: .6; }
.suggest .chip { background: transparent; border: 1px dashed var(--line); color: var(--muted); }

/* ---------- notes list ---------- */
.notes { list-style: none; margin: 0; padding: 4px 16px; display: grid; gap: 10px; }
.note {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; cursor: pointer; border: 2px solid transparent;
}
.note.selected { border-color: var(--accent); }
.note .check {
  flex: none; width: 24px; height: 24px; margin-top: 2px; border-radius: 50%;
  border: 2px solid var(--line); display: grid; place-items: center; font-size: 14px;
}
.note.selected .check { background: var(--grad); border-color: transparent; color: var(--accent-text); }
.note-main { min-width: 0; flex: 1; }
.note-text {
  margin: 0; white-space: pre-wrap; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.note-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.note-meta .chip { padding: 2px 9px; font-size: 12px; cursor: default; }

.empty { text-align: center; padding: 60px 32px; color: var(--muted); }
.empty-title { font-size: 18px; color: var(--text); font-weight: 600; margin-bottom: 4px; }

/* ---------- bottom bar ---------- */
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  max-width: 720px; margin: 0 auto;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; min-height: 46px;
  background: var(--chip); cursor: pointer; font-weight: 600;
}
.btn.ghost { background: var(--surface); box-shadow: var(--shadow); }
.btn.primary { background: var(--grad); color: var(--accent-text); flex: 1; box-shadow: 0 4px 14px var(--glow); }
.btn.primary:disabled { box-shadow: none; }
.btn:disabled { opacity: .45; }
.btn.block { display: block; width: 100%; margin-top: 10px; text-align: center; }
.btn:active:not(:disabled) { transform: scale(.98); }
.fab {
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--grad); color: var(--accent-text); font-size: 30px; line-height: 1;
  box-shadow: 0 6px 18px var(--glow); cursor: pointer;
}
#scriptView .bottombar .btn.ghost { flex: none; }

/* ---------- editor ---------- */
.editor-body { flex: 1; display: flex; flex-direction: column; gap: 14px; padding: 0 16px; }
textarea#noteText {
  flex: 1; min-height: 45dvh; width: 100%; resize: none;
  border: 0; outline: none; background: transparent;
  font-size: 18px; line-height: 1.5;
}
.tags-block { display: grid; gap: 8px; padding-bottom: 8px; }

.btn.mic { flex: 1; background: var(--surface); box-shadow: var(--shadow); }
.btn.mic.rec { background: var(--rec); color: #fff; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(214,40,46,.18); } }

/* ---------- script ---------- */
.script-controls { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; padding: 0 16px 12px; }
.script-controls #scriptSource { grid-column: 1 / -1; }
.script-out {
  margin: 0 16px; padding: 18px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow);
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 17px; line-height: 1.6;
  min-height: 200px;
}
.script-out.loading::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--accent); }
.script-out .err { color: var(--danger); }
.script-used { margin: 12px 16px 0; padding: 12px 14px; border-radius: var(--radius); border: 1px dashed var(--line); }
.script-used p { margin: 0; }
.used-note { margin-top: 8px !important; font-size: 14px; padding-left: 10px; border-left: 3px solid var(--accent); white-space: pre-wrap; overflow-wrap: anywhere; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- menu & toast ---------- */
dialog.sheet {
  width: min(520px, calc(100% - 32px)); border: 0; border-radius: 18px;
  background: var(--surface); color: var(--text); padding: 20px;
}
dialog.sheet::backdrop { background: rgba(0,0,0,.4); }
dialog h2 { margin: 0; font-size: 20px; }
dialog.sheet { max-height: calc(100dvh - 32px); overflow-y: auto; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin: -6px -8px 4px 0; }
.settings-block { padding: 14px 0; border-top: 1px solid var(--line); }
.settings-block h3 { margin: 0 0 4px; font-size: 16px; }
.settings-block p { margin: 0 0 8px; }
.settings-block input[type="password"] { margin-top: 8px; font-size: 18px; letter-spacing: .15em; }
.settings-block input::placeholder { letter-spacing: normal; font-size: 15px; }
.form-msg { min-height: 1.3em; margin: 8px 0 0 !important; color: var(--danger); }
.form-msg.ok { color: #2e8b57; }
.icon-btn.gear { font-size: 22px; }
.file-label { cursor: pointer; }

/* ---------- вкладки ---------- */
.tabs { display: flex; gap: 4px; background: var(--chip); padding: 4px; border-radius: 12px; }
.tab {
  border: 0; background: transparent; border-radius: 9px;
  padding: 8px 14px; font-weight: 600; font-size: 15px; color: var(--muted); cursor: pointer;
}
.tab.on { background: var(--grad); color: #fff; box-shadow: 0 3px 10px var(--glow); }

/* ---------- мой стиль ---------- */
.intro { margin: 0; padding: 4px 16px 12px; font-size: 15px; }
.warn {
  margin: 0 16px 12px; padding: 12px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); font-size: 14px;
}
.card {
  margin: 0 16px 12px; padding: 16px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card.action { border: 2px dashed color-mix(in srgb, var(--accent) 45%, transparent); box-shadow: none; }
.card.action p { margin: 0 0 4px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card h2 { margin: 0; font-size: 17px; }
.portrait-text { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 10px; font-size: 15px; line-height: 1.55; }
.portrait-text.collapsed {
  max-height: 9.5em; overflow: hidden;
  -webkit-mask-image: linear-gradient(#000 60%, transparent); mask-image: linear-gradient(#000 60%, transparent);
}
#portraitEdit {
  width: 100%; min-height: 50dvh; margin-top: 10px; padding: 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  font-size: 15px; line-height: 1.5; resize: vertical; outline: none;
}
.link-btn { border: 0; background: none; color: var(--accent-ink); font-weight: 600; padding: 8px 0; cursor: pointer; }
.row { display: flex; gap: 10px; margin-top: 10px; }
.section-title { margin: 8px 16px 4px; font-size: 15px; }

.note-title { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.style-item { align-items: center; }
.style-item.processing, .style-item.queued, .style-item.uploading { cursor: default; }
.note.pending { cursor: default; color: var(--muted); }
.status { display: block; margin-top: 6px; font-size: 13px; color: var(--muted); }
.status.err { color: var(--danger); }
.bar { display: block; height: 4px; margin-top: 6px; border-radius: 4px; background: var(--chip); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--grad); transition: width .4s; }
.bar.indeterminate i { width: 30%; animation: slide 1.2s infinite ease-in-out; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }

.toggle { position: relative; flex: none; width: 46px; height: 28px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.toggle span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: .2s; pointer-events: none;
}
.toggle span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.toggle input:checked + span { background: var(--grad); }
.toggle input:checked + span::after { transform: translateX(18px); }

.switch-row { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch-row input { width: 20px; height: 20px; accent-color: var(--accent); }
.script-controls .switch-row { grid-column: 1 / -1; padding-top: 4px; }

.transcript-text {
  flex: 1; min-height: 50dvh; width: 100%; resize: none; padding: 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  font-size: 16px; line-height: 1.55; outline: none;
}
#transcriptView .editor-body { gap: 10px; padding-bottom: 8px; }
#styleView .bottombar .btn, #transcriptView .bottombar .btn { flex: 1; text-align: center; }
.file-label { display: inline-flex; align-items: center; justify-content: center; }
.file-label.disabled { opacity: .45; pointer-events: none; }

/* ---------- вход по PIN ---------- */
.lock {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: grid; place-items: center; padding: 24px;
}
.lock-box { width: min(340px, 100%); text-align: center; }
.lock-box img { border-radius: 16px; }
.lock-box h2 {
  margin: 12px 0 4px; font-size: 24px;
  background: var(--grad); -webkit-background-clip: text; background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
}
#pinInput {
  width: 100%; margin-top: 16px; padding: 14px; text-align: center;
  font-size: 28px; letter-spacing: .4em; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); outline: none;
}
#pinInput:focus { border-color: var(--accent); }
.lock-err { min-height: 1.4em; margin: 8px 0 0; color: var(--danger); }

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