/* ---------- theme tokens ---------- */
:root {
  --radius: 18px;
  --radius-sm: 12px;
  --accent-1: #ff5f6d;
  --accent-2: #ff9a5a;
  --accent-grad: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  --berry: #ff5f6d;
  --leaf: #4cc38a;
  --leaf-dark: #2fa06b;
  --seed: #ffe3c2;
  --face: #4a1d2b;
  --blush: rgba(255, 255, 255, 0.35);
  --tear: #6cb8ff;
}

:root[data-theme="light"] {
  --bg: #f5f6fb;
  --bg-glow: radial-gradient(1000px 500px at 50% -10%, #ffe9e4, transparent);
  --card: #ffffff;
  --card-border: rgba(20, 24, 40, 0.06);
  --text: #1d2333;
  --muted: #69708a;
  --cell-future: #eef0f7;
  --cell-missed: #f3d9dd;
  --cell-missed-text: #c05264;
  --shadow: 0 10px 30px rgba(30, 34, 60, 0.08);
}

:root[data-theme="dark"] {
  --bg: #0f1218;
  --bg-glow: radial-gradient(1000px 500px at 50% -10%, rgba(255, 95, 109, 0.12), transparent);
  --card: #181d27;
  --card-border: rgba(255, 255, 255, 0.06);
  --text: #eceef6;
  --muted: #9aa1b7;
  --cell-future: #222836;
  --cell-missed: #3a2229;
  --cell-missed-text: #e0798a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* ---------- base ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html { color-scheme: light dark; }

body {
  font-family: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  background-image: var(--bg-glow);
  background-repeat: no-repeat;
  color: var(--text);
  min-height: 100vh;
  transition: background-color 0.3s, color 0.3s;
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 20px 20px 60px;
}

h1 { font-size: 1.5rem; font-weight: 700; }
.subtitle { color: var(--muted); margin-top: 6px; }

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 2px 18px;
}

.logo { display: flex; align-items: center; gap: 10px; font-size: 1.15rem; font-weight: 800; letter-spacing: -0.01em; }
.logo-mark { font-size: 1.5rem; }
.logo-text em {
  font-style: normal;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.icon-btn {
  border: 1px solid var(--card-border);
  background: var(--card);
  border-radius: 50%;
  width: 42px;
  height: 42px;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.icon-btn:hover { transform: scale(1.08); }

:root[data-theme="light"] .theme-icon-light { display: none; }
:root[data-theme="dark"] .theme-icon-dark { display: none; }

/* ---------- hero: mascot + speech ---------- */
.hero {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.mascot-wrap { flex: 0 0 130px; width: 130px; }
.mascot-svg { width: 100%; height: auto; display: block; }

.mascot-wrap .body,
.mascot-wrap .leaves { transition: transform 0.4s; }

/* gentle idle bob */
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-6px) rotate(-2deg); }
}
.mascot-svg { animation: bob 3.5s ease-in-out infinite; transform-origin: 50% 80%; }

@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-6deg) scale(1.05); }
  75% { transform: rotate(6deg) scale(1.05); }
}
.mascot-wrap.celebrate .mascot-svg { animation: wiggle 0.5s ease-in-out 3; }

/* face parts: hidden by default, shown per mood */
.mouth, .brow, .tears, .eyes-closed, .blush { display: none; }

[data-mood="happy"]   .mouth-happy   { display: block; }
[data-mood="happy"]   .blush         { display: block; }
[data-mood="happy"]   .eyes-open     { display: block; }

[data-mood="excited"] .mouth-excited { display: block; }
[data-mood="excited"] .blush         { display: block; }
[data-mood="excited"] .eyes-open     { display: none; }
[data-mood="excited"] .eyes-closed   { display: block; }

[data-mood="neutral"] .mouth-neutral { display: block; }

[data-mood="worried"] .mouth-worried { display: block; }
[data-mood="worried"] .brow          { display: block; }

[data-mood="sad"]     .mouth-sad     { display: block; }
[data-mood="sad"]     .brow          { display: block; }

[data-mood="devastated"] .mouth-sad  { display: block; }
[data-mood="devastated"] .brow       { display: block; }
[data-mood="devastated"] .tears      { display: block; }

[data-mood="sad"] .mascot-svg,
[data-mood="devastated"] .mascot-svg { animation: none; transform: rotate(-4deg); }

@keyframes drip {
  0% { opacity: 0; transform: translateY(0); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translateY(14px); }
}
.tear { animation: drip 1.6s ease-in infinite; }
.tear-right { animation-delay: 0.8s; }

/* speech bubble */
.speech {
  position: relative;
  flex: 1;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  min-height: 62px;
  display: flex;
  align-items: center;
}
.speech::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 50%;
  width: 16px;
  height: 16px;
  background: var(--card);
  border-left: 1px solid var(--card-border);
  border-bottom: 1px solid var(--card-border);
  transform: translateY(-50%) rotate(45deg);
}
.speech p { font-size: 1rem; line-height: 1.45; }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.speech p.animate { animation: pop-in 0.35s ease-out; }

