:root {
  --bg: #FAF7F0;
  --bg-elev: #FFFFFF;
  --bg-soft: #F2EEE3;
  --ink: #1F1F1F;
  --ink-2: #4A4A4A;
  --ink-3: #8A8579;
  --line: #E4DECE;
  --line-2: #EFEADB;
  --accent: #D97757;
  --accent-soft: #F4DDD0;
  --accent-ink: #8C3E20;
  --danger: #B33A2B;
  --done: #6B8E5A;
  --shadow: 0 1px 0 rgba(0,0,0,.02), 0 6px 24px -12px rgba(60,40,10,.12);
  --radius: 14px;
  --serif: "Iowan Old Style", "Charter", "Georgia", ui-serif, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1A1814;
    --bg-elev: #232019;
    --bg-soft: #2A261D;
    --ink: #EFEADB;
    --ink-2: #C8C0AC;
    --ink-3: #8A8579;
    --line: #3A352A;
    --line-2: #2F2B22;
    --accent: #E8916D;
    --accent-soft: #4A2C20;
    --accent-ink: #F4DDD0;
    --shadow: 0 1px 0 rgba(0,0,0,.2), 0 8px 28px -10px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
}

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px 200px;
  min-height: 100dvh;
}

button { font: inherit; background: none; border: none; color: inherit; cursor: pointer; padding: 0; }
textarea, input { font: inherit; color: inherit; }

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 4px 12px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(to bottom, var(--bg) 78%, transparent);
  backdrop-filter: blur(6px);
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--ink);
}
.logo svg { color: var(--accent); flex: 0 0 auto; }
.nav { display: flex; gap: 2px; }
.nav-btn {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 14px;
  color: var(--ink-2);
  transition: background .15s, color .15s;
}
.nav-btn:hover { color: var(--ink); background: var(--bg-soft); }
.nav-btn.active { color: var(--accent-ink); background: var(--accent-soft); }

/* Page titles */
.page-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 32px;
  letter-spacing: -.02em;
  margin: 18px 0 22px;
  display: flex;
  align-items: baseline;
  gap: 14px;
}
.date-chip {
  font-family: var(--sans);
  font-weight: 400;
  font-size: 14px;
  color: var(--ink-3);
}

/* Sections */
.section { margin-bottom: 32px; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-head h2 {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.text-btn {
  font-size: 13px;
  color: var(--accent-ink);
}
.text-btn:hover { text-decoration: underline; }

/* Items list */
.items-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  transition: background .12s;
  position: relative;
}
.item:hover { background: var(--bg-soft); }
.item .check {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--line);
  border-radius: 6px;
  margin-top: 2px;
  background: var(--bg-elev);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .12s, background .12s;
}
.item .check:hover { border-color: var(--accent); }
.item.done .check {
  background: var(--done);
  border-color: var(--done);
}
.item.done .check::after {
  content: "✓";
  color: white;
  font-size: 12px;
  font-weight: 700;
}
.item.done .body { color: var(--ink-3); text-decoration: line-through; }
.item .kind-icon {
  flex: 0 0 22px;
  font-size: 16px;
  margin-top: 1px;
  color: var(--ink-3);
}
.item .body { flex: 1; min-width: 0; word-wrap: break-word; }
.item .body .title { font-weight: 500; color: var(--ink); line-height: 1.4; }
.item .body .sub { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.item .body a { color: var(--accent-ink); text-decoration: none; }
.item .body a:hover { text-decoration: underline; }
.item .due-chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  margin-left: 6px;
}
.item .due-chip.overdue { background: #F8D9D3; color: var(--danger); }
@media (prefers-color-scheme: dark) {
  .item .due-chip.overdue { background: #4A2520; color: #F4B0A4; }
}
.item .delete-btn {
  opacity: 0;
  align-self: center;
  color: var(--ink-3);
  padding: 4px 8px;
  font-size: 13px;
  transition: opacity .12s, color .12s;
}
.item:hover .delete-btn { opacity: 1; }
.item .delete-btn:hover { color: var(--danger); }

/* Empty hint */
.empty-hint {
  color: var(--ink-3);
  font-size: 14px;
  padding: 14px 12px;
  font-style: italic;
}
.empty-hint.hidden { display: none; }

/* Session grid */
.session-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.session-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, border-color .12s;
  text-align: left;
  font-family: inherit;
  color: inherit;
}
.session-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}
.session-card .sc-name {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 6px;
  color: var(--ink);
}
.session-card .sc-meta {
  font-size: 12px;
  color: var(--ink-3);
  display: flex;
  gap: 10px;
  align-items: center;
}
.session-card .sc-meta .badge {
  background: var(--accent-soft);
  color: var(--accent-ink);
  padding: 1px 8px;
  border-radius: 999px;
  font-weight: 500;
}

