/* Corlane – the page around the game. Same notebook palette as the storybook. */

/* Layout: a header bar, then the 16:9 stage centred on the desk. Touch buttons sit below the
   stage in portrait and over its lower corners in landscape. The title and end cards cover the desk. */

/* Sofía's handwriting, which handwriting/sofia_font.py builds from her sample sheets. Her small letters
   fill a third of the line, as in her exercise book, so size-adjust makes them as tall as other fonts'
   small letters, and the line metrics are Shantell Sans's. It has one weight, her pen's, so it is never
   made bold. */
@font-face {
  font-family: "Sofias Schrift";
  src: url("fonts/sofias-schrift.woff2") format("woff2"), url("fonts/sofias-schrift.ttf") format("truetype");
  font-weight: 100 900;
  size-adjust: 143%;
  ascent-override: 71%;
  descent-override: 22%;
  line-gap-override: 0%;
}

:root {
  --desk: #e6ebf1;
  --desk-ink: #1d2433;
  --desk-muted: #586275;
  --desk-line: rgb(29 36 51 / 0.14);
  --chip: rgb(255 255 255 / 0.72);
  --brand: #b3142c;
  --on-brand: #ffffff;
  --shadow: rgb(16 22 36 / 0.3);
  --veil: rgb(230 235 241 / 0.55);
  /* the notebook itself stays paper-white in both themes */
  --paper: #fdfdfc;
  --paper-ink: #262b3c;
  --paper-muted: #5d6475;
  --paper-red: #b3142c;
  --paper-red-dark: #7d0d1f;
  --grid: rgb(60 125 195 / 0.17);
  --margin: rgb(221 68 68 / 0.55);
  --sticky: #fff1a1;
  --marker: rgb(255 230 64 / 0.75);
  --pad: rgb(253 253 252 / 0.86);
  --pad-ink: #262b3c;
  --pad-line: rgb(38 43 60 / 0.55);
  --font-display: "Shantell Sans", "Chalkboard SE", "Segoe Print", "Comic Sans MS", cursive;
  --font-body: "Andika", "Verdana", "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --desk: #13151c;
    --desk-ink: #e4e7ef;
    --desk-muted: #9ba3b5;
    --desk-line: rgb(228 231 239 / 0.15);
    --chip: rgb(255 255 255 / 0.06);
    --brand: #f0566b;
    --on-brand: #1c0a0e;
    --shadow: rgb(0 0 0 / 0.6);
    --veil: rgb(19 21 28 / 0.55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --desk: #13151c;
  --desk-ink: #e4e7ef;
  --desk-muted: #9ba3b5;
  --desk-line: rgb(228 231 239 / 0.15);
  --chip: rgb(255 255 255 / 0.06);
  --brand: #f0566b;
  --on-brand: #1c0a0e;
  --shadow: rgb(0 0 0 / 0.6);
  --veil: rgb(19 21 28 / 0.55);
  color-scheme: dark;
}

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--desk);
  color: var(--desk-ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
button:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
}

/* header */
.bar {
  padding-block: 8px 6px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.bar-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 26px;
  line-height: 1;
  color: var(--brand);
}
.brand-sub {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--desk-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tools { display: flex; align-items: center; gap: 8px; }
.lang {
  display: flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--chip);
  border: 1px solid var(--desk-line);
}
.lang button {
  min-width: 40px;
  height: 32px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.lang button[aria-pressed="true"] { background: var(--desk-ink); color: var(--desk); }
.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--desk-line);
  background: var(--chip);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.tool svg { width: 20px; height: 20px; flex: none; }
#sound .cross { display: none; }
#sound[aria-pressed="false"] .cross { display: inline; }
#sound[aria-pressed="false"] .waves { display: none; }
@media (max-width: 640px) {
  .tool-label { display: none; }
  .tool { padding: 0 9px; }
  .brand-name { font-size: 22px; }
  .brand-sub { font-size: 14px; }
}
@media (max-width: 420px) {
  .brand-sub { display: none; }
}
/* phones held sideways: every pixel of height goes to the stage */
@media (max-height: 500px) {
  .bar { padding-block: 4px 2px; }
  .tool { height: 32px; }
  .lang button { height: 26px; }
}

