:root {
  --bg: #F4F6FA; --card: #FFFFFF; --line: #D6DCE6; --line2: #B8C1CF;
  --ink: #14213D; --muted: #4A5568; --primary: #1E3A66; --primary-ink: #FFFFFF;
  --flame: #EA580C; --flame-bg: #FFF1E8; --flame-ink: #B3470A;
  --ice: #2563A8; --ice-bg: #E6F0FA; --danger: #B42318; --note: #EEF3FB;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1726; --card: #172238; --line: #2A3852; --line2: #3B4C6B;
    --ink: #E8EDF5; --muted: #A9B4C6; --primary: #8FB3F0; --primary-ink: #0F1726;
    --flame: #FB8A4C; --flame-bg: #3A2418; --flame-ink: #FDA878;
    --ice: #8CC0F5; --ice-bg: #1C3350; --danger: #F2877E; --note: #1C2A44;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 16px; line-height: 1.45; }
a { color: var(--primary); }
h1 { margin: 0; font-size: 24px; }
h2 { margin: 0; font-size: 16px; }
p { margin: 0; }
.app { max-width: 480px; margin: 0 auto; padding-bottom: 88px; }
.pad { padding: 20px 16px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.gap { gap: 12px; }
.center { text-align: center; align-items: center; }
.fill { min-height: 70vh; justify-content: center; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.big { font-size: 22px; }
.strong { font-weight: 700; }
.accent { color: var(--flame-ink); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.testbanner { background: #FFF4CC; color: #5C4400; font-size: 13px; text-align: center; padding: 6px 12px; }
.msg { color: var(--danger); font-size: 14px; min-height: 1em; }
.msg:empty { display: none; }
.note { background: var(--note); border-radius: 12px; padding: 10px 12px; font-size: 14px; }

.btn { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 48px; padding: 10px 16px; border-radius: 14px; border: 1px solid var(--line2); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.tall { min-height: 68px; font-size: 18px; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: .6; cursor: default; }
.link { background: none; border: 0; padding: 0; min-height: 44px; color: var(--primary); font: inherit; font-weight: 600; cursor: pointer; text-align: left; }
:focus-visible { outline: 3px solid var(--flame); outline-offset: 2px; }

input[type=email], input[type=password], input[type=text], select, textarea {
  width: 100%; min-height: 48px; border: 1px solid var(--line2); border-radius: 10px; padding: 10px 12px;
  font: inherit; color: var(--ink); background: var(--card);
}
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.check input { width: 22px; height: 22px; margin-top: 2px; flex-shrink: 0; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--line); border-radius: 12px; }
.tabs button, .seg button { min-height: 44px; border: 0; border-radius: 9px; background: transparent; color: var(--ink); font: inherit; cursor: pointer; }
.tabs button[aria-selected=true], .seg button[aria-pressed=true] { background: var(--card); font-weight: 700; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; background: var(--line); border-radius: 12px; }

.flamebox { width: 56px; height: 56px; border-radius: 16px; background: var(--flame-bg); color: var(--flame); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.flamebox.huge { width: 128px; height: 128px; border-radius: 999px; }
.flamebox.huge .flame { width: 72px; height: 72px; }
.flame { width: 20px; height: 20px; color: var(--flame); }
.flame.big { width: 32px; height: 32px; }
.icon { width: 20px; height: 20px; color: var(--ice); flex-shrink: 0; }
.icon.big { width: 32px; height: 32px; }

.week { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.week li { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.dot { width: 36px; height: 36px; border-radius: 999px; display: flex; align-items: center; justify-content: center; background: var(--line); }
.dot.done { background: var(--flame-bg); }
.dot.frozen { background: var(--ice-bg); }
.dot.today { background: transparent; border: 2px dashed var(--flame); }
.dot.future { opacity: .5; }

.bar { background: var(--card); border-bottom: 1px solid var(--line); padding: 14px 16px; }
footer.bar { border-bottom: 0; border-top: 1px solid var(--line); position: sticky; bottom: 0; }
#view-entry { padding-bottom: 0; }
.progress3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.progress3 span { height: 6px; border-radius: 3px; background: var(--line); }
.progress3 span.on { background: var(--primary); }

fieldset.q { margin: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--card); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
fieldset.q legend { float: left; width: 100%; padding: 0; display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; }
.nums { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.nums.six { grid-template-columns: repeat(6, 1fr); }
.nums button { min-height: 44px; border-radius: 10px; border: 1px solid var(--line2); background: var(--card); color: var(--ink); font: inherit; font-size: 16px; cursor: pointer; }
.nums button[aria-pressed=true] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 700; }
.stepper { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stepper button { width: 56px; height: 56px; border-radius: 14px; border: 1px solid var(--line2); background: var(--card); color: var(--ink); font-size: 26px; cursor: pointer; }
.stepper output { font-size: 30px; font-weight: 700; }

.chartwrap { position: relative; height: 200px; }
table.avg { width: 100%; border-collapse: collapse; font-size: 14px; }
table.avg th { text-align: left; font-weight: 500; padding: 7px 0; border-top: 1px solid var(--line); }
table.avg td { text-align: right; font-weight: 700; padding: 7px 0; border-top: 1px solid var(--line); }

.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid3 .card { padding: 12px; }
.lv-bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.lv-bar span { display: block; height: 100%; background: var(--flame); border-radius: 4px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal.head span { text-align: center; font-size: 11px; font-weight: 600; color: var(--muted); }
.cal .c { height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--muted); background: var(--bg); }
.cal .c.done { background: var(--flame-bg); }
.cal .c.frozen { background: var(--ice-bg); }
.cal .c.today { border: 2px dashed var(--flame); font-weight: 700; color: var(--ink); }
.cal .c.blank { background: transparent; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--card); border-top: 1px solid var(--line); padding: 4px 8px calc(8px + env(safe-area-inset-bottom)); max-width: 480px; margin: 0 auto; }
.tabbar a { min-height: 48px; display: flex; align-items: center; justify-content: center; font-size: 14px; color: var(--muted); text-decoration: none; }
.tabbar a[aria-current=page] { color: var(--primary); font-weight: 700; }
body.entry-mode .tabbar { display: none; }
