/* Dreamary — 莫蘭迪夜空 */
:root {
  --r: 22px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", sans-serif;
}
/* 配色取自 App 圖示：夜空藍、月牙金、薰衣草紫睡衣、暖橘貓 */
:root[data-theme="midnight"] {   /* 霧藍灰夜空 + 沙金、灰丁香 */
  color-scheme: dark;
  --bg1: #1d2230; --bg2: #2c3348;
  --card: rgba(58, 67, 92, .58); --card-solid: #364058; --field: rgba(255,255,255,.055);
  --text: #e6e3e6; --muted: #9ea2b3; --line: rgba(255,255,255,.085);
  --accent: #c9b184; --accent-2: #a89dbb; --on-accent: #26232b;
  --glow: rgba(201,177,132,.12); --stars: .3;
}
:root[data-theme="lavender"] {   /* 灰紫暮色 + 灰丁香、乾燥玫瑰 */
  color-scheme: dark;
  --bg1: #29252f; --bg2: #3d3549;
  --card: rgba(84, 74, 102, .52); --card-solid: #483f58; --field: rgba(255,255,255,.06);
  --text: #e9e4e9; --muted: #aba2b6; --line: rgba(255,255,255,.085);
  --accent: #b5a8c8; --accent-2: #cfa7af; --on-accent: #2b2531;
  --glow: rgba(207,167,175,.11); --stars: .26;
}
:root[data-theme="dawn"] {
  color-scheme: light;
  --bg1: #fbf3e4; --bg2: #ebe4f5;
  --card: rgba(255,255,255,.78); --card-solid: #ffffff; --field: rgba(110,90,170,.08);
  --text: #302b58; --muted: #7b7599; --line: rgba(120,90,40,.15);
  --accent: #b5791a; --accent-2: #8e78c8; --on-accent: #ffffff;
  --glow: rgba(240,184,64,.28); --stars: 0;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg1); }
