:root {
  --bg: #ffffff;
  --page: #ffffff;
  --card: #f3e3bf;
  --ink: #2b1d18;
  --muted: #6e5f4e;
  --accent: #d758a5;
  --accent-soft: #ffddef;
  --line: #35241d;
  --panel-soft: #f9f5eb;
  --success: #57c65b;
  --shadow: none;
  --control-size: 48px;
  --radius-lg: 28px;
  --radius-md: 18px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: 'Nunito', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(120% 100% at 12% 10%, color-mix(in srgb, var(--accent-soft) 46%, transparent) 0%, transparent 58%),
    radial-gradient(100% 95% at 84% 14%, color-mix(in srgb, var(--card) 52%, transparent) 0%, transparent 60%),
    radial-gradient(120% 110% at 54% 88%, color-mix(in srgb, var(--accent-soft) 28%, transparent) 0%, transparent 62%),
    var(--page);
  background-repeat: no-repeat;
  background-size:
    118% 118%,
    116% 116%,
    124% 124%,
    100% 100%;
  animation: pagePulse 9.8s ease-in-out infinite;
  display: grid;
  place-items: center;
  padding:
    max(14px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
}

@keyframes pagePulse {
  0%,
  100% {
    background-position:
      10% 8%,
      84% 12%,
      52% 90%,
      0 0;
    background-size:
      116% 116%,
      114% 114%,
      122% 122%,
      100% 100%;
  }
  50% {
    background-position:
      14% 12%,
      80% 16%,
      56% 86%,
      0 0;
    background-size:
      124% 124%,
      120% 120%,
      130% 130%,
      100% 100%;
  }
}

.app-shell {
  width: min(100%, 520px);
  background: var(--card);
  border-radius: 34px;
  box-shadow: var(--shadow);
  border: 2px solid var(--line);
  padding: 20px;
}

.pin-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(3px);
  padding: 16px;
}

.pin-card {
  width: min(100%, 360px);
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  display: grid;
  gap: 10px;
}

.pin-card h2 {
  margin: 0;
}

.pin-card p {
  margin: 0;
}

.pin-card input {
  border: 1px solid #b9ab9a;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
}

.pin-error {
  min-height: 1.2em;
  color: #8b1c4b;
  font-size: 0.9rem;
}

.onboarding-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(4px);
}

.onboarding-card {
  width: min(100%, 460px);
  border-radius: 28px;
  background: var(--card);
  border: 2px solid var(--line);
  box-shadow: none;
  padding: 24px 20px;
  text-align: center;
}

.onboard-orb {
  position: relative;
  margin: 0 auto 10px;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 28% 22%, rgba(255, 255, 255, 0.92) 0%, rgba(255, 255, 255, 0.2) 32%, transparent 50%),
    radial-gradient(circle at 72% 70%, #98e0d3 0%, #8fd8cb 40%, #6ab8a9 100%);
  box-shadow:
    inset -6px -8px 12px rgba(67, 127, 117, 0.35),
    0 9px 16px rgba(67, 127, 117, 0.26);
}

.onboard-orb .eye-left {
  top: 22px;
  left: 17px;
}

.onboard-orb .eye-right {
  top: 19px;
  left: 33px;
}

.onboard-tag {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
  color: #6a4761;
  letter-spacing: 0.02em;
  text-transform: lowercase;
}

.onboard-slide {
  display: none;
}

.onboard-slide.is-active {
  display: block;
}

.onboard-title {
  margin: 6px 0 8px;
  font-family: 'Baloo 2', system-ui;
  color: #2f2019;
  font-size: 2.2rem;
  line-height: 0.95;
  text-transform: lowercase;
}

.onboard-copy {
  margin: 0 auto 12px;
  max-width: 33ch;
  color: #4f3e31;
  font-size: 1rem;
}

.onboard-steps {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.onboard-steps span {
  border: 2px solid #101012;
  border-radius: 999px;
  background: #ffeef7;
  padding: 6px 10px;
  font-size: 0.88rem;
  font-weight: 700;
  text-transform: lowercase;
}

.onboard-btn {
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 12px 20px;
  width: 100%;
  max-width: 260px;
  background: linear-gradient(145deg, #ef82c0 0%, #db57a6 100%);
  color: #fff;
  font: inherit;
  font-weight: 800;
  font-size: 1rem;
  text-transform: lowercase;
  cursor: pointer;
  min-height: 48px;
}

.onboard-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

#onboardBackBtn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.onboard-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 0 0 14px;
}

.onboard-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 1px solid #1e1b21;
  background: #fff6fb;
  padding: 0;
  cursor: pointer;
}

.onboard-dot.is-active {
  background: #d758a5;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  margin: 0;
  font-size: 0.84rem;
  color: #5f5042;
  letter-spacing: 0.04em;
}

h1,
h2 {
  font-family: 'Baloo 2', system-ui;
  margin: 0;
  line-height: 1;
}

h1 {
  font-size: 1.65rem;
}

h2 {
  font-size: 1.6rem;
}