/* Session detail */
.session-detail .back-btn {
  font-size: 14px;
  color: var(--ink-3);
  margin: 4px 0 8px;
}
.session-detail .back-btn:hover { color: var(--ink); }
.session-head { margin-bottom: 22px; }
.session-name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 32px;
  letter-spacing: -.02em;
  margin: 0;
  outline: none;
  border-radius: 6px;
  padding: 2px 4px;
  margin-left: -4px;
}
.session-name:focus { background: var(--bg-soft); }
.session-meta {
  margin-top: 6px;
  font-size: 13px;
  color: var(--ink-3);
  display: flex;
  gap: 14px;
  align-items: center;
}
.resume-btn {
  margin-top: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: white;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 500;
  font-size: 14px;
  transition: filter .12s;
}
.resume-btn:hover { filter: brightness(1.05); }
.resume-btn:disabled { opacity: .6; cursor: progress; }
.resume-summary {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  padding: 14px 16px;
  border-radius: 8px;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  margin-bottom: 22px;
  white-space: pre-wrap;
}
.session-items { gap: 4px; }

/* Archive */
.archive-list { list-style: none; padding: 0; margin: 0; }
.archive-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--line-2);
}
.archive-row .arc-name { font-family: var(--serif); font-size: 17px; font-weight: 500; }
.archive-row .arc-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.archive-row button { font-size: 13px; color: var(--accent-ink); }

/* Response toast */
.response {
  position: fixed;
  left: 0; right: 0;
  bottom: 96px;
  display: flex;
  justify-content: center;
  padding: 0 12px;
  z-index: 20;
  pointer-events: none;
}
.response-inner {
  pointer-events: auto;
  background: var(--ink);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 540px;
  box-shadow: 0 8px 24px -8px rgba(0,0,0,.3);
  animation: slideUp .25s ease;
}
@media (prefers-color-scheme: dark) {
  .response-inner { background: var(--bg-elev); color: var(--ink); border: 1px solid var(--line); }
}
.response-close {
  color: inherit;
  opacity: .7;
  font-size: 22px;
  line-height: 1;
  padding: 0 0 0 6px;
}
.response.hidden { display: none; }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Composer (sticky bottom) */
.composer {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  padding: 12px 12px max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  display: flex;
  justify-content: center;
  z-index: 30;
}
.composer-context {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-soft);
  color: var(--accent-ink);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .03em;
  max-width: 90%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.composer-context.hidden { display: none; }
.composer-row {
  width: 100%;
  max-width: 760px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 22px;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 6px 6px 6px 14px;
  box-shadow: var(--shadow);
  transition: border-color .15s;
}
.composer-row:focus-within { border-color: var(--accent); }
#composerInput {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  padding: 10px 0;
  max-height: 200px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
}
#composerInput::placeholder { color: var(--ink-3); }
#composerSubmit {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter .12s, transform .12s;
}
#composerSubmit:hover { filter: brightness(1.05); }
#composerSubmit:disabled { opacity: .5; cursor: progress; }
#composerSubmit svg { transform: translate(-1px, 1px); }

/* Loading */
.spinning {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-bottom-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 520px) {
  .page-title { font-size: 26px; }
  .session-name { font-size: 26px; }
  .nav-btn { padding: 6px 10px; font-size: 13px; }
  .logo span { display: none; }
}