body {
  margin: 0; font-family: var(--font); color: var(--text);
  background:
    radial-gradient(520px 420px at 88% -4%, var(--glow), transparent 70%) fixed,
    linear-gradient(180deg, var(--bg1), var(--bg2)) fixed;
  min-height: 100dvh; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: var(--stars);
  background:
    radial-gradient(1.2px 1.2px at 12% 14%, #ffe9b8, transparent),
    radial-gradient(1px 1px at 82% 9%, #ffe9b8, transparent),
    radial-gradient(1.4px 1.4px at 66% 28%, #ffe9b8, transparent),
    radial-gradient(1px 1px at 30% 42%, #ffe9b8, transparent),
    radial-gradient(1.2px 1.2px at 91% 52%, #ffe9b8, transparent),
    radial-gradient(1px 1px at 8% 68%, #ffe9b8, transparent),
    radial-gradient(1.3px 1.3px at 55% 80%, #ffe9b8, transparent),
    radial-gradient(1px 1px at 75% 92%, #ffe9b8, transparent),
    radial-gradient(1px 1px at 40% 6%, #ffe9b8, transparent);
}
body.noscroll { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
input, textarea { font: inherit; color: var(--text); }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: .02em; }
h1 { font-size: 24px; }
h3 { font-size: 16px; }

#app { position: relative; max-width: 480px; margin: 0 auto; min-height: 100dvh; }
#view { padding: calc(20px + env(safe-area-inset-top)) 16px calc(120px + env(safe-area-inset-bottom)); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 30px rgba(0,0,0,.12);
}
.card + .card, .card + .section-title, .section-title + .card { margin-top: 14px; }
.section-title { margin: 22px 4px 10px; font-size: 14px; color: var(--muted); letter-spacing: .08em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); font-size: 13px; }

/* ── 導覽列 ── */
#nav {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(480px, 100%); z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--card-solid); border-top: 1px solid var(--line);
  border-radius: 26px 26px 0 0; box-shadow: 0 -10px 30px rgba(0,0,0,.18);
}
.nav-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; color: var(--muted); font-size: 11px; }
.nav-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-btn.on { color: var(--accent); }
.nav-add {
  justify-self: center; width: 54px; height: 54px; margin-top: -26px; border-radius: 50%;
  display: grid; place-items: center; color: var(--on-accent);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 22px rgba(0,0,0,.28), 0 0 0 5px var(--card-solid);
}
.nav-add svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }

/* ── 月曆 ── */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head h1 { font-size: 22px; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--field); color: var(--text); font-size: 18px; }
.cal-actions { display: flex; gap: 8px; align-items: center; }
.pill-btn { padding: 8px 14px; border-radius: 999px; background: var(--field); font-size: 13px; color: var(--text); }
.cal-count { color: var(--muted); font-size: 13px; margin: 0 4px 10px; }
.dow, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dow span { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.day {
  aspect-ratio: 1 / 1.12; border-radius: 16px; border: 1px solid transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 15px;
}
.day.empty { visibility: hidden; }
.day .dots { display: flex; gap: 3px; height: 7px; align-items: center; }
.day .dots i { width: 6px; height: 6px; border-radius: 50%; display: block; }
.day .dots i.none { background: transparent; border: 1.5px solid var(--muted); width: 6px; height: 6px; }
.day.today .num { color: var(--accent-2); font-weight: 700; }
.day.sel { background: color-mix(in srgb, var(--accent) 20%, transparent); border-color: var(--accent); }

.day-head { display: flex; align-items: center; justify-content: space-between; margin: 20px 4px 10px; }
.day-head h3 { font-size: 17px; }
.btn {
  padding: 10px 16px; border-radius: 999px; font-size: 14px; background: var(--field); color: var(--text);
  border: 1px solid var(--line);
}
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent); border: 0; font-weight: 600; }
.btn.danger { color: #e48c8c; }
.btn.block { display: block; width: 100%; text-align: center; }
.btn:disabled { opacity: .5; }

.empty-note { text-align: center; color: var(--muted); padding: 28px 12px; font-size: 14px; }
.empty-note .big { font-size: 34px; display: block; margin-bottom: 6px; }
.dc { display: block; width: 66px; height: 87px; margin: 0 auto 10px; overflow: visible; }
.dc .ring, .dc .web, .dc .strand { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.dc .ring { stroke: var(--accent); stroke-width: 2.6; }
.dc .web { stroke: var(--accent-2); stroke-width: 1; opacity: .85; }
.dc .strand { stroke: var(--accent); stroke-width: 1.2; }
.dc .bead { fill: var(--accent); }
.dc .feather { fill: color-mix(in srgb, var(--accent-2) 45%, transparent); stroke: var(--accent-2); stroke-width: 1; stroke-linejoin: round; }

/* ── 夢境卡片 ── */
.dcard { font-weight: 400; position: relative; display: block; width: 100%; text-align: left; overflow: hidden; margin-top: 12px; padding: 16px 16px 14px; }
.dcard::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; background: var(--g, var(--accent)); opacity: .85; }
.dcard-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.dcard h3 { font-size: 16px; }
.dcard .ems { white-space: nowrap; font-size: 18px; letter-spacing: 2px; }
.dcard .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.dcard p { margin: 8px 0 0; color: var(--text); opacity: .86; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.mini-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.mini { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--field); color: var(--muted); }
.mini.type { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.stars { color: var(--accent); letter-spacing: 1px; font-size: 12px; }

/* ── 標籤 chips ── */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 13px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--field); font-size: 14px; color: var(--text);
  transition: background .15s, border-color .15s;
}
.chip.sel { background: color-mix(in srgb, var(--c, var(--accent)) 30%, transparent); border-color: var(--c, var(--accent)); }
.chip .x { font-size: 16px; line-height: 1; opacity: .7; padding-left: 2px; }
.chip.sm { padding: 5px 11px; font-size: 13px; }
.chip.add { border-style: dashed; color: var(--accent); background: transparent; min-width: 40px; justify-content: center; font-size: 16px; font-weight: 600; }
.chip.add:active { background: var(--field); }

/* 新增感受 / 類型視窗 */
.modal-back { position: fixed; inset: 0; z-index: 80; display: flex; align-items: flex-end; justify-content: center; background: rgba(10,12,22,.55); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal { width: min(480px, 100%); max-height: 92dvh; overflow-y: auto; background: var(--card-solid); border: 1px solid var(--line); border-radius: 26px 26px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); animation: up .25s ease-out; }
.m-row { display: flex; gap: 10px; }
.m-row .inp { padding: 11px 14px; font-size: 16px; }
.m-row .m-emoji { width: 72px; flex: none; text-align: center; font-size: 24px; padding: 8px; }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 2px; margin: 10px 0 4px; }
.emoji-pick button { font-size: 24px; padding: 5px 7px; border-radius: 12px; }
.emoji-pick button:active { background: var(--field); }
.m-lbl { font-size: 12px; color: var(--muted); letter-spacing: .06em; margin: 14px 2px 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 12px; padding: 2px; }
.sw-dot { width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent; box-shadow: 0 0 0 2px transparent; }
.sw-dot.on { border-color: var(--card-solid); box-shadow: 0 0 0 2.5px var(--text); }
.m-actions { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; margin-top: 20px; }
.m-existing { margin-top: 18px; padding-top: 4px; border-top: 1px solid var(--line); }

/* ── 搜尋 ── */
.searchbox { position: relative; margin-bottom: 14px; }
.searchbox input {
  width: 100%; padding: 14px 16px 14px 44px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); outline: none; font-size: 15px;
}
.searchbox input:focus { border-color: var(--accent); }
.searchbox svg { position: absolute; left: 16px; top: 50%; width: 20px; height: 20px; margin-top: -10px; stroke: var(--muted); fill: none; stroke-width: 2; stroke-linecap: round; }
.filter-block { margin-bottom: 14px; }
.filter-block .fl { font-size: 12px; color: var(--muted); letter-spacing: .08em; margin: 0 4px 8px; }
.result-bar { display: flex; justify-content: space-between; align-items: center; margin: 18px 4px 0; color: var(--muted); font-size: 13px; }
.link-btn { color: var(--accent); font-size: 13px; }

