:root {
  --blue: #2a5a8c;
  --gold: #f5b800;
  --ink: #1f2a36;
  --paper: #f3f7fb;
  --good: #2e8b57;
  --bad: #c0392b;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Trebuchet MS", Verdana, Arial, sans-serif;
  color: var(--ink); background: var(--paper);
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
header { background: var(--blue); color: #fff; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 12px; }
h1 { font-size: 22px; margin: 0; flex: 1; white-space: nowrap; }
a.home { color: #fff; text-decoration: none; font-size: 26px; line-height: 1; padding: 2px 8px; border-radius: 10px; background: rgba(255,255,255,.15); }
nav { display: flex; gap: 5px; flex-wrap: wrap; }
nav button, nav a.help {
  font: inherit; font-size: 16px; border: 0; border-radius: 20px; padding: 8px 15px;
  background: rgba(255,255,255,.18); color: #fff; cursor: pointer; text-decoration: none;
}
nav a.help { border: 1px solid #fff8; background: none; }
nav button.on { background: var(--gold); color: var(--ink); font-weight: bold; }

main { flex: 1; display: flex; min-height: 0; }
#diagwrap { flex: 1; min-width: 0; min-height: 0; padding: 8px; }
#diag { width: 100%; height: 100%; display: block; user-select: none; -webkit-user-select: none; }
#panel { width: 360px; flex: none; overflow-y: auto; padding: 14px 16px 30px; border-left: 3px solid var(--blue); background: #fff; }
@media (max-aspect-ratio: 1/1), (max-width: 760px) {
  main { flex-direction: column; }
  #panel { width: auto; max-height: 46%; border-left: 0; border-top: 3px solid var(--blue); padding: 10px 14px 20px; }
}

/* ---------- diagram ---------- */
.band { stroke: #333; stroke-width: 2.5; cursor: pointer; }
.band:hover { filter: brightness(1.08); }
.band.target { animation: glow 1.1s ease-in-out infinite; stroke: #c98a00; stroke-width: 6; }
.band.picked { stroke: var(--blue); stroke-width: 6; }
.band.right { stroke: var(--good); stroke-width: 6; }
@keyframes glow { 50% { filter: brightness(1.35) saturate(1.4); } }
.edge { fill: none; stroke: #333; stroke-width: 2.5; }
.dash { fill: none; stroke: #333; stroke-width: 3; stroke-dasharray: 18 14; }
.ocean { fill: #7fb8e6; stroke: #2a5a8c; stroke-width: 2; }
.mountain { fill: #a7a07a; stroke: #333; stroke-width: 2.5; }
.illus { fill: none; stroke: #333; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.magnet rect { stroke: #333; stroke-width: 2; }
.magnet text { font-size: 20px; font-weight: bold; fill: #fff; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.bracket { fill: none; stroke: #333; stroke-width: 3; }
.hitzone { fill: transparent; cursor: pointer; }

.slot { cursor: pointer; }
.slot text { font-size: 26px; font-weight: bold; fill: var(--ink); paint-order: stroke; stroke: #fffb; stroke-width: 4px; stroke-linejoin: round; pointer-events: none; }
.slot.small text { font-size: 22px; }
.slot .box { fill: #fff; stroke: #777; stroke-width: 2; stroke-dasharray: 6 4; display: none; }
.slot.blank text, .slot.target text { visibility: hidden; }
.slot.blank .box, .slot.target .box { display: inline; }
.slot.target .box { fill: #fff6c8; stroke: #c98a00; stroke-width: 4; stroke-dasharray: none; animation: pulse 1.1s ease-in-out infinite; }
.slot.done text { fill: #1d6b40; }
.slot.picked text { fill: var(--blue); }
@keyframes pulse { 50% { opacity: .55; } }
.qmark { font-size: 26px; fill: #aaa; text-anchor: middle; dominant-baseline: central; pointer-events: none; display: none; }
.slot.blank .qmark { display: inline; }
.totalbox { fill: #fff; stroke: #333; stroke-width: 2.5; }

/* ---------- panel ---------- */
#panel h2 { margin: 2px 0 8px; font-size: 22px; color: var(--blue); }
#panel p { margin: 6px 0; line-height: 1.45; font-size: 17px; }
.muted { color: #66717d; font-size: 15px !important; }
.big { font-size: 24px; font-weight: bold; margin: 8px 0; line-height: 1.3; }
.card { background: var(--paper); border-radius: 14px; padding: 12px 14px; margin: 10px 0; border-left: 6px solid var(--c, var(--blue)); }
.card h3 { margin: 0 0 6px; font-size: 22px; }
.card ul { margin: 4px 0; padding-left: 20px; font-size: 17px; line-height: 1.45; }
.btn { font: inherit; font-size: 18px; border-radius: 12px; border: 2px solid var(--blue); background: #fff; color: var(--blue); padding: 10px 14px; cursor: pointer; margin: 4px 0; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.small { font-size: 15px; padding: 6px 12px; }
.btn:disabled { opacity: .55; }
.bank { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.bank.wide { grid-template-columns: 1fr; }
.bank .btn { margin: 0; min-height: 52px; font-size: 17px; }
.btn.right { background: var(--good); border-color: var(--good); color: #fff; opacity: 1; }
.btn.nope { background: var(--bad); border-color: var(--bad); color: #fff; opacity: 1; }
.fb { font-size: 20px; font-weight: bold; min-height: 28px; margin: 8px 0; }
.fb.good { color: var(--good); }
.fb.bad { color: var(--bad); }
.bar { height: 10px; background: #dde6ef; border-radius: 5px; overflow: hidden; margin: 6px 0 10px; }
.bar > div { height: 100%; background: var(--gold); transition: width .3s; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
input.answer { font: inherit; font-size: 24px; width: 100%; padding: 10px 12px; border-radius: 12px; border: 2px solid #9aa8b6; margin: 6px 0; }
input.answer:focus { outline: none; border-color: var(--blue); }
.diff { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 22px; letter-spacing: 1px; }
.diff .x { background: #f6c6c0; color: var(--bad); text-decoration: underline; }
.wordbox { background: #fff8dc; border: 2px dashed #e0b400; border-radius: 12px; padding: 8px 12px; margin: 10px 0; }
table.prog { width: 100%; border-collapse: collapse; font-size: 16px; }
table.prog td { padding: 5px 4px; border-bottom: 1px solid #e3e9ef; }
table.prog td.stars { color: var(--gold); white-space: nowrap; text-align: right; letter-spacing: 1px; }
.why { font-size: 16px !important; color: #44505c; }

/* ---------- printing (blank diagram / answer key) ---------- */
#printhead { display: none; }
@media print {
  @page { size: letter portrait; margin: 0.4in; }
  html, body { height: auto; }
  body { display: block; overflow: visible; background: #fff; padding: 0; }
  header, #panel { display: none !important; }
  main { display: block; }
  #printhead { display: flex; justify-content: space-between; font-size: 16pt; font-weight: bold; margin-bottom: 6pt; }
  #diagwrap { height: 9.4in; padding: 0; }
  .band { fill: #fff !important; animation: none !important; filter: none !important; stroke: #000 !important; stroke-width: 2.5 !important; }
  .ocean { fill: #fff; stroke: #000; }
  .mountain { fill: #fff; stroke: #000; }
  .magnet rect { fill: #fff !important; stroke: #000; }
  .magnet text { fill: #000; }
  .slot .box { stroke: #000 !important; fill: #fff !important; animation: none !important; }
  .slot text { fill: #000 !important; }
  .qmark { display: none !important; }
}
