/* Callisto's Pain And Gain — mobile-first stylesheet.
   Palette derives from the app icon: canary blue, sunburst gold, steel. */

:root {
  --blue-900: #0E3266;
  --blue-700: #12417F;
  --blue-600: #1F4E9C;
  --blue-500: #2B6FD4;
  --blue-300: #7FA8E0;
  --blue-100: #E3EEFC;
  --gold-600: #E8971A;
  --gold-500: #F7B733;
  --gold-300: #FFD35C;
  --gold-100: #FFF4DA;
  --ink: #16202E;
  --ink-2: #4A5768;
  --ink-3: #7C8798;
  --bg: #F5F7FA;
  --card: #FFFFFF;
  --line: #E2E7EF;
  --ok: #1E8E5A;
  --warn: #C9660D;
  --bad: #C0392B;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 32, 56, .06), 0 8px 24px rgba(16, 32, 56, .07);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tabbar: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #EAF0F8; --ink-2: #A7B4C6; --ink-3: #77839A;
    --bg: #0E141D; --card: #172231; --line: #26344A;
    --blue-100: #1B2C46; --gold-100: #33280F;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.2; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.18rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .7em; }
a { color: var(--blue-500); }
small, .small { font-size: .82rem; color: var(--ink-2); }
.muted { color: var(--ink-3); }
ul, ol { margin: 0 0 .7em; padding-left: 1.15em; }
li { margin-bottom: .25em; }

/* ---------------------------------------------------------------- shell */
#app { min-height: 100dvh; padding-bottom: calc(var(--tabbar) + var(--safe-b) + 12px); }
.appbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-t) + 10px) 16px 10px;
  background: linear-gradient(135deg, var(--gold-500), var(--gold-600));
  color: #21160A; display: flex; align-items: center; gap: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
}
.appbar .brandmark { width: 36px; height: 36px; border-radius: 9px; flex: 0 0 auto; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.appbar h1 { font-size: 1.02rem; margin: 0; font-weight: 800; letter-spacing: -.02em; }
.appbar .sub { font-size: .74rem; opacity: .78; font-weight: 600; }
.appbar .spacer { flex: 1; }
.appbar button.icon { background: rgba(255,255,255,.35); color: #21160A; border: 0; border-radius: 10px; width: 36px; height: 36px; font-size: 1rem; }

.wrap { padding: 14px 16px 8px; max-width: 720px; margin: 0 auto; }

/* ----------------------------------------------------------------- card */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card.tight { padding: 10px 12px; }
.card h2, .card h3 { margin-bottom: .35em; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap-r { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .72rem; font-weight: 700; background: var(--blue-100); color: var(--blue-600); }
.badge.gold { background: var(--gold-100); color: var(--warn); }
.badge.ok { background: #DCF3E7; color: var(--ok); }
@media (prefers-color-scheme: dark) { .badge.ok { background: #113626; color: #64D6A2; } }

.stat { text-align: center; padding: 10px 6px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.stat .n { font-size: 1.45rem; font-weight: 800; line-height: 1; color: var(--blue-500); }
.stat .l { font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 700; margin-top: 4px; }

/* --------------------------------------------------------------- inputs */
label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: .8rem; font-weight: 700; color: var(--ink-2); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 12px 12px; font-size: 16px; font-family: inherit; color: var(--ink);
  background: var(--card); border: 1.5px solid var(--line); border-radius: 12px; appearance: none;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-500); outline-offset: 1px; border-color: var(--blue-500); }
textarea { min-height: 70px; resize: vertical; }
button {
  font-family: inherit; font-size: .95rem; font-weight: 700; cursor: pointer;
  border-radius: 12px; border: 1.5px solid transparent; padding: 12px 16px;
  background: var(--blue-500); color: #fff; transition: transform .06s ease;
}
button:active { transform: scale(.985); }
button.block { width: 100%; }
button.ghost { background: transparent; color: var(--blue-500); border-color: var(--line); }
button.gold { background: linear-gradient(135deg, var(--gold-500), var(--gold-600)); color: #21160A; }
button.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
button.sm { padding: 8px 12px; font-size: .84rem; border-radius: 10px; }
button:disabled { opacity: .45; }
.err { color: var(--bad); font-size: .85rem; font-weight: 600; margin: 6px 0; }
.ok-msg { color: var(--ok); font-size: .85rem; font-weight: 600; margin: 6px 0; }

/* --------------------------------------------------------------- tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
  backdrop-filter: saturate(180%) blur(12px);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 6px; text-decoration: none; color: var(--ink-3);
  font-size: .64rem; font-weight: 700; letter-spacing: .01em;
}
.tabbar a.on { color: var(--blue-500); }
.tabbar svg { width: 22px; height: 22px; }

/* -------------------------------------------------------------- figures */
.figbox { background: var(--blue-100); border-radius: 12px; padding: 4px; display: block; }
.figbox svg { width: 100%; height: auto; display: block; }
.fig-anim .fig-b { animation: figB 3.2s ease-in-out infinite; }
.fig-anim .fig-a { animation: figA 3.2s ease-in-out infinite; }
@keyframes figA { 0%,32% { opacity: 1 } 50%,82% { opacity: 0 } 100% { opacity: 1 } }
@keyframes figB { 0%,32% { opacity: 0 } 50%,82% { opacity: 1 } 100% { opacity: 0 } }
@media (prefers-reduced-motion: reduce) { .fig-anim .fig-a, .fig-anim .fig-b { animation: none } .fig-anim .fig-b { opacity: .0 } }

.exrow { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.exrow:last-child { border-bottom: 0; }
.exrow .figbox { width: 68px; flex: 0 0 68px; }
.exrow .t { font-weight: 700; font-size: .95rem; }

/* ---------------------------------------------------------------- timer */
.timer { text-align: center; padding: 8px 0 4px; }
.timer .t { font-size: 3rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.03em; color: var(--blue-500); }
.timer.rest .t { color: var(--warn); }

.setchips { display: flex; gap: 8px; flex-wrap: wrap; }
.setchip {
  min-width: 46px; padding: 9px 10px; border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--card); color: var(--ink-2); font-weight: 700; font-size: .84rem;
}
.setchip.done { background: var(--ok); border-color: var(--ok); color: #fff; }

/* -------------------------------------------------------------- calendar */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { text-align: center; font-size: .62rem; font-weight: 800; color: var(--ink-3); text-transform: uppercase; }
.cal .d { aspect-ratio: 1; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: .74rem; font-weight: 700; background: var(--bg); color: var(--ink-3); border: 1px solid var(--line); }
.cal .d.act { background: var(--blue-500); color: #fff; border-color: var(--blue-500); }
.cal .d.walk { background: var(--gold-500); color: #21160A; border-color: var(--gold-600); }
.cal .d.both { background: linear-gradient(135deg, var(--blue-500) 50%, var(--gold-500) 50%); color: #fff; }
.cal .d.today { outline: 2px solid var(--ink); outline-offset: 1px; }
.cal .d.pad { visibility: hidden; }

/* --------------------------------------------------------------- callisto */
.callisto {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--gold-100); border: 1px solid var(--gold-300);
  border-radius: 14px; padding: 10px 12px; margin-bottom: 12px;
}
.callisto img { width: 34px; height: 34px; border-radius: 8px; flex: 0 0 auto; }
.callisto .q { font-size: .9rem; font-weight: 600; }

/* ----------------------------------------------------------------- login */
.auth { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px 20px calc(24px + var(--safe-b)); max-width: 440px; margin: 0 auto; }
.auth .hero { text-align: center; margin-bottom: 18px; }
.auth .hero img { width: 96px; height: 96px; border-radius: 22px; box-shadow: var(--shadow); }
.auth .hero h1 { margin-top: 12px; font-size: 1.4rem; }
.auth .hero p { color: var(--ink-2); font-size: .9rem; }
.profilebtn { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: var(--card); color: var(--ink); border: 1.5px solid var(--line); margin-bottom: 8px; }
.profilebtn .av { width: 34px; height: 34px; border-radius: 999px; background: var(--blue-500); color: #fff; display: grid; place-items: center; font-weight: 800; }

/* ---------------------------------------------------------------- misc */
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; background: transparent; color: var(--ink-2); border: 0; padding: 9px 6px; font-size: .84rem; border-radius: 9px; }
.seg button.on { background: var(--card); color: var(--blue-500); box-shadow: var(--shadow); }
.sheet { position: fixed; inset: 0; background: rgba(8, 14, 24, .5); z-index: 50; display: flex; align-items: flex-end; }
.sheet > div { background: var(--card); width: 100%; max-height: 88dvh; overflow: auto; border-radius: 20px 20px 0 0; padding: 16px 16px calc(20px + var(--safe-b)); }
.hr { height: 1px; background: var(--line); margin: 12px 0; border: 0; }
.install-tip { font-size: .82rem; background: var(--blue-100); border-radius: 12px; padding: 10px 12px; color: var(--ink-2); }

/* ---------------------------------------------------------------- print */
@media print {
  .appbar, .tabbar, .noprint { display: none !important; }
  body { background: #fff; font-size: 11pt; }
  #app { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; page-break-inside: avoid; }
  .printplan { display: block !important; }
  .figbox { background: #fff; }
  .print-day { break-inside: avoid; page-break-inside: avoid; }
}
.printplan { display: none; }

/* ------------------------------------------------------------ readiness */
.readiness { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.rbtn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 2px; background: var(--card); color: var(--ink-2);
  border: 1.5px solid var(--line); border-radius: 12px;
}
.rbtn .rv { font-size: 1.15rem; font-weight: 800; line-height: 1; }
.rbtn .rl { font-size: .6rem; font-weight: 700; text-transform: uppercase; letter-spacing: .02em; }
.rbtn.r1 { border-color: #E3A9A2; color: #B0392B; }
.rbtn.r2 { border-color: #EFC79A; color: #A9660D; }
.rbtn.r3 { border-color: var(--line); }
.rbtn.r4 { border-color: #A8D8BE; color: #17754A; }
.rbtn.r5 { border-color: #7FB3EE; color: var(--blue-600); }
.rbtn:active { transform: scale(.96); }
.readiness-set { border-left: 4px solid var(--blue-500); }

/* ------------------------------------------------------- two-minute door */
.card.door { border-left: 4px solid var(--gold-500); background: linear-gradient(180deg, var(--gold-100), var(--card) 62%); }

/* --------------------------------------------------------- work timer */
.timer.work .t { color: var(--ok); }
.timer button { background: transparent; }

/* ------------------------------------------------------------- toggles */
label.toggle { padding: 10px 0; border-bottom: 1px solid var(--line); align-items: flex-start; gap: 14px; }
label.toggle:last-of-type { border-bottom: 0; }
label.toggle span { font-size: .9rem; font-weight: 600; }
label.toggle input[type=checkbox] { width: 44px; height: 26px; flex: 0 0 44px; margin: 2px 0 0; border-radius: 999px; background: var(--line); border: 0; position: relative; transition: background .15s ease; }
label.toggle input[type=checkbox]::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 999px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s ease; }
label.toggle input[type=checkbox]:checked { background: var(--ok); }
label.toggle input[type=checkbox]:checked::after { transform: translateX(18px); }
label.toggle input[type=checkbox]:disabled { opacity: .4; }

/* ------------------------------------------------- streak insurance etc */
button.stat { border: 1px solid var(--line); width: 100%; }
.stat .shield { font-size: .7rem; margin-left: 4px; vertical-align: super; color: var(--gold-600); }
.stat .of { font-size: .9rem; color: var(--ink-3); font-weight: 700; }

.card.paused { border-left: 4px solid var(--ink-3); background: var(--blue-100); }
.card.miss { border-left: 4px solid var(--warn); }
.card.planner { border-left: 4px solid var(--blue-500); }
.card.timebox { border-left: 4px solid var(--blue-300); }
.card.adjust { border-left: 4px solid var(--warn); }
.card.adjust.up { border-left-color: var(--ok); }

.dayrow { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-top: 10px; }
.dbtn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 0; background: var(--card); color: var(--ink-3); border: 1.5px solid var(--line); border-radius: 10px; }
.dbtn .dn { font-size: 1rem; font-weight: 800; }
.dbtn .dl { font-size: .58rem; font-weight: 700; }
.dbtn.on { background: var(--blue-500); border-color: var(--blue-500); color: #fff; }

/* ------------------------------------------------------------- ghost */
.lasttime { margin-top: 8px; font-size: .82rem; background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; padding: 6px 10px; color: var(--ink-2); }
.lasttime .gl { font-weight: 800; text-transform: uppercase; font-size: .62rem; letter-spacing: .05em; color: var(--ink-3); margin-right: 6px; }
.warn-strip { margin-top: 8px; font-size: .8rem; background: var(--gold-100); border: 1px solid var(--gold-300); border-radius: 10px; padding: 7px 10px; color: var(--warn); font-weight: 600; }
button.hurt { color: var(--bad); border-color: var(--bad); }

.swaprow { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; background: var(--card); color: var(--ink); border: 1.5px solid var(--line); margin-bottom: 8px; padding: 8px 10px; }
.swaprow .figbox { width: 54px; flex: 0 0 54px; }

/* --------------------------------------------------------- SPC chart */
svg.spc { background: var(--card); }
svg.spc .cl-mean { stroke: var(--blue-500); stroke-width: 1.4; }
svg.spc .cl-limit { stroke: var(--bad); stroke-width: 1.2; stroke-dasharray: 5 4; }
svg.spc .cl-series { fill: none; stroke: var(--ink-2); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.spc .pt { fill: var(--ink-2); }
svg.spc .pt-sig { fill: var(--bad); stroke: var(--card); stroke-width: 1.5; }
svg.spc .axl { font-size: 8px; fill: var(--ink-3); font-family: inherit; }
.signals { margin-top: 8px; }
.signals .sig { font-size: .82rem; padding: 4px 0; font-weight: 600; }

/* ------------------------------------------------------------ Pareto */
.pareto-row { margin-bottom: 8px; }
.pareto-row .bar { height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.pareto-row .bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--blue-500), var(--blue-600)); }
.pareto-row:first-of-type .bar span { background: linear-gradient(90deg, var(--gold-500), var(--gold-600)); }
