:root {
  --navy: #003366;
  --blue: #005588;
  --spirit: #88CCEC;
  --dgray: #777777;
  --lgray: #EEEEEE;
  --warm: #CCCCBB;
}

html, body { margin: 0; height: 100%; background: #fff; color: var(--navy); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Helvetica, Arial, sans-serif;
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}

header {
  display: flex; align-items: center; gap: 20px;
  padding: 10px 20px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--navy); color: #fff;
}
header h1 { font-size: 24px; margin: 0; flex: 1; font-weight: 700; }
header a { color: var(--spirit); text-decoration: none; font-weight: 600; font-size: 18px; }
header a.off { visibility: hidden; }

main { flex: 1; min-height: 0; display: flex; padding: 8px 16px 0; cursor: pointer; }
#stage { width: 100%; height: 100%; }

.text { padding: 0 24px; text-align: center; }
#cap {
  font-size: clamp(19px, 2.5vw, 30px); line-height: 1.3;
  margin: 4px auto; max-width: 1050px; min-height: 2.6em;
  transition: opacity .25s;
}
#formula {
  font-size: clamp(24px, 3.4vw, 42px); font-weight: 700; color: var(--blue);
  min-height: 1.3em; margin: 0 0 6px; font-variant-numeric: tabular-nums;
  transition: opacity .25s;
}
.fade { opacity: 0; }

footer {
  display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--lgray);
}
button, .btn {
  font: inherit; font-size: 20px; font-weight: 600;
  padding: 12px 22px; min-height: 52px; border-radius: 12px;
  border: 2px solid var(--navy); background: #fff; color: var(--navy);
  touch-action: manipulation; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center;
}
#next { background: var(--navy); color: #fff; min-width: 140px; justify-content: center; }
button:disabled { opacity: .3; cursor: default; }
#dots { display: flex; gap: 8px; margin: 0 8px; }
#dots span { width: 13px; height: 13px; border-radius: 50%; background: var(--lgray); border: 1px solid #ccc; }
#dots span.on { background: var(--blue); border-color: var(--blue); }

/* SVG pieces */
.shape  { fill: var(--spirit); stroke: var(--navy); stroke-width: 3; stroke-linejoin: round; transition: fill .8s; }
.copy   { fill: var(--warm);   stroke: var(--navy); stroke-width: 3; stroke-linejoin: round; transition: fill .8s; }
.aux    { fill: none; stroke: var(--navy); stroke-width: 3; stroke-dasharray: 10 8; }
.cut    { fill: none; stroke: var(--navy); stroke-width: 4; stroke-dasharray: 4 8; stroke-linecap: round; }
.mark   { fill: none; stroke: var(--navy); stroke-width: 2.5; }
.outline{ fill: none; stroke: var(--dgray); stroke-width: 3; stroke-dasharray: 12 8; }
.corner { fill: var(--lgray); stroke: none; }
.grid   { fill: none; stroke: var(--navy); stroke-width: 1.5; }
.row    { fill: var(--blue); stroke: none; }
.label  {
  fill: var(--navy); font-size: 34px; font-weight: 700; font-style: italic;
  text-anchor: middle; dominant-baseline: middle;
  paint-order: stroke; stroke: #fff; stroke-width: 6px; stroke-linejoin: round;
}

/* Index page */
.index { overflow: auto; }
.index main { display: block; cursor: default; padding: 24px; }
.index p.lead { font-size: 22px; max-width: 900px; margin: 0 auto 24px; text-align: center; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; max-width: 1100px; margin: 0 auto; }
.cards a {
  display: block; text-decoration: none; color: var(--navy);
  border: 2px solid var(--navy); border-radius: 16px; padding: 18px; text-align: center;
}
.cards a:active { background: var(--lgray); }
.cards svg { width: 100%; height: 120px; }
.cards h2 { margin: 10px 0 4px; font-size: 24px; }
.cards p { margin: 0; color: var(--dgray); font-size: 17px; }
