/* Diary — warm, quiet, paper-under-lamplight. */

:root {
  --ink:        #2a2320;
  --ink-soft:   #6b5f57;
  --ink-faint:  #9c8f85;
  --paper:      #f7f2ea;
  --paper-2:    #fffdf9;
  --line:       #e4dace;
  --accent:     #a4643c;
  --accent-2:   #c98a5c;
  --shadow:     0 1px 2px rgba(60,45,30,.05), 0 12px 32px rgba(60,45,30,.07);
  --radius:     14px;
  --serif:      "Fraunces", "Iowan Old Style", Georgia, serif;
  --sans:       "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --lock-bg:    radial-gradient(120% 90% at 50% 0%, #2c2420 0%, #1b1714 60%, #141110 100%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink:       #ece3d8;
    --ink-soft:  #b0a294;
    --ink-faint: #7d7166;
    --paper:     #1a1614;
    --paper-2:   #221d1a;
    --line:      #332c27;
    --accent:    #d68f5f;
    --accent-2:  #e0a87d;
    --shadow:    0 1px 2px rgba(0,0,0,.3), 0 14px 40px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }

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

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ─────────────────────────  LOCK SCREEN  ───────────────────────── */

.lock {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: var(--lock-bg);
  color: #f2e9df;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  opacity: 1;
  visibility: visible;
  transition: opacity .4s ease, visibility 0s linear 0s;
}
.lock.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .4s ease, visibility 0s linear .4s;
}

.lock-inner {
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.lock-mark {
  font-size: 24px;
  color: var(--accent-2);
  opacity: .85;
  margin-bottom: 10px;
}

.lock-brand h1 {
  font-family: var(--serif);
  font-weight: 300;
  font-size: 34px;
  letter-spacing: .02em;
  margin: 0 0 6px;
  text-align: center;
}

.lock-hint {
  margin: 0 0 30px;
  font-size: 13.5px;
  letter-spacing: .04em;
  color: #a9998c;
  text-align: center;
  min-height: 20px;
  transition: color .2s ease;
}
.lock-hint.error { color: #e08b70; }

.dots {
  display: flex;
  gap: 16px;
  margin-bottom: 40px;
}
.dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 1.5px solid #6d5f55;
  background: transparent;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}
.dot.filled {
  background: var(--accent-2);
  border-color: var(--accent-2);
  transform: scale(1.12);
}

.dots.shake { animation: shake .42s cubic-bezier(.36,.07,.19,.97); }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 74px);
  gap: 18px;
  justify-content: center;
}

.key {
  width: 74px; height: 74px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.11);
  background: rgba(255,255,255,.045);
  color: #f2e9df;
  font-family: var(--sans);
  font-size: 26px;
  font-weight: 400;
  cursor: pointer;
  transition: background .12s ease, transform .08s ease;
  -webkit-tap-highlight-color: transparent;
}
.key:active { background: rgba(255,255,255,.16); transform: scale(.94); }
.key-ghost { border-color: transparent; background: transparent; font-size: 20px; color: #a9998c; }

.lock-foot {
  margin-top: 34px;
  font-size: 11.5px;
  letter-spacing: .05em;
  color: #6f625a;
  text-align: center;
}

/* ─────────────────────────  APP SHELL  ───────────────────────── */

.app {
  display: grid;
  grid-template-columns: 290px 1fr;
  height: 100%;
}
.app[hidden] { display: none; }

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--paper-2);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-top: env(safe-area-inset-top);
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 14px;
}
.side-title {
  display: flex; align-items: center; gap: 9px;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 400;
}
.mark { color: var(--accent); font-size: 14px; }

.lock-controls { display: flex; align-items: center; gap: 9px; }

.countdown {
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
  color: var(--ink-faint);
  transition: color .25s ease;
}
.countdown.warn { color: var(--accent); }

.icon-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-family: var(--sans);
  letter-spacing: .03em;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

.today-btn {
  margin: 0 14px 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-family: var(--sans);
  transition: border-color .15s ease, background .15s ease;
}
.today-btn:hover { border-color: var(--accent); }
.today-label { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.today-date { font-family: var(--serif); font-size: 15px; color: var(--ink); }

.side-search { padding: 0 14px 12px; }
#search {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  outline: none;
}
#search:focus { border-color: var(--accent); }

.entry-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 14px;
  min-height: 0;
}

