/* ==========================================================================
   English Copybook — styles
   Designed for iPad + Apple Pencil: full screen with no scrolling,
   big buttons and safe-area support
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: linear-gradient(180deg, #f2f7fd 0%, #e8eefa 55%, #eef3fb 100%);
  color: #1d2b3a;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; cursor: pointer; color: inherit; }
[hidden] { display: none !important; }

/* Only appears when something goes wrong (hidden the rest of the time) */
.boot-error {
  position: fixed; left: 0; right: 0; top: 0; z-index: 999;
  padding: 10px 14px;
  background: #c0392b; color: #fff;
  font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-all;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
}

/* ---------- Overall skeleton ---------- */
.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

/* ---------- Top bar ---------- */
.topbar { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.logo {
  width: 42px; height: 42px; border-radius: 14px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 21px;
  background: #fff4d6; box-shadow: inset 0 -2px 0 #f0dfb4;
}

.brand-text { min-width: 0; }
.eyebrow { margin: 0; font-size: 10px; font-weight: 800; letter-spacing: .14em; color: #5b7ba6; text-transform: uppercase; }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 900; letter-spacing: .02em; }

.progress { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }
.progress-bar { width: 112px; height: 10px; border-radius: 99px; background: #dbe5f3; overflow: hidden; }
.progress-bar i { display: block; height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, #6cb6ff, #2f6fd0); transition: width .3s ease; }
.progress-text { font-size: 12px; font-weight: 800; color: #5b7ba6; font-variant-numeric: tabular-nums; }

/* ---------- Toolbar ---------- */
.toolbar {
  flex: 0 0 auto;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 7px 9px;
  background: rgba(255, 255, 255, .86);
  border: 1px solid #dde7f3;
  border-radius: 17px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.tool-group { display: flex; align-items: center; gap: 6px; }
.tool-group + .tool-group { padding-left: 8px; border-left: 1px solid #e4ecf6; }

.tool {
  border: 1px solid #dde7f3; background: #fff; color: #26405e;
  border-radius: 11px; padding: 8px 10px; min-height: 40px;
  font-size: 13px; font-weight: 800; line-height: 1.1; white-space: nowrap;
  transition: background .12s, color .12s, transform .08s;
}
.tool:active { transform: scale(.95); }
.tool.is-active { background: #2f6fd0; border-color: #2f6fd0; color: #fff; box-shadow: 0 3px 9px rgba(47, 111, 208, .25); }
.tool[disabled] { opacity: .38; }

.swatch {
  width: 34px; height: 34px; padding: 0; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 1px #dde7f3;
  position: relative; transition: transform .08s;
}
.swatch:active { transform: scale(.92); }
.swatch.is-active { box-shadow: 0 0 0 3px #a8cdff, 0 0 0 1px #2f6fd0; }
.swatch.is-active::after {
  content: "✓"; position: absolute; inset: 0; display: grid; place-items: center;
  color: #fff; font-size: 14px; font-weight: 900; text-shadow: 0 1px 3px rgba(0, 0, 0, .45);
}

/* ---------- Paper area ---------- */
.stage { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 7px; }

.sheet-head { flex: 0 0 auto; display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; padding: 0 6px; }
.sheet-title { min-width: 0; }
.sheet-title h2 { margin: 0; font-size: 17px; font-weight: 900; }
.sheet-title p { margin: 2px 0 0; font-size: 12px; color: #6b7f96; }
.chip { flex: 0 0 auto; font-size: 11px; font-weight: 800; color: #7a5a00; background: #fff4d6; border-radius: 99px; padding: 4px 11px; }

.board {
  position: relative; flex: 1 1 auto; min-height: 0;
  background: #fff; border: 1px solid #dde7f3; border-radius: 20px;
  box-shadow: 0 10px 30px rgba(27, 58, 94, .07);
  overflow: hidden;
}

#paper {
  position: absolute; inset: 0; display: block;
  width: 100%; height: 100%;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}

.board-hint {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  pointer-events: none; max-width: 84%; text-align: center;
  background: rgba(47, 111, 208, .94); color: #fff;
  font-size: 13px; font-weight: 800; padding: 11px 18px; border-radius: 99px;
  box-shadow: 0 10px 24px rgba(47, 111, 208, .25);
  transition: opacity .4s ease;
}
.board-hint.is-hidden { opacity: 0; }

/* ---------- Bottom navigation ---------- */
.bottombar { flex: 0 0 auto; display: flex; gap: 8px; }

.nav-btn {
  flex: 1 1 0; min-width: 0; min-height: 50px; padding: 0 8px;
  border: 0; border-radius: 15px;
  background: #2f6fd0; color: #fff; font-size: 15px; font-weight: 900;
  box-shadow: 0 4px 14px rgba(47, 111, 208, .22);
  transition: transform .08s, background .15s;
}
.nav-btn:active { transform: scale(.98); }
.nav-btn.ghost { background: #fff; color: #26405e; border: 1px solid #dde7f3; box-shadow: none; font-weight: 800; font-size: 14px; }
.nav-btn.is-done { background: #12a06a; border-color: #12a06a; color: #fff; }
.nav-btn[disabled] { opacity: .38; }

/* ---------- Scrim / side panel ---------- */
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(13, 37, 64, .3); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }

.panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: min(430px, 92vw);
  display: flex; flex-direction: column;
  background: #fff;
  box-shadow: -16px 0 42px rgba(13, 37, 64, .2);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  animation: slideIn .2s ease-out;
}
@keyframes slideIn { from { transform: translateX(26px); opacity: .35; } to { transform: none; opacity: 1; } }

.panel-head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid #eef3f9; }
.panel-head h3 { margin: 0; font-size: 16px; font-weight: 900; }

.panel-body { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: 12px 16px 28px; }

.icon-btn { width: 38px; height: 38px; border-radius: 12px; border: 1px solid #dde7f3; background: #fff; font-size: 15px; font-weight: 700; line-height: 1; }

.toc-list { display: flex; flex-direction: column; }
.toc-group { margin: 12px 0 6px; font-size: 11px; font-weight: 900; letter-spacing: .1em; color: #7b90a8; }
.toc-group:first-child { margin-top: 0; }

.toc-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  margin-bottom: 6px; padding: 11px 13px;
  border: 1px solid #e8eff8; border-radius: 13px; background: #fbfdff;
  font-size: 14px; font-weight: 700;
}
.toc-item.is-current { border-color: #2f6fd0; background: #eef5ff; box-shadow: 0 0 0 2px rgba(47, 111, 208, .13); }
.toc-item .tick { margin-left: auto; color: #12a06a; font-weight: 900; font-size: 13px; }

.settings h4 { margin: 20px 0 8px; font-size: 13px; font-weight: 900; color: #39536f; }

.seg { display: flex; gap: 5px; padding: 4px; background: #f2f6fb; border-radius: 14px; }
.seg button { flex: 1 1 0; min-height: 40px; border: 0; border-radius: 11px; background: transparent; color: #4a6482; font-size: 13px; font-weight: 800; }
.seg button.is-active { background: #fff; color: #2f6fd0; box-shadow: 0 1px 5px rgba(27, 58, 94, .13); }

.stack { display: flex; flex-direction: column; gap: 8px; }
.wide-btn { border: 1px solid #dde7f3; background: #fff; border-radius: 13px; padding: 13px 14px; font-size: 14px; font-weight: 800; text-align: left; }
.wide-btn:active { background: #f4f8fd; }
.wide-btn.danger { color: #b52537; border-color: #f3d3d7; background: #fff7f8; }

.note { margin: 8px 0 0; font-size: 12px; line-height: 1.6; color: #7b90a8; }

/* ---------- Dialog ---------- */
.dialog { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(13, 37, 64, .4); }
.dialog-card { display: flex; flex-direction: column; width: min(760px, 96vw); max-height: 92vh; overflow: hidden; background: #fff; border-radius: 20px; box-shadow: 0 20px 60px rgba(13, 37, 64, .25); }
.dialog-head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid #eef3f9; }
.dialog-head h3 { margin: 0; font-size: 15px; font-weight: 900; }
.dialog-body { flex: 1 1 auto; overflow: auto; padding: 12px 14px; background: #f6f9fd; -webkit-overflow-scrolling: touch; }
.dialog-body img { display: block; width: 100%; height: auto; border: 1px solid #e2ebf6; border-radius: 10px; background: #fff; }
.dialog-actions { flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px; border-top: 1px solid #eef3f9; }
.dialog-actions button { flex: 1 1 130px; min-height: 46px; border: 1px solid #dde7f3; border-radius: 13px; background: #fff; font-weight: 800; }
.dialog-actions button.primary { background: #2f6fd0; border-color: #2f6fd0; color: #fff; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; z-index: 70;
  bottom: 104px;
  bottom: calc(104px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 86vw; text-align: center;
  padding: 11px 18px; border-radius: 99px;
  background: #12324f; color: #fff; font-size: 14px; font-weight: 800;
  box-shadow: 0 10px 28px rgba(13, 37, 64, .25);
  animation: pop .18s ease-out;
}
@keyframes pop { from { transform: translate(-50%, 8px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ---------- Small screens / short screens ---------- */
@media (max-width: 760px) {
  .eyebrow { display: none; }
  .topbar h1 { font-size: 17px; }
  .logo { width: 36px; height: 36px; font-size: 18px; border-radius: 12px; }
  .progress-bar { width: 72px; }
  .toolbar { gap: 6px; padding: 6px; }
  .tool { padding: 7px 9px; min-height: 38px; font-size: 12px; }
  .swatch { width: 31px; height: 31px; }
  .nav-btn { font-size: 13px; min-height: 46px; }
  .nav-btn.ghost { font-size: 12px; }
  .sheet-title h2 { font-size: 15px; }
  .sheet-title p { display: none; }
}

@media (max-height: 560px) {
  .eyebrow { display: none; }
  .sheet-head { display: none; }
  .logo { width: 34px; height: 34px; }
  .nav-btn { min-height: 44px; }
}

/* ---------- Print: only the picture in the export dialog gets printed ---------- */
@media print {
  @page { size: landscape; margin: 8mm; }
  body { background: #fff; overflow: visible; }
  .app, .panel, .scrim, .toast { display: none !important; }
  .dialog { position: static; display: block; padding: 0; background: #fff; }
  .dialog-card { width: 100%; max-height: none; border-radius: 0; box-shadow: none; }
  .dialog-head, .dialog-actions, .dialog-body .seg, .dialog-body .note { display: none !important; }
  .dialog-body { overflow: visible; padding: 0; background: #fff; }
  .dialog-body img { border: 0; border-radius: 0; }
}

/* ---------------------------------------------------------------------------
   The warm-up gate: nothing opens until the warm-up page is finished, and the
   contents list says so instead of failing silently when a page is tapped. */

.toc-item.is-locked {
  opacity: .5;
  cursor: not-allowed;
}

.toc-item.is-locked .tick { color: #96a4b8; }

/* ---------------------------------------------------------------------------
   Finishing a page: the neatness score and what it paid. The bars are the five
   things the score is measured from, so the number is never a mystery. */

.score-card { padding: 4px 2px 8px; text-align: center; }

.score-big { margin: 4px 0 2px; color: #173b70; }
.score-big strong { font-size: 46px; font-weight: 900; letter-spacing: -.02em; }
.score-big small { font-size: 15px; font-weight: 800; color: #6b7c94; margin-left: 4px; }

.score-stars { margin: 2px 0 10px; font-size: 22px; letter-spacing: 4px; }

.score-paid {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 800;
  color: #12a06a;
}

.score-paid.is-quiet { color: #6b7c94; font-weight: 700; }

.score-lines { list-style: none; margin: 0; padding: 0; text-align: left; }

.score-lines li {
  display: grid;
  grid-template-columns: 1fr 90px 42px;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-top: 1px solid #eef3f9;
  font-size: 13px;
  color: #35486a;
  font-weight: 700;
}

.score-lines li:first-child { border-top: 0; }

.score-lines i {
  display: block;
  height: 8px;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, #7fb2f0, #2f6fd0);
}

.score-lines b { text-align: right; color: #6b7c94; font-weight: 800; }

@media (prefers-reduced-motion: no-preference) {
  .score-lines i { transition: width .5s ease; }
}
