:root {
  --bg: #141414;
  --surface: #1b1b1b;
  --text: #ededed;
  --muted: #9a9a9a;
  --divider: #2a2a2a;
  --accent: #4db6ac;
  --accent-soft: #b9d9d4;
  --danger: #e57373;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- шапка ---------- */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px;
  min-height: 56px;
  background: var(--bg);
}

.topbar__title {
  flex: 1 1 auto;
  margin: 0;
  padding-left: 8px;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.2;
}

.topbar__title--sm {
  font-size: 19px;
  padding-left: 0;
}

.topbar__title--center {
  flex: 1 1 auto;
  padding-left: 0;
  text-align: center;
}

.topbar__spacer { flex: 1 1 auto; }

.icon-btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--text);
  cursor: pointer;
}

.icon-btn:active { background: rgba(255, 255, 255, 0.08); }

.icon-btn svg { width: 24px; height: 24px; display: block; }

.text-btn {
  flex: 0 0 auto;
  padding: 10px 8px;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
}

.text-btn:disabled { color: var(--muted); cursor: default; }

/* ---------- экран ---------- */

.screen {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  outline: none;
}

.splash {
  display: grid;
  place-items: center;
  gap: 12px;
  height: 100%;
  padding: 24px;
  color: var(--muted);
  font-size: 16px;
  text-align: center;
}

/* ---------- поиск ---------- */

.search {
  padding: 2px 16px 8px;
}

.search__row {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--accent);
}

.search__input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 19px;
}

.search__input::placeholder { color: var(--muted); }
.search__input:focus { outline: none; }

.search__icon { color: var(--muted); display: grid; place-items: center; }
.search__icon svg { width: 24px; height: 24px; display: block; }

.search__clear {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.search__clear[hidden] { display: none; }

.search__clear svg { width: 18px; height: 18px; display: block; }

.status {
  padding: 10px 16px 4px;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- список ---------- */

.list {
  margin: 0;
  padding: 0 0 calc(24px + env(safe-area-inset-bottom));
  list-style: none;
}

.row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--divider);
  cursor: pointer;
}

.row:active { background: var(--surface); }

.row__num {
  flex: 0 0 52px;
  width: 52px;
  color: var(--muted);
  font-size: 19px;
  line-height: 25px;
}

.row__title {
  flex: 1 1 auto;
  min-width: 0; /* иначе -webkit-line-clamp не даёт элементу сжиматься */
  font-size: 18px;
  line-height: 25px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.row__dot {
  flex: 0 0 6px;
  width: 6px;
  height: 6px;
  margin-top: 9px;
  border-radius: 50%;
  background: var(--accent);
}

@supports (content-visibility: auto) {
  .row {
    content-visibility: auto;
    contain-intrinsic-size: auto 62px;
  }
}

/* ---------- гимн ---------- */

.hymn {
  padding: 8px 20px calc(40px + env(safe-area-inset-bottom));
}

.hymn__title {
  margin: 0 0 6px;
  font-size: 22px;
  line-height: 30px;
  font-weight: 700;
}

.hymn__edited {
  margin: 0 0 16px;
  color: var(--accent);
  font-size: 12px;
}

.stanza {
  margin: 0 0 14px;
  font-size: 17px;
  line-height: 28px;
  white-space: pre-line;
}

.stanza--chorus {
  color: var(--accent-soft);
  font-style: italic;
}

/* ---------- редактор ---------- */

.editor {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 16px calc(24px + env(safe-area-inset-bottom));
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.field input,
.field textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--divider);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* меньше 16px iOS зумит страницу при фокусе */
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.field textarea {
  min-height: 45vh;
  line-height: 1.5;
  resize: none;
  white-space: pre-wrap;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.draft-note {
  margin: 0;
  color: var(--accent);
  font-size: 13px;
}

/* ---------- служебное ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 12px;
  background: #263a37;
  color: var(--text);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 10;
}

.toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (min-width: 760px) {
  .app {
    max-width: 760px;
    margin: 0 auto;
  }

  .list { border-left: 1px solid var(--divider); border-right: 1px solid var(--divider); }
}
