:root {
  --bg: #F7F8FC;
  --card: #FFFFFF;
  --ink: #1C1F2E;
  --muted: #5B6075;
  --line: #E1E4EF;
  --field: #FFFFFF;
  --field-line: #CDD2E2;
  --accent: #3442A6;
  --accent-hover: #283490;
  --accent-ink: #FFFFFF;
  --accent-soft: #E7EAFB;
  --shadow: 0 1px 2px rgba(28, 31, 46, .05), 0 8px 24px -12px rgba(28, 31, 46, .16);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141F; --card: #1B1E2D; --ink: #EDEFF7; --muted: #A6ABC2; --line: #2B2F45;
    --field: #12141F; --field-line: #3A3F5C; --accent: #A3B1FF; --accent-hover: #BFC9FF; --accent-ink: #12141F;
    --accent-soft: #262B4A;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12141F; --card: #1B1E2D; --ink: #EDEFF7; --muted: #A6ABC2; --line: #2B2F45;
  --field: #12141F; --field-line: #3A3F5C; --accent: #A3B1FF; --accent-hover: #BFC9FF; --accent-ink: #12141F;
  --accent-soft: #262B4A;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, p { margin: 0; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: 12px; top: -48px; z-index: 10; background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 8px; }
.skip:focus { top: 12px; }

/* Header / hero */
.top { max-width: 1100px; margin: 0 auto; padding: 18px 24px 0; display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 750; font-size: 19px; }
.brand-mark { width: 30px; height: 30px; }
.mark-bg { fill: var(--accent); }
.mark-fg { stroke: var(--bg); }
.theme-toggle { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); display: grid; place-items: center; cursor: pointer; }
.theme-toggle svg { width: 20px; height: 20px; }
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: block; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}
.hero { max-width: 1100px; margin: 0 auto; padding: 28px 24px 22px; }
.hero h1 { font-size: clamp(30px, 4.4vw, 46px); line-height: 1.08; letter-spacing: -.025em; font-weight: 800; }
.hero p { margin-top: 10px; font-size: clamp(17px, 1.6vw, 20px); color: var(--muted); }

/* Layout */
.tool { max-width: 1100px; margin: 0 auto; padding: 0 24px 40px; display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr) minmax(0, 400px); align-items: start; }
.col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.card h2 { font-size: 18px; font-weight: 750; display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.num { width: 26px; height: 26px; border-radius: 99px; display: grid; place-items: center; font-size: 14px; background: var(--accent-soft); color: var(--accent); flex: none; }
.help { color: var(--muted); font-size: 15px; margin: -4px 0 12px; }

/* Buttons and fields */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 52px; padding: 0 20px; border-radius: 12px; border: 1px solid transparent; font-weight: 650; font-size: 17px; cursor: pointer; touch-action: manipulation; }
.btn-ghost { background: var(--card); border-color: var(--field-line); }
.btn-ghost:hover { border-color: var(--ink); }
.start-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
input[type="time"], input[type="number"] {
  height: 52px; padding: 0 14px; font-size: 20px; font-weight: 650; border: 1px solid var(--field-line); border-radius: 12px; background: var(--field); min-width: 0; width: 100%;
}
input[type="time"] { font-size: 22px; }

.choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.choice { min-height: 52px; border-radius: 12px; border: 1px solid var(--field-line); background: var(--field); font-weight: 700; font-size: 17px; cursor: pointer; touch-action: manipulation; }
.choice:hover { border-color: var(--accent); }
.choice[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.other { margin-top: 14px; }
.other-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.other-row.one { grid-template-columns: minmax(0, 1fr); max-width: 220px; }
.other label { display: grid; gap: 6px; font-weight: 600; font-size: 15px; }

/* Result */
.result { position: sticky; top: 16px; text-align: center; padding: 26px 20px; }
.result .result-label { justify-content: center; color: var(--muted); font-size: 17px; font-weight: 650; margin-bottom: 4px; }
.out-time { font-size: clamp(52px, 9vw, 72px); font-weight: 800; letter-spacing: -.03em; line-height: 1.05; color: var(--accent); font-variant-numeric: tabular-nums; }
.out-day { display: inline-block; margin-top: 8px; padding: 3px 12px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 15px; }
.out-math { margin-top: 12px; color: var(--muted); font-size: 15px; }
.countdown { margin-top: 10px; font-weight: 650; font-size: 17px; }
.tip-box { margin: 0; font-size: 15px; color: var(--muted); }
.tip-box:not(:empty) { margin-top: 12px; }
.tip-box a { color: var(--accent); font-weight: 650; text-decoration: underline; text-underline-offset: 3px; }
.remember { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }

/* Common shifts table */
.how { max-width: 1100px; margin: 0 auto; padding: 8px 24px 40px; }
.how h2 { font-size: 22px; font-weight: 750; margin-bottom: 12px; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 16px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 14px; color: var(--muted); font-weight: 650; }
tbody tr:last-child td { border-bottom: 0; }
td:last-child { font-weight: 700; }
.how-note { margin-top: 12px; color: var(--muted); font-size: 15px; }

/* Footer */
.foot { max-width: 1100px; margin: 0 auto; padding: 24px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; display: grid; gap: 6px; }
.foot-links { display: flex; gap: 8px; flex-wrap: wrap; }
.foot a { color: var(--accent); font-weight: 650; text-underline-offset: 3px; }

@media (max-width: 860px) {
  .tool { grid-template-columns: minmax(0, 1fr); padding: 0 16px 32px; gap: 16px; }
  .col { gap: 16px; }
  /* On phones the answer sits right under the hero so it's seen without scrolling back up. */
  .result { position: static; order: -1; }
  .top, .hero, .how, .foot { padding-left: 16px; padding-right: 16px; }
  .hero { padding-top: 22px; padding-bottom: 16px; }
}
@media (max-width: 380px) {
  .choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
