:root {
  --sky-top: #162456;
  --sky-low: #4a5db0;
  --wall: #151d43;
  --pane: #2b3a7c;
  --lamp: #ffd257;
  --ink: #10163a;
  --text: #eef2ff;
  --soft: #c3cefa;
  --ring: #ff9f2e;
  --plate: #eef1f8;
  --plate-edge: #9aa6cc;
  --display: "ZCOOL XiaoWei", "Songti SC", serif;
  --digits: "Barlow Condensed", "Arial Narrow", sans-serif;
  --plain: system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { background: var(--sky-top); }
body {
  min-height: 100vh; min-height: 100dvh;
  background: linear-gradient(var(--sky-top), var(--sky-low));
  color: var(--text); font-family: var(--display);
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--ring); outline-offset: 3px; }
.banner button:focus-visible, dialog button:focus-visible, dialog input:focus-visible { outline-color: var(--ink); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* 熄灯以后：天色压暗，星星出来 */
.night-veil { position: fixed; inset: 0; pointer-events: none; background: #080d28; opacity: 0; transition: opacity 1.2s; }
.done .night-veil { opacity: .45; }
.stars i { position: fixed; width: 3px; height: 3px; border-radius: 50%; background: #fff; opacity: .12; pointer-events: none; transition: opacity 1.6s .5s; }
.done .stars i { opacity: .95; }

main {
  position: relative; max-width: 390px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + clamp(12px, 3vh, 26px)) 16px calc(env(safe-area-inset-bottom) + 16px);
}
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
h1 { font-family: var(--digits); font-size: clamp(48px, 7.8vh, 66px); font-weight: 400; line-height: 1; }
h1.words { font-family: var(--display); }
.goal {
  flex: none; padding: 8px 12px; border-radius: 8px; font-size: 15px;
  background: #29356b; border: 1px solid rgba(238, 242, 255, .35);
}
.sub { margin-top: clamp(4px, 1.2vh, 10px); font-size: clamp(16px, 2.2vh, 18px); line-height: 1.5; color: var(--soft); min-height: 3em; white-space: pre-line; }

.banner { margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: var(--lamp); color: var(--ink); font-family: var(--plain); font-size: 14px; line-height: 1.5; }
.banner-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.banner button { padding: 6px 10px; border: 1.5px solid var(--ink); border-radius: 6px; background: transparent; font-size: 14px; }

.roof { position: relative; height: clamp(24px, 4.7vh, 40px); margin-top: 4px; }
.roof svg { position: absolute; bottom: 0; left: 0; width: 100%; height: 100%; fill: var(--wall); }
.building { position: relative; margin-top: -1px; background: var(--wall); padding: 4px 14px 14px; }
.month { display: flex; align-items: center; justify-content: space-between; }
.month h2 { font-size: 17px; font-weight: 400; }
.month button { width: 44px; height: 34px; border: 0; background: none; font-family: var(--plain); font-size: 24px; line-height: 1; }
.month button:disabled { opacity: .25; }
.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: clamp(5px, 1.05vh, 9px) 6px; }
.dows { text-align: center; font-size: 13px; color: var(--soft); margin: 2px 0 6px; }

.win {
  position: relative; display: block; width: 100%; height: clamp(34px, 5.5vh, 47px);
  border: 0; border-bottom: 3px solid #5565ad; border-radius: 2px;
  font-family: var(--digits); line-height: 1;
}
.win .d { position: absolute; top: 3px; left: 4px; font-size: 11px; }
.win .m { position: absolute; top: 2px; right: 3px; font-family: var(--plain); font-size: 9px; }
.win .t { position: absolute; left: 0; right: 0; bottom: 3px; text-align: center; font-size: 14px; }
.win.ok {
  background:
    linear-gradient(90deg, transparent 49%, var(--wall) 49% 51%, transparent 51%),
    repeating-linear-gradient(90deg, var(--pane) 0 4px, #263370 4px 8px);
  color: #d5ddff;
}
.win.late { background: var(--lamp); color: var(--ink); box-shadow: 0 0 14px rgba(255, 210, 87, .55); border-bottom-color: #fff0bd; }
.win.late .t { font-weight: 600; }
.win.miss { background: transparent; border: 1.5px dashed #7482c2; color: #a9b5e8; }
.win.blank { background: #222d61; color: #a9b5e8; border-bottom-color: #38457f; }
.win.later { background: #1b2452; color: #7683bd; border-bottom-color: #28336a; }
.win.now { background: #ffe694; color: var(--ink); box-shadow: 0 0 22px 4px rgba(255, 214, 96, .75); }
.win.now .t { font-family: var(--display); }
.win.tonight { outline: 2.5px solid var(--ring); outline-offset: 2px; }
button.win:focus-visible { outline: 3px solid #fff; outline-offset: 2px; z-index: 1; }
.win.off { animation: off .7s steps(1) both; }
@keyframes off { 0% { filter: brightness(2.4); } 30% { filter: brightness(.6); } 50% { filter: brightness(2); } 70%, 100% { filter: none; } }

.tally { display: flex; gap: 18px; margin: clamp(8px, 1.7vh, 14px) 2px clamp(10px, 1.9vh, 16px); font-size: 16px; }
.tally > span { display: inline-flex; align-items: center; gap: 6px; }
.tally b { width: 12px; height: 16px; }
.tally .k-ok b { background: var(--pane); border: 1px solid #a3b0ee; }
.tally .k-late b { background: var(--lamp); }

/* 墙壁开关。屏幕太矮时贴在底部，保证随手能按到 */
.dock { position: sticky; bottom: calc(env(safe-area-inset-bottom) + 10px); z-index: 2; }
.switch {
  display: flex; align-items: center; gap: 18px; width: 100%; text-align: left;
  padding: clamp(8px, 1.3vh, 11px) 14px; border: 0; border-radius: 12px;
  background: var(--plate); color: var(--ink); box-shadow: 0 5px 0 var(--plate-edge);
}
.switch:active:enabled { transform: translateY(3px); box-shadow: 0 2px 0 var(--plate-edge); }
.switch:disabled { background: #cfd5e8; }
.rocker {
  flex: none; display: grid; place-items: start center; padding-top: 9px;
  width: 52px; height: clamp(46px, 7vh, 60px); border-radius: 6px; border: 1px solid #a7b0ca;
  background: linear-gradient(#fff 0 46%, #c6cde0 100%);
}
.rocker::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--ring); }
.switch[data-off="true"] .rocker { background: linear-gradient(#c0c8dc 0, #fff 54% 100%); place-items: end center; padding-bottom: 9px; }
.switch[data-off="true"] .rocker::after, .switch:disabled .rocker::after { background: #6d79a6; }
.switch strong { display: block; font-size: clamp(21px, 3vh, 24px); font-weight: 400; }
.switch small { display: block; margin-top: 3px; font-family: var(--plain); font-size: 13px; color: #3d4670; }

dialog {
  width: min(390px, 100%); max-width: 100%; max-height: 90vh; max-height: 90dvh; overflow: auto;
  margin: auto auto 0; padding: 20px 18px calc(env(safe-area-inset-bottom) + 20px);
  border: 0; border-radius: 18px 18px 0 0; background: var(--plate); color: var(--ink); color-scheme: light;
}
dialog::backdrop { background: rgba(8, 13, 40, .72); }
dialog h2 { font-size: 24px; font-weight: 400; }
dialog h3 { font-size: 19px; font-weight: 400; margin-top: 22px; padding-top: 16px; border-top: 1px solid #bcc4dc; }
.note { margin-top: 8px; font-family: var(--plain); font-size: 14px; line-height: 1.6; color: #39426b; }
.field { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; font-size: 18px; }
.field input { min-width: 140px; padding: 8px 10px; border: 1.5px solid #6d79a6; border-radius: 8px; background: #fff; color: var(--ink); font-family: var(--plain); font-size: 20px; }
.error { margin-top: 8px; font-family: var(--plain); font-size: 14px; font-weight: 700; color: var(--ink); }
.error:not(:empty) { padding: 8px 10px; border-radius: 6px; background: var(--lamp); }
.error:not(:empty)::before { content: "⚠ "; }
dialog button { display: block; width: 100%; margin-top: 10px; padding: 12px; border: 1.5px solid var(--ink); border-radius: 10px; background: transparent; font-size: 18px; }
dialog button.primary { background: var(--ink); color: #fff; }
dialog button.warn { background: var(--ring); border-color: var(--ring); }
.pair { display: flex; gap: 10px; }

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