:root {
  color-scheme: dark;
  --bg: #12100e;
  --surface: #1c1916;
  --surface-2: #26221d;
  --line: #352f28;
  --text: #ebe3d5;
  --muted: #a1978a;
  --accent: #dca64d;
  --accent-ink: #1d1508;
  --secret: #b39cf0;
  --secret-bg: #1f1b2c;
  --secret-line: #3e3560;
  --danger: #e27d6d;
  --story: "Noto Serif", Georgia, "Times New Roman", serif;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--ui);
  -webkit-tap-highlight-color: transparent;
}

button, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.primary {
  min-height: 44px; padding: 0 18px;
  background: var(--accent); color: var(--accent-ink);
  border-radius: 10px; font-weight: 650;
}
.ghost {
  min-height: 44px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 10px; color: var(--text);
}
.link { color: var(--accent); font-weight: 600; min-height: 44px; padding: 0 4px; white-space: nowrap; }
.wide { width: 100%; }
.danger { color: var(--danger); }
.muted { color: var(--muted); margin: 0; }

/* Вхід */
.login {
  min-height: 100dvh; padding: 24px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
.login img { border-radius: 22px; }
.login h1 { font: 600 34px/1.2 var(--story); margin: 20px 0 6px; }
.tagline { font: italic 17px/1.5 var(--story); color: var(--muted); margin: 0 0 22px; }

/* Каркас */
.app { height: 100dvh; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; }
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(6px, env(safe-area-inset-top)) 6px 6px 16px;
  border-bottom: 1px solid var(--line);
}
.top h1 { font: 600 19px/1.2 var(--story); margin: 0; letter-spacing: .02em; }
.icon-button { width: 44px; height: 44px; display: grid; place-items: center; }
.icon-button svg { fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; }

.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 2px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  font-size: 14px; color: var(--muted);
}

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.feed, .chat-list, .settings { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 16px; }

/* Стрічка */
.older { display: block; margin: 16px auto 0; color: var(--muted); }
.scene { padding: 24px 0 8px; }
.scene + .scene { border-top: 1px solid var(--line); margin-top: 16px; }
/* Остання сцена займає щонайменше весь екран, щоб її початок можна було підняти до верху. */
.scene:last-child { min-height: var(--feed-height, 100%); }
.scene-title {
  font: 600 13px/1.3 var(--ui); letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 12px;
}
.scene-body { font: 18px/1.62 var(--story); }
.scene-body p { margin: 0 0 .85em; white-space: pre-line; overflow-wrap: anywhere; }

.scene-secret {
  margin: 8px 0 14px; padding: 12px 14px;
  background: var(--secret-bg); border: 1px solid var(--secret-line); border-radius: 10px;
}
.scene-secret h3 {
  margin: 0 0 6px; font: 600 12px/1.3 var(--ui); letter-spacing: .08em; text-transform: uppercase; color: var(--secret);
}
.scene-secret p { margin: 0; font: 17px/1.55 var(--story); white-space: pre-line; overflow-wrap: anywhere; }

.moves { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 8px; }
.move { padding: 10px 12px; background: var(--surface); border-left: 3px solid var(--line); border-radius: 0 8px 8px 0; }
.move.mine { border-left-color: var(--accent); }
.move.secret { background: var(--secret-bg); border-left-color: var(--secret); }
.move-who { font-size: 13px; font-weight: 650; color: var(--muted); display: flex; gap: 8px; align-items: baseline; }
.move-tag { color: var(--secret); font-weight: 500; }
.move-text { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.move-hidden { margin: 2px 0 0; color: var(--muted); font-style: italic; }

.empty { color: var(--muted); text-align: center; font: italic 17px/1.5 var(--story); padding: 56px 12px; margin: 0; }

/* Хід */
.dock { border-top: 1px solid var(--line); background: var(--surface); padding: 10px 16px; }
.dock-status { display: flex; flex-direction: column; gap: 8px; }
.dock-status p { margin: 0; font-size: 15px; color: var(--muted); }
.lock-bar { height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.lock-bar span { display: block; height: 100%; width: 100%; background: var(--accent); transform-origin: left; }

.move-form { display: flex; flex-direction: column; gap: 8px; }
textarea {
  width: 100%; padding: 10px 12px; resize: none;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; line-height: 1.45;
}
#move-input { max-height: 38dvh; }
.move-actions { display: flex; align-items: center; gap: 8px; }
.move-actions .primary { margin-left: auto; }
.secret-toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding-right: 4px; color: var(--muted); }
.secret-toggle input { width: 20px; height: 20px; margin: 0; accent-color: var(--secret); }
.secret-toggle:has(input:checked) { color: var(--secret); }
.secret-hint { margin: 0; font-size: 13px; color: var(--secret); }

/* Чат */
.chat-list { padding-top: 12px; padding-bottom: 12px; }
#messages { display: flex; flex-direction: column; gap: 6px; }
.message { max-width: 84%; align-self: flex-start; padding: 7px 11px; background: var(--surface); border-radius: 12px 12px 12px 3px; }
.message.mine { align-self: flex-end; background: var(--surface-2); border-radius: 12px 12px 3px 12px; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.message-time { font-size: 11px; color: var(--muted); text-align: right; margin-top: 1px; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--surface); }
#chat-input { flex: 1; max-height: 30dvh; }

/* Налаштування */
.settings h2 { font: 600 22px/1.2 var(--story); margin: 22px 0 6px; }
.settings > .ghost { width: 100%; margin-top: 12px; }
.card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 18px; padding: 14px; background: var(--surface); border-radius: 12px;
}
.card p { font-size: 14px; margin-top: 2px; }

/* Вкладки */
.tabs { display: flex; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tab { flex: 1; height: 50px; color: var(--muted); font-weight: 600; position: relative; }
.tab.active { color: var(--accent); }
.dot {
  display: inline-block; width: 8px; height: 8px; margin-left: 6px; vertical-align: 2px;
  border-radius: 50%; background: var(--accent);
}

.toast {
  position: fixed; left: 16px; right: 16px; bottom: 76px; z-index: 5; margin: 0 auto; max-width: 480px;
  padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line);
  text-align: center;
}
