:root {
  --night: #0F1B36;
  --night-2: #1D2C4F;
  --rule: rgba(214, 226, 245, 0.22);
  --ink: #EEF2F8;
  --muted: #A9B6CC;
  --sun: #F6C453;
  --alert: #FF5A3C;
  --display: "Fraunces", Georgia, serif;
  --ui: "Instrument Sans", ui-sans-serif, system-ui, sans-serif;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--night);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
h1, h2, p, ol, fieldset { margin: 0; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--sun); outline-offset: 3px; }

.stage { position: relative; height: 100svh; min-height: 520px; overflow: hidden; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.stage.playing canvas { cursor: crosshair; touch-action: none; }

/* The title block, placed like a map cartouche in the South Pacific */
.card {
  position: absolute;
  left: 24px; bottom: 24px;
  width: min(348px, 100% - 32px);
  padding: 26px 26px 20px;
  background: var(--night);
  border: 1px solid var(--rule);
  outline: 1px solid var(--rule);
  outline-offset: -7px;
  border-radius: 3px;
  box-shadow: 0 18px 50px rgba(6, 12, 28, 0.45);
  transition: opacity 0.35s, transform 0.35s;
}
.stage.playing .card { opacity: 0; transform: translateY(14px); pointer-events: none; visibility: hidden; transition: opacity 0.35s, transform 0.35s, visibility 0s 0.35s; }
h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.5rem, 3.6vw, 3.1rem);
  line-height: 0.98;
  letter-spacing: -0.02em;
  font-variation-settings: "opsz" 144;
}
.role { margin-top: 14px; font-weight: 600; }
.role span { font-weight: 400; color: var(--muted); }
.about { margin-top: 10px; font-size: 0.9375rem; color: var(--muted); }
.actions { margin-top: 20px; display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  display: inline-block;
  padding: 10px 16px;
  min-height: 44px;
  border-radius: 3px;
  background: var(--sun);
  color: var(--night);
  border: 1px solid var(--sun);
  font: inherit; font-weight: 600; font-size: 0.9375rem;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: #FFD877; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--rule); }
.btn.ghost:hover { border-color: var(--ink); background: transparent; }
.card .btn { flex: 1; text-align: center; }
.card .btn:first-child { flex-basis: 100%; padding-block: 9px; line-height: 1.25; }
.btn small { display: block; font-size: 0.8125rem; font-weight: 500; opacity: 0.8; }
.link { margin-top: 14px; padding: 4px 0; font: inherit; font-size: 0.875rem; color: var(--muted); background: none; border: 0; text-decoration: underline; text-underline-offset: 0.18em; cursor: pointer; }
.link:hover { color: var(--ink); }

/* "What is this?" in the corner: the explanation shows on hover or focus */
.what { position: absolute; z-index: 2; top: max(16px, env(safe-area-inset-top)); right: 16px; }
.stage.playing .what { display: none; }
.what button {
  font: inherit; font-size: 0.875rem; font-weight: 600; color: var(--ink);
  padding: 8px 14px; min-height: 40px;
  background: var(--night); border: 1px solid var(--rule); border-radius: 3px;
  cursor: help;
}
.what button:hover { border-color: var(--ink); }
.what p {
  position: absolute; right: 0; top: calc(100% + 8px);
  width: min(320px, 100vw - 32px);
  padding: 14px 16px;
  background: var(--night); border: 1px solid var(--rule); border-radius: 3px;
  box-shadow: 0 18px 50px rgba(6, 12, 28, 0.45);
  font-size: 0.9375rem; color: var(--muted);
  opacity: 0; visibility: hidden; transition: opacity 0.15s, visibility 0s 0.15s;
}
.what:hover p, .what:focus-within p { opacity: 1; visibility: visible; transition-delay: 0s; }

.hud {
  position: absolute; z-index: 3;
  top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: clamp(12px, 2.6vw, 28px);
  padding: 10px 10px 10px 20px;
  background: var(--night);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: 0 12px 34px rgba(6, 12, 28, 0.4);
  white-space: nowrap;
}
.hud > div { display: grid; line-height: 1.2; width: 6.4rem; flex: none; }
.hud span { font-size: 0.8125rem; color: var(--muted); }
/* Fixed cell widths and equal-width digits, so the bar never resizes as numbers change */
.hud b { font-size: 1.1875rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow: hidden; }
.hud b.low { color: var(--alert); }
.hud .day { width: clamp(84px, 14vw, 170px); }
.hud .day b { font-size: 0.9375rem; }
.hud .sla { width: 6.2rem; }
.hud .sla b { color: var(--alert); letter-spacing: 0.16em; }
.hud > div:nth-of-type(4) { width: 3.8rem; }
.hud > div:nth-of-type(5) { width: 3.9rem; }
.bar { height: 6px; margin-top: 8px; background: var(--night-2); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--sun); }
.quit { font: inherit; font-size: 0.875rem; color: var(--ink); background: none; border: 1px solid var(--rule); border-radius: 3px; padding: 8px 12px; min-height: 40px; cursor: pointer; }
.quit:hover { border-color: var(--ink); }

.hint, .banner {
  position: absolute; z-index: 3;
  left: 50%; transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 10px 16px;
  background: var(--night);
  border: 1px solid var(--rule);
  border-radius: 3px;
  font-size: 0.9375rem;
  text-align: center;
  pointer-events: none;
}
.hint { bottom: max(18px, env(safe-area-inset-bottom)); }
.hint.warn { border-color: var(--alert); }
.banner { top: calc(max(12px, env(safe-area-inset-top)) + 76px); border-color: var(--sun); box-shadow: 0 12px 34px rgba(6, 12, 28, 0.4); }

