/* 三套配色取自上游 Palette.Apply / The three palettes come from upstream Palette.Apply. */
:root, [data-theme="midnight"] {
  --bg: #F1F4FA; --surface: #FFFFFF; --surface-alt: #E7EDF8; --stroke: #D6DFEE; --ink: #27364D; --muted: #74839A;
  --accent: #526FA8; --accent-ink: #FFFFFF; --tile-top: #DEE7F4; --tile-bottom: #D2DFF0;
  --red: #BD465D; --red-track: #F1DEE4; --page: #E4EAF4;
}
[data-theme="forest"] {
  --bg: #242337; --surface: #302D46; --surface-alt: #3C3755; --stroke: #504969; --ink: #F5F0FC; --muted: #B7ACC9;
  --accent: #D5BDEB; --accent-ink: #302441; --tile-top: #45405C; --tile-bottom: #3A354F;
  --red: #F298AA; --red-track: #533747; --page: #1A192A;
}
[data-theme="paper"] {
  --bg: #F7F1E8; --surface: #FFFCF7; --surface-alt: #F0E5D6; --stroke: #DED2C3; --ink: #4B3A31; --muted: #89796B;
  --accent: #9B674B; --accent-ink: #FFFFFF; --tile-top: #EEE2D2; --tile-bottom: #E7D8C6;
  --red: #BD465D; --red-track: #F1DEE4; --page: #EDE4D6;
}
:root { --speed: 420ms; --num: "DIN Alternate", "Bahnschrift", "DIN", "Barlow", "Roboto Condensed", system-ui, sans-serif; }
[data-font="Mono"] { --num: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
[data-font="Classic"] { --num: Georgia, "Times New Roman", serif; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--page); color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", sans-serif;
  display: flex; flex-direction: column; align-items: center; padding: 24px 16px;
}
[hidden] { display: none !important; }
button, select, input { font: inherit; color: inherit; }
button {
  background: transparent; border: 1px solid var(--stroke); border-radius: 9px; padding: 7px 12px; cursor: pointer; font-size: 13px;
  transition: opacity .15s;
}
button:hover { opacity: .72; } button:active { opacity: .5; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary, button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.small, select.small { padding: 5px 8px; font-size: 12px; }
button.icon { padding: 0 7px; line-height: 20px; }
button:disabled { opacity: .35; cursor: default; }
select { background: var(--surface); border: 1px solid var(--stroke); border-radius: 9px; padding: 7px 8px; }

.app {
  width: 100%; max-width: 536px; background: var(--bg); border: 1px solid var(--stroke); border-radius: 22px;
  padding: 16px 22px 18px; box-shadow: 0 18px 50px rgb(30 40 70 / 12%);
}
.bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 15px; }
.brand img { border-radius: 7px; }
.bar-actions { display: flex; gap: 5px; }
.intro { margin: 6px 0 16px; }
.kicker-row { display: flex; justify-content: space-between; margin-bottom: 12px; }
.kicker { font-size: 11px; color: var(--muted); font-family: var(--num); letter-spacing: .02em; }
h1 { font-size: 26px; font-weight: 600; margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.accent { color: var(--accent); }
.tiny { font-size: 11px; } .small-text { font-size: 12px; }
.num { font-family: var(--num); font-variant-numeric: tabular-nums; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.intro p { margin: 8px 0 0; font-size: 12px; }

.card { background: var(--surface); border-radius: 15px; padding: 15px 18px; margin-top: 12px; }
.card.alt { background: var(--surface-alt); border: 1px solid var(--stroke); }
.hero { border: 1px solid var(--stroke); border-radius: 16px; padding: 17px 19px 16px; margin-top: 0; }
.badge { background: var(--surface-alt); color: var(--accent); border-radius: 10px; padding: 4px 9px; font-size: 11px; }
.countdown { font-size: 32px; line-height: 1; }
.big { font-size: 25px; margin-top: 7px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tiles .card { margin-top: 12px; padding: 13px 17px; min-width: 0; overflow: hidden; }
.progress { height: 4px; background: var(--stroke); border-radius: 2px; margin: 14px 0 9px; overflow: hidden; }
.progress.thin { height: 3px; margin: 12px 0 9px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.progress.red { background: var(--red-track); margin: 10px 0 8px; height: 6px; border-radius: 3px; }
.progress.red i { background: var(--red); }
.red-text { color: var(--red); }
.goal-nav { display: flex; align-items: center; gap: 4px; }
.goal-nav .accent { margin-right: 5px; }
.goal-title { margin-top: 9px; }
.goal-title strong { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expense-rows { margin-top: 8px; display: grid; gap: 8px; }
.expense-rows .row { font-size: 12px; }
.expense-rows .progress { margin: 4px 0 0; height: 4px; }
.footnote { margin: 12px 2px 0; font-size: 10px; }
.actions { display: flex; justify-content: space-between; margin-top: 14px; gap: 8px; flex-wrap: wrap; }
.actions div { display: flex; gap: 6px; }
.actions .primary { padding: 8px 14px; }
.credit { font-size: 11px; color: var(--muted); text-align: center; margin-top: 16px; }
.credit a { color: inherit; }

/* 翻页数字 / Flip digits */
.flip-host { height: 96px; margin: 9px 0 8px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.flip-row { display: flex; align-items: center; transform-origin: center; white-space: nowrap; }
.sym { font-family: var(--num); font-size: 34px; color: var(--accent); margin: 0 2px; }
.sym.space { font-size: 15px; }
.tile { position: relative; width: 48px; height: 82px; margin: 0 2px; perspective: 300px; font-family: var(--num); font-size: 58px; font-weight: 600; }
.tile .half, .tile .flap { position: absolute; left: 0; width: 48px; height: 41px; overflow: hidden; }
.tile .top, .tile .flap.fold { top: 0; background: var(--tile-top); border-radius: 7px 7px 0 0; transform-origin: 50% 100%; }
.tile .bottom, .tile .flap.unfold { top: 41px; background: var(--tile-bottom); border-radius: 0 0 7px 7px; transform-origin: 50% 0; }
.tile b { display: block; width: 48px; height: 82px; line-height: 82px; text-align: center; font-weight: 600; }
.tile .bottom b, .tile .flap.unfold b { margin-top: -41px; }
.tile::before { content: ""; position: absolute; left: 0; right: 0; top: 41px; height: 1px; background: var(--bg); opacity: .8; z-index: 3; }
.tile::after { content: ""; position: absolute; left: 0; right: 0; top: 38px; height: 6px; z-index: 3;
  background: linear-gradient(var(--muted), var(--muted)) left/3px 6px no-repeat, linear-gradient(var(--muted), var(--muted)) right/3px 6px no-repeat; border-radius: 1px; }
.tile .flap.fold { z-index: 2; animation: fold calc(var(--speed) / 2) ease-in forwards; }
.tile .flap.unfold { z-index: 2; transform: rotateX(90deg); animation: unfold calc(var(--speed) / 2) ease-out calc(var(--speed) / 2) forwards; }
@keyframes fold { to { transform: rotateX(-90deg); } }
@keyframes unfold { to { transform: rotateX(0); } }
.tile.plain { background: none; }
.tile.plain::before, .tile.plain::after { display: none; }
.tile.slide { background: var(--tile-bottom); border-radius: 7px; overflow: hidden; }
.tile.slide::before, .tile.slide::after { display: none; }
.tile.slide b { position: absolute; top: 0; left: 0; }
.tile.slide b.out { animation: slide-out var(--speed) forwards; }
.tile.slide b.in { animation: slide-in var(--speed) cubic-bezier(.2,.7,.3,1) forwards; }
@keyframes slide-out { to { transform: translateY(-30px); opacity: 0; } }
@keyframes slide-in { from { transform: translateY(30px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .tile .flap, .tile.slide b { animation-duration: 1ms !important; animation-delay: 0ms !important; } }

/* 迷你模式 / Mini mode */
.app.mini #intro, .app.mini #details, .app.mini #ratePanel { display: none; }

/* 设置弹窗 / Settings sheet */
dialog.sheet {
  width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--stroke); border-radius: 18px;
  background: var(--bg); color: var(--ink); box-shadow: 0 24px 70px rgb(0 0 0 / 25%);
}
dialog.sheet.narrow { width: min(520px, calc(100vw - 24px)); }
dialog::backdrop { background: rgb(20 25 40 / 45%); }
dialog form { padding: 22px; display: flex; flex-direction: column; gap: 10px; }
dialog h2 { margin: 0 0 4px; font-size: 22px; font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--stroke); padding-bottom: 8px; overflow-x: auto; }
.tabs button { border: 0; white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--surface-alt); color: var(--accent); font-weight: 600; }
.pane { display: flex; flex-direction: column; gap: 10px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label input, label select { color: var(--ink); font-size: 14px; }
input:not([type="checkbox"]) { background: var(--surface); border: 1px solid var(--stroke); border-radius: 9px; padding: 8px 10px; width: 100%; min-width: 0; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 13px; }
label.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.weekdays { display: flex; flex-wrap: wrap; gap: 6px; }
.weekdays label { flex-direction: row; align-items: center; gap: 4px; color: var(--ink); background: var(--surface); border: 1px solid var(--stroke); border-radius: 8px; padding: 5px 9px; font-size: 13px; }
.help { font-size: 11px; color: var(--muted); margin: 0; }
.link { border: 0; padding: 2px 0; color: var(--accent); text-align: left; align-self: flex-start; }
.list-head { display: flex; justify-content: space-between; align-items: center; }
.list { display: flex; flex-direction: column; gap: 6px; }
.item { display: grid; grid-template-columns: 1fr 110px auto; gap: 6px; align-items: center; }
.item .ops { display: flex; gap: 3px; }
.item .ops button { padding: 5px 8px; }
.empty { font-size: 12px; color: var(--muted); padding: 8px 0; }
.error { color: var(--red); font-size: 12px; margin: 0; min-height: 1em; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--bg); padding-top: 8px; }
.help-box { background: var(--surface); border-radius: 12px; padding: 10px 14px; font-size: 12px; }
.help-box p { margin: 4px 0 0; color: var(--muted); }
.big-text { font-size: 18px; margin: 0; }
dialog p { margin: 0; }

.cal-head { display: flex; align-items: center; gap: 6px; }
.cal-head strong { flex: 1; text-align: center; }
.segmented { display: flex; gap: 6px; }
.segmented button { flex: 1; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-grid .dow { text-align: center; font-size: 11px; color: var(--muted); padding: 2px 0; }
.cal-grid button { padding: 6px 0; display: flex; flex-direction: column; align-items: center; gap: 0; font-family: var(--num); min-height: 46px; border-radius: 8px; }
.cal-grid button small { font-size: 10px; min-height: 14px; font-family: inherit; }
.cal-grid button.work { background: var(--surface); }
.cal-grid button.off { background: transparent; color: var(--muted); }
.cal-grid button.rest-x small { color: var(--red); }
.cal-grid button.work-x small { color: var(--accent); }
.cal-grid button.today { border-color: var(--accent); }
.cal-grid button.other { opacity: .4; }

@media (max-width: 480px) {
  body { padding: 0; }
  .app { border-radius: 0; border: 0; min-height: 100vh; padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: none; }
  h1 { font-size: 22px; }
  .countdown { font-size: 28px; }
  .big { font-size: 21px; }
  .grid2 { grid-template-columns: 1fr; }
  .item { grid-template-columns: 1fr 90px; }
  .item .ops { grid-column: 1 / -1; justify-content: flex-end; }
  .credit { margin: 12px 16px 20px; }
}