/* ---------- setup ---------- */
#setup-view { padding: 28px; text-align: center; }

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 26px 0 16px;
}

.stepper-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--bg);
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  transition: transform 0.12s, background 0.2s;
}
.stepper-btn:hover { transform: scale(1.1); }

#days-input {
  width: 130px;
  text-align: center;
  font-size: 2.6rem;
  font-weight: 800;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  outline: none;
  -moz-appearance: textfield;
  appearance: textfield;
}
#days-input::-webkit-inner-spin-button { display: none; }

.presets { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-bottom: 26px; }

.chip {
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  background: var(--bg);
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.chip:hover { color: var(--text); transform: translateY(-2px); }
.chip-featured { border-color: var(--accent-1); color: var(--accent-1); }

/* ---------- buttons ---------- */
.btn-primary {
  display: inline-block;
  border: none;
  background: var(--accent-grad);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: inherit;
  padding: 14px 28px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(255, 95, 109, 0.35);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(255, 95, 109, 0.45); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.55; cursor: default; transform: none; box-shadow: none; }

.btn-check { width: 100%; padding: 18px; font-size: 1.15rem; margin-bottom: 16px; }

.btn-ghost {
  background: none;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.btn-ghost:hover { color: var(--accent-1); }

/* ---------- stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.stat-icon { font-size: 1.3rem; }
.stat-value { font-size: 1.5rem; font-weight: 800; }
.stat-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* ---------- progress ---------- */
.progress-wrap { padding: 16px 18px; margin-bottom: 16px; }
.progress-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 10px;
}
.progress-bar {
  height: 12px;
  border-radius: 999px;
  background: var(--cell-future);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent-grad);
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- day grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 8px;
  padding: 18px;
  margin-bottom: 20px;
}

.cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--cell-future);
  color: var(--muted);
  user-select: none;
  position: relative;
  transition: transform 0.12s;
}

.cell.checked {
  background: var(--accent-grad);
  color: #fff;
}
.cell.checked::after { content: "✓"; position: absolute; font-size: 0.6rem; bottom: 3px; right: 5px; opacity: 0.8; }

.cell.missed {
  background: var(--cell-missed);
  color: var(--cell-missed-text);
}
.cell.missed::after { content: "✕"; position: absolute; font-size: 0.6rem; bottom: 3px; right: 5px; opacity: 0.8; }

.cell.rescue { cursor: pointer; outline: 2px dashed var(--cell-missed-text); outline-offset: -2px; }
.cell.rescue:hover { transform: scale(1.08); }

.cell.today {
  outline: 2px solid var(--accent-1);
  outline-offset: 2px;
  color: var(--text);
  cursor: pointer;
  animation: pulse 2s ease-in-out infinite;
}
.cell.today:hover { transform: scale(1.08); }
.cell.today.checked { color: #fff; animation: none; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 95, 109, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(255, 95, 109, 0); }
}

.cell.future { opacity: 0.55; }

/* ---------- sync ---------- */
.sync { padding: 16px 18px; margin-bottom: 20px; }

.sync-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.sync-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#sync-code {
  flex: 1;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-1);
  background: var(--cell-future);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  text-align: center;
  min-width: 160px;
  user-select: all;
}

.sync-hint {
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
}

.btn-secondary {
  border: 1px solid var(--card-border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 9px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}
.btn-secondary:hover { transform: translateY(-1px); border-color: var(--accent-1); }

/* ---------- link box (setup) ---------- */
.linkbox {
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--card-border);
}

.linkbox p { font-size: 0.88rem; color: var(--muted); margin-bottom: 10px; }

.linkbox-row {
  display: flex;
  justify-content: center;
  gap: 8px;
}

#link-input {
  flex: 0 1 240px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  background: var(--bg);
  color: var(--text);
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}
#link-input:focus { border-color: var(--accent-1); }

/* ---------- misc views ---------- */
.danger-zone { text-align: center; }

#end-view { padding: 40px 28px; text-align: center; }
.end-emoji { font-size: 4rem; margin-bottom: 10px; }
.end-stats {
  display: flex;
  justify-content: center;
  gap: 26px;
  margin: 24px 0 28px;
  color: var(--muted);
  font-size: 0.95rem;
}
.end-stats strong { color: var(--text); font-size: 1.3rem; display: block; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal { max-width: 400px; padding: 28px; text-align: center; }
.modal h2 { margin-bottom: 10px; }
.modal p { color: var(--muted); margin-bottom: 22px; }
.modal-actions { display: flex; flex-direction: column; gap: 12px; align-items: center; }

/* ---------- confetti ---------- */
#confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 40;
}
.confetti {
  position: absolute;
  top: -12px;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(720deg); }
}

/* ---------- responsive ---------- */
@media (max-width: 480px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .hero { flex-direction: column; text-align: center; }
  .mascot-wrap { flex-basis: auto; }
  .speech::before {
    left: 50%;
    top: -8px;
    transform: translateX(-50%) rotate(135deg);
  }
}
