:root {
  --bg: #f6f1e7;
  --bg-card: #fffbf3;
  --ink: #2a2522;
  --ink-soft: #6b6258;
  --rule: #e6dcc9;
  --accent: #8a5a44;
  --accent-soft: #c79c7e;
  --danger: #b14a3a;
  --ok: #5b7c4e;
  --shadow: 0 1px 2px rgba(60, 40, 20, 0.06), 0 4px 16px rgba(60, 40, 20, 0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --handwriting: "Bradley Hand", "Snell Roundhand", "Apple Chancery", cursive;
  --serif: Georgia, "Iowan Old Style", "Apple Garamond", "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

button {
  font-family: inherit;
  font-size: 0.95rem;
  border: 1px solid var(--rule);
  background: var(--bg-card);
  color: var(--ink);
  padding: 0.55rem 0.95rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
button:hover { background: #fff7e6; border-color: var(--accent-soft); }
button:active { transform: translateY(1px); }
button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button.primary:hover { background: #74442f; }
button.ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
button.ghost:hover { color: var(--ink); background: rgba(0,0,0,0.03); }
button.danger { color: var(--danger); border-color: rgba(177, 74, 58, 0.3); }
button.danger:hover { background: #fbeae6; }

input, textarea, select {
  font-family: inherit;
  font-size: 0.95rem;
  border: 1px solid var(--rule);
  background: var(--bg-card);
  color: var(--ink);
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(199, 156, 126, 0.18);
}

a { color: var(--accent); }

/* ============ Login ============ */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 2.2rem 2rem;
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 360px;
  width: 100%;
}
.login-card h1 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: normal;
  margin: 0 0 1.5rem;
  font-size: 2rem;
  color: var(--ink);
}
.login-card input { width: 100%; margin-bottom: 0.9rem; }
.login-card button { width: 100%; }
.login-error { color: var(--danger); font-size: 0.85rem; min-height: 1.2em; }

/* ============ App shell ============ */
.app { display: none; }
.app.active { display: block; }

.header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--rule);
  padding: 0.9rem 1.2rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  max-width: 920px;
  margin: 0 auto;
}
.brand {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.45rem;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}
.search-cluster {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.search-cluster input { padding: 0.45rem 0.6rem; font-size: 0.9rem; }
.search-cluster input[type="search"] { min-width: 180px; }
.search-cluster input[type="date"] { width: 150px; }

.nav {
  max-width: 920px;
  margin: 0 auto;
  padding: 0.6rem 0 0;
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.nav button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink-soft);
  font-size: 0.9rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
}
.nav button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.nav button:hover:not(.active) {
  color: var(--ink);
  border-color: var(--rule);
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 1.5rem 1.2rem 4rem;
}

.view { display: none; }
.view.active { display: block; }

/* ============ Composer ============ */
.entry-header {
  margin-bottom: 1.2rem;
}
.entry-header h2 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: normal;
  margin: 0 0 0.5rem;
  font-size: 1.7rem;
  color: var(--ink);
}
.entry-meta {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  color: var(--ink-soft);
  font-size: 0.92rem;
}
.entry-meta input { padding: 0.35rem 0.55rem; font-size: 0.9rem; }
.entry-meta .pill {
  background: #efe6d3;
  color: var(--ink);
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.85rem;
}

.mic-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  margin: 1.5rem 0;
}
.mic {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 2.2rem;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(138, 90, 68, 0.25);
  transition: transform 100ms ease, background 120ms ease;
}
.mic:hover { background: #74442f; }
.mic.recording {
  background: var(--danger);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(177, 74, 58, 0.45); }
  50%      { box-shadow: 0 0 0 14px rgba(177, 74, 58, 0); }
}
.mic-status { color: var(--ink-soft); font-size: 0.88rem; min-height: 1.2em; }
.mic-interim {
  width: 100%;
  min-height: 1.4em;
  color: var(--ink-soft);
  font-style: italic;
  text-align: center;
  font-size: 0.95rem;
}

.composer-text {
  width: 100%;
  max-width: 720px;
  min-height: 700px;
  font-family: var(--handwriting);
  font-style: italic;
  font-size: 1.25rem;
  line-height: 1.6;
  padding: 1rem;
  resize: vertical;
  background: var(--bg-card);
}
.composer-text[readonly] {
  background: #fdf8eb;
  color: var(--ink);
}

.composer-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.9rem 0 0;
  align-items: center;
}
.composer-actions .spacer { flex: 1; }
.save-status { color: var(--ink-soft); font-size: 0.85rem; }