/* ── 統計 ── */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi { text-align: center; padding: 14px 6px; }
.kpi b { display: block; font-size: 24px; color: var(--accent); }
.kpi span { font-size: 12px; color: var(--muted); }
.hero-line { font-size: 15px; margin-bottom: 14px; }
.hero-line b { color: var(--accent-2); }
.bar-row { display: grid; grid-template-columns: 74px 1fr 30px; align-items: center; gap: 10px; margin: 9px 0; font-size: 14px; }
.bar-track { height: 10px; border-radius: 99px; background: var(--field); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; }
.bar-row .n { text-align: right; color: var(--muted); font-size: 13px; }
.cloud { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; align-items: center; padding: 6px 0; }
.cloud button { line-height: 1.25; }
.mbars { display: flex; align-items: flex-end; gap: 5px; height: 150px; padding-top: 6px; }
.mb { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.mb .mv { font-size: 11px; color: var(--muted); height: 14px; }
.mb .mbar { width: 100%; max-width: 22px; border-radius: 8px 8px 4px 4px; background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 45%, transparent)); }
.mb.cur .mbar { background: linear-gradient(180deg, var(--accent-2), color-mix(in srgb, var(--accent-2) 45%, transparent)); }
.mb .ml { font-size: 11px; color: var(--muted); }

