/* PHONEME WORLD on the web — the iPad build's look, in CSS.
   Painted cards in a pixel studio: everything drawn by the game is rendered
   nearest-neighbour, and only the paintings are allowed to be smooth. */

:root {
  /* Defaults only. theme.js overwrites these on every theme change, which is
     how SPELLBOI does it: a theme is a handful of variables, not a stylesheet. */
  --ink: #241826;
  --strip: #20141f;
  --tool: #402a3a;
  --fg: #ffffff;
  --cream: #f5ead2;
  --card-ink: #17202e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--fg);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

canvas, img { image-rendering: pixelated; }

button { font: inherit; border: 0; cursor: pointer; }

/* MARK: - the child's screen */

#game {
  display: flex;
  flex-direction: column;
  height: 100svh;
}

/* The room keeps its 320:86 shape whatever the window does. A max-height on the
   box itself squashed it instead — 4.9x across and 3.1x down, which is not
   pixel art any more — so the HEIGHT is the cap and the width follows it. On a
   screen wider than that the band beside it is painted the wall's own colour,
   which is what SpriteKit's aspectFit did with the scene's background. */
#stage {
  flex: none;
  width: 100%;
  background: var(--wall, #241826);
}
#roombox {
  position: relative;
  width: min(100%, calc(38svh * 320 / 86));
  aspect-ratio: 320 / 86;
  margin-inline: auto;
}
#roombox #room { display: block; width: 100%; height: 100%; }

#shelf { position: absolute; inset: 0; pointer-events: none; }
.shelf-art {
  position: absolute;
  top: 0; left: 0;
  object-fit: contain;
  image-rendering: auto;       /* the paintings stay painted */
  transform-origin: center;
}

#play {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 0;
  padding: 10px 16px;
}
#play > canvas { flex: none; }

.headline { margin-bottom: 2px; }

.rack { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; justify-content: center; }
.stack { display: flex; flex-direction: column; align-items: center; gap: 8px; }

/* The one big card. The double edge is the same one the iPad draws: a white
   keyline, then the sound's colour glowing outside it. */
.card {
  position: relative;
  width: var(--size, 300px);
  height: var(--size, 300px);
  max-width: 78vw;
  padding: 10px;
  border-radius: 34px;
  background: var(--cream);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.85),
              0 0 0 11px color-mix(in srgb, var(--glow) 50%, transparent),
              0 10px 26px rgba(0, 0, 0, 0.3);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.card img { width: 100%; height: 100%; object-fit: contain; image-rendering: auto; }
.card img.pixel { image-rendering: pixelated; }
.card.word-only { background: var(--cream); }
.card .speaker { position: absolute; right: 12px; bottom: 10px; font-size: 20px; opacity: 0.45; }
.card.wrong { animation: wobble 0.5s; }
.card.inviting { animation: invite 2.2s ease-in-out infinite; }
.card:active { transform: scale(0.98); }

@keyframes invite { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.02); } }

/* a card arrives rather than appearing: a beat of movement tells a child that
   this is a NEW one, which a straight swap does not */
.card.arriving { animation: arrive 0.34s cubic-bezier(0.2, 0.9, 0.25, 1.1); }
@keyframes arrive {
  0%   { opacity: 0; transform: translateY(14px) scale(0.94); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* the word and the prompt follow it in, a touch later */
#play > canvas { animation: rise 0.34s ease-out; }
.recsay { animation: rise 0.4s ease-out; }
@keyframes rise {
  0%   { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* the chart and the game hand over rather than cutting */
#picker, #game { animation: fadein 0.26s ease-out; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes wobble { 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }

/* MARK: - the grown-up's quiet strip
   Never big enough or bright enough to pull a child's hand towards it. */

#strip {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 22px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--strip);
}
#strip .count { font-size: 15px; color: color-mix(in srgb, var(--fg) 50%, transparent); }
#strip .count b { font-size: 24px; color: var(--fg); margin-right: 4px; }
#strip .midline { flex: 1; text-align: center; font-size: 14px; font-weight: 700; letter-spacing: 0.04em; }
#strip .tools { display: flex; gap: 8px; }

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 62px;
  padding: 7px 8px;
  border-radius: 11px;
  background: var(--tool);
  color: var(--fg);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.tool.live { background: #5a3a50; }
/* recording is the one control that has to be readable across the room */
.tool.theme { letter-spacing: 0; }
.tool:disabled { opacity: 0.4; cursor: default; }

/* MARK: - the tape
   No record button. A line under the card that moves when the child speaks,
   red while a take is running, and the finished take drawn in its place. */

.recorder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.tape {
  width: min(330px, 82vw);
  height: 54px;
  border-radius: 8px;
  image-rendering: auto;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--fg) 14%, transparent);
}
.recorder[data-state="recording"] .tape {
  box-shadow: 0 0 0 2px #e23b2e, 0 0 18px rgba(226, 59, 46, 0.55);
}

/* the microphone's own light: green when it is hearing the room, red while a
   take is running, so a child can see the machine is awake before he speaks */
.recsay {
  font-size: 15px;
  font-weight: 600;
  color: color-mix(in srgb, var(--fg) 70%, transparent);
}
.recsay b { font-weight: 900; color: var(--fg); }
body.mic-live .recsay::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: #5fd35f;
  vertical-align: middle;
}
.recorder[data-state="recording"] .recsay::before { background: #e23b2e; animation: pulse 0.9s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.again {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.06em;
  padding: 5px 12px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--fg) 12%, transparent);
  color: var(--fg);
  visibility: hidden;
}
.recorder[data-state="listen"] .again { visibility: visible; }

