:root {
  color-scheme: light dark;
  --bg: #f6f8f9;
  --surface: #ffffff;
  --surface-soft: #eef3f1;
  --text: #161a1d;
  --muted: #667073;
  --line: rgba(22, 26, 29, 0.14);
  --accent: #0f766e;
  --accent-2: #9a4f2d;
  --danger: #a12d2d;
  --shadow: 0 12px 34px rgba(16, 24, 28, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111416;
    --surface: #1b2023;
    --surface-soft: #151a1d;
    --text: #f3f6f7;
    --muted: #a5afb2;
    --line: rgba(243, 246, 247, 0.14);
    --accent: #66c8bc;
    --accent-2: #d28d61;
    --danger: #f08a80;
    --shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
  }
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f8f9;
  --surface: #ffffff;
  --surface-soft: #eef3f1;
  --text: #161a1d;
  --muted: #667073;
  --line: rgba(22, 26, 29, 0.14);
  --accent: #0f766e;
  --accent-2: #9a4f2d;
  --danger: #a12d2d;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111416;
  --surface: #1b2023;
  --surface-soft: #151a1d;
  --text: #f3f6f7;
  --muted: #a5afb2;
  --line: rgba(243, 246, 247, 0.14);
  --accent: #66c8bc;
  --accent-2: #d28d61;
  --danger: #f08a80;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled, textarea:disabled, input:disabled { cursor: progress; opacity: 0.64; }
.hidden { display: none !important; }
.is-invisible { visibility: hidden; pointer-events: none; }
h1, h2, p { margin: 0; }
p { color: var(--muted); }

.app-shell { min-height: 100dvh; }

.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

h1 { font-size: 28px; }
h2 { font-size: 17px; margin-bottom: 10px; }

.auth-form {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 12px 13px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.auth-form button,
.primary-btn {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 12px 14px;
  font-weight: 700;
}

.text-btn,
.ghost-btn,
.small-btn,
.icon-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
}

.text-btn {
  border: 0;
  color: var(--accent);
  padding-left: 0;
}

.ghost-btn:hover,
.small-btn:hover,
.icon-btn:hover,
.bottom-nav button:hover {
  border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
}

.icon-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.wide-btn { width: 100%; }

.status {
  min-height: 20px;
  color: var(--muted);
  font-size: 14px;
}

.error { color: var(--danger) !important; }

.main-screen {
  min-height: 100dvh;
  width: min(840px, 100%);
  margin: 0 auto;
  padding: 0 16px 94px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 88px 1fr 88px;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.top-spacer { width: 88px; height: 1px; }

.top-title {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-width: 0;
}

.top-title strong { font-size: 18px; }
.top-title span { color: var(--muted); font-size: 13px; }

.tab {
  display: none;
  width: 100%;
  padding-top: 14px;
}

.tab.active { display: block; }

.date-row {
  display: grid;
  grid-template-columns: 44px minmax(148px, 1fr) 44px 104px;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.journal-textarea {
  display: block;
  height: clamp(320px, calc(100dvh - 310px), 640px);
  min-height: 0;
  resize: none;
  line-height: 1.62;
  font-size: 18px;
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    linear-gradient(180deg, color-mix(in srgb, var(--accent) 18%, transparent), transparent) border-box;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), var(--shadow);
}

.editor-footer {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  margin-top: 10px;
  color: var(--muted);
}

#char-count {
  justify-self: end;
  font-size: 14px;
}

.range-row,
.analysis-head {
  display: grid;
  grid-template-columns: 1fr 1fr minmax(160px, 1.2fr) auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.analysis-head {
  grid-template-columns: minmax(150px, 220px) auto;
  justify-content: start;
}

.feed-list,
.analysis-list,
.profile-grid {
  display: grid;
  gap: 12px;
}

.feed-day,
.analysis-card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 8px 22px rgba(16, 24, 28, 0.05);
}

.feed-day time,
.analysis-card time {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
}

.feed-day pre,
.analysis-card pre {
  margin: 0;
  white-space: pre-wrap;
  font-family: inherit;
  line-height: 1.5;
}

.empty-note { padding: 14px 0; }

#profile-import { margin-bottom: 12px; }

.bottom-nav {
  position: fixed;
  inset: auto 0 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.bottom-nav button {
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 11px 6px;
}

.bottom-nav button.active {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

@media (max-width: 720px) {
  .main-screen { padding-left: 12px; padding-right: 12px; }

  .topbar {
    grid-template-columns: 72px 1fr 72px;
    min-height: 60px;
  }

  .top-spacer { width: 72px; }

  .date-row {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
  }

  .date-row .small-btn {
    grid-column: 1 / -1;
    height: 44px;
  }

  .journal-textarea {
    height: clamp(300px, calc(100dvh - 336px), 600px);
    font-size: 16px;
  }

  .range-row,
  .analysis-head {
    grid-template-columns: 1fr;
  }
}
