:root {
  --bg: #F5F5F0;
  --card: #FFFFFF;
  --card-2: #F3F1FB;
  --text: #1A1A2E;
  --text-2: #5B6272;
  --muted: #626876;
  --accent: #7C3AED;
  --accent-light: #C4B5FD;
  --accent-soft: #EDE9FE;
  --on-accent: #FFFFFF;
  --border: #E5E7EB;
  --danger: #B91C1C;
  --danger-soft: #FEE2E2;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  --m5: #34D399;
  --m4: #60A5FA;
  --m3: #FBBF24;
  --m2: #F97316;
  --m1: #EF4444;
  --radius: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
}

:root:not([data-theme="light"]) {
  @media (prefers-color-scheme: dark) {
    --bg: #141420;
    --card: #1E1E30;
    --card-2: #262640;
    --text: #EEEEF5;
    --text-2: #B8B8CC;
    --muted: #A0A0BA;
    --accent: #B49BFF;
    --accent-light: #8B5CF6;
    --accent-soft: #3B2580;
    --on-accent: #1A1033;
    --border: #2E2E48;
    --danger: #FCA5A5;
    --danger-soft: #602020;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  --bg: #141420;
  --card: #1E1E30;
  --card-2: #262640;
  --text: #EEEEF5;
  --text-2: #B8B8CC;
  --muted: #A0A0BA;
  --accent: #B49BFF;
  --accent-light: #8B5CF6;
  --accent-soft: #3B2580;
  --on-accent: #1A1033;
  --border: #2E2E48;
  --danger: #FCA5A5;
  --danger-soft: #602020;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
@media (min-width: 760px) { body { padding-bottom: 40px; } }

a { color: var(--accent); }
.link { color: var(--accent); text-decoration: none; font-weight: 700; font-size: 13.5px; }
.link:hover { text-decoration: underline; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 16px; top: -60px; z-index: 100; padding: 10px 14px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-weight: 700; text-decoration: none; }
.skip:focus { top: 16px; }

/* ---------- header + tabs ---------- */
.top { max-width: 960px; margin: 0 auto; padding: 18px 16px 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-size: 11.5px; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); text-decoration: none; }
.brand:hover { color: var(--text-2); }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 15px; letter-spacing: 0; color: #fff; background: linear-gradient(150deg, #241B63, #100A32); box-shadow: 1.5px 0 0 rgba(255, 23, 68, 0.75), -1.5px 0 0 rgba(0, 229, 255, 0.75); }

.tabs { display: flex; gap: 4px; }
.tabs a { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; font-size: 13.5px; font-weight: 700; color: var(--text-2); text-decoration: none; }
.tabs a:hover { background: var(--card); }
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.tab-icon { font-size: 14px; }
@media (max-width: 759px) {
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; margin: 0; padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: var(--card); border-top: 1px solid var(--border); box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.06);
    justify-content: space-around;
  }
  .tabs a { flex-direction: column; gap: 2px; padding: 6px 10px; font-size: 11px; border-radius: 14px; }
  .tab-icon { font-size: 20px; }
}

