.print-only { display: none; }
/* Static copies of textarea/input text, shown only in print: a textarea
   prints just its visible rows, so long notes would be truncated. */
.cell-print, .title-print, .notes-print { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:root {
  --bg: #eff7fd;
  --surface: #ffffff;
  --fg: #3f4f66;
  /* Dark enough for >=4.5:1 on every pastel surface it sits on (worst
     case: --blue tab background, 5.0:1) — pastel backgrounds, not
     pastel text (issue #9). */
  --muted: #3f5a75;
  --border: #cfe3f3;
  --blue: #b9ddf7;
  --blue-deep: #5ea3d8;
  --sky: #d3ecff;
  --mint: #c9f2dd;
  --mint-deep: #4fbf8b;
  --lav: #dbeafe;
  --cream: #fff3b8;
  --radius: 20px;
  --shadow: 0 6px 24px rgba(94, 163, 216, 0.18);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { width: 100%; }
body {
  margin: 0;
  overflow-x: clip;
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--fg);
  background:
    radial-gradient(circle at 12% 8%, var(--blue) 0, transparent 26rem),
    radial-gradient(circle at 88% 4%, var(--sky) 0, transparent 24rem),
    radial-gradient(circle at 50% 110%, var(--mint) 0, transparent 30rem),
    var(--bg);
  min-height: 100vh;
}
h1, h2, .bubble-title, .timer-digits { font-family: "Fredoka", "Nunito", sans-serif; }
button, input, textarea { font: inherit; color: inherit; }
.page { width: 100%; max-width: none; margin: 0; padding: clamp(12px, 1.6vw, 28px) clamp(10px, 1.8vw, 36px) 48px; display: flex; flex-direction: column; gap: clamp(14px, 1.4vw, 24px); }
.page > * { min-width: 0; }

/* ---------- hero ---------- */
.hero {
  display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
  background: var(--surface); border: 3px solid var(--border); border-radius: 28px;
  padding: 20px 24px; box-shadow: var(--shadow);
}
.hero-mascot { font-size: 56px; animation: bob 3s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-7px) rotate(4deg); } }
.hero-text { flex: 1 1 320px; }
.hero-text h1 { margin: 0; font-size: clamp(1.7rem, 1.2rem + 1.6vw, 2.9rem); font-weight: 700; color: #256a99; }
.hero-sub { font-size: 1.05rem; color: var(--muted); font-weight: 600; }
.hero-tag { margin: 6px 0 0; font-size: 1.02rem; line-height: 1.5; }
.hero-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- cards & buttons ---------- */
.card {
  background: var(--surface); border: 3px solid var(--border); border-radius: var(--radius);
  padding: clamp(16px, 1.6vw, 28px) clamp(14px, 1.8vw, 32px); box-shadow: var(--shadow); min-width: 0;
}
.card h2 { margin: 0 0 14px; font-size: 1.35rem; font-weight: 600; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.card-ico { margin-right: 4px; }
.card-sub, .saved-note { font-family: "Nunito", sans-serif; font-size: .82rem; color: var(--muted); font-weight: 700; }
.saved-note { margin-left: auto; color: #17693f; }
.saved-note-failed { color: var(--error, #b3261e); }
.save-warning {
  background: var(--surface); border: 3px solid var(--warning, #e6a817); border-radius: var(--radius);
  padding: 16px 20px; box-shadow: var(--shadow); display: flex; gap: 14px;
  align-items: center; flex-wrap: wrap;
}
.save-warning p { margin: 0; flex: 1 1 320px; line-height: 1.5; font-weight: 700; }
.btn {
  border: 2px solid var(--border); background: #fff; border-radius: 999px;
  padding: 8px 16px; font-weight: 800; cursor: pointer; transition: transform .12s, box-shadow .12s, background .12s;
}
.btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 14px rgba(74,63,85,.14); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-main { background: linear-gradient(135deg, var(--blue), var(--sky)); border-color: var(--blue-deep); color: #1d4e6e; }
.btn-soft { background: #f0f8ff; }
.btn-chip { padding: 4px 12px; font-size: .85rem; }
.btn-pro { background: var(--blue); }
.btn-con { background: var(--mint); }

/* ---------- setup ---------- */
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 800; font-size: .9rem; }
.field-wide { grid-column: 1 / -1; }
.field input, .field textarea, .fr-title input {
  border: 2px solid var(--border); border-radius: 14px; padding: 10px 12px; background: #fffdf9; font-weight: 600;
}
.field input:focus, .field textarea:focus, .fr-title input:focus, .cell textarea:focus {
  outline: 3px solid var(--sky); border-color: var(--blue-deep);
}
.topic-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: -4px; }
.topic-note { font-family: "Nunito", sans-serif; font-size: .82rem; color: var(--muted); font-weight: 700; margin: 0; }
.howto { display: flex; align-items: stretch; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.howto-step {
  flex: 1 1 200px; display: flex; flex-direction: column; gap: 4px;
  background: linear-gradient(160deg, #eef7ff, #f6faff); border: 2px dashed var(--blue-deep);
  border-radius: 16px; padding: 12px 14px; font-size: .92rem; line-height: 1.45;
}
.howto-arrow { align-self: center; font-size: 1.4rem; color: var(--blue-deep); }

/* ---------- guide / stepper ---------- */
.stepper { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin-bottom: 16px; }
.step-wrap { display: inline-flex; align-items: center; gap: 2px; }
.step-arrow { color: var(--blue-deep); font-size: .8rem; }
.step-chip {
  border: 2px solid var(--border); background: #f7fbff; border-radius: 999px;
  padding: 5px 11px; font-size: .8rem; font-weight: 800; cursor: pointer; white-space: nowrap;
}
.step-chip:hover { border-color: var(--blue-deep); }
.step-chip.is-done { background: var(--mint); border-color: var(--mint-deep); color: #14532d; }
.step-chip.is-now { background: linear-gradient(135deg, #1f5c86, #256a99); color: #fff; border-color: #1f5c86; transform: scale(1.06); box-shadow: 0 4px 12px rgba(47,127,184,.35); }
.guide-body { display: grid; grid-template-columns: minmax(0, 1fr) clamp(250px, 22vw, 380px); gap: clamp(12px, 1.4vw, 24px); }
.guide-body > * { min-width: 0; }
.bubble-wrap { display: flex; gap: 12px; align-items: flex-start; }
.mascot { font-size: 44px; animation: bob 3.4s ease-in-out infinite; }
.bubble {
  position: relative; flex: 1; background: linear-gradient(160deg, #e8f4fd, #eef6ff);
  border: 3px solid var(--blue); border-radius: 22px; padding: 16px 18px;
}
.bubble::before {
  content: ""; position: absolute; left: -14px; top: 30px;
  border: 8px solid transparent; border-right: 12px solid var(--blue); border-left: 0;
}
.bubble-title { margin: 0; font-size: 1.2rem; font-weight: 600; color: #256a99; }
.bubble-time { color: var(--muted); font-size: .9rem; }
.bubble-main { margin: 6px 0 10px; font-size: 1.05rem; font-weight: 700; line-height: 1.5; }
.bubble-list { margin: 0; padding-left: 18px; line-height: 1.55; display: flex; flex-direction: column; gap: 5px; }
.timer-box {
  background: linear-gradient(160deg, var(--cream), #fff8e1); border: 3px solid #f2df8e;
  border-radius: 22px; padding: 16px; text-align: center; display: flex; flex-direction: column; gap: 9px;
}
.timer-label { font-weight: 800; color: #6b5410; }
.timer-digits { font-size: clamp(2.2rem, 1.6rem + 1.4vw, 3.4rem); font-weight: 700; line-height: 1; color: #6b5410; }
.timer-digits.timer-done { color: #b3261e; animation: bob 1s ease-in-out infinite; }
.timer-btns, .prep-row, .step-nav { display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; }
.prep-row { font-size: .85rem; font-weight: 800; color: var(--muted); border-top: 2px dashed #f2df8e; padding-top: 9px; }
.focus-toggle { display: flex; gap: 10px; align-items: flex-start; margin-top: 16px; background: #eef6ff; border: 2px solid var(--lav); border-radius: 14px; padding: 12px 14px; cursor: pointer; line-height: 1.45; }
.focus-toggle input { width: 20px; height: 20px; accent-color: #2f7fb8; margin-top: 2px; }

/* ---------- flow grid ---------- */
.tabs { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.tab {
  border: 3px solid var(--border); background: #f7fbff; border-radius: 18px;
  padding: 10px 18px; font-family: "Fredoka", sans-serif; font-size: 1.05rem; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
}
.tab-hint { font-family: "Nunito", sans-serif; font-size: .72rem; font-weight: 700; color: var(--muted); }
.tab-pro.tab-on { background: var(--blue); border-color: var(--blue-deep); box-shadow: 0 6px 16px rgba(94,163,216,.4); }
.tab-con.tab-on { background: var(--mint); border-color: var(--mint-deep); box-shadow: 0 6px 16px rgba(79,191,139,.35); }
.tab-arrow { color: var(--muted); font-weight: 800; }
.flow-legend { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 14px; font-weight: 700; }
.legend-chip { background: #f7fbff; border: 2px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: .8rem; }
/* Top padding must clear the .fh-badge, which hangs 11px above the active
   header, plus its translateY(-2px) lift — overflow-x: auto otherwise
   clips both at the scroll container's top edge. */
.flow-scroll { overflow-x: auto; border-radius: 16px; padding: 14px 0 6px; max-width: 100%; }
.flow-grid { display: grid; gap: clamp(6px, .6vw, 10px); width: 100%; min-width: 64rem; }
.flow-grid > * { min-width: 0; }
.fh {
  border-radius: 14px; padding: 9px 10px; font-weight: 800; font-size: .82rem; line-height: 1.3;
  background: var(--lav); display: flex; flex-direction: column; gap: 1px; position: relative;
}
.sheet-pro .fh { background: #d9edfb; }
.sheet-con .fh { background: #dff7ea; }
.fh-sub { font-size: .7rem; color: var(--muted); font-weight: 700; }
.fh-now { outline: 3px solid var(--blue-deep); outline-offset: 1px; transform: translateY(-2px); }
/* Focus-mode dimming must not fade text (opacity .38 failed contrast,
   issue #9): desaturate + cool the background instead, text stays full-strength. */
.fh-dim, .cell-dim { filter: saturate(.45); }
.cell-dim { background: #e9eff5; }
.fh-badge {
  position: absolute; top: -11px; right: 6px; background: #256a99; color: #fff;
  font-size: .62rem; padding: 2px 8px; border-radius: 999px; letter-spacing: .02em;
}
.fr-title { display: flex; gap: 6px; align-items: flex-start; }
.fr-title input { flex: 1; min-width: 0; font-family: "Fredoka", sans-serif; font-weight: 600; }
.sheet-pro .fr-title input { background: #edf6fd; }
.sheet-con .fr-title input { background: #f2fbf6; }
.row-del { border: none; background: transparent; color: var(--muted); cursor: pointer; font-weight: 800; padding: 10px 2px; }
.row-del:hover { color: #b3261e; }
.row-del-armed { color: #b3261e; }
/* Anchored bubble: hangs off the ✕ itself instead of a browser dialog
   appearing at some unrelated corner of the window. */
.row-del-wrap { position: relative; flex: none; }
.row-del-pop {
  position: absolute; right: -6px; top: calc(100% + 7px); z-index: 30;
  display: flex; flex-direction: column; gap: 7px; width: max-content;
  background: var(--surface); border: 2px solid #f0b7c3; border-radius: 14px;
  padding: 9px 10px; box-shadow: var(--shadow);
  font-size: .82rem; font-weight: 800;
}
.row-del-pop::before {
  content: ""; position: absolute; top: -7px; right: 12px; width: 11px; height: 11px;
  background: var(--surface); border-left: 2px solid #f0b7c3; border-top: 2px solid #f0b7c3;
  transform: rotate(45deg);
}
.row-del-actions { display: flex; gap: 6px; }
.row-del-confirm, .row-del-keep {
  border-radius: 999px; padding: 4px 12px; font-size: .8rem; font-weight: 800; cursor: pointer;
}
.row-del-confirm { border: 2px solid #b3261e; background: #fde8e8; color: #8c1d18; }
.row-del-confirm:hover { background: #b3261e; color: #fff; }
.row-del-keep { border: 2px solid var(--border); background: #f0f8ff; color: var(--fg); }
.row-del-keep:hover { background: var(--sky); }
.cell {
  position: relative; background: #fffdf9; border: 2px solid var(--border);
  border-radius: 14px; padding: 6px; display: flex; flex-direction: column; gap: 5px;
  transition: opacity .2s;
}
.cell-now { border-color: var(--blue-deep); box-shadow: 0 0 0 3px var(--blue), var(--shadow); background: #f2f9ff; }
.cell textarea {
  border: none; background: transparent; resize: vertical; min-height: 62px;
  font-weight: 600; line-height: 1.4; width: 100%;
}
.cell textarea:focus { outline: none; }
.cell:focus-within { border-color: var(--blue-deep); }
.cell-arrow {
  position: absolute; left: -13px; top: 16px; z-index: 2; color: var(--blue-deep);
  font-size: .78rem; background: #fff; border-radius: 50%; width: 17px; height: 17px;
  display: flex; align-items: center; justify-content: center;
}
.cell-dropped { background: #eef1ff; border-color: #b9c4f5; }
.cell-extended { background: #eefbf3; border-color: var(--mint-deep); }
.cell-key { background: #fff8d6; border-color: #e8c832; box-shadow: 0 0 0 2px #ffe97a; }
.cell-marks { display: flex; gap: 4px; flex-wrap: wrap; }
.mark-btn {
  border: 1.5px solid var(--border); background: #fff; border-radius: 999px;
  font-size: .66rem; font-weight: 800; padding: 2px 7px; cursor: pointer; color: var(--muted);
}
.mark-btn:hover { border-color: var(--blue-deep); color: var(--fg); }
.mark-btn.mark-on { background: var(--fg); color: #fff; border-color: var(--fg); }
.mark-print { display: none; font-size: .72rem; font-weight: 800; }
.add-row { margin-top: 12px; }
.sheet-tip { color: var(--muted); font-weight: 700; font-size: .88rem; margin: 10px 0 0; }
.shorthand { margin-top: 18px; border-top: 2px dashed var(--border); padding-top: 14px; }
.shorthand summary { font-weight: 800; cursor: pointer; }
.shorthand-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.short-chip {
  display: inline-flex; gap: 7px; align-items: baseline; border: 2px solid var(--border);
  background: #f7fbff; border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: .82rem;
}
.short-chip:hover { border-color: var(--blue-deep); transform: translateY(-1px); }
.short-chip b { font-size: 1rem; }
.shorthand-note { color: var(--muted); font-size: .88rem; line-height: 1.5; }
.shorthand-hint { background: #fff3f6; border: 2px solid var(--pink, #f2a7bb); border-radius: 14px; padding: 10px 14px; font-weight: 700; line-height: 1.5; }
.big-notes {
  width: 100%; border: 2px solid var(--border); border-radius: 14px; padding: 12px;
  background: #fffdf9; font-weight: 600; line-height: 1.5; resize: vertical;
}
.big-notes:focus { outline: 3px solid var(--sky); border-color: var(--blue-deep); }

/* ---------- ballot ---------- */
.ballot-intro { font-weight: 700; margin: 0 0 6px; }
.ballot-qs { line-height: 1.6; margin: 0 0 14px; padding-left: 22px; }
.dropped-box { background: #eef1ff; border: 2px solid #b9c4f5; border-radius: 16px; padding: 12px 16px; margin-bottom: 16px; line-height: 1.5; }
.dropped-title { margin: 0 0 6px; font-weight: 800; }
.dropped-box ul { margin: 0; padding-left: 18px; }
.dropped-none { background: #f2fbf6; border: 2px solid var(--mint); border-radius: 16px; padding: 12px 16px; font-weight: 700; margin: 0 0 16px; }
.winner-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; font-weight: 800; }
/* Unselected winner stays readable (no opacity fade, issue #9):
   desaturated until chosen, then full colour + outline. */
.winner-btn { font-size: 1.05rem; padding: 10px 22px; filter: saturate(.45); }
.winner-btn.winner-on { filter: none; transform: scale(1.05); outline: 3px solid var(--fg); }
.winner-print { display: none; font-family: "Fredoka", sans-serif; font-size: 1.2rem; }
.ballot-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.footer { text-align: center; color: var(--muted); line-height: 1.6; padding: 0 12px; font-weight: 600; }
.footer-small { font-size: .82rem; }

/* ---------- responsive ---------- */
/* Wide screens: content already stretches full-width via .page + 1fr flow
   columns; give the timer/guide sidebar and type a little more room. */
@media (min-width: 1920px) {
  body { font-size: 1.06rem; }
  .cell textarea { min-height: 76px; }
}
@media (max-width: 1180px) {
  .guide-body { grid-template-columns: minmax(0, 1fr) 250px; }
  .howto-step { flex-basis: 160px; }
}
@media (max-width: 860px) {
  .guide-body { grid-template-columns: 1fr; }
  .setup-grid { grid-template-columns: 1fr; }
  .howto-arrow { display: none; }
  .page { padding: 12px 10px 40px; }
  .card { padding: 16px 14px; }
  /* Long rows of chips scroll sideways instead of wrapping into a tall stack. */
  .stepper { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; }
  .step-wrap { flex: 0 0 auto; }
  .flow-legend { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .legend-chip { flex: 0 0 auto; }
}
@media (max-width: 600px) {
  .hero { flex-direction: column; align-items: stretch; text-align: center; padding: 16px; }
  .hero-mascot { font-size: 42px; }
  .hero-text { flex-basis: auto; }
  .hero-actions { justify-content: center; }
  .bubble-wrap { gap: 8px; }
  .mascot { font-size: 32px; }
  .bubble { padding: 13px 14px; }
  .tabs .tab { flex: 1 1 140px; }
  .tab-arrow { display: none; }
  .winner-btn { flex: 1 1 120px; }
  .ballot-actions .btn, .hero-actions .btn { flex: 1 1 auto; }
  .cell textarea { min-height: 54px; }
  .timer-digits { font-size: 2.2rem; }
}
@media (max-width: 400px) {
  .page { padding: 10px 6px 32px; gap: 12px; }
  .card { padding: 13px 10px; border-radius: 16px; }
  .btn { padding: 8px 12px; }
  .mark-btn { padding: 2px 5px; }
}

/* ---------- print: the paper flow, both sheets ---------- */
@page { size: landscape; margin: 8mm; }
@media print {
  .no-print, .hero-actions, .guide-card, .tabs, .cell-marks, .row-del, .add-row { display: none !important; }
  .print-only { display: block !important; break-inside: auto; }
  /* Each sheet starts its own landscape page, like the two paper pages. */
  .print-only h2:not(:first-of-type) { break-before: page; }
  .flow-card { display: none !important; }
  body { background: #fff; font-size: 9pt; }
  .page { max-width: none; padding: 0; gap: 8px; }
  .card, .hero { box-shadow: none; border-color: #ccc; break-inside: avoid; padding: 10px; }
  /* The 9-column grid must fit the landscape page width: shrink type,
     gaps and padding instead of clipping the rightmost columns. */
  .flow-scroll { overflow: visible; padding: 0; }
  .flow-grid { min-width: 0; width: 100%; gap: 4px; }
  .fh { font-size: 7.5pt; padding: 4px 5px; border: 1px solid #ccc; }
  .fh-sub { font-size: 6.5pt; }
  .cell { padding: 4px; border-width: 1px; break-inside: avoid; }
  .cell-arrow { display: none; }
  /* Textareas print only their visible viewport — hide them and show
     the static print copies, which expand to the full text. */
  .cell textarea, .big-notes, .fr-title input { display: none !important; }
  .cell-print {
    display: block; white-space: pre-wrap; overflow-wrap: break-word;
    font-weight: 600; line-height: 1.35; font-size: 8pt; min-height: 34px;
  }
  .title-print {
    display: block; white-space: pre-wrap; overflow-wrap: break-word;
    font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 8.5pt; line-height: 1.3;
  }
  .notes-print {
    display: block; white-space: pre-wrap; overflow-wrap: break-word;
    font-weight: 600; line-height: 1.4; font-size: 9pt; min-height: 34px;
    border: 1px solid #ccc; border-radius: 8px; padding: 6px 8px;
  }
  .mark-print { display: inline; }
  .winner-print { display: block; }
  .cell-dim, .fh-dim { opacity: 1; filter: none; }
}
