[hidden] { display: none !important; }
:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #1d1e21;
  --ink-2: #5c5f66;
  --ink-3: #8b8e95;
  --line: #e6e4de;
  --soft: #efede7;
  --accent: #3d6df2;
  --good: #2f9e62;
  --danger: #d0453a;
  --radius: 16px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --card: #212226;
    --ink: #ececee;
    --ink-2: #a9abb2;
    --ink-3: #7a7d85;
    --line: #2f3036;
    --soft: #2a2b30;
    --accent: #7b9cff;
    --good: #4cc584;
    --danger: #f06a5f;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }

#view {
  max-width: 560px; margin: 0 auto;
  padding: calc(var(--safe-t) + 16px) 16px calc(var(--tabs-h) + var(--safe-b) + 24px);
}

/* ---------- 底部分頁 ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 11px; color: var(--ink-3); gap: 2px;
}
.tabs a .ti { font-size: 20px; filter: grayscale(1); opacity: .6; }
.tabs a.on { color: var(--ink); font-weight: 600; }
.tabs a.on .ti { filter: none; opacity: 1; }

/* ---------- 共用 ---------- */
h1 { font-size: 26px; margin: 0; letter-spacing: .5px; }
h2 { font-size: 15px; margin: 24px 4px 8px; color: var(--ink-2); font-weight: 600; }
.muted { color: var(--ink-3); font-size: 13px; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: 0 1px 0 rgba(0,0,0,.03);
  border: 1px solid var(--line);
}
.stack > * + * { margin-top: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.btn {
  border: 0; border-radius: 12px; padding: 10px 16px; background: var(--soft);
  font-weight: 600; font-size: 15px;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: transparent; color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; padding: 13px; }
.btn:disabled { opacity: .45; }
.icon-btn {
  border: 0; background: var(--soft); width: 40px; height: 40px; border-radius: 12px;
  font-size: 18px; display: inline-flex; align-items: center; justify-content: center;
}
.link-btn { border: 0; background: none; color: var(--accent); padding: 4px; font-size: 14px; }

/* ---------- 今天頁面 ---------- */
.day-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.day-head .sub { color: var(--ink-3); font-size: 14px; margin-top: 2px; }
.day-nav { display: flex; gap: 6px; }
.summary {
  margin-top: 14px; display: flex; align-items: center; gap: 14px;
}
.ring { width: 54px; height: 54px; flex: none; }
.ring circle { fill: none; stroke-width: 6; }
.ring .bg { stroke: var(--soft); }
.ring .fg { stroke: var(--good); stroke-linecap: round; transition: stroke-dashoffset .4s; }
.summary .big { font-size: 20px; font-weight: 700; }

.habit {
  position: relative; display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 12px 12px 14px; overflow: hidden;
}
.habit + .habit { margin-top: 8px; }
.habit .hicon {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 22px;
  background: color-mix(in srgb, var(--hc) 16%, transparent);
}
.habit .hname { font-weight: 600; }
.habit .hmeta { font-size: 13px; color: var(--ink-3); display: flex; gap: 8px; flex-wrap: wrap; }
.habit .bar { height: 4px; border-radius: 4px; background: var(--soft); margin-top: 6px; overflow: hidden; }
.habit .bar i { display: block; height: 100%; border-radius: 4px; background: var(--hc); transition: width .3s; }
.habit.done { border-color: color-mix(in srgb, var(--hc) 45%, var(--line)); }
.habit.done .hname { color: var(--ink-2); }
.check {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  border: 2px solid var(--line); background: transparent;
  display: flex; align-items: center; justify-content: center; font-size: 18px; color: #fff;
}
.habit.done .check { background: var(--hc); border-color: var(--hc); }
.counter { display: flex; align-items: center; gap: 6px; }
.counter .num { min-width: 22px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.timer-run { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--hc); font-size: 15px; }
.habit.running { border-color: var(--hc); }
.streak { color: #e8833a; }

.empty { text-align: center; padding: 28px 16px; color: var(--ink-3); }

/* 日記 */
.moods { display: flex; justify-content: space-between; gap: 6px; }
.moods button {
  flex: 1; border: 1px solid var(--line); background: transparent; border-radius: 12px;
  font-size: 24px; padding: 6px 0; filter: grayscale(1); opacity: .5; transition: .15s;
}
.moods button.on { filter: none; opacity: 1; background: var(--soft); border-color: var(--ink-3); }
.prompt-tag { font-size: 12px; color: var(--ink-3); }
.prompt-text { font-weight: 600; margin: 2px 0 8px; }
textarea {
  width: 100%; min-height: 96px; resize: vertical; border: 1px solid var(--line);
  background: var(--bg); border-radius: 12px; padding: 10px 12px; line-height: 1.6;
  font-size: 16px; /* 避免 iOS 自動放大 */
}
textarea:focus, input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 0; }
.save-state { font-size: 12px; color: var(--ink-3); text-align: right; min-height: 18px; }

/* ---------- 回顧（月曆） ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .wd { text-align: center; font-size: 12px; color: var(--ink-3); padding-bottom: 4px; }
.cal .d {
  aspect-ratio: 1 / 1.15; border-radius: 10px; border: 0; padding: 4px 0 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  background: var(--soft); font-size: 13px; position: relative;
}
.cal .d.out { visibility: hidden; }
.cal .d.today { outline: 2px solid var(--ink); }
.cal .d.future { opacity: .35; }
.cal .d .m { font-size: 14px; line-height: 1; min-height: 14px; }
.cal .d .jdot { width: 5px; height: 5px; border-radius: 50%; background: var(--ink-2); }
.legend { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-3); margin-top: 10px; flex-wrap: wrap; }
.legend .sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12px; color: var(--ink-3); }

/* ---------- 統計 ---------- */
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; margin-top: 10px; }
.heat i { aspect-ratio: 1; border-radius: 3px; background: var(--soft); display: block; }
.heat i.none { background: transparent; }
.stat-line { display: flex; gap: 14px; font-size: 13px; color: var(--ink-2); flex-wrap: wrap; margin-top: 4px; }
.stat-line b { color: var(--ink); font-variant-numeric: tabular-nums; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--ink-3); font-size: 11px; }
.chart .val { fill: var(--ink); font-size: 12px; font-weight: 600; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.tipline { font-size: 13px; color: var(--ink-2); min-height: 20px; margin-top: 6px; }

/* ---------- 設定與表單 ---------- */
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > .li { display: flex; align-items: center; gap: 12px; padding: 13px 16px; min-height: 52px; }
.list > .li + .li { border-top: 1px solid var(--line); }
.list > a.li { color: inherit; }
.li .chev { color: var(--ink-3); }
.field { display: block; margin-top: 14px; }
.field > span { display: block; font-size: 13px; color: var(--ink-2); margin: 0 2px 6px; font-weight: 600; }
input[type=text], input[type=number], input[type=time], input[type=password], select {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 11px 12px; font-size: 16px; min-height: 46px;
}
.seg { display: flex; background: var(--soft); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 8px 4px; font-size: 14px; color: var(--ink-2); }
.seg button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.chips { display: flex; gap: 6px; }
.chips button {
  flex: 1; aspect-ratio: 1; max-width: 46px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); font-size: 14px; color: var(--ink-2);
}
.chips button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; }
.swatches button.on { border-color: var(--ink); }
.emojis { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.emojis button { border: 0; background: var(--soft); border-radius: 10px; width: 40px; height: 40px; font-size: 20px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 30px; transition: .2s; }
.switch span::before { content: ''; position: absolute; width: 26px; height: 26px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::before { transform: translateX(20px); }
.note { font-size: 13px; color: var(--ink-2); background: var(--soft); border-radius: 12px; padding: 10px 12px; line-height: 1.6; }

/* ---------- 底部彈出面板 ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; background: var(--card); border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(18px + var(--safe-b)); animation: up .2s ease-out;
}
.sheet h3 { margin: 0 0 6px; font-size: 18px; }
.sheet .actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet .actions .btn { flex: 1; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 40;
  bottom: calc(var(--tabs-h) + var(--safe-b) + 12px);
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 20px; font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,.2); max-width: 90vw;
}

/* 登入 */
.login { max-width: 360px; margin: 18vh auto 0; text-align: center; }
.login .logo { font-size: 48px; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 46px; }
.pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: 0; background: none; padding: 8px; font-size: 18px; line-height: 1; border-radius: 9px; }
.pw-toggle:active { background: var(--soft); }

/* 登入：鍵帽錦鯉。整頁蓋掉，所以不受 App 本身的亮色主題影響。 */
.login-koi {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
  background: radial-gradient(ellipse at 50% 36%, #111c31 0%, #070b14 62%);
}
.login-koi .koi { width: min(420px, 90vw); display: block; }
.koi-title {
  margin: 10px 0 0; font-size: 24px; font-weight: 600;
  letter-spacing: .36em; text-indent: .36em; color: #eaf2ff;
}
.koi-sub {
  margin: 8px 0 26px; font-size: 11px; letter-spacing: .24em;
  text-transform: uppercase; color: #6d84ab;
}
.login-koi .pw-wrap { width: min(320px, 82vw); }
.login-koi input[type=password], .login-koi input[type=text] {
  background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .14);
  color: #eaf2ff; border-radius: 13px;
}
.login-koi input::placeholder { color: #61749a; letter-spacing: .06em; }
.login-koi input:focus { outline-color: color-mix(in srgb, #6fd3f7 55%, transparent); }
/* 用文字而不是 emoji：emoji 在部分平台是單色字形，會繼承文字色而在深色底上隱形。 */
.login-koi .pw-wrap input { padding-right: 62px; }
.login-koi .pw-toggle {
  right: 6px; padding: 7px 8px; color: #7d93b8; letter-spacing: .1em;
  font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.login-koi .pw-toggle:active { background: rgba(255, 255, 255, .1); color: #eaf2ff; }
.login-koi .btn.primary {
  width: min(320px, 82vw); margin-top: 12px; border-radius: 13px;
  background: #ff6b4a; letter-spacing: .1em;
}
.koi-err { margin-top: 12px; min-height: 18px; font-size: 13px; color: #ff8a8a; letter-spacing: .04em; }

/* ---------- 臘腸狗 ---------- */
.dog-card { padding: 14px 16px 10px; }
.dog-card .row { align-items: baseline; }
.dog-track { position: relative; height: 70px; margin-top: 6px; }
.dog-track::after { content: ''; position: absolute; left: 0; right: 0; bottom: 4px; height: 2px; border-radius: 2px; background: var(--soft); }
.dog { --len: 34px; --fur: #b9733f; --fur-d: #8f5428; position: absolute; left: 0; top: 0; height: 70px; width: calc(var(--len) + 84px); }
.dog .tail { position: absolute; left: 2px; top: 22px; width: 28px; height: 7px; border-radius: 6px; background: var(--fur); transform-origin: 100% 50%; transform: rotate(28deg); }
.dog .dbody { position: absolute; left: 24px; top: 24px; height: 30px; width: var(--len); border-radius: 16px 20px 15px 17px; background: var(--fur); transition: width .7s cubic-bezier(.34,1.45,.55,1); }
.dog .leg { position: absolute; bottom: -12px; width: 9px; height: 16px; border-radius: 3px 3px 6px 6px; background: var(--fur); }
.dog .l1 { left: 5px; background: var(--fur-d); } .dog .l2 { left: 15px; }
.dog .l3 { right: 17px; background: var(--fur-d); } .dog .l4 { right: 6px; }
.dog .collar { position: absolute; right: 0; top: 4px; width: 7px; height: 22px; border-radius: 4px; background: var(--accent); }
.dog .dhead { position: absolute; top: 4px; left: calc(24px + var(--len) - 12px); width: 40px; height: 34px; border-radius: 48% 52% 46% 50%; background: var(--fur); transition: left .7s cubic-bezier(.34,1.45,.55,1); }
.dog .snout { position: absolute; left: 24px; top: 13px; width: 30px; height: 17px; border-radius: 6px 12px 12px 8px; background: var(--fur); }
.dog .nose { position: absolute; left: 50px; top: 12px; width: 9px; height: 8px; border-radius: 50%; background: #2a1d16; }
.dog .eye { position: absolute; left: 23px; top: 9px; width: 6px; height: 6px; border-radius: 50%; background: #2a1d16; }
.dog .ear { position: absolute; left: 4px; top: 6px; width: 16px; height: 28px; border-radius: 8px 8px 10px 10px; background: var(--fur-d); transform: rotate(14deg); transform-origin: 50% 0; }
.dog.happy .tail { animation: wag .35s ease-in-out infinite alternate; }
.dog.happy .dhead { animation: bob .7s ease-in-out infinite alternate; }
@keyframes wag { from { transform: rotate(10deg); } to { transform: rotate(52deg); } }
@keyframes bob { to { transform: translateY(-3px) rotate(-4deg); } }

/* ---------- 今天的畫 ---------- */
.art-card { display: flex; gap: 14px; align-items: center; }
.art-frame { width: 132px; aspect-ratio: 1; flex: none; border-radius: 6px; overflow: hidden; box-shadow: 0 0 0 6px var(--card), 0 0 0 7px var(--line), 0 6px 18px rgba(0,0,0,.12); }
.painting { display: block; }

/* ---------- 專注模式 ---------- */
.focus { position: fixed; inset: 0; z-index: 25; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-t) + 18px) 24px calc(var(--safe-b) + 28px); animation: fadein .25s ease-out; }
.focus .fhead { text-align: center; }
.focus .fname { font-size: 18px; font-weight: 700; }
.focus canvas { width: min(84vw, 46vh); height: min(84vw, 46vh); touch-action: none; }
.focus .felapsed { font-size: 56px; font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: 1px; line-height: 1; }
.focus .fsub { color: var(--ink-3); font-size: 14px; text-align: center; margin-top: 6px; }
.focus .factions { display: flex; gap: 12px; width: 100%; max-width: 360px; }
.focus .factions .btn { flex: 1; padding: 14px; }
@keyframes fadein { from { opacity: 0; } }

/* ---------- 回顧：切換與畫廊 ---------- */
.seg.mini { max-width: 200px; margin: 0 auto 14px; }
.gallery { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.gcard { perspective: 900px; aspect-ratio: 1 / 1.2; border: 0; padding: 0; background: none; text-align: left; }
.gcard .inner { position: relative; width: 100%; height: 100%; transition: transform .6s cubic-bezier(.2,.8,.2,1); transform-style: preserve-3d; }
.gcard.flipped .inner { transform: rotateY(180deg); }
.gcard .face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 12px; overflow: hidden;
  background: var(--card); border: 1px solid var(--line); box-shadow: 0 4px 14px rgba(0,0,0,.07); }
.gcard .front { display: flex; flex-direction: column; padding: 10px; }
.gcard .front .art-wrap { aspect-ratio: 1; border-radius: 4px; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(0,0,0,.06); }
.gcard .front .plate { margin-top: auto; padding-top: 8px; display: flex; justify-content: space-between; align-items: baseline; }
.gcard .front .plate b { font-size: 15px; }
.gcard .front .plate span { font-size: 12px; color: var(--ink-3); }
.gcard .back { transform: rotateY(180deg); padding: 12px; display: flex; flex-direction: column; font-size: 13px; line-height: 1.55; }
.gcard .back .bq { color: var(--ink-3); font-size: 12px; }
.gcard .back .ba { margin: 2px 0 8px; }
.gcard .back .scroll { overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.gcard .back .bfoot { display: flex; justify-content: space-between; align-items: center; padding-top: 6px; border-top: 1px solid var(--line); font-size: 12px; }

@media (prefers-reduced-motion: reduce) {
  .dog .dbody, .dog .dhead, .gcard .inner { transition: none; }
  .dog.happy .tail, .dog.happy .dhead, .focus, .sheet { animation: none; }
}
