/* ---------- Шрифты (лежат в папке fonts, интернет не нужен) ---------- */
@font-face { font-family: "Nunito"; font-weight: 400; src: url("fonts/nunito-cyrillic-400-normal.woff2") format("woff2"); unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Nunito"; font-weight: 400; src: url("fonts/nunito-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Nunito"; font-weight: 700; src: url("fonts/nunito-cyrillic-700-normal.woff2") format("woff2"); unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Nunito"; font-weight: 700; src: url("fonts/nunito-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Nunito"; font-weight: 800; src: url("fonts/nunito-cyrillic-800-normal.woff2") format("woff2"); unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Nunito"; font-weight: 800; src: url("fonts/nunito-latin-800-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Rubik"; font-weight: 700; src: url("fonts/rubik-cyrillic-700-normal.woff2") format("woff2"); unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Rubik"; font-weight: 700; src: url("fonts/rubik-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Rubik"; font-weight: 800; src: url("fonts/rubik-cyrillic-800-normal.woff2") format("woff2"); unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Rubik"; font-weight: 800; src: url("fonts/rubik-latin-800-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }


/* ---------- Цвета ---------- */
:root {
  --night: #1B2F5C;
  --night2: #2B4C8C;
  --paper: #FFFDF6;
  --card: #FFFFFF;
  --ink: #23304A;
  --soft: #66738A;
  --line: #DCE4EE;
  --red: #D63C3C;
  --red-dark: #A82A2A;
  --red-light: #FDEAEA;
  --green: #2E9B5F;
  --green-light: #E2F4EA;
  --gold: #F2B33D;
  --gold-light: #FFF4D6;
  --blue: #2F63B5;
  --blue-light: #E7F0FB;
  --wood: #C8925A;
  --wood-dark: #9B6A3A;
  --wood-light: #E8C79C;
  --shadow: 0 6px 0 rgba(0,0,0,.08), 0 18px 40px rgba(0,0,0,.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  font-family: "Nunito", "Segoe UI", Arial, sans-serif; color: var(--ink);
  background: radial-gradient(ellipse at 50% 0%, var(--night2) 0%, var(--night) 70%) fixed, var(--night);
  font-size: clamp(15px, min(1.15vw, 2.1vh), 21px); line-height: 1.4; overflow-x: hidden;
}
h1, h2, h3, .btn, .badge, .pill, .letter-from, .dot, .mail-num, .store-head h3, .dip-top { font-family: "Rubik", "Nunito", sans-serif; }

.screen { display: none; min-height: 100vh; padding: clamp(10px, 2vh, 28px) clamp(12px, 2vw, 32px); position: relative; z-index: 1; }
.screen.active { display: flex; flex-direction: column; animation: fade .35s ease; }
.hidden { display: none !important; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Снег ---------- */
.snow { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.flake { position: absolute; top: -20px; border-radius: 50%; background: #fff; opacity: .8; animation: fall linear infinite; }
@keyframes fall { to { transform: translate(var(--drift), 110vh); } }
@media (prefers-reduced-motion: reduce) { .flake { display: none; } }

/* ---------- Кнопки ---------- */
.btn { border: 2px solid transparent; cursor: pointer; font-weight: 700; font-size: 1em; padding: .7em 1.3em; border-radius: 16px; transition: transform .12s, box-shadow .12s, background .2s; white-space: nowrap; }
.btn:active { transform: translateY(3px); }
.btn-primary { background: var(--red); color: #fff; box-shadow: 0 5px 0 var(--red-dark); }
.btn-primary:hover { background: #E04A4A; }
.btn-primary:active { box-shadow: 0 2px 0 var(--red-dark); }
.btn-secondary { background: #fff; color: var(--red); border-color: var(--line); box-shadow: 0 5px 0 var(--line); }
.btn-green { background: var(--green); color: #fff; box-shadow: 0 5px 0 #1F7546; }
.btn-big { font-size: 1.2em; padding: .8em 1.8em; }
.icon-btn { background: rgba(255,255,255,.95); border: none; border-radius: 12px; width: 2.4em; height: 2.4em; font-size: 1em; cursor: pointer; }
.badge { display: inline-block; background: var(--gold-light); color: #8A5A00; font-weight: 700; font-size: .85em; padding: .35em .9em; border-radius: 999px; margin-bottom: .6em; }

/* ---------- Обложка ---------- */
#screen-start { align-items: center; justify-content: center; }
.cover { position: relative; max-width: 1400px; width: 100%; background: var(--paper); border-radius: 0 0 32px 32px; box-shadow: var(--shadow);
  display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 24px; align-items: center; padding: clamp(24px, min(4vw, 6vh), 64px); overflow: hidden;
  border-top: 14px solid; border-image: repeating-linear-gradient(90deg, var(--red) 0 40px, #fff 40px 60px, var(--blue) 60px 100px, #fff 100px 120px) 14; }
h1 { font-size: clamp(30px, min(3.6vw, 6.6vh), 66px); font-weight: 800; line-height: 1.08; color: var(--red); margin-bottom: .4em; }
.lead { font-size: 1.1em; color: var(--soft); margin-bottom: 1em; }
.cover-tagline { font-size: clamp(17px, 1.5vw, 24px); font-weight: 700; line-height: 1.35; color: var(--ink); margin-bottom: .9em; }
.how { list-style: none; display: grid; gap: .5em; margin-bottom: 1.5em; }
.how li { display: flex; align-items: center; gap: .7em; font-weight: 700; }
.how-num { flex: none; width: 1.9em; height: 1.9em; border-radius: 50%; background: var(--red-light); color: var(--red); display: grid; place-items: center; font-family: "Rubik"; }
.start-actions { display: flex; gap: 14px; flex-wrap: wrap; align-items: stretch; }
.start-actions .btn { font-size: 1.1em; padding: .8em 1.6em; }
@media (max-width: 600px) { .start-actions .btn { white-space: normal; flex: 1 1 100%; } }
.save-note { margin-top: 1em; font-size: .85em; color: var(--soft); }
.save-note::before { content: "💾 "; }
.teacher-link { display: inline-block; margin-left: 10px; padding: 3px 0; background: none; border: 0; border-bottom: 1px dotted currentColor; color: #00777b; font: inherit; font-weight: 700; cursor: pointer; }
.teacher-link:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.guide-modal { width: min(1100px, 96vw); height: min(880px, 94vh); height: min(880px, 94dvh); max-width: none; max-height: none; padding: 0; border: 0; border-radius: 20px; margin: auto; background: #eaf1f4; color: var(--ink); box-shadow: 0 20px 80px #0006; }
.guide-modal[open] { display: flex; flex-direction: column; }
.guide-modal::backdrop { background: #0a142db3; }
.guide-modal-head { flex: none; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 18px; background: white; border-bottom: 1px solid #d9e5e9; }
.guide-modal-head h2 { font-size: clamp(16px, 2vw, 22px); }
.guide-modal-head .btn { font-size: 13px; padding: 8px 12px; }
.guide-modal iframe { display: block; width: 100%; flex: 1; min-height: 0; border: 0; background: white; }
.cover-ded { display: flex; justify-content: center; }
.cover-ded img { max-height: min(62vh, 560px); max-width: 100%; animation: bob 4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-10px); } }

/* ---------- Верхняя панель ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: clamp(8px, 1.6vh, 18px); }
.progress { display: flex; gap: 6px; flex-wrap: wrap; }
.dot { width: 2.1em; height: 2.1em; border-radius: 50%; background: rgba(255,255,255,.15); border: 2px solid rgba(255,255,255,.35); color: #fff; display: grid; place-items: center; font-size: .78em; font-weight: 700; overflow: hidden; }
.dot.current { background: #fff; color: var(--red); border-color: #fff; transform: scale(1.12); }
.dot.done { background: #fff; border-color: var(--gold); padding: 2px; }
.dot.done img { width: 100%; height: 100%; object-fit: contain; }
.topbar-right { display: flex; gap: 10px; align-items: center; }
.pill { background: rgba(255,255,255,.95); border: none; border-radius: 12px; padding: .35em .8em; font-weight: 700; white-space: nowrap; font-size: 1em; color: var(--ink); }
.pill-btn { cursor: pointer; }
.pill.bump { animation: bump .5s; }
@keyframes bump { 40% { transform: scale(1.25); } }

/* ---------- Сцены ---------- */
.stage { flex: 1; width: 100%; max-width: 1600px; margin: 0 auto; }

/* Пришло письмо */
#stage-mail { display: flex; align-items: center; justify-content: center; }
.mailbox-wrap { background: var(--paper); border-radius: 30px; box-shadow: var(--shadow); padding: clamp(24px, 4vh, 56px) clamp(24px, 4vw, 64px); display: grid; grid-template-columns: auto 1fr; gap: clamp(24px, 4vw, 64px); align-items: center; max-width: 1100px; width: 100%; }
.envelope { position: relative; width: clamp(240px, 26vw, 420px); aspect-ratio: 1.6; background: #F6E7C8; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.2); animation: arrive .8s cubic-bezier(.3,1.4,.5,1); overflow: hidden;
  border: 8px solid; border-image: repeating-linear-gradient(135deg, var(--red) 0 14px, #fff 14px 24px, var(--blue) 24px 38px, #fff 38px 48px) 8; }
@keyframes arrive { from { transform: translate(-60px, -40px) rotate(-14deg); opacity: 0; } to { transform: none; opacity: 1; } }
.env-flap { position: absolute; left: 0; right: 0; top: 0; height: 55%; background: linear-gradient(to bottom right, transparent 49.5%, #EAD4A8 50%) left / 50% 100% no-repeat, linear-gradient(to bottom left, transparent 49.5%, #EAD4A8 50%) right / 50% 100% no-repeat; transform: scaleY(-1); transform-origin: top; opacity: .9; }
.env-stamp { position: absolute; right: 6%; top: 8%; width: 18%; aspect-ratio: .85; background: #fff; border: 3px dashed var(--red); display: grid; place-items: center; color: var(--blue); font-size: 1.6em; }
.env-to { position: absolute; right: 8%; bottom: 12%; text-align: right; font-weight: 800; font-size: 1em; color: var(--ink); }
.env-to small { font-weight: 600; color: var(--soft); }
.env-from { position: absolute; left: 8%; top: 12%; font-family: "Rubik"; font-weight: 700; color: var(--red); font-size: 1.05em; }
.mail-num { color: var(--red); font-weight: 700; font-size: .9em; margin-bottom: .3em; }
.mail-text h2 { font-size: clamp(26px, 2.6vw, 46px); line-height: 1.1; margin-bottom: .5em; }
.mail-hint { background: var(--blue-light); color: #1D4A8F; font-weight: 700; padding: .6em 1em; border-radius: 14px; margin-bottom: 1.2em; }
.mail-hint::before { content: "✨ "; }
.mail-note { margin-top: .9em; color: var(--soft); font-size: .85em; }

/* Письмо + кладовая */
#stage-letter { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(14px, 2vw, 32px); align-items: start; }
#stage-letter.reading { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.letter-col { display: flex; flex-direction: column; gap: 12px; }
.letter { background: var(--paper); border-radius: 0 0 24px 24px; box-shadow: var(--shadow); padding: clamp(16px, 2.2vw, 34px); position: relative;
  border-top: 10px solid; border-image: repeating-linear-gradient(90deg, var(--red) 0 30px, #fff 30px 44px, var(--blue) 44px 74px, #fff 74px 88px) 10; }
.letter-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: .8em; }
.letter-from { font-weight: 700; color: var(--red); font-size: 1.15em; }
.letter-mech { background: var(--blue-light); color: #1D4A8F; font-weight: 700; font-size: .8em; padding: .35em .8em; border-radius: 999px; }
.letter-body { overflow: hidden; }
.letter-text { position: relative; font-size: clamp(19px, min(1.6vw, 3vh), 30px); line-height: 2; font-weight: 600; color: #2A2F3A; word-break: break-word; }
#stage-letter:not(.reading) .letter-text { font-size: clamp(16px, min(1.25vw, 2.4vh), 24px); }
.letter-text .gap { letter-spacing: .05em; color: #8A93A3; }
.letter-text .extra { color: #B5BECB; }
.letter-text.is-noise { letter-spacing: .12em; }
.letter-text.is-solid { word-break: break-all; }
.letter-text.flip-180 { transform: rotate(180deg); }
.letter-text.flip-y { transform: scaleY(-1); }
/* маски «закрыта часть строки»: строка = 2em, буквы примерно посередине */
.letter-text.mask-bottom::after, .letter-text.mask-top::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
.letter-text.mask-bottom::after { background: repeating-linear-gradient(to bottom, transparent 0, transparent 1.2em, var(--paper) 1.2em, var(--paper) 2em); }
.letter-text.mask-top::after { background: repeating-linear-gradient(to bottom, var(--paper) 0, var(--paper) .88em, transparent .88em, transparent 2em); }
.letter-text.plain { transform: none; }
.letter-text.plain::after { display: none; }
.letter-text.reveal { animation: reveal .6s; }
@keyframes reveal { from { opacity: 0; filter: blur(4px); } to { opacity: 1; filter: none; } }
.letter-foot { display: flex; justify-content: flex-end; margin-top: 1em; }
.decoded-label { font-weight: 800; color: var(--green); font-size: .85em; margin-bottom: .2em; }
.decoded-label::before { content: "✓ "; }

.result { border-radius: 20px; padding: .9em 1.2em; display: flex; align-items: center; gap: 1em; box-shadow: var(--shadow); animation: fade .3s; }
.result.good { background: var(--green-light); }
.result.bad { background: var(--red-light); }
.result img { width: 3.6em; height: 3.6em; object-fit: contain; flex: none; }
.result .r-text { flex: 1; }
.result .r-title { font-family: "Rubik"; font-weight: 800; font-size: 1.15em; }
.result.good .r-title { color: var(--green); }
.result.bad .r-title { color: var(--red); }
.result .r-sub { font-size: .9em; color: var(--soft); font-weight: 600; }

.side { min-width: 0; }
.ded-reading { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.ded-reading img { max-height: min(58vh, 520px); max-width: 100%; }
.ded-bubble { background: #fff; border-radius: 18px; padding: .8em 1.1em; font-weight: 700; text-align: center; max-width: 360px; position: relative; order: -1; }
.ded-bubble::after { content: ""; position: absolute; bottom: -12px; left: 50%; transform: translateX(-50%); border: 12px solid transparent; border-top-color: #fff; border-bottom: 0; }

/* Кладовая */
.storeroom { background: #6E4A2B; border-radius: 24px; padding: clamp(12px, 1.4vw, 22px); box-shadow: var(--shadow); animation: fade .35s; border: 4px solid #8A5E36; }
.store-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; color: #fff; margin-bottom: .6em; }
.store-head h3 { font-size: 1.25em; }
.store-hint { color: #F3DDBE; font-size: .85em; font-weight: 600; }
.shelves { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0 6px; }
.item { position: relative; border: none; background: transparent; cursor: pointer; padding: 6px 4px 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; font-family: inherit; color: #fff;
  border-bottom: 12px solid var(--wood); margin-bottom: 12px; box-shadow: 0 6px 0 var(--wood-dark); transition: transform .12s; }
.item:nth-child(7n+1) { border-bottom-left-radius: 4px; }
.item img { width: 100%; aspect-ratio: 1; object-fit: contain; filter: drop-shadow(0 4px 3px rgba(0,0,0,.35)); transition: transform .15s; }
.item:hover:not(:disabled) img { transform: translateY(-6px) scale(1.06); }
.item .iname { font-size: .68em; font-weight: 700; line-height: 1.15; min-height: 2.3em; text-align: center; color: #FCEBD3; padding: 2px 0 4px; }
.item:disabled { cursor: default; }
.item.given img { opacity: .25; filter: grayscale(1); }
.item.given::after { content: "✓"; position: absolute; top: 18%; left: 50%; transform: translateX(-50%); width: 1.6em; height: 1.6em; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; font-weight: 800; }
.item.wrong img { animation: shake .45s; filter: drop-shadow(0 0 8px var(--red)); }
.item.right img { transform: scale(1.15); filter: drop-shadow(0 0 12px #FFE27A); }
@keyframes shake { 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }

/* Летящий подарок */
.flyer { position: fixed; z-index: 30; pointer-events: none; object-fit: contain; transition: transform .9s cubic-bezier(.5,-0.3,.6,1), opacity .9s; }

/* Тосты наград */
.toast-box { position: fixed; right: 16px; bottom: 16px; width: min(380px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 10px; z-index: 40; pointer-events: none; }
.toast { background: #fff; border-radius: 18px; padding: .7em 1.1em; display: flex; align-items: center; gap: .8em; box-shadow: 0 12px 30px rgba(0,0,0,.3); border: 3px solid var(--gold); animation: toastIn .5s cubic-bezier(.3,1.5,.5,1); }
.toast.out { animation: toastOut .4s forwards; }
.toast .t-icon { font-size: 2em; }
.toast .t-small { font-size: .75em; color: #8A5A00; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.toast .t-name { font-family: "Rubik"; font-weight: 800; }
.toast .t-desc { font-size: .8em; color: var(--soft); }
@keyframes toastIn { from { transform: translateX(120%); } to { transform: none; } }
@keyframes toastOut { to { transform: translateX(130%); opacity: 0; } }

/* Награды */
.awards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.award { display: flex; gap: .6em; align-items: center; background: var(--gold-light); border: 2px solid var(--gold); border-radius: 14px; padding: .4em .7em; }
.award.locked { background: #F1F3F6; border-color: var(--line); }
.award.locked .a-icon { filter: grayscale(1); opacity: .4; }
.award .a-icon { font-size: 1.6em; flex: none; }
.award .a-name { font-weight: 800; font-size: .9em; line-height: 1.2; }
.award .a-desc { font-size: .72em; color: var(--soft); line-height: 1.25; }

/* Окна */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(10, 20, 45, .6); display: grid; place-items: center; padding: 20px; animation: fade .25s; }
.card { background: #fff; border-radius: 26px; max-width: 980px; width: 100%; padding: clamp(18px, 2.6vw, 36px); max-height: 96vh; overflow-y: auto; }
.card h2 { color: var(--red); margin-bottom: .7em; }
.card-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 1.2em; }

/* Финал */
#screen-finish { align-items: center; justify-content: center; }
.finish { max-width: 1500px; width: 100%; background: var(--paper); border-radius: 32px; box-shadow: var(--shadow); display: grid; grid-template-columns: minmax(0, .32fr) minmax(0, 1fr); gap: clamp(16px, 2vw, 32px); padding: clamp(18px, 2.4vw, 40px); align-items: center; }
.finish-ded img { width: 100%; max-height: 70vh; object-fit: contain; }
.finish-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: .7em; }
@media (min-width: 1101px) { .finish-head { flex-wrap: nowrap; } }
.finish h1 { margin-bottom: 0; font-size: clamp(28px, min(3vw, 5.4vh), 54px); }
.finish-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: .8em; }
.stat { background: var(--blue-light); border-radius: 14px; padding: .45em .8em; line-height: 1.25; }
.stat b { display: block; font-family: "Rubik"; font-size: 1.25em; color: var(--blue); line-height: 1.2; }
.stat span { font-size: .8em; color: var(--soft); font-weight: 700; }
.sub { font-size: 1em; margin: .6em 0 .45em; }
.kids { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; }
.kid { background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 4px; text-align: center; font-size: .72em; font-weight: 700; line-height: 1.2; }
.kid img { width: min(70%, 9vh); aspect-ratio: 1; object-fit: contain; display: block; margin: 0 auto 2px; }
.kid .k-time { color: var(--soft); font-weight: 600; }
.kid.fast { border-color: var(--gold); background: var(--gold-light); }

/* Грамота */
.diploma-card { max-width: 820px; }
.diploma { position: relative; border: 10px double var(--gold); border-radius: 18px; padding: 28px clamp(150px, 30%, 260px) 24px 28px; text-align: center; background: #FFFDF2; overflow: hidden; }
.dip-top { font-size: 3em; font-weight: 800; color: var(--red); letter-spacing: .12em; }
.dip-sub { color: var(--soft); font-weight: 700; margin-bottom: .5em; }
.dip-name { width: 100%; font-family: "Rubik"; font-size: 1.8em; font-weight: 700; text-align: center; border: none; border-bottom: 2px solid var(--ink); background: transparent; color: var(--blue); padding: .1em; outline: none; }
.dip-text { margin: 1em auto .8em; max-width: 30em; font-weight: 700; font-size: 1.05em; }
.dip-row { display: flex; justify-content: center; gap: 2em; color: var(--soft); font-weight: 700; font-size: .9em; }
.dip-ded { position: absolute; right: 12px; bottom: 8px; width: clamp(125px, 26%, 230px); height: auto; max-height: 92%; object-fit: contain; object-position: bottom; }
.dip-sign { margin-top: 1.4em; text-align: left; font-style: italic; font-weight: 700; color: var(--soft); }
.dip-sign::before { content: "Подпись: "; font-style: normal; }

/* ---------- Узкие экраны ---------- */
@media (max-width: 1100px) {
  .cover { grid-template-columns: minmax(0, 1fr); }
  .cover-ded { order: -1; } .cover-ded img { max-height: 26vh; }
  #stage-letter, #stage-letter.reading { grid-template-columns: minmax(0, 1fr); }
  .ded-reading { display: none !important; }
  .mailbox-wrap { grid-template-columns: minmax(0, 1fr); justify-items: center; text-align: center; }
  .finish { grid-template-columns: minmax(0, 1fr); } .finish-ded { display: none; }
  .awards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .diploma { padding: 22px 18px; }
  .dip-ded { position: static; display: block; width: 120px; margin: 10px auto 0; }
  .dip-top { font-size: 2.2em; }
}
@media (max-width: 700px) {
  .shelves { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kids { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .topbar { flex-wrap: wrap; }
}

/* ---------- Печать грамоты ---------- */
@media print {
  @page { size: A4 landscape; margin: 12mm; }
  body { background: #fff; }
  .screen, .snow, .modal:not(#diploma-modal), .toast-box, .flyer { display: none !important; }
  #diploma-modal { display: block !important; position: static; background: none; padding: 0; }
  .diploma-card { max-width: none; box-shadow: none; padding: 0; max-height: none; overflow: visible; }
  .diploma-card .card-actions { display: none; }
  .diploma { -webkit-print-color-adjust: exact; print-color-adjust: exact; height: 180mm; font-size: 22px; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 16mm 95mm 22mm 24mm; }
  .dip-top { font-size: 3.4em; }
  .dip-name { width: 100%; font-size: 2em; }
  .dip-ded { width: auto; height: 58%; max-height: none; right: 10mm; bottom: 6mm; }
  .dip-sign { position: absolute; left: 24mm; bottom: 14mm; margin: 0; }
  .dip-name::placeholder { color: transparent; }
}

/* ---------- Кнопочный телефон и SMS ---------- */
#stage-letter, #stage-letter.reading { grid-template-columns: minmax(290px, .75fr) minmax(0, 1.6fr); }
.letter-col { align-items: center; min-width: 0; }
.phone { width: 100%; max-width: 350px; padding: 17px 19px 22px; border: 4px solid #092f35; border-radius: 48px; background: linear-gradient(130deg, #079a9b, #007879); box-shadow: inset 3px 3px 0 #ffffff45, 0 12px 0 #062b35, 0 22px 35px #0004; color: #17373c; }
.phone-speaker { height: 10px; width: 65px; border: 2px solid #93aab1; border-radius: 8px; background: #163c43; margin: 0 auto 16px; }
.phone-screen { min-height: 170px; background: #c3dfec; border: 7px solid #08323c; border-radius: 28px; padding: 13px; box-shadow: inset 0 3px 8px #1234; overflow-wrap: anywhere; }
.phone-status { display: flex; justify-content: space-between; gap: 8px; padding-bottom: 8px; margin-bottom: 9px; border-bottom: 1px solid #7197a5; font-size: 10px; font-weight: 800; letter-spacing: .1em; }
.phone .letter-head { gap: 7px; margin-bottom: 14px; }
.phone .letter-from { font-size: 16px; color: #17373c; }
.phone .letter-mech { font-size: 11px; background: #e6f4fa; color: #254c59; }
.phone .letter-text.sms-code, #stage-letter:not(.reading) .phone .letter-text.sms-code { font: 700 clamp(24px, 2.1vw, 34px)/1.5 'Rubik', sans-serif; letter-spacing: .1em; color: #11323e; text-align: center; overflow-wrap: anywhere; }
.phone .decoded-label { font-size: 17px; letter-spacing: .08em; color: #25674a; }
.phone .decoded-word { font-size: 19px; letter-spacing: .03em; }
.phone-nav { display: flex; justify-content: space-around; align-items: center; margin: 11px 0; color: #e7f6f4; font-size: 22px; }
.phone-nav span:nth-child(2) { padding: 0 15px; border: 2px solid #a1d5cc; border-radius: 10px; }
.phone-keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; padding: 10px; border: 2px solid #bee8de; border-radius: 20px; }
.phone-key { background: linear-gradient(#fff, #dae6e4); border: 2px solid #3c5e60; border-bottom: 5px solid #1c4144; border-radius: 8px; text-align: center; padding: 3px 0; line-height: 1.15; }
.phone-key b { display: block; font-family: 'Rubik', sans-serif; font-size: 26px; color: #007b7e; }
.phone-key span { display: block; font-size: 16px; font-weight: 800; color: #162d35; }
.phone-key:last-child { grid-column: 2; }
.phone-incoming { animation: sms-arrive .6s ease; }
.sms-notification { margin: 8px auto; font-family: 'Rubik', sans-serif; font-size: 36px; font-weight: 800; text-align: center; }
.sms-badge { display: inline-grid; place-items: center; vertical-align: top; width: 25px; height: 25px; border-radius: 50%; background: var(--red); color: white; font-size: 16px; }
#env-from, .phone-caption { text-align: center; font-weight: 800; }
.phone-caption { font-size: 12px; color: #416675; margin-top: 5px; }
.sms-help { max-width: 350px; margin-top: 12px; color: #eef8ff; text-align: center; font-weight: 700; }
.letter-col .result { width: 100%; flex-wrap: wrap; }
.letter-col .result .btn { width: 100%; white-space: normal; }
.item { min-width: 0; }
.btn:focus-visible, .item:focus-visible, .pill-btn:focus-visible, .icon-btn:focus-visible { outline: 4px solid #ffcf54; outline-offset: 4px; }
.cover { border-image: none; border-top-color: #079a9b; }
@keyframes sms-arrive { 0%, 40%, 80% { transform: rotate(-3deg); } 20%, 60% { transform: rotate(3deg); } 100% { transform: none; } }
@media (max-width: 1100px) {
  #stage-letter, #stage-letter.reading { grid-template-columns: minmax(270px, .8fr) minmax(0, 1.4fr); }
  .shelves { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  #stage-letter, #stage-letter.reading { grid-template-columns: minmax(0, 1fr); }
  .phone { max-width: 315px; }
  .topbar-right { flex-wrap: wrap; gap: 6px; }
  .mailbox-wrap { padding: 24px 16px; }
  .mail-text .btn { white-space: normal; }
  .result .r-text { min-width: 160px; }
}
/* Дед Мороз встречает новое SMS рядом с телефоном. */
#stage-mail { gap: clamp(22px, 3vw, 48px); }
#stage-mail .mailbox-wrap { min-width: 0; flex: 1; grid-template-columns: minmax(190px, .65fr) minmax(0, 1fr); gap: clamp(20px, 2.5vw, 40px); padding: clamp(24px, 3vw, 48px); }
#stage-mail .mail-text { min-width: 0; }
#stage-mail .mail-text h2 { font-size: clamp(26px, 2.4vw, 42px); }
#stage-mail .mail-text .btn { white-space: normal; }
.incoming-assistant { flex: 0 0 clamp(240px, 24vw, 350px); display: flex; flex-direction: column; align-items: center; gap: 18px; }
.incoming-bubble { position: relative; margin: 0; padding: 18px 22px; background: #fffdf6; border-radius: 24px; color: var(--ink); font-weight: 800; font-size: clamp(17px, 1.4vw, 22px); line-height: 1.4; text-align: center; box-shadow: 0 8px 24px #0002; }
.incoming-bubble::after { content: ""; position: absolute; left: 50%; bottom: -13px; transform: translateX(-50%); border: 14px solid transparent; border-top-color: #fffdf6; border-bottom: 0; }
.incoming-assistant img { display: block; width: 100%; height: auto; max-height: min(62vh, 620px); object-fit: contain; filter: drop-shadow(0 12px 12px #0003); }
@media (min-width: 901px) and (max-width: 1100px) {
  #stage-mail .mailbox-wrap { text-align: left; justify-items: stretch; }
}
@media (max-width: 900px) {
  #stage-mail { flex-direction: column; justify-content: flex-start; padding: 16px 0; }
  #stage-mail .mailbox-wrap { flex: none; }
  .incoming-assistant { flex: none; width: min(100%, 320px); }
  .incoming-assistant img { max-height: 380px; }
}
@media (max-width: 600px) {
  #stage-mail .mailbox-wrap { grid-template-columns: minmax(0, 1fr); justify-items: center; text-align: center; padding: 24px 16px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* Игра занимает доступную высоту. Результат — отдельная строка под обеими колонками. */
@media screen {
  #screen-game { height: 100vh; height: 100dvh; min-height: 0; padding: clamp(8px, 1.4vh, 20px) clamp(10px, 1.6vw, 28px); }
  #screen-game .topbar { flex: none; margin-bottom: 12px; }
  #screen-game .stage { min-height: 0; }
  #stage-letter, #stage-letter.reading { grid-template-columns: minmax(190px, .65fr) minmax(0, 1.6fr); grid-template-rows: minmax(0, 1fr) auto; gap: 12px 24px; align-items: stretch; }
  #stage-letter .letter-col { container-type: size; min-height: 0; justify-content: center; gap: 8px; }
  #stage-letter .phone { width: min(350px, 100%, 53cqh); flex: none; }
  .phone { container-type: inline-size; padding: 12px; border-radius: 36px; }
  .phone-speaker { height: 3cqw; width: 22cqw; margin-bottom: 4cqw; }
  .phone-screen { min-height: 51cqw; border-width: 2cqw; border-radius: 8cqw; padding: 3cqw; }
  .phone-status { font-size: 3cqw; margin-bottom: 2cqw; padding-bottom: 2cqw; }
  .phone .letter-head { gap: 2cqw; margin-bottom: 3cqw; }
  .phone .letter-from { font-size: 4.8cqw; }
  .phone .letter-mech { font-size: 3.2cqw; }
  .phone .letter-text.sms-code, #stage-letter:not(.reading) .phone .letter-text.sms-code { font-size: 8cqw; line-height: 1.35; letter-spacing: .07em; }
  .phone .decoded-label { font-size: 5.5cqw; }
  .phone .decoded-word { font-size: 5.8cqw; }
  .phone-nav { font-size: 7cqw; margin: 3cqw 0; }
  .phone-nav span:nth-child(2) { padding: 0 4cqw; }
  .phone-keypad { gap: 2cqw; padding: 3cqw; border-radius: 6cqw; }
  .phone-key { padding: 1cqw 0; border-width: 1px; border-bottom-width: 3px; border-radius: 2cqw; }
  .phone-key b { font-size: 8cqw; }
  .phone-key span { font-size: 4.8cqw; }
  .phone .sms-notification { font-size: 11cqw; margin: 2cqw auto; }
  .phone #env-from { font-size: 5cqw; }
  .phone .phone-caption { font-size: 3.5cqw; }
  #stage-letter .sms-help { flex: none; font-size: clamp(11px, 1.5vh, 16px); margin: 0; line-height: 1.25; }
  #stage-letter .side { container-type: size; min-height: 0; display: flex; align-items: center; justify-content: center; }
  #stage-letter .storeroom { width: min(100%, 1000px); height: min(100%, calc(min(100cqw, 1000px) * .43 + 110px)); min-height: 0; display: flex; flex-direction: column; padding: clamp(8px, 1.5vh, 18px); border-width: 2px; border-radius: 20px; box-shadow: 0 8px 24px #0002; }
  @media (min-width: 521px) {
    #stage-letter .side { align-items: flex-start; }
    #stage-letter .storeroom { height: min(100%, var(--phone-height, 100%)); margin-top: var(--phone-offset, 0px); }
  }
  #stage-letter .store-head { flex: none; gap: 4px 12px; margin-bottom: 8px; }
  #stage-letter .store-head h3 { font-size: clamp(14px, 2.2vh, 24px); }
  #stage-letter .store-hint { font-size: clamp(10px, 1.6vh, 16px); }
  /* Всегда 7 × 3. Размер всех картинок ограничен одним квадратом,
     поэтому изменение пропорций окна не меняет их относительный масштаб. */
  #stage-letter .shelves { container-type: size; flex: 1; min-height: 0; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); gap: 8px 6px; }
  #stage-letter .item { --gift-size: max(0px, min(calc((100cqw - 36px) / 7 - 4px), calc((100cqh - 16px) / 3 - 40px))); min-height: 0; padding: 2px 2px 0; margin: 0; justify-content: flex-end; gap: 2px; border-bottom-width: 5px; box-shadow: 0 2px 0 var(--wood-dark); }
  #stage-letter .item img { flex: none; min-height: 0; width: var(--gift-size); height: var(--gift-size); aspect-ratio: 1; object-fit: contain; align-self: center; }
  #stage-letter .item .iname { flex: none; height: 26px; min-height: 0; width: 100%; display: grid; place-items: center; font-size: clamp(8px, .65vw, 12px); padding: 0; overflow-wrap: anywhere; }
  #stage-letter > .result { grid-column: 1 / -1; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; padding: 10px 16px; font-size: clamp(12px, 1.7vh, 18px); }
  #stage-letter > .result img { width: 3em; height: 3em; }
  #stage-letter > .result .btn { white-space: normal; }
  #stage-mail { container-type: size; padding: 0 0 12px; }
  #stage-mail .mailbox-wrap { flex: 1; max-height: 100%; }
  #stage-mail .phone { width: min(350px, 100%, 52cqh); justify-self: center; }
  #stage-mail .incoming-assistant { max-height: 100%; min-height: 0; }
  #stage-mail .incoming-assistant img { min-height: 0; max-height: calc(100cqh - 150px); }
  @media (max-width: 1100px) {
    #screen-game .topbar { gap: 6px; flex-wrap: wrap; }
    #screen-game .progress { gap: 4px; }
    #screen-game .dot { width: 1.85em; height: 1.85em; }
    #screen-game .topbar-right { gap: 5px; }
    #screen-game .pill { padding: .3em .5em; }
    #stage-mail { flex-direction: row; gap: 16px; }
    #stage-mail .mailbox-wrap { grid-template-columns: minmax(140px, .65fr) minmax(0, 1fr); padding: 20px; gap: 16px; text-align: left; }
    #stage-mail .incoming-assistant { flex: 0 0 24%; }
    #stage-mail .incoming-bubble { padding: 12px; font-size: 15px; }
  }
  @media (max-width: 750px) {
    #stage-letter, #stage-letter.reading { grid-template-columns: minmax(170px, .7fr) minmax(0, 1.3fr); gap: 10px; }
    #stage-letter > .result { gap: 8px; padding: 8px 10px; }
    #stage-letter > .result .r-sub { font-size: 11px; }
    #stage-letter > .result img { width: 2em; height: 2em; }
    #stage-mail { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
    #stage-mail .mailbox-wrap { height: 100%; }
    #stage-mail .incoming-assistant { width: 100%; flex-direction: row; justify-content: center; gap: 12px; }
    #stage-mail .incoming-assistant img { width: auto; height: min(18vh, 130px); }
    #stage-mail .incoming-bubble { max-width: 300px; }
    #stage-mail .incoming-bubble::after { display: none; }
    #stage-mail .mail-text h2 { font-size: 24px; }
    #stage-mail .mail-note { font-size: 12px; }
  }
  @media (max-width: 520px) {
    #screen-game .topbar { font-size: 12px; margin-bottom: 8px; }
    #stage-letter, #stage-letter.reading { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, .85fr) minmax(0, 1.3fr) auto; }
    #stage-letter .letter-col { container-type: normal; }
    #stage-letter .phone { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1fr); gap: 8px; width: 100%; max-width: none; height: 100%; padding: 8px; border-radius: 24px; box-shadow: 0 4px 0 #062b35; }
    #stage-letter .phone-speaker, #stage-letter .phone-nav, #stage-letter .sms-help { display: none; }
    #stage-letter .phone-screen { min-height: 0; padding: 8px; border-width: 4px; border-radius: 16px; }
    #stage-letter .phone-status { font-size: 8px; }
    #stage-letter .phone .letter-from { font-size: 12px; }
    #stage-letter .phone .letter-mech { font-size: 9px; }
    #stage-letter .phone .letter-head { margin-bottom: 8px; }
    #stage-letter .phone .letter-text.sms-code { font-size: 20px; }
    #stage-letter .phone .decoded-word, #stage-letter .phone .decoded-label { font-size: 13px; }
    #stage-letter .phone-keypad { min-height: 0; padding: 4px; gap: 3px; border-radius: 14px; }
    #stage-letter .phone-key { display: flex; flex-direction: column; justify-content: center; padding: 0; border-radius: 5px; }
    #stage-letter .phone-key b { font-size: 17px; }
    #stage-letter .phone-key span { font-size: 10px; }
    #stage-letter .store-head h3 { font-size: 13px; }
    #stage-letter .store-hint { font-size: 10px; }
    #stage-letter > .result { grid-template-columns: minmax(0, 1fr) auto; }
    #stage-letter > .result img { display: none; }
    #stage-letter > .result .r-title { font-size: 12px; }
    #stage-letter > .result .btn { font-size: 12px; padding: 8px; max-width: 120px; }
    #stage-mail .mailbox-wrap { padding: 10px; gap: 10px; grid-template-columns: minmax(110px, .7fr) minmax(0, 1fr); }
    #stage-mail .mail-text h2 { font-size: 18px; }
    #stage-mail .mail-hint { padding: 8px; font-size: 12px; }
    #stage-mail .mail-note { font-size: 10px; }
    #stage-mail .mail-text .btn { font-size: 14px; padding: 10px; }
  }
}