/* the desk and the stage */
.desk {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  container-type: size;
  padding-block: 4px 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  /* the game is written in Sofía's handwriting; the bar above it keeps the page's fonts */
  --font-display: "Sofias Schrift", "Shantell Sans", "Chalkboard SE", "Segoe Print", "Comic Sans MS", cursive;
  --font-body: "Sofias Schrift", "Andika", "Verdana", "Segoe UI", sans-serif;
  font-family: var(--font-body);
}
.stage-box {
  container-type: size;
  min-height: 0;
  display: grid;
  place-items: center;
}
.stage {
  position: relative;
  width: min(100cqw, 100cqh * 16 / 9);
  max-width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 14px 34px -16px var(--shadow), 0 0 0 1px var(--desk-line);
  container-type: inline-size;
  outline: none;
}
#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* the goal, on a sticky note in the corner of the page */
.note {
  position: absolute;
  top: 2cqw;
  right: 2cqw;
  max-width: 34cqw;
  margin: 0;
  padding: 0.8em 1em 0.9em;
  background: var(--sticky);
  color: var(--paper-ink);
  font-family: var(--font-display);
  font-size: clamp(10px, 1.7cqw, 17px);
  font-weight: 600;
  line-height: 1.28;
  border-radius: 2px 2px 12px 2px;
  box-shadow: 0 8px 14px -8px rgb(0 0 0 / 0.4);
  transform: rotate(1.3deg);
  text-wrap: pretty;
  pointer-events: none;
}
.note small {
  display: block;
  margin-top: 0.45em;
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 0.82em;
  color: var(--paper-muted);
}
.note small:empty { display: none; }
.note.bump { animation: bump 0.6s ease-out; }
/* on a small stage the note keeps to the goal; the controls are on the title card */
@container (max-width: 480px) {
  .note { max-width: 46cqw; padding: 0.5em 0.7em 0.6em; }
  .note small { display: none; }
}
@keyframes bump {
  0% { transform: rotate(1.3deg) scale(1); }
  35% { transform: rotate(-1deg) scale(1.08); }
  100% { transform: rotate(1.3deg) scale(1); }
}

/* the music lock's piano, in the sticky note's place while it's open so it never hides Corlane at the door */
.piano {
  position: absolute;
  top: 2cqw;
  right: 2cqw;
  display: grid;
  gap: 0.55em;
  padding: 0.65em 0.9em 0.85em;
  background: var(--paper);
  color: var(--paper-ink);
  border: 2px solid var(--paper-ink);
  border-radius: 14px;
  box-shadow: 0 10px 20px -10px rgb(0 0 0 / 0.45);
  font-size: clamp(10px, 1.55cqw, 16px);
}
.piano-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
  font-family: var(--font-display);
  font-weight: 700;
}
.piano-head button {
  padding: 0.25em 0.8em;
  border-radius: 999px;
  border: 1.5px solid var(--paper-ink);
  background: var(--sticky);
  color: var(--paper-ink);
  font-family: var(--font-display);
  font-size: 0.85em;
  font-weight: 600;
  cursor: pointer;
}
.melody {
  display: flex;
  justify-content: center;
  gap: 0.45em;
  margin: 0;
  padding: 0;
  list-style: none;
}
.melody li {
  width: 1.9em;
  height: 1.9em;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--paper-ink);
  background: var(--paper);
  color: var(--k);
  font-size: 0.95em;
  line-height: 1;
  transition: transform 0.12s;
}
.melody li.lit { background: var(--k); color: var(--paper); transform: scale(1.18); }
.melody li.done { background: var(--k); color: var(--paper); }
.melody.wrong li { animation: shake 0.35s; }
@keyframes shake {
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
.keys { display: flex; gap: 0.4em; }
.keys button {
  width: 3.3em;
  height: 4.6em;
  display: grid;
  grid-template-rows: 1fr auto;
  justify-items: center;
  align-items: center;
  padding: 0.3em 0 0.35em;
  border: 2px solid var(--paper-ink);
  border-radius: 0 0 10px 10px;
  background: var(--paper);
  color: var(--paper-ink);
  font-family: var(--font-display);
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.keys .mark { color: var(--k); font-size: 1.45em; line-height: 1; }
.keys .num { font-size: 0.75em; color: var(--paper-muted); }
.keys button.lit { background: var(--k); }
.keys button.lit .mark, .keys button.lit .num { color: var(--paper); }

.turn-hint {
  margin: 8px 0 0;
  text-align: center;
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--desk-muted);
}

/* touch buttons */
.pad {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  padding-top: 12px;
  pointer-events: none;
}
.pad-group { display: flex; align-items: flex-end; gap: 12px; pointer-events: auto; }
.pad button {
  width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--pad-line);
  background: var(--pad);
  color: var(--pad-ink);
  box-shadow: 0 6px 14px -8px rgb(0 0 0 / 0.5);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}