/* the microphone switch: only on screen while the microphone is off */
.allow {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.04em;
  padding: 9px 16px;
  border-radius: 12px;
  background: var(--accent, #ffc53d);
  color: #101010;
}
.allow:hover { filter: brightness(1.1); }

/* the start gate: one press, and the browser hands over the microphone */
#start {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--ink) 82%, transparent);
  z-index: 40;
}
.startbtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 26px 54px;
  border-radius: 22px;
  background: var(--accent, #ffc53d);
  color: #101010;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.startbtn span { font-size: 34px; font-weight: 900; letter-spacing: 0.06em; }
.startbtn small { font-size: 12px; font-weight: 700; opacity: 0.72; }
.startbtn:active { transform: scale(0.97); }

/* MARK: - the phonemic chart */

#picker {
  min-height: 100svh;
  padding: 18px 34px max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.positions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }
.pos {
  padding: 9px 16px;
  border-radius: 11px;
  background: color-mix(in srgb, var(--fg) 10%, transparent);
  color: color-mix(in srgb, var(--fg) 80%, transparent);
  font-size: 13px;
  font-weight: 900;
}
.pos.on { background: var(--fg); color: var(--ink); }
.said { font-size: 14px; font-weight: 800; color: #ffc53d; }

.chart { width: 100%; max-width: 1180px; display: flex; flex-direction: column; gap: 12px; }
.group h3 { margin: 0 0 5px; font-size: 11px; font-weight: 900; color: color-mix(in srgb, var(--fg) 40%, transparent); letter-spacing: 0.08em; }
.tiles { display: flex; gap: 12px; flex-wrap: wrap; }

.tile {
  position: relative;
  width: clamp(88px, 12vw, 132px);
  aspect-ratio: 1 / 0.72;
  border-radius: 20px;
  color: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.tile b { font-size: clamp(22px, 3.2vw, 34px); line-height: 1; }
.tile span { font-size: clamp(9px, 1.1vw, 13px); font-weight: 700; opacity: 0.62; }
/* the chart's own convention: a mark for voiced */
.tile.voiced::after {
  content: "";
  position: absolute;
  top: 8px; right: 8px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4);
}
.tile:hover { filter: brightness(1.08); transform: translateY(-1px); }

.foot { font-size: 12px; color: color-mix(in srgb, var(--fg) 35%, transparent); margin: 0; }
.none { color: color-mix(in srgb, var(--fg) 40%, transparent); font-weight: 600; padding-top: 30px; }

/* `hidden` is only a default and every rule here sets `display`, so without
   this the summary's black scrim sat over the chart and the game stacked under
   it. One cause, two symptoms. */
[hidden] { display: none !important; }

/* MARK: - the sheet */

#summary {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  display: grid;
  place-items: center;
  padding: 24px;
}
.sheet { display: flex; flex-direction: column; gap: 14px; align-items: center; max-width: 560px; width: 100%; }
/* the round sheet holds six cards in a row, so it needs the width for them */
.sheet.round { max-width: 940px; }
/* .tools is scoped to the strip, so the sheet's buttons had no row to sit in */
.sheet .tools { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.sheet h2 { margin: 0; font-size: 34px; }
.sheet p { margin: 0; font-size: 20px; font-weight: 600; }
.sheet .rows { width: 100%; max-height: 40svh; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.sheet .row {
  display: flex;
  justify-content: space-between;
  padding: 8px 14px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--fg) 12%, var(--ink));
  font-size: 18px;
  font-weight: 700;
}
.sheet .row b.all { color: #5fd35f; }

/* the end of a round: what he said, in a row, and the stars so far */
.sheet.round { gap: 18px; }
.roundrow { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; max-width: 760px; }
.roundcard {
  width: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  animation: arrive 0.4s backwards;
}
.roundcard:nth-child(2) { animation-delay: 0.07s; }
.roundcard:nth-child(3) { animation-delay: 0.14s; }
.roundcard:nth-child(4) { animation-delay: 0.21s; }
.roundcard:nth-child(5) { animation-delay: 0.28s; }
.roundcard:nth-child(6) { animation-delay: 0.35s; }
.roundcard img {
  width: 96px; height: 96px;
  object-fit: contain;
  border-radius: 14px;
  background: var(--cream);
  padding: 5px;
}
.roundcard span { font-size: 13px; font-weight: 800; color: var(--fg); }

.stars { font-size: 26px; letter-spacing: 4px; color: #ffc53d; text-align: center; }
.stars small { display: block; font-size: 12px; letter-spacing: 0; color: color-mix(in srgb, var(--fg) 55%, transparent); }

/* MARK: - narrow screens
   Last in the file, because a media query placed next to the rules it modifies
   loses to any base rule declared after it. On a phone the strip becomes two
   rows — who and what on top, the grown-up's controls under — instead of one
   row that wraps through itself and pushes DATA off the edge. */

@media (max-width: 760px) {
  #strip {
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 8px;
    padding-inline: 12px;
  }
  #strip .count { order: 1; }
  #strip .midline { order: 2; flex: 1; font-size: 13px; }
  #strip .chip { order: 3; }
  #strip .tools { order: 4; width: 100%; justify-content: center; flex-wrap: wrap; }
  #picker { padding-inline: 16px; }
  .tool { min-width: 52px; padding-inline: 6px; }
  #strip .tools { gap: 6px; }
}