/* ── 設定 ── */
.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.theme-opt { border-radius: 18px; border: 2px solid var(--line); padding: 8px; text-align: center; font-size: 13px; }
.theme-opt.on { border-color: var(--accent); }
.theme-opt .sw { height: 54px; border-radius: 12px; margin-bottom: 6px; position: relative; overflow: hidden; }
.theme-opt .sw i { position: absolute; border-radius: 50%; }
.theme-opt small { display: block; color: var(--muted); font-size: 11px; }
.setting-block + .setting-block { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.setting-block h4 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
.setting-block p { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.btn-col { display: flex; flex-direction: column; gap: 8px; }
.field-in {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--field); outline: none; font-size: 14px;
}
.field-in:focus { border-color: var(--accent); }
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%;
  padding: 12px 16px; border-radius: 999px; background: #fff; color: #3c4043;
  font-size: 15px; font-weight: 600; border: 1px solid rgba(0,0,0,.12); box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
.btn-google svg { width: 20px; height: 20px; flex: none; }
.btn-google:disabled { opacity: .6; }
.ok-pill { display: inline-block; vertical-align: middle; margin-left: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }
.about { text-align: center; color: var(--muted); font-size: 12px; margin-top: 24px; }
details.help { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
details.help summary { cursor: pointer; color: var(--accent); }
details.help ol { padding-left: 18px; margin: 8px 0 0; }
details.help code { background: var(--field); padding: 1px 6px; border-radius: 6px; word-break: break-all; }

/* ── 編輯器 ── */
.sheet {
  position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column;
  max-width: 480px; margin: 0 auto;
  background: linear-gradient(180deg, var(--bg1), var(--bg2));
  animation: up .25s ease-out;
}
@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-h {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 14px 12px; border-bottom: 1px solid var(--line);
}
.sheet-h h2 { font-size: 17px; }
.sheet-b { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 16px 16px calc(40px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
.sec { margin-bottom: 22px; }
.sec > label, .sec > .lbl { display: block; font-size: 13px; color: var(--muted); letter-spacing: .06em; margin: 0 2px 8px; }
.inp {
  width: 100%; padding: 13px 15px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--card); outline: none; font-size: 16px;
}
.inp:focus { border-color: var(--accent); }
textarea.inp { resize: none; min-height: 190px; line-height: 1.7; padding-bottom: 54px; }
.ta-wrap { position: relative; }
.mic {
  position: absolute; right: 12px; bottom: 12px; width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent);
  display: grid; place-items: center; box-shadow: 0 6px 16px rgba(0,0,0,.25);
}
.mic svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mic.rec { animation: pulse 1.2s infinite; background: #e07a8f; color: #fff; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(224,122,143,.55); } 70% { box-shadow: 0 0 0 14px rgba(224,122,143,0); } 100% { box-shadow: 0 0 0 0 rgba(224,122,143,0); } }
.tag-in { display: flex; gap: 8px; margin-top: 8px; }
.tag-in .inp { flex: 1; padding: 11px 14px; font-size: 15px; }
.suggest-lbl { font-size: 12px; color: var(--muted); margin: 10px 2px 6px; }
.star-row { display: flex; gap: 6px; }
.star-row button { font-size: 30px; line-height: 1; color: var(--muted); opacity: .45; }
.star-row button.on { color: var(--accent); opacity: 1; }
.time-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.time-row > div { min-width: 0; }
/* iOS Safari 的日期 / 時間欄位有自己的最小寬度，要強制重設，否則會撐破版面 */
input[type="date"].inp, input[type="time"].inp {
  -webkit-appearance: none; appearance: none; display: block;
  width: 100%; min-width: 0; max-width: 100%; min-height: 50px; text-align: left;
}
input.inp::-webkit-date-and-time-value { text-align: left; }
input.inp::-webkit-datetime-edit { padding: 0; }
.time-row label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }
.dur { font-size: 13px; color: var(--accent); margin: 8px 2px 0; min-height: 20px; }

#toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translate(-50%, 10px);
  z-index: 90; background: var(--card-solid); color: var(--text); border: 1px solid var(--line);
  padding: 11px 18px; border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; max-width: 90vw; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.3);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