/* ---------- layout ---------- */
.main { max-width: 960px; margin: 0 auto; padding: 18px 16px 24px; }
.view { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; animation: rise 0.35s ease both; }
.view[hidden] { display: none; }
.h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.date { margin: 2px 0 0; color: var(--text-2); font-size: 14px; }
.greeting { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px 16px; }
.streak { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; font-weight: 800; background: var(--card); box-shadow: var(--shadow); border: 1px solid var(--border); }
.streak b { font-size: 16px; }
.streak.hot { background: linear-gradient(135deg, #FDE68A, #F97316); color: #3b1d05; border-color: transparent; }

.card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.card-title { margin: 0 0 12px; font-size: 12px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.hint { margin: 0 0 10px; color: var(--text-2); font-size: 13px; }
.hint:last-child { margin-bottom: 0; }

/* ---------- inputs ---------- */
.input, .textarea, .datetime {
  width: 100%; font: inherit; color: var(--text); background: var(--card-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px; outline: none; min-height: 46px;
}
.input:focus, .textarea:focus, .datetime:focus { border-color: var(--accent-light); box-shadow: 0 0 0 4px var(--accent-soft); }
.textarea { resize: vertical; min-height: 84px; line-height: 1.5; }
.datetime { width: auto; max-width: 100%; min-width: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 44px; padding: 0 18px; border-radius: 999px;
  border: 1px solid transparent; cursor: pointer; font: inherit; font-size: 14px; font-weight: 700; color: var(--on-accent); background: var(--accent);
  transition: transform 0.12s, filter 0.12s;
}
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn:active { transform: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; filter: none; }
.btn.ghost { background: var(--card-2); color: var(--text); border-color: var(--border); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn:focus-visible, .icon-btn:focus-visible, .level:focus-visible, .chip:focus-visible, .range button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.wide { width: 100%; height: 50px; font-size: 15px; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: var(--card-2); color: var(--text-2); cursor: pointer; font: inherit; font-weight: 700; }
.icon-btn:hover { color: var(--text); }
.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form .input { flex: 1; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }

/* ---------- mood form ---------- */
.levels { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.level {
  display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; padding: 12px 4px; border-radius: var(--radius-md); cursor: pointer;
  border: 2px solid transparent; background: var(--card-2); font: inherit; font-size: 11.5px; font-weight: 700; color: var(--text-2);
  transition: transform 0.12s, background 0.15s, border-color 0.15s;
}
.level .e { font-size: 30px; line-height: 1; }
@media (max-width: 360px) {
  .levels { gap: 5px; }
  .level { padding: 10px 2px; font-size: 10.5px; }
  .level .e { font-size: 24px; }
  .form-foot .btn { min-width: 100%; }
  .card { padding: 16px 14px; }
}
.level:hover { transform: translateY(-2px); }
.level.on { border-color: var(--lvl); background: color-mix(in srgb, var(--lvl) 18%, var(--card)); color: var(--text); }
@supports not (color: color-mix(in srgb, red 10%, blue)) { .level.on { background: var(--accent-soft); } }
.moods { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600;
  background: var(--card-2); color: var(--text-2); border: 1px solid var(--border); transition: background 0.15s, color 0.15s;
}
.chip:hover { color: var(--text); }
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-light); }
.chip.mood.on { background: color-mix(in srgb, var(--c) 20%, var(--card)); color: var(--text); border-color: var(--c); }
@supports not (color: color-mix(in srgb, red 10%, blue)) { .chip.mood.on { background: var(--accent-soft); } }
.chip .x { margin-left: 2px; opacity: 0.6; }
.chip .x:hover { opacity: 1; }
.form-row { margin-top: 14px; }
.form-row .label { display: block; margin-bottom: 8px; font-size: 12.5px; font-weight: 700; color: var(--text-2); }
.form-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.form-foot .btn { flex: 1; min-width: 160px; }
.counter { font-size: 12px; color: var(--muted); }
.prompt { margin: 0 0 12px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent); font-size: 13.5px; font-weight: 600; }

/* ---------- entries ---------- */
.entry-list { display: grid; gap: 10px; }
.entry {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: start; padding: 12px; border-radius: var(--radius-md);
  background: var(--card-2); border: 1px solid var(--border); border-left: 4px solid var(--c, var(--border));
}
.entry .e { font-size: 30px; line-height: 44px; text-align: center; }
.entry .l { font-weight: 800; }
.entry .t { font-size: 12.5px; color: var(--muted); margin-left: 8px; font-weight: 500; }
.entry .n { margin: 4px 0 0; color: var(--text-2); font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.entry .tags { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.entry .tag { font-size: 11.5px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 3px 8px; border-radius: 999px; }
.entry .ops { display: flex; gap: 6px; }
.empty { padding: 22px 12px; text-align: center; color: var(--muted); font-size: 14px; }
.empty b { display: block; color: var(--text-2); font-size: 15px; margin-bottom: 4px; }
.journal { display: grid; gap: 18px; }
.day-group h3 { margin: 0 0 8px; font-size: 13px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; }
.day-group h3 span { font-weight: 600; letter-spacing: 0; text-transform: none; }
.toolbar { display: grid; gap: 10px; }

.week-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.week-day { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 2px; border-radius: var(--radius-sm); background: var(--card-2); font-size: 11px; font-weight: 700; color: var(--muted); }
.week-day .e { font-size: 22px; line-height: 1; }
.week-day.today { outline: 2px solid var(--accent-light); color: var(--accent); }
.week-day.empty-day .e { opacity: 0.35; }

/* ---------- insights ---------- */
.range { display: inline-flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--card); border: 1px solid var(--border); }
.range button { height: 34px; padding: 0 14px; border: 0; border-radius: 999px; background: transparent; color: var(--text-2); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.range button.on { background: var(--accent-soft); color: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.tile { padding: 14px; border-radius: var(--radius-md); background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow); }
.tile .k { font-size: 11.5px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.tile .v { margin-top: 4px; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-width: 0; overflow-wrap: anywhere; }
.tile .v small { font-size: 13px; font-weight: 600; color: var(--text-2); }
.tile.t5 { background: color-mix(in srgb, var(--m5) 16%, var(--card)); }
.tile.t4 { background: color-mix(in srgb, var(--m4) 16%, var(--card)); }
.tile.t3 { background: color-mix(in srgb, var(--m3) 16%, var(--card)); }
.tile.t2 { background: color-mix(in srgb, var(--m2) 16%, var(--card)); }
.tile.t1 { background: color-mix(in srgb, var(--m1) 16%, var(--card)); }

.trend { width: 100%; height: auto; display: block; overflow: visible; }
.trend .grid { stroke: var(--border); stroke-width: 1; }
.trend .area { fill: var(--accent); opacity: 0.12; }
.trend .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.trend .dot { stroke: var(--card); stroke-width: 1.5; }
.trend .axis { font-size: 10px; fill: var(--muted); font-family: inherit; }
.trend .ylab { font-size: 12px; }

.heat { display: grid; grid-template-columns: 28px 1fr; gap: 6px; }
.heat .days { display: grid; grid-template-rows: repeat(7, 1fr); font-size: 10px; color: var(--muted); font-weight: 700; padding-top: 16px; }
.heat .days span { line-height: 1; display: flex; align-items: center; }
.heat .grid { overflow-x: auto; }
.heat .months { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; font-size: 10px; color: var(--muted); font-weight: 700; height: 14px; margin-bottom: 2px; }
.heat .cells { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; min-width: 360px; }
.heat .cell { aspect-ratio: 1; border-radius: 3px; background: var(--card-2); border: 1px solid var(--border); }
.heat .cell.future { opacity: 0.35; border-style: dashed; }
.heat .cell.today { outline: 2px solid var(--accent); outline-offset: 1px; }
.heat .cell.has { border-color: transparent; }
.heat-legend { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 11px; color: var(--muted); }
.heat-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(72px, 30%) 1fr 36px; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .k { font-weight: 700; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .track { height: 10px; border-radius: 999px; background: var(--card-2); overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 999px; transition: width 0.35s ease; }
.bar-row .v { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar-row .v small { font-weight: 500; color: var(--muted); }

.pattern-list { display: grid; gap: 10px; }
.pattern { display: grid; grid-template-columns: 40px 1fr; gap: 12px; padding: 12px; border-radius: var(--radius-md); background: var(--card-2); border: 1px solid var(--border); }
.pattern .i { font-size: 26px; line-height: 40px; text-align: center; }
.pattern .t { font-weight: 800; }
.pattern .b { margin: 2px 0 0; color: var(--text-2); font-size: 13.5px; }
.pattern.positive { border-left: 4px solid var(--m5); }
.pattern.warning { border-left: 4px solid var(--m2); }
.pattern.neutral { border-left: 4px solid var(--m4); }

/* ---------- dialog, toast, confetti ---------- */
.dialog { width: min(560px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; background: var(--card); color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3); }
.dialog::backdrop { background: rgba(10, 8, 30, 0.55); backdrop-filter: blur(3px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.dialog-head .card-title { margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); z-index: 60;
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 999px; background: var(--text); color: var(--bg); font-weight: 700; font-size: 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; max-width: calc(100vw - 32px);
}
@media (min-width: 760px) { .toast { bottom: 24px; } }
.toast.show { opacity: 1; transform: translateX(-50%); pointer-events: auto; }
.toast button { border: 0; background: var(--accent); color: var(--on-accent); font: inherit; font-weight: 800; padding: 6px 12px; border-radius: 999px; cursor: pointer; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.confetti i { position: absolute; top: 40%; left: 50%; width: 10px; height: 14px; border-radius: 2px; opacity: 0; animation: pop 1s ease-out forwards; }
@keyframes pop {
  0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(540deg); }
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .view, .confetti i { animation: none; }
  .btn, .level, .bar-row .fill, .toast { transition: none; }
}
