/* Sweedi - playful kids UI, mobile-first.
   Palette: Swedish flag blue #006AA7 + yellow #FECC02, sky background, white cards.
   Rules: tap targets >= 48px, chunky pills, soft shadows, bouncy easing, reduced-motion respected. */

:root {
  --blue: #006AA7;
  --blue-deep: #004C78;
  --blue-bright: #0A7DC2;
  --yellow: #FECC02;
  --yellow-deep: #D9A900;
  --ink: #0B2A40;
  --ink-soft: #4F6F86;      /* English text, 5:1 on white */
  --sky: #E3F2FD;
  --sky-2: #CFE8FA;
  --white: #fff;
  --pink: #FF9EB5;
  --green: #2DB67C;
  --radius: 28px;
  --radius-pill: 999px;
  --shadow-soft: 0 6px 20px rgba(0, 76, 120, .14);
  --shadow-card: 0 4px 0 rgba(0, 76, 120, .08), 0 10px 24px rgba(0, 76, 120, .12);
  --bounce: cubic-bezier(.34, 1.56, .64, 1);
  --font: "Nunito", ui-rounded, "SF Pro Rounded", "Hiragino Maru Gothic ProN", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Baloo 2", "Nunito", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  --bar-h: 148px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-weight: 600;
  font-size: 18px;
  line-height: 1.35;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky) 0%, var(--sky-2) 100%) fixed;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
