:root {
  --bg: #1a1c1a;
  --panel: #232623;
  --line: #3a4038;
  --text: #e8ebe4;
  --muted: #9aa396;
  --accent: #c4a35a;
  --accent-ink: #1a1c1a;
  --danger: #c45a5a;
  --ok: #7a9e6a;
  --radius: 6px;
  --font-ui: "IBM Plex Mono", ui-monospace, monospace;
  --font-body: "Source Serif 4", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background:
    radial-gradient(1200px 600px at 10% -10%, #2a3228 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #2c2820 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden { display: none !important; }
.brand {
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--accent);
  margin: 0 0 0.75rem;
}
h1 {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1.6rem;
  margin: 0 0 0.5rem;
}
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
code {
  background: #121412;
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-size: 0.92em;
}
.error { color: var(--danger); margin: 0; }

.panel.gate {
  max-width: 480px;
  margin: 8vh auto;
  padding: 1.75rem;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
}
.stack { display: grid; gap: 0.9rem; margin-top: 1.25rem; }
label { display: grid; gap: 0.35rem; color: var(--muted); font-size: 12px; }
input, textarea {
  width: 100%;
  background: #121412;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.8rem;
  font: inherit;
  font-size: 16px; /* iOS: без зума при фокусе */
}
textarea {
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.55;
  min-height: 50vh;
  resize: vertical;
}
input:focus, textarea:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}

.row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #2b302b;
  color: var(--text);
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  min-height: 44px;
  touch-action: manipulation;
}
.back-list {
  display: none;
  margin-bottom: 0.75rem;
  width: fit-content;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { border-color: var(--danger); color: #f0c8c8; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}
.sidebar {
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.sidebar-top, .sidebar-foot { padding: 1rem; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line); display: grid; gap: 0.5rem; }
.note-list {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
  overflow: auto;
  flex: 1;
}
.note-list li button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #2c312c;
  color: var(--text);
  padding: 0.85rem 1rem;
  cursor: pointer;
  font: inherit;
}
.note-list li button:hover,
.note-list li button.active {
  background: #2d332c;
}
.note-list .t {
  display: block;
  font-family: var(--font-body);
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-list .d {
  display: block;
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 11px;
}

.editor { padding: 1.25rem 1.5rem 2rem; }
.editor-form { display: grid; gap: 0.85rem; max-width: 920px; }
#note-title {
  font-family: var(--font-body);
  font-size: 1.45rem;
  font-weight: 600;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  padding-left: 0;
  padding-right: 0;
}
.empty {
  max-width: 420px;
  margin-top: 20vh;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 1.2rem;
}

.files-block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  background: #1c1f1c;
}
.file-pick { cursor: pointer; margin: 0; }
.file-list {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}
.file-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.35rem 0;
  border-top: 1px solid #2c312c;
}
.file-list li:first-child { border-top: 0; }
.file-list a {
  color: var(--accent);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-list a:hover { text-decoration: underline; }
.tiny-btn {
  padding: 0.15rem 0.45rem;
  min-width: 1.6rem;
  line-height: 1.2;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: #101210;
  border: 1px solid var(--ok);
  color: var(--text);
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  z-index: 20;
}

@media (max-width: 800px) {
  .panel.gate {
    margin: 1.5rem 0.75rem;
    padding: 1.25rem;
  }
  .layout {
    grid-template-columns: 1fr;
    min-height: 100dvh;
  }
  .sidebar {
    min-height: 100dvh;
    max-height: none;
    border-right: 0;
  }
  .editor {
    display: none;
    padding: 1rem;
    min-height: 100dvh;
  }
  .layout.editing .sidebar { display: none; }
  .layout.editing .editor { display: block; }
  .back-list { display: inline-flex; align-items: center; }
  .note-list li button {
    padding: 1rem;
    min-height: 56px;
  }
  #note-title { font-size: 1.25rem; }
  textarea { min-height: 45dvh; font-size: 16px; }
  .file-list li {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
  }
  .file-list li a { grid-column: 1 / -1; }
  .row.between {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }
  .row.between > .row {
    justify-content: stretch;
  }
  .row.between > .row .btn { flex: 1; }
  .toast {
    left: 1rem;
    right: 1rem;
    bottom: calc(1rem + env(safe-area-inset-bottom));
  }
}
