:root {
  --bg: #f7f7f9;
  --bg-raised: #ffffff;
  --text: #1a1a1e;
  --text-muted: #5b5b63;
  --border: #e0e0e6;
  --accent: #2b6cb0;
  --accent-text: #ffffff;
  --danger: #b0392b;
  --focus: #2b6cb0;
  --radius: 12px;
  --nav-size: 64px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121214;
    --bg-raised: #1c1c1f;
    --text: #f0f0f2;
    --text-muted: #a5a5ad;
    --border: #303035;
    --accent: #6ea8dc;
    --accent-text: #0d1b2a;
    --danger: #e08677;
    --focus: #6ea8dc;
  }
}

:root[data-theme="light"] {
  --bg: #f7f7f9;
  --bg-raised: #ffffff;
  --text: #1a1a1e;
  --text-muted: #5b5b63;
  --border: #e0e0e6;
  --accent: #2b6cb0;
  --accent-text: #ffffff;
  --danger: #b0392b;
  --focus: #2b6cb0;
}

:root[data-theme="dark"] {
  --bg: #121214;
  --bg-raised: #1c1c1f;
  --text: #f0f0f2;
  --text-muted: #a5a5ad;
  --border: #303035;
  --accent: #6ea8dc;
  --accent-text: #0d1b2a;
  --danger: #e08677;
  --focus: #6ea8dc;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

a { color: inherit; }

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

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

#main {
  flex: 1;
  padding: 16px 16px calc(var(--nav-size) + 16px);
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

#main:focus { outline: none; }

.nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-size);
  display: flex;
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-link {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 12px;
  min-height: 44px;
}

.nav-link .nav-icon { font-size: 20px; }

.nav-link[aria-current="page"] {
  color: var(--accent);
}

.nav-link:focus-visible,
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

h1, h2, h3 { line-height: 1.2; }

.screen-title {
  margin: 0 0 16px;
  font-size: 1.5rem;
}

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.muted { color: var(--text-muted); }

.placeholder {
  color: var(--text-muted);
  padding: 32px 0;
  text-align: center;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.today-header .screen-title { margin: 4px 0 0; }

.clock {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.day-nav {
  display: flex;
  gap: 8px;
  margin: 20px 0;
}

.day-nav button {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  cursor: pointer;
}

section + section { margin-top: 28px; }

section h2 { font-size: 1.05rem; margin: 0 0 12px; }

.event-list, .todo-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.event-row {
  display: flex;
  gap: 12px;
  align-items: baseline;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-left: 4px solid var(--event-colour, var(--accent));
  text-align: left;
  cursor: pointer;
}

.event-time {
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.todo-row label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 2px;
}

.todo-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
}

.todo-done { color: var(--text-muted); text-decoration: line-through; }

.todo-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.todo-form input {
  flex: 1;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
}

.todo-form button {
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}

.mood-picker {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.mood-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.mood-dot-active {
  background: var(--accent);
  border-color: var(--accent);
}

.journal-text {
  width: 100%;
  min-height: 160px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  resize: vertical;
}

.saved-indicator {
  min-height: 1.2em;
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.saved-indicator.saved-visible { opacity: 1; }

/* Calendar */

.calendar-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin: 16px 0;
}

.calendar-toolbar-right { display: flex; gap: 8px; }

.calendar-toolbar button {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  cursor: pointer;
}

#new-event { background: var(--accent); color: var(--accent-text); border-color: transparent; }

.month-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.month-cell {
  min-height: 64px;
  background: var(--bg-raised);
  border: none;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
}

.month-cell-outside { color: var(--text-muted); background: var(--bg); }
.month-cell-today .month-cell-num {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.month-cell-holiday {
  font-size: 10px;
  color: var(--danger);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.month-cell-marks { display: flex; gap: 4px; margin-top: auto; }
.mark-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); display: inline-block; }
.mark-underline { width: 12px; height: 2px; background: var(--text-muted); display: inline-block; }

.week-grid {
  display: grid;
  grid-template-columns: 56px repeat(7, 1fr);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 12px;
}

.week-corner, .week-day-head, .week-allday-label, .week-hour-label {
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 4px;
}

.week-day-head { text-align: center; font-weight: 600; }
.week-day-head-today { color: var(--accent); }
.week-hour-label { color: var(--text-muted); text-align: right; }

.week-allday-cell, .week-hour-cell {
  min-height: 32px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--bg);
  padding: 2px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.week-holiday { font-size: 10px; color: var(--danger); }

.week-event {
  border: none;
  border-left: 3px solid var(--event-colour, var(--accent));
  background: var(--bg-raised);
  border-radius: 4px;
  padding: 2px 4px;
  font-size: 11px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  width: 100%;
}

/* Event editor dialog */

dialog.event-editor {
  border: none;
  border-radius: var(--radius);
  padding: 20px;
  width: min(480px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-raised);
  color: var(--text);
}

dialog.event-editor::backdrop { background: rgb(0 0 0 / 0.4); }

.event-form { display: flex; flex-direction: column; gap: 14px; }
.event-form h2 { margin: 0; font-size: 1.2rem; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--text-muted); }
.field input, .field textarea, .field select {
  font-size: 1rem;
  color: var(--text);
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  min-height: 44px;
}
.field textarea { min-height: 72px; resize: vertical; }

.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.field-check, .field-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
}