.badge {
  border: 1.5px solid var(--line);
  border-radius: 999px;
  min-height: var(--control-size);
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  font-weight: 700;
  background: var(--panel-soft);
  cursor: pointer;
}

.icon-btn {
  width: var(--control-size);
  height: var(--control-size);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--panel-soft);
  font-size: 1.2rem;
  cursor: pointer;
}

.orb-3d {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  background:
    radial-gradient(circle at 28% 22%, rgba(255, 255, 255, 0.88) 0%, rgba(255, 255, 255, 0.18) 33%, transparent 50%),
    radial-gradient(circle at 72% 72%, #8fd8cb 0%, #9de3d6 46%, #71bcae 80%, #63a99d 100%);
  box-shadow:
    inset -4px -7px 12px rgba(70, 128, 117, 0.35),
    inset 3px 4px 9px rgba(255, 255, 255, 0.5),
    0 7px 14px rgba(74, 129, 120, 0.22);
}

.orb-3d:focus-visible {
  outline: 2px solid #2f3c56;
  outline-offset: 2px;
}

.orb-3d.is-squishing {
  animation: orbSquish 260ms cubic-bezier(0.22, 0.7, 0.22, 1);
}

.kid-title {
  font-family: 'Baloo 2', system-ui;
  color: #2f2019;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 0.95;
  letter-spacing: 0.01em;
  text-transform: lowercase;
  max-width: none;
}

.title-line {
  display: flex;
  gap: 6px;
}

.kid-title span {
  display: inline-block;
}

.line-1 span:nth-child(1) {
  transform: rotate(-4deg) translateY(1px);
}

.line-1 span:nth-child(2) {
  transform: rotate(3deg) translateY(-2px);
}

.line-2 span:nth-child(1) {
  transform: rotate(-2deg) translateY(2px);
}

.line-2 span:nth-child(2) {
  transform: rotate(2deg) translateY(-1px);
}

.orb-eye {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #f6f6f6;
  box-shadow:
    inset -1.5px -1.5px 2px rgba(0, 0, 0, 0.12),
    inset 1px 1px 2px rgba(255, 255, 255, 0.75);
  transform-origin: center 55%;
  animation: orbBlink 19.6s ease-in-out infinite;
}

.orb-eye::after {
  content: '';
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: #20263a;
  top: 2.5px;
  left: 2.2px;
  transform: translate(var(--pupil-x, 0px), var(--pupil-y, 0px));
  transition: transform 140ms ease-out;
}

.eye-left {
  top: 13px;
  left: 10px;
}

.eye-right {
  top: 11px;
  left: 20px;
  animation-delay: 0.12s;
}

.top-bar .orb-3d.focus-blink .orb-eye {
  animation: orbQuickBlink 300ms ease-in-out 1;
}

.top-bar .orb-3d.wink-left .eye-left {
  animation: orbQuickBlink 320ms ease-in-out 1;
}

.top-bar .orb-3d.wink-right .eye-right {
  animation: orbQuickBlink 320ms ease-in-out 1;
}

@keyframes orbBlink {
  0%,
  10%,
  90%,
  100% {
    transform: scaleY(1);
  }
  6% {
    transform: scaleY(0.16);
  }
}

@keyframes orbQuickBlink {
  0%,
  100% {
    transform: scaleY(1);
  }
  45%,
  55% {
    transform: scaleY(0.14);
  }
}

@keyframes orbSquish {
  0% {
    transform: scale(1, 1);
  }
  35% {
    transform: scale(1.16, 0.78) translateY(1px);
  }
  62% {
    transform: scale(0.9, 1.12) translateY(-0.5px);
  }
  100% {
    transform: scale(1, 1);
  }
}

.camera-card {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #fffaf0;
  aspect-ratio: 4 / 5;
  min-height: min(56dvh, 620px);
  border: 1.5px solid var(--line);
}

.content-layout {
  display: grid;
  gap: 14px;
}

#camera,
#snapshotCanvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#snapshotCanvas {
  display: none;
}

.camera-overlay {
  position: absolute;
  inset: auto 0 0;
  padding: 16px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent 75%);
  color: #fff;
}

.search-eyes-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.24);
  z-index: 2;
}

.search-eyes {
  display: flex;
  align-items: center;
  gap: 18px;
  transform: translateY(-4%);
}

.search-eye {
  width: 108px;
  height: 108px;
  border-radius: 999px;
  background: #ffffff;
  position: relative;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
}

.search-eye .pupil {
  position: absolute;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: #111111;
  top: 38px;
  left: 37px;
  transform: translate(var(--search-pupil-x, 0px), var(--search-pupil-y, 0px));
  transition: transform 120ms ease-out;
}

#statusText {
  margin: 0 0 12px;
  font-size: 1.05rem;
  font-weight: 700;
}

.camera-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.rotate-btn {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.85);
  color: #222;
  border-color: #222;
  font-size: 1.35rem;
  font-weight: 700;
}

.stop-btn {
  background: rgba(255, 255, 255, 0.85);
  color: #222;
  border-color: #222;
  font-size: 1.1rem;
  font-weight: 700;
}

