:root {
  --bg: #faf8f4;
  --ink: #2b2a27;
  --ink-soft: #8a857c;
  --line: #e8e3da;
  --card: #ffffff;
  --accent: #2b2a27;
  --accent-ink: #ffffff;
  --winter: #9db4c8;
  --spring: #93b48a;
  --summer: #d9b266;
  --autumn: #c98a5e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(40, 36, 30, 0.06), 0 6px 18px rgba(40, 36, 30, 0.07);
  --shadow-lift: 0 4px 10px rgba(40, 36, 30, 0.14), 0 18px 40px rgba(40, 36, 30, 0.18);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

:root[data-theme="dark"] {
  --bg: #1a1916;
  --ink: #f0ece4;
  --ink-soft: #9a948a;
  --line: #322f29;
  --card: #232019;
  --accent: #efe9df;
  --accent-ink: #1a1916;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.35);
  --shadow-lift: 0 4px 10px rgba(0, 0, 0, 0.5), 0 18px 40px rgba(0, 0, 0, 0.55);
}

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Top bar ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 18px 12px;
  background: var(--bg);
}

/* ---------- Boot + Welcome ---------- */

.boot {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  background: var(--bg);
}

.boot .wordmark { font-size: 20px; opacity: 0.5; letter-spacing: 0.1em; }

.boot-retry {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.boot-retry p { margin: 0; color: var(--ink-soft); font-size: 14px; }

.welcome {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 22px calc(env(safe-area-inset-bottom, 0px) + 32px);
}

.welcome-inner { width: 100%; max-width: 440px; }

.welcome-mark {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.welcome h1 {
  margin: 14px 0 16px;
  font-size: clamp(30px, 7vw, 40px);
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.welcome-lede {
  margin: 0 0 30px;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink-soft);
}

.signin label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.signin-row { display: flex; gap: 8px; }

.signin-row input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-size: 16px;
  outline: none;
}

.signin-row input:focus { border-color: var(--ink-soft); }

.signin-row .done { padding: 12px 18px; white-space: nowrap; }

.signin-note { margin: 12px 2px 0; font-size: 13px; color: var(--ink-soft); line-height: 1.5; }

.signin.sent #emailRow,
.signin.sent label[for="emailInput"] { display: none; }
.signin.sent .signin-note { font-size: 15px; color: var(--ink); }

.code-entry { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
#codeInput { letter-spacing: 6px; font-weight: 600; }

.wordmark {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.06em;
}

.bar-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  font-size: 18px;
  line-height: 1;
}

.add-btn {
  height: 36px;
  padding: 0 14px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.menu-wrap { position: relative; }

.menu {
  position: absolute;
  right: 0;
  top: 42px;
  display: flex;
  flex-direction: column;
  min-width: 170px;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.menu button {
  border: none;
  background: none;
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 14px;
}

.menu button:hover { background: var(--bg); }

/* ---------- Board ---------- */

#board {
  max-width: 1080px;
  margin: 0 auto;
  padding: 10px 18px calc(env(safe-area-inset-bottom, 0px) + 60px);
}

.year-label {
  margin: 30px 0 6px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.year-label:first-child { margin-top: 16px; }

.season {
  margin: 14px 0 22px;
}

.season-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.season-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.season-dot.s0 { background: var(--winter); }
.season-dot.s1 { background: var(--spring); }
.season-dot.s2 { background: var(--summer); }
.season-dot.s3 { background: var(--autumn); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  min-height: 64px;
  padding: 4px;
  margin: -4px;
  border-radius: var(--radius);
  transition: background 0.15s;
}

.cards.drop-target { background: rgba(43, 42, 39, 0.05); }

.cards:empty::after {
  content: "";
  grid-column: 1 / -1;
  height: 56px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
}

/* ---------- Cards ---------- */

.card {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  overflow: hidden;
  background-size: cover;
  background-position: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
  cursor: pointer;
}

.card .card-title {
  position: absolute;
  inset: auto 0 0 0;
  padding: 26px 12px 10px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: break-word;
}

.card.has-photo .card-title {
  color: #fff;
  background: linear-gradient(to top, rgba(15, 14, 12, 0.62), rgba(15, 14, 12, 0));
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.card .card-date {
  position: absolute;
  top: 9px;
  left: 9px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
}

.card.dragging { opacity: 0.35; }

.drag-ghost {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  box-shadow: var(--shadow-lift);
  transform: scale(1.04) rotate(1.5deg);
  border-radius: var(--radius);
  overflow: hidden;
}

/* ---------- Add year / empty state ---------- */

.add-year {
  display: block;
  margin: 8px auto 0;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
}

.empty-hint {
  margin: 60px auto;
  max-width: 300px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.5;
}

/* ---------- Detail sheet ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(30, 28, 24, 0.4);
}

.sheet {
  width: 100%;
  max-width: 480px;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  padding: 16px 18px calc(env(safe-area-inset-bottom, 0px) + 18px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

@media (min-width: 640px) {
  .overlay { align-items: center; padding: 24px; }
  .sheet { border-radius: 20px; max-height: 86vh; }
}

.photo-zone {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  background-color: var(--card);
  border: 1.5px dashed var(--line);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.photo-zone.has-photo { border-style: solid; border-color: transparent; }

.photo-zone span {
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
}

.photo-zone.has-photo span { display: none; }

.title-input {
  border: none;
  background: none;
  font-size: 22px;
  font-weight: 700;
  padding: 4px 2px;
  outline: none;
}

.title-input::placeholder { color: var(--line); }

.when-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chip .season-dot { width: 7px; height: 7px; }

.chip.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

#yearSelect {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 13px;
  font-weight: 600;
}

.date-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
}

.date-row em { color: var(--ink-soft); font-style: normal; font-weight: 500; }

.date-row input {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}

#notesInput {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  padding: 10px 12px;
  resize: vertical;
  min-height: 90px;
  outline: none;
  line-height: 1.5;
}

.sheet-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

.sheet-actions .quiet {
  border: none;
  background: none;
  color: var(--ink-soft);
  font-size: 13px;
  padding: 8px 4px;
}

.sheet-actions .danger {
  border: none;
  background: none;
  color: #b3553f;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 4px;
  margin-left: auto;
}

.done {
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  padding: 10px 22px;
}

.sheet-title { margin: 0 0 4px; font-size: 20px; font-weight: 700; }

.setting-block { display: flex; flex-direction: column; gap: 10px; }

.setting-label {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.setting-value { margin: 0; font-size: 15px; }

.photo-zone.busy { opacity: 0.55; pointer-events: none; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow-lift);
}

@media (prefers-reduced-motion: no-preference) {
  .card { transition: box-shadow 0.15s; }
  .sheet { animation: sheet-in 0.22s ease-out; }
  @keyframes sheet-in {
    from { transform: translateY(24px); opacity: 0; }
    to { transform: none; opacity: 1; }
  }
}