.pad button svg { width: 30px; height: 30px; }
#pad-fly { width: 82px; height: 82px; }
#pad-fly svg { width: 44px; height: 34px; }
.pad button.on { background: var(--sticky); transform: scale(0.95); }
#pad-act.cool { opacity: 0.45; }
@media (orientation: landscape) {
  .pad {
    position: absolute;
    left: max(16px, env(safe-area-inset-left, 0px));
    right: max(16px, env(safe-area-inset-right, 0px));
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    padding: 0;
  }
  .pad button { background: rgb(253 253 252 / 0.72); }
}

/* title and end cards */
.screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px max(16px, env(safe-area-inset-right, 0px)) 12px max(16px, env(safe-area-inset-left, 0px));
  background: var(--veil);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 5;
}
.card {
  position: relative;
  box-sizing: border-box;
  width: min(620px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 1.3em 1.6em 1.2em 3.1em;
  border-radius: 6px;
  color: var(--paper-ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 22px 22px;
  box-shadow: 0 20px 40px -18px rgb(0 0 0 / 0.45);
  font-size: clamp(13px, min(2.4cqw, 3.4cqh), 17px);
  text-align: left;
}
.card::before {
  content: "";
  position: absolute;
  left: 1.75em;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--margin);
}
.kicker {
  margin: 0 0 0.3em;
  font-family: var(--font-body);
  font-size: 0.85em;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--paper-muted);
}
.card h1, .card h2 {
  margin: 0 0 0.35em;
  font-family: var(--font-display);
  font-weight: 800;
  line-height: 1.02;
  color: var(--paper-red);
  text-wrap: balance;
}
.card h1 { font-size: 2.7em; }
.card h2 { font-size: 2.4em; }
.card h1 span {
  display: inline-block;
  padding: 0 0.2em;
  background: var(--marker);
  color: var(--paper-ink);
  transform: rotate(-3deg);
}
.card h1 b { display: block; font-weight: 800; margin-top: 0.1em; }
.intro { margin: 0 0 1em; font-size: 1.12em; line-height: 1.42; max-width: 34em; }
.help { margin: 1em 0 0.2em; color: var(--paper-muted); font-size: 0.92em; line-height: 1.4; }
.byline { margin: 0.6em 0 0; font-family: var(--font-display); color: var(--paper-muted); font-size: 0.9em; }
.big {
  padding: 0.38em 1.5em 0.42em;
  border: 0;
  border-radius: 999px;
  background: var(--paper-red);
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.45em;
  font-weight: 800;
  box-shadow: 0 4px 0 var(--paper-red-dark);
  cursor: pointer;
}
.big:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--paper-red-dark); }
.cast {
  display: flex;
  align-items: flex-end;
  gap: 0.6em;
  height: 6.5em;
  margin: 0.2em 0 0.8em;
}
.cast img { height: 100%; width: auto; filter: drop-shadow(0 3px 3px rgb(0 0 0 / 0.18)); }
.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6em 1.6em;
  margin: 0 0 1em;
}
.stats div { display: grid; gap: 0.1em; }
.stats dt { font-size: 0.85em; color: var(--paper-muted); }
.stats dd { margin: 0; font-family: var(--font-display); font-size: 1.5em; font-weight: 800; font-variant-numeric: tabular-nums; }

.buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6em 0.8em; }
.soft {
  padding: 0.45em 1.2em 0.5em;
  border: 2px solid var(--paper-ink);
  border-radius: 999px;
  background: var(--paper);
  color: var(--paper-ink);
  font-family: var(--font-display);
  font-size: 1.05em;
  font-weight: 700;
  cursor: pointer;
}
.soft:active { transform: translateY(1px); }
.quote small { display: block; margin-top: 0.3em; font-size: 0.72em; color: var(--paper-muted); }