.entry-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: 10px;
  padding: 11px 12px;
  margin-bottom: 2px;
  cursor: pointer;
  display: block;
  font-family: var(--sans);
  transition: background .12s ease;
}
.entry-item:hover { background: rgba(164,100,60,.07); }
.entry-item.active { background: rgba(164,100,60,.13); }
.entry-day {
  font-family: var(--serif);
  font-size: 14px;
  color: var(--ink);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.entry-day small { font-family: var(--sans); font-size: 10.5px; color: var(--ink-faint); letter-spacing: .04em; }
.entry-preview {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 3px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.list-empty {
  color: var(--ink-faint);
  font-size: 12.5px;
  padding: 18px 12px;
  line-height: 1.6;
}

.side-foot {
  border-top: 1px solid var(--line);
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  font-size: 11.5px;
  color: var(--ink-faint);
  letter-spacing: .03em;
}
.dot-sep { margin: 0 6px; }

/* ─────────────────────────  MAIN  ───────────────────────── */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 26px;
  padding-top: calc(16px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.day-nav { display: flex; align-items: center; gap: 6px; }
.nav-arrow {
  border: none;
  background: transparent;
  color: var(--ink-faint);
  font-size: 24px;
  line-height: 1;
  width: 30px; height: 30px;
  border-radius: 8px;
  cursor: pointer;
  transition: color .12s ease, background .12s ease;
}
.nav-arrow:hover { color: var(--accent); background: rgba(164,100,60,.08); }
.nav-arrow:disabled { opacity: .28; cursor: default; background: transparent; color: var(--ink-faint); }

.day-title { position: relative; display: flex; align-items: center; }
.day-title h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 20px;
  margin: 0;
  letter-spacing: .01em;
  cursor: pointer;
  white-space: nowrap;
}
#dayPicker {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  border: none;
  cursor: pointer;
}

.save-state {
  font-size: 11.5px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  transition: color .2s ease, opacity .2s ease;
  white-space: nowrap;
}
.save-state.saving { color: var(--accent); }
.save-state.error  { color: #c0553a; }

.sheet {
  flex: 1;
  overflow-y: auto;
  padding: 34px 26px 90px;
  scroll-behavior: smooth;
}

.section {
  max-width: 720px;
  margin: 0 auto 34px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 22px 10px;
  border-bottom: 1px solid var(--line);
}
.section-head h3 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 16.5px;
  margin: 0;
  color: var(--ink);
  letter-spacing: .01em;
}
.section[data-field="tell"]    .section-head { border-bottom-color: rgba(164,100,60,.28); }
.section[data-field="respond"] .section-head { border-bottom-color: rgba(116,134,102,.32); }
.section[data-field="help"]    .section-head { border-bottom-color: rgba(120,110,150,.30); }

.counter {
  font-size: 10.5px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-faint);
  white-space: nowrap;
}

.writing {
  display: block;
  width: 100%;
  min-height: 168px;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16.5px;
  font-weight: 300;
  line-height: 1.78;
  padding: 18px 22px 22px;
  overflow: hidden;
}
.writing::placeholder { color: var(--ink-faint); opacity: .75; font-style: italic; }

.sheet-foot {
  max-width: 720px;
  margin: 0 auto;
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-faint);
  letter-spacing: .04em;
}

.scrim { display: none; }
.only-mobile { display: none; }

/* ─────────────────────────  MOBILE  ───────────────────────── */

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 82vw;
    max-width: 320px;
    z-index: 40;
    transform: translateX(-102%);
    transition: transform .26s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.18);
  }
  .app.nav-open .sidebar { transform: translateX(0); }

  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(20,15,12,.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity .26s ease;
    z-index: 30;
  }
  .app.nav-open .scrim { opacity: 1; pointer-events: auto; }

  .only-mobile { display: inline-flex; align-items: center; justify-content: center; }
  #menuBtn { font-size: 15px; padding: 5px 11px; }

  .topbar { padding: 12px 14px; padding-top: calc(12px + env(safe-area-inset-top)); }
  .day-title h2 { font-size: 17px; }
  .save-state { font-size: 10px; }
  .sheet { padding: 20px 14px 70px; }
  .section { margin-bottom: 22px; }
  .section-head { padding: 14px 16px 9px; }
  .section-head h3 { font-size: 15px; }
  .writing { padding: 14px 16px 18px; font-size: 16px; min-height: 150px; }

  .keypad { grid-template-columns: repeat(3, 70px); gap: 16px; }
  .key { width: 70px; height: 70px; font-size: 24px; }
}
