/* Colours follow the Mr Reyy website: navy and sky blue, on a light ground
   so the game is easy for children to read. */
:root {
  --navy: #0f1422; --navy-2: #1c2a4a; --sky: #86bdf3; --blue: #2d5d9f;
  --bg: #e8f0fa; --card: #ffffff; --line: #cfd9e8; --ink: #0f1422; --muted: #4d586c;
  --good: #1f8a5b; --good-bg: #e3f6ec; --fix: #b25a00; --fix-bg: #fff1dc; --star: #ffc93c;
  --display: "Baloo 2", "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --shadow: 0 10px 24px -16px rgba(15, 20, 34, .45);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 18px/1.5 var(--body); }
h1, h2 { font-family: var(--display); line-height: 1.1; margin: 0; }
p { margin: 0; }
ol, ul { margin: 0; padding: 0; list-style: none; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.noscript { padding: 24px; text-align: center; }
[hidden] { display: none !important; }

main { max-width: 1040px; margin: 0 auto; padding: 0 16px 40px; }
.card { background: var(--card); border-radius: 18px; padding: 20px; box-shadow: var(--shadow); }

/* ---------- buttons and inputs ---------- */
.btn { border: 0; border-radius: 14px; padding: 12px 22px; min-height: 48px; font-weight: 700; background: var(--blue); color: #fff; box-shadow: 0 4px 0 #1d4279; transition: transform .1s, box-shadow .1s; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #1d4279; }
.btn.big { font-family: var(--display); font-size: 22px; padding: 10px 30px; }
.btn.ghost { background: #fff; color: var(--blue); box-shadow: inset 0 0 0 2px var(--blue); }
.in { width: 100%; min-height: 48px; padding: 8px 12px; border: 2px solid var(--line); border-radius: 12px; background: #fff; }
.in:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(45, 93, 159, .2); }
.in.bad { border-color: #e08a1e; background: var(--fix-bg); }
.field-label { display: block; font-weight: 700; margin-bottom: 6px; padding: 0; }

/* ---------- top bar ---------- */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; flex-wrap: wrap; }
.bar-btn { border: 0; background: none; color: var(--blue); font-weight: 700; padding: 10px 4px; min-height: 44px; text-decoration: underline; text-underline-offset: 3px; }
.tag { background: var(--navy-2); color: #fff; font-weight: 700; font-size: 15px; padding: 6px 14px; border-radius: 999px; }

/* ---------- home ---------- */
.home { max-width: 640px; padding-top: 24px; }
.hero { display: flex; align-items: center; gap: 16px; background: var(--navy-2); color: #fff; border-radius: 22px; padding: 20px; margin-bottom: 18px; }
.hero-reyy { flex: 0 0 120px; align-self: flex-end; margin-bottom: -20px; }
.hero-reyy svg { display: block; width: 100%; }
.kicker { color: var(--sky); font-weight: 700; font-size: 15px; text-transform: uppercase; letter-spacing: .08em; }
.hero h1 { font-size: clamp(40px, 9vw, 60px); }
.hero-say { margin-top: 6px; color: #dbe6f6; }
.start { display: grid; gap: 14px; }
.years { display: flex; gap: 10px; flex-wrap: wrap; }
.year-pill { flex: 1 1 90px; position: relative; }
.year-pill input { position: absolute; opacity: 0; inset: 0; }
.year-pill span { display: block; text-align: center; font-weight: 700; padding: 12px; border-radius: 12px; border: 2px solid var(--line); background: #fff; cursor: pointer; }
.year-pill input:checked + span { background: var(--blue); border-color: var(--blue); color: #fff; }
.year-pill input:focus-visible + span { outline: 3px solid var(--blue); outline-offset: 2px; }
.form-msg { color: var(--fix); font-weight: 700; min-height: 1.5em; }
.start .btn { justify-self: start; }

/* ---------- level list ---------- */
.levels { max-width: 640px; }
.levels h1 { font-size: clamp(28px, 6vw, 38px); margin: 6px 0 16px; }
.level-list { display: grid; gap: 12px; }
.level { width: 100%; display: flex; align-items: center; gap: 14px; text-align: left; background: #fff; border: 0; border-radius: 18px; padding: 14px 16px; box-shadow: 0 5px 0 var(--line); transition: transform .1s, box-shadow .1s; }
.level:not(:disabled):active { transform: translateY(3px); box-shadow: 0 2px 0 var(--line); }
.level:disabled { cursor: default; background: #dfe7f2; box-shadow: none; color: var(--muted); }
.level-n { flex: 0 0 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-weight: 800; font-size: 26px; background: var(--sky); color: var(--navy); }
.level:disabled .level-n { background: #c5d0df; }
.level-text { flex: 1; display: grid; }
.level-text strong { font-family: var(--display); font-size: 22px; line-height: 1.2; }
.level-text span { color: var(--muted); font-size: 16px; }
.lock { font-size: 14px; font-weight: 700; }
.stars { font-size: 24px; letter-spacing: 2px; color: #c5d0df; white-space: nowrap; }
.stars .on { color: var(--star); text-shadow: 0 1px 0 #c98f00; }

/* ---------- Mr Reyy ---------- */
.coach { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 8px 14px 8px 8px; margin-bottom: 14px; background: #fff; border-radius: 18px; border: 3px solid var(--line); box-shadow: var(--shadow); min-height: 84px; }
.coach-face { flex: 0 0 68px; height: 68px; border-radius: 50%; background: var(--sky); overflow: hidden; }
.coach-face svg { display: block; width: 100%; height: 100%; }
.coach-bubble { flex: 1; font-weight: 700; line-height: 1.35; }
.coach-bm { margin-top: 4px; font-weight: 400; font-style: italic; }
.coach[data-tone="fix"] { background: var(--fix-bg); border-color: #f0a640; }
.coach[data-tone="fix"] .coach-face { background: #ffd591; }
.coach[data-tone="good"] { background: var(--good-bg); border-color: #56c08d; }
.coach[data-tone="good"] .coach-face { background: #a9e3c5; }
.coach.pop { animation: pop .35s cubic-bezier(.3, 1.5, .5, 1); }
.coach.pop .coach-face { animation: nod .5s ease; }
@keyframes pop { from { transform: scale(.94) translateY(-8px); } to { transform: none; } }
@keyframes nod { 30% { transform: rotate(-9deg); } 65% { transform: rotate(6deg); } }

/* ---------- the board ---------- */
.board { display: grid; gap: 14px; }
.ticket { background: var(--navy-2); color: #fff; border-radius: 18px; padding: 16px; }
.friend { display: flex; gap: 12px; align-items: flex-start; }
.friend svg { flex: 0 0 60px; width: 60px; height: 60px; background: #fff; border-radius: 50%; }
.lead { margin: 12px 0 8px; color: var(--sky); font-weight: 700; }
.bubbles { display: grid; gap: 8px; }
.bubbles li { display: flex; align-items: center; gap: 10px; background: #fff; color: var(--ink); border-radius: 16px 16px 16px 4px; padding: 8px 12px; border: 3px solid transparent; transition: background .2s; }
.bubbles li > span:nth-child(2) { flex: 1; }
.num { flex: 0 0 28px; width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 700; font-size: 16px; background: var(--sky); color: var(--navy); }
.tick { flex: 0 0 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: #dfe7f2; color: transparent; font-weight: 700; }
.bubbles li.now { border-color: var(--star); }
.bubbles li.done { background: var(--good-bg); }
.bubbles li.done .tick { background: var(--good); color: #fff; animation: pop .35s cubic-bezier(.3, 1.5, .5, 1); }
.checks { display: flex; flex-wrap: wrap; gap: 6px 8px; margin-top: 12px; }
.checks li { font-size: 15px; padding: 4px 10px; border-radius: 999px; background: rgba(255, 255, 255, .12); }
.checks li::before { content: "○ "; }
.checks li.done { background: var(--good); font-weight: 700; }
.checks li.done::before { content: "✓ "; }
.target { margin-top: 12px; font-size: 16px; color: #dbe6f6; }

.email { background: #fff; border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; border-bottom: 2px solid #e6ecf4; font-size: 16px; }
.row span:first-child { flex: 0 0 84px; padding: 8px 12px; background: #f1f5fa; color: var(--muted); font-weight: 700; }
.row span:last-child { padding: 8px 12px; overflow-wrap: anywhere; }
.body { padding: 14px; display: grid; gap: 8px; min-height: 120px; align-content: start; }
.slot { border-radius: 12px; padding: 8px 12px; }
.slot.filled { padding: 2px 4px; animation: land .3s ease; }
.slot.wait { border: 2px dashed var(--line); color: #8a96aa; font-size: 15px; }
.slot.now { border: 2px dashed var(--blue); background: #e8f1fc; color: var(--blue); font-weight: 700; animation: glow 1.4s ease-in-out infinite; }
@keyframes land { from { opacity: 0; transform: translateY(8px); } }
@keyframes glow { 50% { background: #d3e5fa; } }

.tray-title { font-family: var(--display); font-weight: 600; font-size: 21px; margin-bottom: 8px; }
.tiles { display: grid; gap: 10px; }
.tile { text-align: left; background: #fff; border: 2px solid var(--navy-2); border-radius: 14px; padding: 10px 14px; min-height: 50px; box-shadow: 0 4px 0 var(--navy-2); transition: transform .1s, box-shadow .1s; }
.tile:not(:disabled):active { transform: translateY(3px); box-shadow: 0 1px 0 var(--navy-2); }
.tile.wrong { border-color: #c5d0df; box-shadow: none; color: #8a96aa; text-decoration: line-through; cursor: default; }
.tile.shake { animation: shake .35s; border-color: #e08a1e; }
@keyframes shake { 20% { transform: translateX(-7px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(4px); } }

/* level 1: the email and its parts stay on screen together, so nobody has
   to scroll up and down to remember what they are looking for */
.play.lv1 { max-width: 1240px; }
.lv1 .slot { padding: 5px 10px; scroll-margin-top: 112px; }
.lv1 .slot.filled { padding: 1px 4px; font-size: 16px; }
.lv1 .slot.over { border-style: solid; border-color: var(--blue); background: #cfe2f9; }
.lv1 .tile { padding: 6px 12px; min-height: 44px; font-size: 16px; line-height: 1.35; user-select: none; -webkit-user-select: none; }
.lv1 .tray-title { margin-bottom: 0; }
.lv1 .tray-title strong { color: var(--blue); }
.tray-help { font-size: 15px; color: var(--muted); margin-bottom: 8px; }
.wide-only { display: none; }
.tile.ghost { position: fixed; z-index: 50; margin: 0; pointer-events: none; transform: rotate(-2deg); box-shadow: 0 16px 30px -12px rgba(15, 20, 34, .55); }
.tile.lifted { opacity: .3; }
@media (max-width: 759px) {
  /* phone: the parts sit in a panel fixed to the bottom of the screen */
  .lv1 .tray { position: sticky; bottom: 0; z-index: 9; margin: 0 -16px -40px; padding: 10px 16px 14px; max-height: 46vh; overflow-y: auto; background: #fff; border-radius: 18px 18px 0 0; box-shadow: 0 -10px 24px -12px rgba(15, 20, 34, .5); }
}
@media (min-width: 760px) {
  /* tablet and computer: email on the left, parts on the right, and dragging works */
  .lv1 .board { grid-template-columns: 1fr 1fr; grid-template-areas: "ticket ticket" "email tray"; align-items: start; }
  .lv1 .ticket { grid-area: ticket; }
  .lv1 .email { grid-area: email; }
  .lv1 .tray { grid-area: tray; }
  .lv1 .bubbles { grid-template-columns: repeat(3, 1fr); }
  .lv1 .tile { touch-action: none; cursor: grab; }
  .wide-only { display: inline; }
}
@media (min-width: 1000px) {
  .lv1 .board { grid-template-columns: 300px 1fr 1fr; grid-template-areas: "ticket email tray"; }
  .lv1 .bubbles { grid-template-columns: 1fr; gap: 6px; }
  .lv1 .ticket { padding: 12px; font-size: 16px; line-height: 1.4; }
  .lv1 .friend svg { flex-basis: 48px; width: 48px; height: 48px; }
  .lv1 .lead { margin: 8px 0 6px; }
  .lv1 .bubbles li { padding: 5px 10px; }
  .lv1 .bar { padding: 6px 0; }
  .lv1 .coach { min-height: 76px; margin-bottom: 10px; }
}

/* level 3 */
.fill { display: grid; gap: 10px; }
.in.short { max-width: 240px; }
.frow { display: grid; gap: 4px; }
.frow label { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.given { padding: 2px 4px; }

/* levels 4 and 5: the writing box lies on top of an invisible copy of its
   text (.hl-back), and only the orange marks in that copy show through */
.hl { position: relative; background: #fff; border-radius: 12px; }
.hl-back, textarea { margin: 0; padding: 12px; border: 2px solid transparent; border-radius: 12px; font: inherit; line-height: 1.7; letter-spacing: normal; white-space: pre-wrap; overflow-wrap: break-word; }
.hl-back { position: absolute; inset: 0; color: transparent; overflow: hidden; pointer-events: none; }
textarea { position: relative; display: block; width: 100%; min-height: 240px; border-color: var(--line); background: transparent; resize: none; overflow: hidden; }
mark { background: #ffd591; color: inherit; border-radius: 4px; box-shadow: 0 2px 0 #e08a1e; }
.hl-back mark { color: transparent; }
.hl-key { font-size: 15px; color: var(--muted); }
.hl-key.in-email { padding: 0 14px 14px; }

.meter-track { position: relative; height: 16px; border-radius: 999px; background: #d5deeb; overflow: hidden; }
.meter-zone { position: absolute; top: 0; bottom: 0; left: 50%; width: 33.34%; background: #b5e3c9; }
.meter-fill { position: absolute; top: 0; bottom: 0; left: 0; width: 0; border-radius: 999px; background: #e08a1e; opacity: .9; transition: width .25s; }
.meter[data-state="good"] .meter-fill { background: var(--good); }
.meter-text { margin-top: 4px; font-weight: 700; font-size: 16px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 14px; }
.actions.center { justify-content: center; margin-top: 22px; }
.sure { flex: 1 1 100%; font-weight: 700; }

/* ---------- result ---------- */
.result-top { display: flex; align-items: center; gap: 16px; background: var(--navy-2); color: #fff; border-radius: 22px; padding: 18px 20px; margin-bottom: 16px; }
.result-reyy { flex: 0 0 110px; }
.result-reyy svg { display: block; width: 100%; }
.sent { font-family: var(--display); font-weight: 800; font-size: clamp(30px, 7vw, 42px); line-height: 1.1; }
.result-top .stars { font-size: 40px; color: #44557a; }
.result-top .stars .on { animation: pop .5s cubic-bezier(.3, 1.6, .5, 1) backwards; display: inline-block; }
.result-top .stars .on:nth-child(2) { animation-delay: .2s; }
.result-top .stars .on:nth-child(3) { animation-delay: .4s; }
.result-say { color: #dbe6f6; }
.result-grid { display: grid; gap: 14px; }
.result h2 { font-size: 24px; margin-bottom: 10px; }
.notes { display: grid; gap: 8px; }
.notes li { display: grid; gap: 2px; padding: 8px 12px 8px 40px; border-radius: 12px; position: relative; }
.notes li::before { position: absolute; left: 12px; top: 8px; font-weight: 700; }
.notes li.ok { background: var(--good-bg); }
.notes li.ok::before { content: "✓"; color: var(--good); }
.notes li.no { background: var(--fix-bg); }
.notes li.no::before { content: "!"; color: var(--fix); }
.notes li span { font-size: 16px; }
.sent-body { display: block; line-height: 1.7; overflow-wrap: anywhere; }

/* AI feedback card */
.ai { display: grid; gap: 10px; }
.ai h2 { margin: 0; }
.ai h3 { font-family: var(--display); font-size: 19px; margin: 6px 0 0; }
.ai-wait { color: var(--muted); }
.ai-scores { display: flex; gap: 10px; flex-wrap: wrap; }
.ai-scores p { flex: 1 1 120px; background: var(--navy-2); color: #fff; border-radius: 14px; padding: 10px 14px; }
.ai-scores strong { font-family: var(--display); font-size: 32px; line-height: 1; }
.ai-scores span { display: block; color: var(--sky); font-weight: 700; font-size: 15px; }
.ai-est, .ai-left { font-size: 15px; color: var(--muted); }
.ai-good { background: var(--good-bg); border-radius: 12px; padding: 8px 12px; }
.ai-list { display: grid; gap: 6px; padding-left: 22px; list-style: disc; }
.ai-fix { display: grid; gap: 8px; }
.ai-fix li { background: var(--fix-bg); border-radius: 12px; padding: 8px 12px; }
.ai-fix li p + p { font-size: 16px; }

@media (min-width: 860px) {
  .board { grid-template-columns: 340px 1fr; align-items: start; }
  .play:not(.lv1) .ticket { grid-row: span 2; }
  .result-grid { grid-template-columns: 1fr 1fr; align-items: start; }
  .ai { grid-column: 1 / -1; }
  .lv2 .tiles { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  body { font-size: 17px; }
  .hero-reyy { flex-basis: 92px; }
  .result-reyy { flex-basis: 84px; }
  .coach-face { flex-basis: 56px; height: 56px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