/* the chapter map: Corlane's diary, one tile per chapter with one of Sofía's drawings */
.map-card { width: min(900px, 100%); }
.close {
  position: absolute;
  top: 0.4em;
  right: 0.5em;
  width: 2em;
  height: 2em;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--paper-ink);
  font-size: 1.4em;
  line-height: 1;
  cursor: pointer;
}
.chapters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.6em, 1fr));
  gap: 0.8em;
  margin: 0;
  padding: 0;
  list-style: none;
}
.chapter {
  position: relative;
  width: 100%;
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 0.15em;
  padding: 0.45em 0.45em 0.6em;
  border: 2px solid var(--paper-ink);
  border-radius: 10px;
  background: var(--paper);
  color: var(--paper-ink);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 3px 0 rgb(38 43 60 / 0.25);
}
.chapter:hover { background: #fffbe0; }
.chapter img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--desk-line);
  background: #fff;
}
.chapter .num { font-size: 0.78em; font-weight: 700; color: var(--paper-muted); letter-spacing: 0.04em; text-transform: uppercase; }
.chapter .name { font-family: var(--font-display); font-weight: 800; font-size: 1.02em; line-height: 1.1; color: var(--paper-red); }
.chapter .check {
  position: absolute;
  top: 0.3em;
  right: 0.3em;
  width: 1.6em;
  height: 1.6em;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #4fae5b;
  color: #fff;
  font-weight: 800;
  border: 2px solid var(--paper-ink);
}

/* the worksheet in chapter 2: a sheet of squared paper over the classroom */
.sheet {
  position: absolute;
  inset: 3.5cqh 9cqw;
  display: flex;
  flex-direction: column;
  gap: 0.55em;
  padding: 0.9em 1.3em 1em;
  overflow: auto;
  background-color: var(--paper);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 1.4em 1.4em;
  color: var(--paper-ink);
  border: 2px solid var(--paper-ink);
  border-radius: 10px;
  box-shadow: 0 12px 24px -12px rgb(0 0 0 / 0.5);
  font-family: var(--font-body);
  font-size: clamp(11px, 1.65cqw, 18px);
  transform: rotate(-0.5deg);
}
.sheet p { margin: 0; }
.sheet-head { font-family: var(--font-display); font-weight: 800; font-size: 1.35em; }
.sheet-task {
  font-family: var(--font-display);
  font-size: 1.15em;
  line-height: 1.4;
  padding: 0.35em 0.6em;
  background: var(--marker);
  border-radius: 4px;
  align-self: flex-start;
}
.sheet-ask { font-weight: 700; }
.sheet-juices { display: flex; flex-wrap: wrap; gap: 0.45em; }
.sheet-juices button {
  display: grid;
  justify-items: center;
  gap: 0.15em;
  width: 3.4em;
  padding: 0.3em 0 0.25em;
  border: 1.5px dashed var(--paper-ink);
  border-radius: 8px;
  background: rgb(255 255 255 / 0.7);
  color: var(--paper-ink);
  font: 700 0.8em var(--font-body);
  cursor: pointer;
}
.sheet-juices button svg { width: 1.8em; height: 2.3em; }
.sheet-juices button.bought { border-style: solid; background: #fff1d6; }
.sheet-juices button:disabled { cursor: default; }
.sheet-sum { font-weight: 700; font-size: 1.1em; }
.sheet-choices { display: flex; flex-wrap: wrap; gap: 0.5em; }
.sheet-choices button {
  padding: 0.35em 1em;
  border: 2px solid var(--paper-ink);
  border-radius: 999px;
  background: var(--sticky);
  color: var(--paper-ink);
  font: 700 1em var(--font-display);
  cursor: pointer;
}
.sheet-choices button.go { background: var(--paper-red); border-color: var(--paper-red-dark); color: #fff; }
.sheet-reply { font-weight: 700; min-height: 1.3em; }
.sheet-reply.right { color: #2c7a3a; }
.sheet-reply.wrong { color: var(--paper-red); }

/* a story card: her drawing beside a few lines of the book */
.story-card {
  width: min(880px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  align-items: center;
  gap: 1.2em;
}
.story-card img {
  width: 100%;
  max-height: min(62cqh, 30em);
  object-fit: contain;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 6px 16px -10px rgb(0 0 0 / 0.5);
  transform: rotate(-1.2deg);
}
.story-card img[hidden] + .story-words { grid-column: 1 / -1; }
.story-card:has(> img[hidden]) { width: min(640px, 100%); }
.story-text p { margin: 0 0 0.7em; font-size: 1.12em; line-height: 1.45; text-wrap: pretty; }
.story-words .big { margin-top: 0.3em; }
@container (max-width: 640px) {
  .story-card { grid-template-columns: minmax(0, 1fr); gap: 0.7em; }
  .story-card img { max-height: 34cqh; }
}

@media (prefers-reduced-motion: reduce) {
  .note.bump, .melody.wrong li { animation: none; }
}

/* The page shows and hides its parts with the hidden attribute; keep that stronger than the display rules above. */
[hidden] { display: none !important; }