fieldset.field { border: none; padding: 0; margin: 0; }
fieldset.field legend { font-size: 0.85rem; color: var(--text-muted); padding: 0; margin-bottom: 4px; }

.colour-swatches { display: flex; gap: 10px; }
.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--sw, transparent);
  border: 2px solid var(--border);
  display: inline-flex;
  cursor: pointer;
}
.swatch-none { background: repeating-linear-gradient(45deg, var(--border), var(--border) 2px, transparent 2px, transparent 5px); }
.swatch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.swatch:has(input:checked) { border-color: var(--text); }

.weekday-picker { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.weekday-check { display: flex; align-items: center; gap: 4px; font-size: 0.85rem; }

.ends-picker { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.ends-label { margin: 0; font-size: 0.85rem; color: var(--text-muted); }
.ends-picker input[type="date"], .ends-picker input[type="number"] { min-height: 36px; }

.editor-footer { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.editor-footer button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
}
.editor-footer button[data-action="save"], .editor-footer button[data-choice="this"], .editor-footer button[data-choice="series"] {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}
.editor-footer button.danger, .editor-footer button[data-choice="confirm"] {
  background: var(--danger);
  color: var(--accent-text);
  border-color: transparent;
}
.scope-prompt { flex-basis: 100%; margin: 0 0 4px; font-size: 0.9rem; }

/* Journal */

.journal-search {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
}

.journal-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.journal-row {
  width: 100%;
  min-height: 44px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  cursor: pointer;
}

.journal-date { font-weight: 600; flex-basis: 100%; }
.journal-first-line { color: var(--text-muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.journal-mood { color: var(--accent); letter-spacing: 1px; font-size: 0.8rem; }

/* Settings */

.settings-section { margin: 24px 0; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.settings-section:last-child { border-bottom: none; }
.settings-section h2 { font-size: 1.05rem; margin: 0 0 12px; }
.settings-section .field { margin-bottom: 14px; max-width: 320px; }

.settings-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-actions button, .settings-actions input[type="text"] {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  cursor: pointer;
}
.settings-actions input[type="text"] { cursor: text; background: var(--bg); }

.settings-note { color: var(--text-muted); font-size: 0.85rem; margin: 10px 0 0; }

button.danger {
  background: var(--danger);
  color: var(--accent-text);
  border-color: transparent;
}
button.danger:disabled { background: var(--border); color: var(--text-muted); cursor: not-allowed; }

@media (min-width: 900px) {
  .app { flex-direction: row; }

  .nav {
    order: -1;
    position: sticky;
    top: 0;
    left: 0;
    height: 100vh;
    width: 220px;
    flex-direction: column;
    border-top: none;
    border-right: 1px solid var(--border);
    padding: 24px 8px;
    gap: 4px;
  }

  .nav-link {
    flex: none;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 14px;
  }

  .nav-link[aria-current="page"] {
    background: var(--bg-raised);
  }

  #main {
    padding: 32px calc(var(--nav-size) / 2) 32px 32px;
    max-width: 900px;
  }
}