.capture-btn {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  border: 4px solid #ffffff;
  background: transparent;
  padding: 8px;
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--line);
  min-width: 48px;
  min-height: 48px;
}

.capture-btn span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: linear-gradient(145deg, #e97cbc 0%, #cf569d 100%);
}

.result-card {
  margin-top: 14px;
  border-radius: var(--radius-md);
  background: var(--panel-soft);
  border: 1.5px solid var(--line);
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  transform: translateY(0);
  animation: pop 220ms ease;
}

.result-head {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
}

.result-main {
  min-width: 0;
}

.result-audio-col {
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
}

.sound-btn {
  border: 1.5px solid var(--line);
  background: #ffe7f3;
  border-radius: 14px;
  font-size: 1.2rem;
  width: 48px;
  height: 48px;
  cursor: pointer;
  min-width: 48px;
  min-height: 48px;
}

.sci-line,
#descriptionText {
  margin: 8px 0 0;
}

.sci-line {
  color: #242433;
}

#descriptionText {
  color: #2f3140;
}

.synopsis-text {
  margin: 10px 0 0;
  color: #4f3e31;
}

.images-head {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.images-head a {
  color: #6a2f92;
  font-weight: 700;
  text-decoration: none;
}

.images-head a:hover {
  text-decoration: underline;
}

.fact-text {
  margin: 8px 0 0;
  padding: 8px 10px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.45);
  color: #4f3e31;
  font-size: 0.95rem;
}

.image-strip {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.image-card {
  border: 1.5px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  aspect-ratio: 1 / 1;
}

.image-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.hidden {
  display: none;
}

.settings-dialog {
  border: none;
  border-radius: 18px;
  width: min(360px, 90vw);
  padding: 0;
}

@media (max-width: 430px) {
  .icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 14px;
  }

  .onboarding-card {
    border-radius: 22px;
    padding: 20px 14px;
  }

  .onboard-title {
    font-size: 1.9rem;
  }

  .app-shell {
    border-radius: 24px;
    padding: 14px;
  }

  .kid-title {
    font-size: 1.5rem;
  }

  .badge {
    padding: 5px 10px;
    font-size: 0.85rem;
  }

  .camera-card {
    border-radius: 22px;
    min-height: 52dvh;
  }

  .capture-btn {
    width: 82px;
    height: 82px;
  }

  .search-eye {
    width: 84px;
    height: 84px;
  }

  .search-eye .pupil {
    width: 28px;
    height: 28px;
    top: 28px;
    left: 28px;
  }
}

@media (min-width: 768px) {
  .onboarding-card {
    width: min(100%, 560px);
    padding: 28px 24px;
  }

  .onboard-title {
    font-size: 2.5rem;
  }

  body {
    padding:
      max(24px, env(safe-area-inset-top))
      max(22px, env(safe-area-inset-right))
      max(24px, env(safe-area-inset-bottom))
      max(22px, env(safe-area-inset-left));
  }

  .app-shell {
    width: min(100%, 760px);
    padding: 22px;
    border-radius: 30px;
  }

  .top-bar {
    margin-bottom: 16px;
  }

  .kid-title {
    font-size: 2rem;
  }

  .orb-3d {
    width: 44px;
    height: 44px;
  }

  .orb-eye {
    width: 10px;
    height: 10px;
  }

  .orb-eye::after {
    width: 4.2px;
    height: 4.2px;
    top: 2.7px;
    left: 2.5px;
  }

  .eye-left {
    top: 16px;
    left: 12px;
  }

  .eye-right {
    top: 13px;
    left: 24px;
  }

  .camera-card {
    aspect-ratio: 16 / 10;
    min-height: min(58dvh, 700px);
    border-radius: 24px;
  }

  #statusText {
    font-size: 1rem;
  }

  .capture-btn {
    width: 88px;
    height: 88px;
  }

  .result-card {
    margin-top: 16px;
    padding: 16px;
  }
}

@media (min-width: 1024px) and (orientation: landscape) {
  .app-shell {
    width: min(100%, 1040px);
  }

  .content-layout {
    grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.65fr);
    align-items: stretch;
    gap: 16px;
  }

  .camera-card {
    aspect-ratio: auto;
    min-height: min(66dvh, 740px);
  }

  .result-card {
    margin-top: 0;
    height: 100%;
    align-self: stretch;
    grid-template-columns: minmax(0, 1fr) auto;
    align-content: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

.settings-dialog::backdrop {
  background: rgba(10, 10, 20, 0.45);
}

.settings-form {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.settings-form h3 {
  margin: 0;
  font-family: 'Baloo 2', system-ui;
  font-size: 1.5rem;
}

.settings-form label {
  font-weight: 700;
}

.settings-form input {
  border: 1px solid #b9ab9a;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
}

.helper {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.secondary-btn,
.primary-btn {
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
}

.secondary-btn {
  background: var(--panel-soft);
  color: #3f3128;
}

.primary-btn {
  background: linear-gradient(145deg, #ef82c0 0%, #db57a6 100%);
  color: #fff;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