:focus-visible { outline: 4px solid var(--ink); outline-offset: 3px; }
h1, h2 { font-family: var(--font-display); margin: 0; line-height: 1.1; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; opacity: 0; }

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 24px);
}
body[data-view="result"] .app { padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 24px); }
.view { animation: pop-in .45s var(--bounce) both; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 56px; padding: 0 26px;
  border-radius: var(--radius-pill);
  font-family: var(--font-display); font-weight: 800; font-size: 21px; line-height: 1;
  transition: transform .18s var(--bounce), box-shadow .18s;
  user-select: none; -webkit-user-select: none;
}
.btn:active { transform: translateY(4px) scale(.97); }
.btn-small { min-height: 52px; padding: 0 18px; font-size: 18px; }
.btn-yellow { background: var(--yellow); color: var(--ink); box-shadow: 0 5px 0 var(--yellow-deep), 0 10px 18px rgba(217, 169, 0, .35); }
.btn-yellow:active { box-shadow: 0 1px 0 var(--yellow-deep); }
.btn-blue { background: var(--blue); color: #fff; box-shadow: 0 5px 0 var(--blue-deep), 0 10px 18px rgba(0, 76, 120, .25); }
.btn-blue:active { box-shadow: 0 1px 0 var(--blue-deep); }
.btn-white { background: #fff; color: var(--blue-deep); box-shadow: 0 5px 0 rgba(0, 0, 0, .18); }
.btn-ghost { background: rgba(255, 255, 255, .75); color: var(--blue-deep); box-shadow: 0 3px 0 rgba(0, 76, 120, .15); }
.btn-ghost-dark { background: rgba(255, 255, 255, .18); color: #fff; box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .55); }
.btn-ghost-dark[aria-pressed="true"] { background: #fff; color: var(--blue-deep); }

.btn-round {
  flex: none; width: 60px; height: 60px; border-radius: 50%;
  background: #fff; color: var(--blue-deep); font-size: 24px; display: grid; place-items: center;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .18);
  transition: transform .18s var(--bounce), opacity .2s;
}
.btn-round:active { transform: translateY(4px) scale(.94); }
.btn-round:disabled { opacity: .45; }

/* ---------- Home ---------- */
.brand { text-align: center; padding-top: 6px; }
.logo {
  font-size: 54px; font-weight: 800; color: var(--blue); letter-spacing: -.5px;
  text-shadow: 0 3px 0 #fff, 0 6px 14px rgba(0, 76, 120, .2);
  position: relative; display: inline-block;
}
.logo-spark { position: absolute; top: -2px; right: -26px; font-size: 28px; color: var(--yellow); text-shadow: 0 2px 0 var(--yellow-deep); animation: twinkle 2.4s ease-in-out infinite; }
.tagline { margin: 2px 24px 0; font-size: 17px; color: var(--blue-deep); }

.hero { position: relative; display: flex; flex-direction: column; align-items: center; margin-top: 4px; }
.moose { display: block; overflow: visible; filter: drop-shadow(0 6px 8px rgba(0, 76, 120, .25)); }
.moose-hero { width: 168px; height: auto; margin-bottom: -40px; position: relative; z-index: 0; animation: bob 3.2s ease-in-out infinite; transform-origin: 50% 90%; }
.moose-small { width: 110px; height: auto; margin: 0 auto 8px; }
.moose-oops { animation: wobble 1.2s ease-in-out infinite; }
.moose-eyes { animation: blink 4.5s infinite; transform-origin: 100px 106px; }

.scan-wrap { position: relative; z-index: 1; }
.btn-scan {
  width: min(56vw, 212px); aspect-ratio: 1; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: radial-gradient(circle at 35% 28%, #FFE45C 0%, var(--yellow) 55%, #F2BE00 100%);
  color: var(--ink);
  box-shadow: 0 10px 0 var(--yellow-deep), 0 22px 36px rgba(217, 169, 0, .45), inset 0 -6px 0 rgba(0, 0, 0, .05);
  transition: transform .2s var(--bounce), box-shadow .2s;
  animation: pulse 2.6s ease-in-out infinite;
}
.btn-scan:active { transform: translateY(8px) scale(.96); box-shadow: 0 2px 0 var(--yellow-deep), 0 8px 16px rgba(217, 169, 0, .4); animation: none; }
.btn-scan-icon { font-size: 54px; line-height: 1; }
.btn-scan-label { font-family: var(--font-display); font-weight: 800; font-size: 30px; line-height: .95; text-align: center; max-width: 7ch; }

.sparkle { position: absolute; color: var(--yellow); font-size: 26px; text-shadow: 0 2px 0 var(--yellow-deep); animation: twinkle 2.2s ease-in-out infinite; pointer-events: none; }
.s1 { top: -6px; right: -10px; }
.s2 { bottom: 14px; left: -18px; font-size: 20px; color: var(--blue); text-shadow: none; animation-delay: .5s; }
.s3 { top: 30px; left: -22px; font-size: 18px; color: var(--pink); text-shadow: none; animation-delay: 1s; }
.s4 { bottom: -4px; right: 0; font-size: 18px; animation-delay: 1.5s; }

.home-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 22px; }

.switch { display: inline-flex; align-items: center; gap: 12px; min-height: 48px; cursor: pointer; font-weight: 800; color: var(--blue-deep); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 58px; height: 34px; border-radius: var(--radius-pill); background: #9DB9CC; position: relative; transition: background .2s; box-shadow: inset 0 2px 4px rgba(0, 0, 0, .15); flex: none; }
.switch-thumb { position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .25); transition: transform .25s var(--bounce); }
.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(24px); }
.switch input:focus-visible + .switch-track { outline: 4px solid var(--ink); outline-offset: 3px; }

.history { margin-top: 22px; }
.history h2 { font-size: 24px; color: var(--blue-deep); margin: 0 4px 10px; }
.history-list { list-style: none; margin: 0 -16px; padding: 4px 16px 14px; display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.history-list::-webkit-scrollbar { display: none; }
.hist {
  scroll-snap-align: start; flex: none; width: 128px; text-align: left;
  background: #fff; border-radius: 20px; padding: 6px 6px 10px; box-shadow: var(--shadow-card);
  transition: transform .18s var(--bounce);
}
.history-list > li { position: relative; flex: none; }
/* 44px hit area, small visual badge */
.hist-del { position: absolute; top: -8px; right: -8px; width: 44px; height: 44px; display: grid; place-items: center; z-index: 2; }
.hist-del span { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: rgba(11, 42, 64, .75); color: #fff; font-size: 12px; font-weight: 800; box-shadow: 0 2px 4px rgba(0, 0, 0, .25); }
.hist-del:active span { background: var(--ink); }
.hist:active { transform: scale(.95); }
.hist img { display: block; width: 100%; height: 92px; object-fit: cover; border-radius: 14px; background: var(--sky); }
.hist-wide img { object-fit: contain; }
.hist-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: 6px 4px 0; font-size: 15px; font-weight: 800; line-height: 1.2; min-height: 36px; }
.hist-time { display: block; margin: 2px 4px 0; font-size: 13px; color: var(--ink-soft); }

/* Layout segmented control (home) */
.layout-seg { display: flex; gap: 4px; margin: 0; padding: 4px; border: 0; width: 100%; max-width: 360px; background: rgba(255, 255, 255, .7); border-radius: var(--radius-pill); box-shadow: inset 0 2px 4px rgba(0, 76, 120, .12); }
.layout-seg label { flex: 1; position: relative; }
.layout-seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.layout-seg span { display: flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 6px; border-radius: var(--radius-pill); font-family: var(--font-display); font-weight: 800; font-size: 16px; line-height: 1; white-space: nowrap; color: var(--blue-deep); transition: background .2s, transform .18s var(--bounce); }
.layout-seg input:checked + span { background: var(--blue); color: #fff; box-shadow: 0 3px 0 var(--blue-deep); }
.layout-seg input:active + span { transform: scale(.96); }
.layout-seg input:focus-visible + span { outline: 4px solid var(--ink); outline-offset: 2px; }
@media (max-width: 350px) { .layout-seg span { font-size: 14px; } }

/* ---------- Loading ---------- */
.view-loading { min-height: 80dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 14px; }
.loading-moose { position: relative; width: 220px; height: 220px; display: grid; place-items: center; }
.moose-load { width: 170px; height: auto; animation: bounce-load 1s var(--bounce) infinite alternate; }
.orbit { position: absolute; top: 50%; left: 50%; font-size: 30px; color: var(--yellow); text-shadow: 0 2px 0 var(--yellow-deep); animation: orbit 3.6s linear infinite; }
.o2 { animation-delay: -1.2s; color: var(--blue); text-shadow: none; }
.o3 { animation-delay: -2.4s; }
.loading-msg { font-family: var(--font-display); font-weight: 800; font-size: 26px; color: var(--blue-deep); margin: 0; padding: 0 12px; min-height: 2.4em; animation: pop-in .4s var(--bounce); }
.dots { display: flex; gap: 10px; }
.dots i { width: 16px; height: 16px; border-radius: 50%; background: var(--blue); animation: dot 1s ease-in-out infinite; }
.dots i:nth-child(2) { background: var(--yellow); animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
#btn-cancel { margin-top: 18px; }

/* ---------- Result ---------- */
.result-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 2px; }
/* Delete: deliberately quiet, top of page (never in the sticky bar) */
.btn-delete { min-height: 44px; padding: 0 14px; border-radius: var(--radius-pill); background: rgba(255, 255, 255, .5); color: var(--ink-soft); font-family: var(--font-display); font-weight: 800; font-size: 15px; line-height: 1; border: 2px dashed rgba(79, 111, 134, .45); }
.btn-delete:active { background: #fff; }
.result-title { font-size: 30px; font-weight: 800; color: var(--blue); margin: 12px 4px 14px; text-shadow: 0 2px 0 #fff; outline: none; }

.page-peek { background: #fff; border-radius: 22px; box-shadow: var(--shadow-card); overflow: hidden; margin-bottom: 18px; }
.peek-toggle { width: 100%; min-height: 52px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; font-family: var(--font-display); font-weight: 800; font-size: 19px; color: var(--blue-deep); }
.chev { transition: transform .25s var(--bounce); font-size: 22px; }
.peek-toggle[aria-expanded="false"] .chev { transform: rotate(-90deg); }
.peek-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .3s ease; }
.peek-body > img { min-height: 0; overflow: hidden; width: 100%; max-height: 240px; object-fit: contain; background: var(--sky); display: block; }
.page-peek.wide .peek-body > img { max-height: 200px; }
.page-peek.collapsed .peek-body { grid-template-rows: 0fr; }
.page-peek.collapsed .peek-body > img { max-height: 0; }

.segments { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; counter-reset: seg; }
.seg {
  position: relative; display: block; width: 100%; text-align: left;
  background: #fff; border-radius: var(--radius); padding: 18px 18px 16px 18px;
  box-shadow: var(--shadow-card);
  border-left: 10px solid var(--yellow);
  transition: transform .25s var(--bounce), background .2s, box-shadow .2s, border-color .2s;
  animation: pop-in .5s var(--bounce) both; animation-delay: calc(var(--i, 0) * 60ms);
  scroll-margin-top: 16px; scroll-margin-bottom: calc(var(--bar-h) + 24px);
}
/* Spread: page dividers (not tappable, not part of reading) + page-2 accent */
.page-divider { display: flex; justify-content: center; margin: 6px 0 -2px; pointer-events: none; }
.page-divider span { padding: 8px 18px; border-radius: var(--radius-pill); background: var(--blue); color: #fff; font-family: var(--font-display); font-weight: 800; font-size: 17px; box-shadow: 0 3px 0 var(--blue-deep); }
.page-divider.p2 span { background: var(--yellow); color: var(--ink); box-shadow: 0 3px 0 var(--yellow-deep); }
.seg-p2 { border-left-color: var(--blue-bright); }
.seg:active { transform: scale(.98); }
.seg-num { position: absolute; top: 10px; right: 12px; min-width: 30px; height: 30px; padding: 0 8px; display: grid; place-items: center; border-radius: var(--radius-pill); background: var(--sky); color: var(--blue-deep); font-family: var(--font-display); font-weight: 800; font-size: 15px; }
.seg-sv { display: block; padding-right: 30px; font-family: var(--font-display); font-weight: 800; font-size: 28px; line-height: 1.18; color: var(--ink); }
.seg-en { display: block; margin-top: 10px; padding-top: 10px; border-top: 3px dotted var(--sky-2); font-size: 17px; font-weight: 600; color: var(--ink-soft); }
.seg-state { position: absolute; right: 12px; bottom: 10px; font-size: 20px; opacity: .85; }
.seg[data-ready="0"] .seg-state::before { content: ""; display: block; width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--sky-2); border-top-color: var(--blue); animation: spin .8s linear infinite; }
.seg[data-ready="1"] .seg-state::before { content: "\1F50A"; }
.seg[data-ready="err"] .seg-state::before { content: "\21BB"; color: var(--blue); font-weight: 800; }
.seg.active, .seg-p2.active {
  background: #FFF6C7; border-left-color: var(--blue);
  box-shadow: 0 0 0 4px var(--yellow), 0 12px 28px rgba(217, 169, 0, .4);
  transform: scale(1.02);
}
.seg.active .seg-en { color: var(--ink); border-top-color: #F2D45E; }
.seg.active .seg-state::before { content: "\1F3B5"; animation: wiggle .7s ease-in-out infinite; display: block; width: auto; height: auto; border: 0; }

.card-msg { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-card); padding: 26px 22px 26px; text-align: center; margin-top: 18px; }
.card-msg h2 { font-size: 30px; color: var(--blue); margin-bottom: 8px; }
.card-msg p { margin: 0 0 20px; font-size: 19px; color: var(--ink-soft); }
.view-error { padding-top: 12vh; }
.error-actions { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.error-actions .btn-ghost { background: var(--sky); }

/* ---------- Sticky bar ---------- */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  max-width: 520px; margin: 0 auto;
  padding: 14px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: var(--blue);
  border-radius: 30px 30px 0 0;
  box-shadow: 0 -8px 24px rgba(0, 76, 120, .3), inset 0 4px 0 rgba(255, 255, 255, .25);
  display: flex; flex-direction: column; gap: 12px;
  animation: slide-up .5s var(--bounce) both;
}
.bar-row { display: flex; gap: 12px; align-items: center; }
.btn-read { flex: 1; min-height: 60px; font-size: 24px; }
.btn-read #read-icon { font-size: 22px; }
.btn-read.hint { animation: pulse 1.1s ease-in-out infinite; }
.btn-speed { flex: none; min-width: 124px; }
.btn-next { flex: 1; }

/* ---------- Confirm sheet (delete) ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.sheet-wrap[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(11, 42, 64, .5); animation: fade-in .2s both; }
.sheet { position: relative; width: 100%; max-width: 480px; background: #fff; border-radius: 28px 28px 0 0; padding: 20px 22px calc(22px + env(safe-area-inset-bottom)); text-align: center; box-shadow: 0 -10px 30px rgba(0, 76, 120, .25); animation: sheet-up .35s var(--bounce) both; }
.sheet .moose-small { width: 84px; height: auto; }
.sheet h2 { font-size: 28px; color: var(--blue); margin: 6px 0 6px; }
.sheet p { margin: 0 0 18px; color: var(--ink-soft); font-size: 17px; }
.sheet-actions { display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.sheet-actions .btn-danger { color: var(--ink-soft); box-shadow: none; border: 2px solid rgba(79, 111, 134, .35); background: #fff; }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Misc: offline, toast, confetti ---------- */
.offline { position: sticky; top: 0; z-index: 40; background: var(--ink); color: #fff; text-align: center; padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; font-weight: 800; font-size: 16px; }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 10px); z-index: 50; max-width: 480px; margin: 0 auto; background: var(--ink); color: #fff; padding: 14px 18px; border-radius: 20px; font-weight: 800; text-align: center; box-shadow: var(--shadow-soft); animation: pop-in .35s var(--bounce); }
body:not([data-view="result"]) .toast { bottom: calc(env(safe-area-inset-bottom) + 24px); }

.confetti { position: fixed; inset: 0; z-index: 60; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; width: 10px; height: 16px; border-radius: 3px; animation: confetti 1.3s cubic-bezier(.2, .7, .3, 1) forwards; }

/* ---------- Animations ---------- */
@keyframes pop-in { from { opacity: 0; transform: translateY(14px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes slide-up { from { transform: translateY(110%); } to { transform: none; } }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-1.5deg); } 50% { transform: translateY(-8px) rotate(1.5deg); } }
@keyframes wobble { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.045); } }
@keyframes twinkle { 0%, 100% { transform: scale(.7) rotate(0); opacity: .6; } 50% { transform: scale(1.2) rotate(25deg); opacity: 1; } }
@keyframes bounce-load { from { transform: translateY(8px) scale(1.04, .94); } to { transform: translateY(-14px) scale(.97, 1.04); } }
@keyframes orbit { from { transform: rotate(0) translateX(100px) rotate(0); } to { transform: rotate(360deg) translateX(100px) rotate(-360deg); } }
@keyframes dot { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes wiggle { 0%, 100% { transform: rotate(-12deg); } 50% { transform: rotate(12deg) scale(1.15); } }
@keyframes confetti {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; }
}

@media (min-width: 560px) { body { font-size: 19px; } .bar { border-radius: 30px; bottom: 12px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .confetti { display: none; }
}