.panel {
  position: absolute; z-index: 4;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(560px, 100% - 20px);
  max-height: calc(100% - 20px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 28px 30px 24px;
  background: var(--night);
  border: 1px solid var(--rule);
  outline: 1px solid var(--rule);
  outline-offset: -7px;
  border-radius: 3px;
  box-shadow: 0 30px 80px rgba(4, 10, 24, 0.55);
}
.panel h2 { font-family: var(--display); font-weight: 400; font-size: 2.5rem; line-height: 1; letter-spacing: -0.02em; font-variation-settings: "opsz" 144; }
.goal { margin-top: 10px; color: var(--muted); }
.note { margin-top: 10px; font-size: 0.875rem; color: var(--muted); }
.note:empty { display: none; }

.seg { border: 0; padding: 0; margin-top: 14px; display: flex; align-items: center; flex-wrap: wrap; gap: 0; }
.seg legend { float: left; width: 92px; padding: 0; font-size: 0.875rem; color: var(--muted); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; padding: 9px 16px; min-width: 76px; text-align: center; border: 1px solid var(--rule); margin-left: -1px; font-weight: 600; font-size: 0.9375rem; }
.seg label:first-of-type span { border-radius: 3px 0 0 3px; margin-left: 0; }
.seg label:last-of-type span { border-radius: 0 3px 3px 0; }
.seg input:checked + span { background: var(--sun); color: var(--night); border-color: var(--sun); }
.seg input:focus-visible + span { outline: 2px solid var(--sun); outline-offset: 3px; }

.rules { list-style: none; padding: 0; margin-top: 18px; display: grid; gap: 11px; }
.rules li { display: grid; grid-template-columns: 34px 1fr; gap: 14px; align-items: start; }
.rules svg { width: 34px; height: 34px; }
.rules p { font-size: 0.9rem; line-height: 1.4; color: var(--muted); }
.rules b { color: var(--ink); font-weight: 600; }
.panel .actions { margin-top: 18px; }

.r-label { color: var(--muted); font-size: 0.9375rem; }
.r-avail { font-family: var(--display); font-size: clamp(3.5rem, 13vw, 5.5rem); line-height: 1; letter-spacing: -0.03em; font-variation-settings: "opsz" 144; }
.r-verdict { margin-top: 10px; font-size: 1.125rem; }
.r-stats { margin-top: 6px; color: var(--muted); font-size: 0.9375rem; }
.share { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--rule); display: flex; flex-wrap: wrap; gap: 8px; }

/* Feedback sheet */
dialog.sheet {
  width: min(480px, 100% - 20px);
  max-height: calc(100% - 20px);
  padding: 26px 26px 22px;
  background: var(--night);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: 0 30px 80px rgba(4, 10, 24, 0.6);
}
dialog.sheet::backdrop { background: rgba(6, 12, 28, 0.6); }
.sheet h2 { font-family: var(--display); font-weight: 400; font-size: 2rem; line-height: 1; font-variation-settings: "opsz" 144; }
.sheet .seg { margin-top: 16px; }
.sheet .seg legend { width: auto; margin-right: 14px; }
.sheet label.field { display: block; margin-top: 14px; font-size: 0.875rem; color: var(--muted); }
.sheet textarea, .sheet input[type="email"] {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  font: inherit; font-size: 1rem; color: var(--ink);
  background: var(--night-2); border: 1px solid var(--rule); border-radius: 3px;
}
.sheet textarea { min-height: 120px; resize: vertical; }
.sheet .count { float: right; }
.sheet .status { min-height: 1.4em; margin-top: 12px; font-size: 0.9375rem; }
.sheet .status.bad { color: #FF9A86; }
.page-sheet { display: grid; place-items: center; min-height: 100svh; padding: 10px; }
.page-sheet dialog.sheet { position: static; margin: 0; }

@media (max-width: 819px) {
  .card { left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); width: auto; padding: 22px 22px 16px; }
  .hud { gap: 8px; padding: 7px 7px 7px 10px; max-width: calc(100% - 8px); }
  .hud span { font-size: 0.6875rem; }
  .hud b { font-size: 0.9375rem; }
  .hud > div { width: 4.2rem; }
  .hud .day { width: 3.6rem; }
  .hud .day b { font-size: 0.75rem; }
  .hud .sla { width: 3rem; }
  .hud .sla span { font-size: 0; }
  .hud .sla span::before { content: "SLA"; font-size: 0.6875rem; }
  .hud .sla b { letter-spacing: 0.06em; }
  .hud > div:nth-of-type(4) { width: 2.6rem; }
  .hud > div:nth-of-type(5) { width: 3rem; }
  .bar { margin-top: 6px; }
  .quit { padding: 6px 8px; }
  .hint, .banner { font-size: 0.875rem; padding: 8px 12px; width: auto; min-width: min(300px, 100% - 24px); }
  .banner { top: calc(max(12px, env(safe-area-inset-top)) + 64px); }
  .panel { padding: 22px 20px 18px; }
  .panel h2 { font-size: 2rem; }
  .seg legend { width: 100%; float: none; margin-bottom: 6px; }
  .seg span { min-width: 0; padding: 9px 14px; }
  .rules { gap: 9px; margin-top: 14px; }
  .rules li { grid-template-columns: 28px 1fr; gap: 11px; }
  .rules svg { width: 28px; height: 28px; }
  .rules p { font-size: 0.875rem; }
}
/* Phones keep the short card; tablets and desktops also show the personal line */
@media (max-width: 600px) {
  .about { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .card, .stage.playing .card { transition: none; }
}
