:root {
  --bg: #0c0c0b;
  --panel: #151513;
  --panel-strong: #1c1c19;
  --text: #f2f0e8;
  --muted: #9d9b92;
  --line: #34332e;
  --accent: #e8b15c;
  --danger: #ee806f;
  --focus: #8cc8ff;
  --radius: 8px;
  --space-1: 0.5rem;
  --space-2: 0.75rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--text);
  background: var(--bg);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button { touch-action: manipulation; }
[hidden] { display: none !important; }

.shell {
  width: min(100%, 52rem);
  min-height: 100dvh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) max(1.1rem, env(safe-area-inset-right)) max(3rem, env(safe-area-inset-bottom)) max(1.1rem, env(safe-area-inset-left));
}

.topbar {
  min-height: 4.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.wordmark {
  color: var(--text);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.top-actions { display: flex; gap: var(--space-3); }

main { padding-top: clamp(2.5rem, 9vw, 5rem); }

.gate { width: min(100%, 34rem); }

.eyebrow {
  margin: 0 0 var(--space-2);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: var(--space-4);
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  font-size: clamp(2.7rem, 11vw, 5.5rem);
  font-weight: 500;
  line-height: 0.93;
  letter-spacing: -0.045em;
}

.lede {
  max-width: 31rem;
  margin-bottom: var(--space-5);
  color: var(--muted);
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  font-size: 1.08rem;
  line-height: 1.6;
}

.stack { display: grid; gap: var(--space-2); }

label {
  margin-top: var(--space-1);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  background: var(--panel);
  color: var(--text);
}

input { min-height: 3.25rem; padding: 0.8rem 0.9rem; }

textarea {
  min-height: 11rem;
  padding: 1rem;
  resize: vertical;
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  font-size: 1.15rem;
  line-height: 1.65;
}

input:focus, textarea:focus, button:focus-visible, summary:focus-visible {
  border-color: var(--focus);
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

button {
  min-height: 3rem;
  border-radius: var(--radius);
  cursor: pointer;
}

button:disabled { cursor: wait; opacity: 0.55; }

.primary, .secondary {
  border: 1px solid transparent;
  padding: 0.8rem 1rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.primary { margin-top: var(--space-2); background: var(--text); color: var(--bg); }
.secondary { border-color: var(--line); background: var(--panel); color: var(--text); }
.compact { min-height: 2.65rem; margin-top: 0; padding: 0.65rem 0.85rem; }

.text-button {
  min-height: 2.75rem;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.text-button:hover { color: var(--text); }

.warning, .quiet {
  margin-top: var(--space-4);
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.55;
}

.warning { color: var(--danger); }

.restore-panel { margin-top: var(--space-5); border-top: 1px solid var(--line); padding-top: var(--space-3); }
.restore-panel summary { min-height: 2.75rem; cursor: pointer; color: var(--muted); font-size: 0.8rem; line-height: 2.75rem; }
.restore-form { margin-top: var(--space-2); }

.diary-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: var(--space-3);
}

.diary-heading h1 { margin-bottom: var(--space-5); }

.offline-state {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.65rem;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
}

.composer {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: var(--space-4) 0;
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-2);
  color: var(--muted);
  font-size: 0.7rem;
}

.entry-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: var(--space-5);
  border-bottom: 1px solid var(--line);
  padding-bottom: var(--space-2);
}

.entry-header h2 { margin: 0; font-size: 0.8rem; letter-spacing: 0.12em; text-transform: uppercase; }
.entry-header span { color: var(--muted); font-size: 0.75rem; }
.entries { margin: 0; padding: 0; list-style: none; }
.entries li { border-bottom: 1px solid var(--line); padding: var(--space-4) 0 var(--space-5); }

.entries header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.45;
  text-transform: uppercase;
}

.entries header span { flex: 0 0 auto; color: var(--accent); }
.entries p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif; font-size: 1.08rem; line-height: 1.65; }
.empty-state { padding: var(--space-5) 0; color: var(--muted); font-size: 0.85rem; }

.install-hint {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  left: max(1rem, env(safe-area-inset-left));
  z-index: 10;
  width: min(calc(100% - 2rem), 31rem);
  margin-left: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-3);
  background: var(--panel-strong);
  box-shadow: 0 10px 40px rgb(0 0 0 / 0.45);
}

.install-hint p { margin-bottom: var(--space-2); font-size: 0.8rem; line-height: 1.5; }
.install-hint div { display: flex; justify-content: flex-end; gap: var(--space-3); }

.toast {
  position: fixed;
  top: max(1rem, env(safe-area-inset-top));
  left: 50%;
  z-index: 20;
  width: min(calc(100% - 2rem), 34rem);
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  background: var(--panel-strong);
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.45);
  font-size: 0.78rem;
  line-height: 1.4;
}

.toast[data-kind="error"] { border-color: var(--danger); color: var(--danger); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 48rem) {
  .shell { padding-right: 2rem; padding-left: 2rem; }
  .install-hint { left: auto; }
}

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in 160ms ease-out; }
  @keyframes toast-in { from { opacity: 0; transform: translate(-50%, -0.5rem); } }
}
