@font-face { font-family: "Rounded Elegance"; src: url("/web/assets/rounded-elegance.ttf") format("truetype"); font-display: swap; }

:root {
  /* палитра Ainala из гайдлайна */
  --coral: #ff8c82;
  --orange: #f9520d;
  --yellow: #ffd877;
  --green: #70ba69;
  --blue: #008cb4;
  --sky: #54c3ea;
  --bg: #f7f5f2;
  --card: #fff;
  --ink: #26324a;
  --muted: #7c8496;
  --line: #e8e3dc;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 16px/1.45 "Rounded Elegance", system-ui, sans-serif; background: var(--bg); color: var(--ink); }
h1, h2, h3 { font-weight: 400; text-transform: uppercase; letter-spacing: .03em; }
h1 { font-size: clamp(22px, 4vw, 32px); color: var(--orange); margin: 8px 0 6px; }
.lead { color: var(--blue); max-width: 720px; margin: 0 0 18px; }
.note { color: var(--muted); font-size: 13px; min-height: 1.3em; margin: 8px 0 0; }
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
button:disabled { opacity: .55; cursor: progress; }

/* шапка и шаги */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.logo { height: 34px; }
.steps { display: flex; gap: 4px; margin: 0 auto; }
.steps button { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; color: var(--muted); }
.steps b { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--line); color: var(--ink); font-weight: 400; font-size: 13px; }
.steps button.active { color: var(--green); }
.steps button.active b { background: var(--green); color: #fff; }
.saved { color: var(--green); font-size: 13px; min-width: 90px; text-align: right; }
@media (max-width: 640px) { .steps span { display: none; } .saved { min-width: 0; } }

.screen { max-width: 1240px; margin: 0 auto; padding: 18px 16px 40px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.top-actions { justify-content: flex-start; margin: 0 0 6px; }
.cta { background: var(--orange); color: #fff; padding: 12px 22px; border-radius: 999px; text-transform: uppercase; letter-spacing: .04em; }
.ghost { border: 2px solid var(--green); color: var(--green); padding: 10px 20px; border-radius: 999px; text-transform: uppercase; letter-spacing: .04em; }

/* 1. семья */
.family { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.member { position: relative; background: var(--card); border: 2px solid var(--line); border-radius: 20px; padding: 14px; text-align: center; }
.member canvas { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; }
.member h3 { margin: 6px 0 2px; font-size: 18px; }
.member p { margin: 0; color: var(--muted); font-size: 13px; }
.member.on { border-color: var(--green); }
.member.off canvas { opacity: .35; filter: grayscale(1); }
.member .toggle { margin-top: 10px; padding: 8px 14px; border-radius: 999px; background: var(--line); }
.member.on .toggle { background: var(--green); color: #fff; }

/* 2. персонажи */
.char-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; }
.char-tabs button { display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 6px; border-radius: 999px; background: var(--card); border: 2px solid var(--line); white-space: nowrap; }
.char-tabs button canvas { width: 34px; height: 34px; border-radius: 50%; background: #eef6f9; object-fit: contain; }
.char-tabs button.active { border-color: var(--orange); color: var(--orange); }
.builder { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 440px); gap: 18px; align-items: start; }
.portrait-card { background: radial-gradient(circle at 50% 40%, #e9f6fb, #d3ecf5); border-radius: 24px; padding: 12px; position: sticky; top: 70px; }
.portrait-card canvas { width: 100%; max-height: 70vh; object-fit: contain; display: block; }
@media (max-width: 860px) {
  .builder { grid-template-columns: 1fr; }
  .portrait-card { top: 58px; z-index: 2; }
  .portrait-card canvas { max-height: 34vh; }
}
.controls { background: var(--card); border-radius: 20px; padding: 6px 16px; border: 1px solid var(--line); }
.group { padding: 12px 0; border-top: 1px solid var(--line); }
.group:first-child { border-top: 0; }
.group h3 { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.group .hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.swatch.active { box-shadow: 0 0 0 3px var(--orange); }
.swatch.picker { position: relative; overflow: hidden; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); cursor: pointer; display: inline-block; }
.swatch.picker input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 7px 14px; border-radius: 999px; border: 2px solid var(--line); }
.chips button.active { border-color: var(--green); background: var(--green); color: #fff; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.thumbs button { height: 88px; border-radius: 14px; background: #eef6f9; display: grid; grid-template-rows: 1fr auto; place-items: center; padding: 4px; border: 2px solid transparent; overflow: hidden; }
.thumbs img { max-width: 100%; max-height: 64px; object-fit: contain; }
.thumbs span { font-size: 11px; color: var(--muted); }
.thumbs button.active { border-color: var(--orange); }

/* 3. книга */
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-top: 14px; }
.page { background: var(--card); border-radius: 14px; overflow: hidden; border: 1px solid var(--line); text-align: left; padding: 0; }
.page .img { aspect-ratio: 2 / 1; background: #ddd; }
.page canvas, .page img { width: 100%; height: 100%; object-fit: cover; display: block; }
.page .cap { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; font-size: 14px; }
.badge { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--line); color: var(--muted); text-transform: uppercase; }
.badge.live { background: var(--green); color: #fff; }

.lightbox { position: fixed; inset: 0; z-index: 20; background: rgba(20, 24, 40, .85); display: grid; place-items: center; padding: 16px; }
.lightbox .lb-body { max-width: min(1600px, 100%); width: 100%; }
.lightbox canvas, .lightbox img { width: 100%; height: auto; display: block; border-radius: 6px; }
.lightbox .close { position: absolute; top: 8px; right: 16px; color: #fff; font-size: 40px; line-height: 1; }

/* калибровка (?calibrate=1) */
.calib { position: fixed; right: 16px; bottom: 16px; z-index: 30; background: #fff; border: 2px solid var(--yellow); border-radius: 16px; padding: 12px; width: 290px; box-shadow: 0 8px 30px rgba(0,0,0,.2); font-size: 14px; }
.calib h2 { margin: 0 0 6px; font-size: 15px; }
.calib label { display: block; margin: 6px 0; font-size: 13px; }
.calib select { width: 100%; font: inherit; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; text-align: center; align-items: center; margin: 8px 0; }
.pad button { background: var(--line); border-radius: 8px; padding: 6px; }
.pad button:nth-child(1), .pad button:nth-child(5) { grid-column: 2; }

/* grid-ячейки не должны растягиваться по натуральной ширине canvas */
.builder > *, .pages > *, .family > * { min-width: 0; }
canvas { max-width: 100%; }
@media (max-width: 640px) { .top { gap: 8px; } .logo { height: 26px; } .steps button { padding: 6px 6px; } .saved { font-size: 11px; } }

/* имя ребёнка (стр. 3 макета) */
@font-face { font-family: "VividSans"; src: url("fonts/VividSans.ttf"); }
@font-face { font-family: "RoundedElegance"; src: url("fonts/RoundedElegance.ttf"); }
.child-name { display: block; max-width: 420px; margin: 24px auto 0; font-weight: 600; }
.child-name span { font-weight: 400; opacity: .6; }
.child-name input { display: block; width: 100%; margin-top: 8px; padding: 12px 14px; font: 600 22px "VividSans", "RoundedElegance", sans-serif;
  color: #EA551E; border: 1px solid #ddd; border-radius: 12px; box-sizing: border-box; }

/* 3. книга — листалка */
.flip { position: relative; margin: 8px auto 0; max-width: min(1200px, calc((100vh - 250px) * 2), 100%); outline: none; perspective: 2400px; }
.stage { position: relative; aspect-ratio: 2 / 1; display: grid; grid-template-columns: 1fr 1fr; border-radius: 6px;
  box-shadow: 0 24px 60px rgba(38, 50, 74, .28), 0 4px 12px rgba(38, 50, 74, .15); background: #fff; cursor: pointer;
  transform-style: preserve-3d; touch-action: pan-y; user-select: none; }
.stage .half { overflow: hidden; background: #f1ede7; min-width: 0; }
.stage .half.left { border-radius: 6px 0 0 6px; }
.stage .half.right { border-radius: 0 6px 6px 0; }
.stage canvas { width: 100%; height: 100%; display: block; }
.stage .spine { position: absolute; inset: 0 auto 0 50%; width: 60px; margin-left: -30px; pointer-events: none; z-index: 3;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,.08) 45%, rgba(0,0,0,.16) 50%, rgba(0,0,0,.08) 55%, transparent); }
.stage .leaf { position: absolute; top: 0; bottom: 0; width: 50%; transform-style: preserve-3d; z-index: 2;
  transition: transform .85s cubic-bezier(.45, .05, .25, 1); }
.stage .leaf.fwd { left: 50%; transform-origin: left center; }
.stage .leaf.bwd { left: 0; transform-origin: right center; }
.stage .leaf.fwd.turn { transform: rotateY(-180deg); }
.stage .leaf.bwd.turn { transform: rotateY(180deg); }
.stage .face { position: absolute; inset: 0; backface-visibility: hidden; overflow: hidden; background: #fff; }
.stage .face.back { transform: rotateY(180deg); }
.stage .face::after { content: ""; position: absolute; inset: 0; pointer-events: none; transition: opacity .85s; opacity: 0;
  background: linear-gradient(90deg, rgba(0,0,0,.22), transparent 45%); }
.stage .leaf.turn .face::after { opacity: 1; }
.stage .loading { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; color: var(--muted); background: #fff; border-radius: 6px; }
.flip .nav { position: absolute; top: calc(50% - 24px); width: 48px; height: 48px; border-radius: 50%;
  background: #fff; color: var(--orange); font-size: 34px; line-height: 44px; box-shadow: 0 4px 14px rgba(0,0,0,.18); z-index: 5; }
.flip .nav.prev { left: -24px; }
.flip .nav.next { right: -24px; }
.flip .nav:disabled { opacity: 0; pointer-events: none; }
.flip-bar { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 14px; color: var(--muted); font-size: 14px; }
.flip-full { font-size: 20px; color: var(--blue); }
.flip:fullscreen { max-width: none; background: #26324a; display: grid; align-content: center; padding: 3vw 5vw; }
.flip:fullscreen .stage { width: min(100%, 170vh); margin: 0 auto; }
.flip:fullscreen .flip-bar { color: #fff; }
.flip:fullscreen .nav.prev { left: 1vw; }
.flip:fullscreen .nav.next { right: 1vw; }
.strip { display: flex; gap: 8px; overflow-x: auto; padding: 18px 2px 6px; }
.strip .thumb { flex: 0 0 120px; position: relative; border: 2px solid transparent; border-radius: 6px; overflow: hidden; background: #ddd; padding: 0; }
.strip .thumb.active { border-color: var(--orange); }
.strip .thumb canvas, .strip .thumb img { width: 100%; aspect-ratio: 2 / 1; display: block; object-fit: cover; }
.strip .thumb span { position: absolute; left: 4px; bottom: 2px; font-size: 11px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
@media (max-width: 640px) {
  .flip .nav { width: 38px; height: 38px; font-size: 26px; line-height: 34px; top: calc(50% - 19px); }
  .flip .nav.prev { left: -6px; } .flip .nav.next { right: -6px; }
}