/* ============ Photos ============ */
.photo-section { margin-top: 1.6rem; }
.photo-section h3 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: normal;
  margin: 0 0 1rem;
  font-size: 1.15rem;
  color: var(--ink);
}
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.6rem;
}
.photo-tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #eee;
}
.photo-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-tile .remove {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.9rem;
}
.drop-zone {
  border: 2px dashed var(--rule);
  border-radius: var(--radius);
  padding: 1.2rem;
  text-align: center;
  color: var(--ink-soft);
  margin-bottom: 0.7rem;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent-soft);
  background: #fdf6e3;
}
.drop-zone input { display: none; }

/* ============ On this day ============ */
.otd {
  margin-top: 2rem;
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
}
.otd summary {
  cursor: pointer;
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink);
  font-size: 1.05rem;
  list-style: none;
}
.otd summary::-webkit-details-marker { display: none; }
.otd summary::before { content: "▸ "; color: var(--ink-soft); }
.otd[open] summary::before { content: "▾ "; }
.otd ul { list-style: none; padding: 0; margin: 0.6rem 0 0; }
.otd li {
  padding: 0.55rem 0.4rem;
  border-top: 1px solid var(--rule);
  cursor: pointer;
}
.otd li:first-child { border-top: none; }
.otd li:hover { background: #fdf6e3; }
.otd .year { color: var(--ink-soft); font-size: 0.85rem; margin-right: 0.6rem; }
.otd .snip { color: var(--ink); }
.otd .empty { color: var(--ink-soft); font-style: italic; padding: 0.5rem 0.2rem; }

/* ============ Calendar ============ */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.cal-header h2 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: normal;
  margin: 0;
  font-size: 1.7rem;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  background: var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--rule);
}
.cal-dow, .cal-cell {
  background: var(--bg-card);
  padding: 0.5rem;
  text-align: center;
  min-height: 64px;
  position: relative;
}
.cal-dow {
  font-size: 0.78rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  min-height: auto;
  padding: 0.4rem 0.2rem;
}
.cal-cell { cursor: pointer; transition: background 100ms ease; }
.cal-cell:hover { background: #fdf6e3; }
.cal-cell.other-month { color: #c9bea8; background: #f0e9d8; }
.cal-cell.today { outline: 2px solid var(--accent); outline-offset: -3px; }
.cal-cell .num { font-size: 0.95rem; }
.cal-cell .dot {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent-soft);
}

/* ============ Past entry view ============ */
.past-entry h2 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: normal;
  margin: 0 0 0.6rem;
  font-size: 1.8rem;
}
.past-meta {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
}
.past-body {
  width: 100%;
  max-width: 720px;
  min-height: 700px;
  font-family: var(--handwriting);
  font-style: italic;
  font-size: 1.55rem;
  line-height: 1.55;
  color: var(--ink);
  white-space: pre-wrap;
}
.past-photos {
  margin: 1.5rem 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.7rem;
}
.past-photos img {
  width: 100%;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.past-actions {
  margin-top: 1.4rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.original-block {
  background: #f3ecda;
  border-left: 3px solid var(--accent-soft);
  padding: 0.9rem 1rem;
  margin-top: 1rem;
  border-radius: var(--radius-sm);
  font-family: var(--sans);
  font-style: normal;
  font-size: 0.95rem;
  white-space: pre-wrap;
  color: var(--ink-soft);
}

/* ============ Search ============ */
.search-results { display: flex; flex-direction: column; gap: 0.7rem; }
.search-result {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  cursor: pointer;
}
.search-result:hover { border-color: var(--accent-soft); }
.search-result .sr-date {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
  margin-bottom: 0.3rem;
}
.search-result .sr-snippet { color: var(--ink-soft); font-size: 0.92rem; }
.search-empty { color: var(--ink-soft); font-style: italic; padding: 2rem 0; text-align: center; }

/* ============ Settings ============ */
.settings h2 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: normal;
  margin: 0 0 1rem;
  font-size: 1.6rem;
}
.names-list {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1rem;
}
.name-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1.2fr auto;
  gap: 0.6rem;
  padding: 0.7rem 0.9rem;
  border-top: 1px solid var(--rule);
  align-items: center;
}
.name-row:first-child { border-top: none; }
.name-row input { font-size: 0.9rem; padding: 0.4rem 0.55rem; }
.name-row .label { color: var(--ink-soft); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.name-row.header { background: #efe6d3; }
.name-row.header > div { color: var(--ink-soft); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.settings-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1.4rem; }

/* ============ Misc ============ */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
  z-index: 100;
}
.toast.show { opacity: 1; }

@media (max-width: 600px) {
  .name-row { grid-template-columns: 1fr; }
  .name-row.header { display: none; }
  .name-row > div::before {
    display: block;
    content: attr(data-label);
    color: var(--ink-soft);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.2rem;
  }
  .search-cluster input[type="search"] { min-width: 0; flex: 1; }
  .past-body { font-size: 1.35rem; }
  .mic { width: 76px; height: 76px; font-size: 1.9rem; }
}
