:root {
  color-scheme: light dark;
  --bg: #f3f7fa;
  --surface: #ffffff;
  --surface-2: #e8f0f5;
  --ink: #102a43;
  --muted: #627d98;
  --line: #d6e2eb;
  --brand: #00796b;
  --brand-2: #0b5f57;
  --accent: #f59e0b;
  --danger: #b42318;
  --success: #16794b;
  --shadow: 0 8px 24px rgb(16 42 67 / 9%);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { min-width: 320px; overflow-x: hidden; background: var(--bg); }
body { margin: 0; min-height: 100vh; overflow-x: hidden; background: var(--bg); color: var(--ink); font-family: system-ui, -apple-system, "Noto Sans TC", sans-serif; line-height: 1.55; }
button, input, select, textarea { color: inherit; font: inherit; }
button, a, input[type="checkbox"], input[type="radio"] { touch-action: manipulation; }
button, .button, nav a { min-height: 44px; }
button { cursor: pointer; }
a { color: var(--brand); }
h1, h2, h3, p { margin-top: 0; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
.app-shell { width: min(100%, 760px); min-height: 100vh; margin: 0 auto; }
.app-header { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; min-height: 76px; padding: calc(12px + env(safe-area-inset-top)) 18px 12px; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(14px); }
.app-header h1 { margin: 0; font-size: 1.55rem; line-height: 1.2; }
.eyebrow { margin: 0 0 2px; color: var(--muted); font-size: .75rem; font-weight: 700; letter-spacing: .08em; }
.icon-button { width: 48px; padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); font-size: 1.25rem; }
main { padding: 6px 16px calc(104px + env(safe-area-inset-bottom)); outline: none; }
.tab-bar { position: fixed; z-index: 30; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(5, 1fr); width: min(100%, 760px); margin: auto; padding: 7px 6px calc(7px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(16px); }
.tab-bar a { display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 1px; border-radius: 12px; color: var(--muted); font-size: .75rem; font-weight: 700; text-decoration: none; }
.tab-bar a span:first-child { font-size: 1.15rem; }
.tab-bar a.active { background: var(--surface-2); color: var(--brand-2); }
.stack { display: grid; gap: 14px; }
.card { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); overflow-wrap: anywhere; }
.card > :last-child { margin-bottom: 0; }
.hero { background: linear-gradient(135deg, #0b5f57, #00796b); color: white; }
.hero .muted { color: #d8f3ee; }
.row { display: flex; align-items: center; gap: 12px; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.muted, .help { color: var(--muted); }
.help { font-size: .86rem; }
.metric { font-size: 2rem; font-weight: 800; line-height: 1; }
.button, button.primary, button.secondary, button.danger { display: inline-flex; align-items: center; justify-content: center; padding: 10px 16px; border-radius: 12px; font-weight: 750; text-decoration: none; }
button.primary, .button.primary { border: 1px solid var(--brand); background: var(--brand); color: white; }
button.secondary, .button.secondary { border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); }
button.danger { border: 1px solid #f2c6c2; background: #fff0ef; color: var(--danger); }
button.ghost { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--brand); font-weight: 700; font-size: 14px; }
.daily-input { margin-top: 6px; font-size: 14px; }
.daily-line { display: block; margin-top: 6px; color: var(--brand); font-weight: 650; }
button:disabled { cursor: not-allowed; opacity: .55; }
.full { width: 100%; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.segmented button { border: 0; border-radius: 11px; background: transparent; }
.segmented button.active { background: var(--surface); color: var(--brand-2); box-shadow: 0 2px 8px rgb(16 42 67 / 10%); font-weight: 800; }
label { display: grid; gap: 5px; font-weight: 700; }
input:not([type="checkbox"]):not([type="radio"]), select, textarea { width: 100%; min-height: 44px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
textarea { min-height: 130px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 34%, transparent); outline-offset: 2px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.check-row { display: grid; grid-template-columns: 28px 1fr; align-items: start; gap: 10px; min-height: 48px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.check-row:last-child { border-bottom: 0; }
.check-row input[type="checkbox"] { width: 24px; height: 24px; margin: 1px 0; accent-color: var(--brand); }
.ring { --rate: 0; position: relative; display: grid; place-items: center; flex: 0 0 auto; width: 92px; height: 92px; border-radius: 50%; background: conic-gradient(var(--brand) calc(var(--rate) * 1%), var(--surface-2) 0); }
.ring::after { position: absolute; width: 70px; height: 70px; border-radius: 50%; background: var(--surface); content: ""; }
.ring-value { z-index: 1; font-size: 1.15rem; font-weight: 850; }
.template-list, .clean-list { margin: 0; padding: 0; list-style: none; }
.template-list li { display: grid; grid-template-columns: 30px 1fr; gap: 9px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.template-list li:last-child { border-bottom: 0; }
.slot { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); color: var(--brand-2); font-weight: 850; }
.subject-grid { display: grid; gap: 9px; }
.subject-item { padding: 11px; border-left: 4px solid var(--brand); border-radius: 8px; background: var(--surface-2); }
.subject-item strong { display: block; color: var(--brand-2); }
.day-dots { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; text-align: center; }
.day-dot { display: grid; gap: 5px; justify-items: center; color: var(--muted); font-size: .72rem; }
.day-dot i { display: grid; place-items: center; width: 32px; height: 32px; border: 2px solid var(--line); border-radius: 50%; background: var(--surface); font-style: normal; }
.day-dot.done i { border-color: var(--brand); background: var(--brand); color: white; }
.day-dot.makeup i { border-style: dashed; }
.badge-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.badge { min-height: 150px; padding: 15px 10px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); text-align: center; }
.badge .icon { display: block; margin-bottom: 7px; font-size: 2.1rem; filter: grayscale(1); opacity: .35; }
.badge.unlocked { border-color: #f4ca64; background: #fff9e7; }
.badge.unlocked .icon { filter: none; opacity: 1; }
.badge p { margin: 5px 0 0; font-size: .8rem; }
.week-history { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mini-ring { --rate: 0; display: grid; place-items: center; aspect-ratio: 1; border-radius: 50%; background: conic-gradient(var(--brand) calc(var(--rate) * 1%), var(--surface-2) 0); font-size: .76rem; font-weight: 800; }
.mini-ring::before { grid-area: 1/1; width: 72%; height: 72%; border-radius: 50%; background: var(--surface); content: ""; }
.mini-ring span { z-index: 1; grid-area: 1/1; text-align: center; }
.timeline { position: relative; display: grid; gap: 14px; }
.timeline::before { position: absolute; top: 18px; bottom: 18px; left: 15px; width: 3px; background: var(--line); content: ""; }
.timeline-item { position: relative; padding-left: 44px; }
.timeline-item::before { position: absolute; top: 15px; left: 8px; width: 17px; height: 17px; border: 3px solid var(--surface); border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 2px var(--brand); content: ""; }
.chart { width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .goal { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 5 4; }
.chart .trend { fill: none; stroke: var(--brand); stroke-width: 3; }
.chart .point { fill: var(--brand); stroke: var(--surface); stroke-width: 2; }
.notice { padding: 11px 13px; border-left: 4px solid var(--accent); border-radius: 8px; background: #fff8e5; color: #694b00; }
.error-list { padding: 10px 12px 10px 30px; border-radius: 10px; background: #fff0ef; color: var(--danger); }
.diff-list { display: grid; gap: 8px; padding: 0; list-style: none; }
.diff-list li { padding: 9px; border-radius: 9px; background: var(--surface-2); }
.diff-list code { white-space: pre-wrap; overflow-wrap: anywhere; }
.toast-region { position: fixed; z-index: 100; right: 16px; bottom: calc(88px + env(safe-area-inset-bottom)); left: 16px; display: grid; justify-items: center; pointer-events: none; }
.toast { max-width: 460px; padding: 12px 18px; border-radius: 12px; background: #102a43; color: white; box-shadow: var(--shadow); animation: toast-in .2s ease-out; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
.hidden { display: none !important; }

/* 登入遮罩（雲端同步版） */
.login-overlay { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 24px; background: color-mix(in srgb, var(--bg) 82%, black); backdrop-filter: blur(6px); }
.login-card { display: grid; gap: 12px; width: min(100%, 340px); }
.login-card h2 { margin: 0; }
.login-err { min-height: 1.2em; color: var(--danger); }

/* task-completion progress bars (with time marker) */
.pbar + .pbar { margin-top: 16px; }
.pbar-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 5px; }
.pbar-label { font-weight: 750; }
.pbar-val { font-weight: 800; }
.pbar-val small { font-weight: 600; color: var(--muted); }
.pbar-track { position: relative; height: 14px; border-radius: 99px; background: var(--surface-2); }
.pbar-fill { position: absolute; top: 0; left: 0; height: 100%; border-radius: 99px; background: var(--brand); transition: width .3s ease; }
.pbar-fill.warn { background: #e0a400; }
.pbar-fill.bad { background: var(--danger); }
.pbar-time { position: absolute; top: -3px; width: 0; height: 20px; border-left: 2px solid var(--ink); }
.pbar-time::after { position: absolute; top: -7px; left: -4px; font-size: 9px; content: "▲"; color: var(--ink); }
.pbar-foot { margin-top: 6px; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .74rem; font-weight: 750; }
.chip.good { background: color-mix(in srgb, var(--brand) 18%, var(--surface)); color: var(--brand-2); }
.chip.warn { background: color-mix(in srgb, #e0a400 24%, var(--surface)); color: #8a6500; }
.chip.bad { background: color-mix(in srgb, var(--danger) 18%, var(--surface)); color: var(--danger); }

/* time-passing bar + month calendar */
.bar { margin-top: 12px; height: 8px; border-radius: 99px; background: color-mix(in srgb, var(--surface-2) 80%, transparent); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 99px; background: var(--brand); }
.cal-month { scroll-margin-top: 88px; }
.cal-month.current { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand), var(--shadow); }
.cal-weekhead { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 12px 0 6px; text-align: center; font-size: .74rem; color: var(--muted); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-cell { position: relative; aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); font-size: .8rem; }
.cal-cell.outside { border: 0; background: transparent; }
.cal-cell.future { color: var(--muted); }
.cal-cell.future .cal-num { opacity: .55; }
.cal-cell.rest { background: var(--surface-2); color: var(--muted); }
.cal-cell.missed { background: color-mix(in srgb, var(--muted) 16%, var(--surface)); color: var(--muted); }
.cal-cell.partial { background: color-mix(in srgb, var(--brand) 22%, var(--surface)); }
.cal-cell.done { background: color-mix(in srgb, var(--brand) var(--fill, 80%), var(--surface)); color: #fff; border-color: transparent; }
.cal-cell.today { outline: 2px solid var(--brand); outline-offset: 1px; }
.cal-cell.today .cal-num { font-weight: 850; }
.cal-num { font-weight: 700; line-height: 1; }
.cal-rate { font-size: .58rem; line-height: 1; opacity: .92; }
.cal-rate.miss { font-size: .9rem; opacity: .5; }
.cal-mock { position: absolute; top: 0; right: 2px; font-size: .6rem; }
.cal-tag { position: absolute; right: 3px; bottom: 0; font-size: .52rem; opacity: .7; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .8rem; color: var(--muted); }
.cal-legend > span { display: inline-flex; align-items: center; gap: 5px; }
.dot { display: inline-block; width: 13px; height: 13px; border-radius: 4px; }
.dot.done { background: var(--brand); }
.dot.missed { background: color-mix(in srgb, var(--muted) 30%, var(--surface)); }
.dot.today { background: transparent; outline: 2px solid var(--brand); }
.dot.rest { background: var(--surface-2); border: 1px solid var(--line); }

@media (min-width: 620px) {
  main { padding-right: 24px; padding-left: 24px; }
  .badge-grid { grid-template-columns: repeat(4, 1fr); }
  .subject-grid { grid-template-columns: 1fr 1fr; }
  .week-history { grid-template-columns: repeat(5, 1fr); }
}

@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1723; --surface: #122536; --surface-2: #1c3447; --ink: #e8f1f7; --muted: #9fb5c5; --line: #29465c; --brand: #42c7b4; --brand-2: #76e0d0; --shadow: 0 8px 24px rgb(0 0 0 / 22%); }
  .hero { background: linear-gradient(135deg, #09544d, #087d70); }
  .notice { background: #3a3017; color: #ffe8a4; }
  .badge.unlocked { border-color: #8f721f; background: #332c18; }
  button.danger, .error-list { background: #3c1d1c; }
}
