:root {
  --paper: #fefbf3;
  --paper-line: #e4dcc8;
  --ink: #2e2a26;
  --pink: #f582ae;
  --pink-dark: #d95d8f;
  --blue: #8bd3dd;
  --blue-dark: #4fa8b5;
  --yellow: #f3d576;
  --green: #86c78a;
  --shadow: 0 8px 24px rgba(0,0,0,0.12);
  --radius: 20px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #e8ddc9;
  font-family: -apple-system, "Avenir Next Rounded", "SF Pro Rounded", Verdana, sans-serif;
  color: var(--ink);
  touch-action: none;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--pink);
  color: white;
  flex: 0 0 auto;
  box-shadow: var(--shadow);
  z-index: 10;
}

#topbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 800;
}

#topbar .sub {
  font-size: 12px;
  opacity: 0.9;
}

.icon-btn {
  border: none;
  background: rgba(255,255,255,0.25);
  color: white;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,0.4); }

/* ---------- Progress dots ---------- */
#progress {
  display: flex;
  gap: 6px;
  justify-content: center;
  padding: 8px;
  flex: 0 0 auto;
  background: #f3ead6;
  overflow-x: auto;
}
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--paper-line);
  flex: 0 0 auto;
}
.dot.done { background: var(--green); }
.dot.current { background: var(--pink-dark); transform: scale(1.3); }

/* ---------- Sheet area ---------- */
#sheet-wrap {
  flex: 1 1 auto;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 16px;
  background: #e8ddc9;
}

#sheet-page {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 900px;
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sheet-instructions {
  flex: 0 0 auto;
  padding: 18px 26px 10px;
  border-bottom: 2px dashed var(--paper-line);
}
.sheet-instructions h2 {
  margin: 0 0 4px 0;
  font-size: 22px;
}
.sheet-instructions p {
  margin: 0;
  font-size: 15px;
  color: #5a5142;
  line-height: 1.4;
}

/* Fixed 800:900 ratio so on-screen drawing coordinates always line up
   1:1 with the exported/print flatten canvas, regardless of viewport. */
.sheet-body-wrap {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  aspect-ratio: 800 / 900;
  overflow: hidden;
  touch-action: none;
}

#sheet-svg-host {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#sheet-svg-host svg {
  width: 100%;
  height: 100%;
  display: block;
}

#draw-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---------- Bottom toolbar ---------- */
#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: var(--blue);
  flex: 0 0 auto;
  flex-wrap: wrap;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.1);
}

.tool-group { display: flex; gap: 8px; align-items: center; }

.nav-btn {
  border: none;
  background: white;
  color: var(--ink);
  border-radius: 14px;
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 800;
  box-shadow: 0 3px 0 rgba(0,0,0,0.15);
  cursor: pointer;
}
.nav-btn:active { transform: translateY(2px); box-shadow: none; }
.nav-btn.primary { background: var(--pink-dark); color: white; }
.nav-btn:disabled { opacity: 0.4; }

.small-btn {
  border: none;
  background: rgba(255,255,255,0.6);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.small-btn.active { background: white; box-shadow: 0 0 0 2px var(--pink-dark) inset; }

.color-dot {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
}
.color-dot.selected { border-color: var(--ink); }

/* ---------- Screens (start / finish) ---------- */
.screen {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
}
.screen h2 { font-size: 26px; margin: 0; }
.screen p { max-width: 480px; line-height: 1.5; margin: 0; }

.field {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}
.field label { font-weight: 700; font-size: 14px; }
.field input {
  font-size: 18px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid var(--paper-line);
  background: white;
}

.grade-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.grade-btn {
  border: 2px solid var(--paper-line);
  background: white;
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
}
.grade-btn.selected {
  background: var(--pink-dark);
  border-color: var(--pink-dark);
  color: white;
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  width: 100%;
  max-width: 900px;
}
.thumb-grid img {
  width: 100%;
  border-radius: 10px;
  border: 2px solid var(--paper-line);
  background: white;
}
.thumb-grid .thumb-label { font-size: 12px; font-weight: 700; margin-top: 4px; }

.hidden { display: none !important; }

/* Sits above the toolbar, clear of the iPad home indicator. Aimed at the
   grown-up, not the child, so it stays quiet and out of the drawing area. */
#notice {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  z-index: 50;
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  box-shadow: var(--shadow);
  pointer-events: none;
}

#print-area { display: none; }

@media print {
  #app > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  .print-page {
    page-break-after: always;
    padding: 24px;
  }
  .print-page img { width: 100%; border-radius: 12px; }
  .print-page h3 { margin: 0 0 8px 0; }
}
