/* ============================================================================
   OLIVIA'S MAGICAL PROJECT CASTLE — styles
   Soft pastel storybook look, large readable text, responsive & accessible.
   ========================================================================== */

:root {
  --pink:   #ff8fb1;
  --pink-d: #e04d95;
  --purple: #7c5cff;
  --blue:   #7fa8ff;
  --yellow: #ffd36b;
  --cream:  #fff8ef;
  --ink:    #4a3b7a;
  --ink-soft:#6b5ca0;
  --card:   #ffffff;
  --shadow: 0 10px 30px rgba(90, 63, 214, 0.18);
  --shadow-sm: 0 4px 14px rgba(90, 63, 214, 0.14);
  --radius: 22px;
  --focus: 3px solid #2b1a66;
  --font: "Baloo 2", "Comic Sans MS", "Trebuchet MS", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(160deg, #bfe3ff 0%, #e7d8ff 55%, #ffe0ee 100%);
  -webkit-text-size-adjust: 100%;
}

body { overflow: hidden; }
body.scroll-ok { overflow: auto; }

/* Focus visibility for keyboard users */
a:focus-visible, button:focus-visible, [tabindex]:focus-visible {
  outline: var(--focus);
  outline-offset: 3px;
  border-radius: 12px;
}

img { max-width: 100%; display: block; }

/* ---------- App shell ---------- */
#app { position: fixed; inset: 0; }

#scene-3d { position: absolute; inset: 0; z-index: 1; }
#scene-3d canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* Overlay layer holds the 2D UI on top of / instead of the 3D scene */
#overlay {
  position: absolute; inset: 0; z-index: 2;
  pointer-events: none;              /* let 3D receive events by default */
}
#overlay > * { pointer-events: auto; }

/* ---------- Top bar (home, breadcrumb, controls) ---------- */
.topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  z-index: 5;
  flex-wrap: wrap;
}
.topbar .spacer { flex: 1; }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--card);
  border: none;
  color: var(--ink);
  font-family: var(--font); font-weight: 700; font-size: 1rem;
  padding: 10px 16px; border-radius: 999px;
  box-shadow: var(--shadow-sm); cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.pill:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.pill:active { transform: translateY(0); }
.pill .ic { font-size: 1.2rem; line-height: 1; }
.pill.small { padding: 9px 12px; font-size: .95rem; }
.pill.toggle[aria-pressed="true"] { background: var(--yellow); color: #6a4d00; }

.breadcrumb {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.8);
  padding: 8px 14px; border-radius: 999px;
  font-weight: 700; box-shadow: var(--shadow-sm);
  max-width: 60vw; overflow: hidden;
}
.breadcrumb button {
  background: none; border: none; color: var(--ink-soft);
  font-family: var(--font); font-weight: 700; font-size: .95rem; cursor: pointer;
  padding: 2px 4px; border-radius: 8px; white-space: nowrap;
}
.breadcrumb button:last-child { color: var(--ink); }
.breadcrumb .sep { color: #b9a9e6; }

/* ---------- Screens (full 2D pages) ---------- */
.screen {
  position: absolute; inset: 0; z-index: 3;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 84px 20px 40px;
  display: none;
}
.screen.active { display: block; }
.screen-inner { max-width: 1040px; margin: 0 auto; }

/* Entrance screen sits over the 3D exterior; it is see-through */
#screen-entrance {
  background: transparent;
  align-items: center; justify-content: center;
  text-align: center; padding: 20px;
}
#screen-entrance.active { display: flex; }

/* Hero layout: title floats over the sky, castle stays visible in the middle,
   and a frosted glass panel holds the welcome + Enter button at the bottom. */
#screen-entrance.hero.active {
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: clamp(16px, 4vh, 40px) 16px clamp(16px, 3vh, 30px);
  pointer-events: none;          /* let clicks reach the 3D castle door */
}

.entrance-top { text-align: center; pointer-events: none; }
.entrance-top .crest { font-size: 2.2rem; line-height: 1; }
.entrance-top h1 {
  font-size: clamp(2rem, 6vw, 3.4rem);
  margin: 4px 0 2px; color: var(--pink-d); line-height: 1.05;
  text-shadow: 0 2px 0 #fff, 0 3px 0 #fff, 0 4px 14px rgba(120,80,200,0.35);
}
.entrance-top .subtitle {
  font-size: clamp(1rem, 2.6vw, 1.25rem); color: #5a4a94; margin: 0; font-weight: 800;
  text-shadow: 0 1px 0 #fff, 0 2px 8px rgba(255,255,255,0.7);
}

/* Middle spacer so the castle shows through between title and panel */
.entrance-mid { flex: 1; min-height: 40px; }

/* Decorative castle shown only when the 3D scene is NOT available */
.entrance-fallback {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
}
.entrance-fallback .big-castle { font-size: clamp(5rem, 22vw, 9rem); line-height: 1;
  filter: drop-shadow(0 12px 18px rgba(120,80,200,0.25)); }
.entrance-fallback .clouds { font-size: 1.8rem; letter-spacing: 12px; opacity: 0.9; }

.entrance-bottom {
  width: 100%; max-width: 600px;
  pointer-events: auto;          /* but keep the welcome panel interactive */
  background: rgba(255,255,255,0.58);
  backdrop-filter: blur(9px); -webkit-backdrop-filter: blur(9px);
  border: 2px solid rgba(255,255,255,0.8);
  border-radius: 30px; padding: 20px 24px 22px;
  box-shadow: 0 12px 34px rgba(90,63,214,0.22);
  text-align: center;
}
.entrance-bottom .welcome {
  font-size: clamp(1rem, 2.5vw, 1.16rem); line-height: 1.5; margin: 4px 0 16px; color: var(--ink);
}

.entrance-card {
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(4px);
  border-radius: 30px; padding: 30px 28px;
  box-shadow: var(--shadow); max-width: 560px;
  border: 4px solid #fff;
}
.entrance-card h1 {
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  margin: 6px 0 4px; color: var(--pink-d); line-height: 1.1;
}
.entrance-card .welcome { font-size: 1.15rem; line-height: 1.5; margin: 14px 0 20px; }
.guide {
  display: inline-flex; align-items: center; gap: 10px;
  background: #fff4fb; border: 2px dashed var(--pink);
  border-radius: 18px; padding: 10px 16px; margin: 6px 0 4px;
  font-size: 1rem;
}
.guide .face { font-size: 1.8rem; }

.btn-big {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: var(--font); font-weight: 800;
  font-size: 1.35rem; color: #fff;
  background: linear-gradient(180deg, #ffa6c4, var(--pink-d));
  border: none; border-radius: 999px;
  padding: 16px 34px; cursor: pointer;
  box-shadow: 0 10px 24px rgba(224,77,149,0.45);
  transition: transform .14s ease, box-shadow .14s ease;
}
.btn-big:hover { transform: translateY(-3px) scale(1.02); box-shadow: 0 14px 30px rgba(224,77,149,0.5); }
.btn-big:active { transform: translateY(0); }
.btn-big.secondary {
  background: linear-gradient(180deg, #b9c8ff, #7c5cff);
  box-shadow: 0 10px 24px rgba(124,92,255,0.4);
  font-size: 1.05rem; padding: 12px 24px;
}

.mode-switch { margin-top: 14px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.scroll-tip {
  margin: 14px 0 0; font-size: 0.98rem; font-weight: 700; color: var(--ink-soft);
  animation: tipbob 1.8s ease-in-out infinite;
}
@keyframes tipbob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(4px); } }

/* white seam flash for the scroll fly-in */
#intro-fade {
  position: absolute; inset: 0; z-index: 15;
  background: #ffffff; opacity: 0; pointer-events: none;
  transition: opacity 0.5s ease;
}
#screen-entrance { transition: opacity 0.2s ease; }

/* Compact entrance so the whole castle stays visible above the panel */
.entrance-top { margin-top: 2px; }
.entrance-top .crest { font-size: 1.5rem; margin-bottom: 2px; }
.entrance-bottom { padding: 15px 20px 15px; }
.entrance-bottom .guide { margin: 0 0 11px; padding: 7px 14px; font-size: 0.95rem; }
.entrance-bottom .btn-big { font-size: 1.25rem; padding: 14px 30px; }
.pill.tiny { padding: 7px 12px; font-size: 0.85rem; }
@media (max-width: 560px) {
  #screen-entrance.hero.active { padding: 12px 12px 14px; }
  .entrance-top h1 { font-size: 1.7rem; }
  .entrance-bottom { padding: 12px 14px; border-radius: 24px; }
  .entrance-bottom .guide { font-size: 0.86rem; margin-bottom: 8px; }
  .entrance-bottom .btn-big { font-size: 1.12rem; padding: 12px 24px; }
  .scroll-tip { font-size: 0.82rem; margin-top: 10px; }
}

/* ---------- Section headings ---------- */
.room-header { text-align: center; margin-bottom: 22px; }
.room-header .emoji { font-size: 3rem; }
.room-header h2 { font-size: clamp(1.6rem, 4vw, 2.4rem); margin: 6px 0; }
.room-header p { font-size: 1.1rem; color: var(--ink-soft); margin: 0 auto; max-width: 640px; }

/* ---------- Card grids (hall menu, room project lists) ---------- */
.card-grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.door-card {
  background: var(--card); border-radius: var(--radius);
  padding: 22px 20px; text-align: center; cursor: pointer;
  box-shadow: var(--shadow-sm); border: 3px solid transparent;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font: inherit; color: inherit;
}
.door-card:hover, .door-card:focus-visible {
  transform: translateY(-5px); box-shadow: var(--shadow);
  border-color: var(--card-accent, var(--purple));
}
.door-card .card-emoji {
  font-size: 3.2rem; line-height: 1;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.12));
}
.door-card h3 { margin: 8px 0 2px; font-size: 1.3rem; }
.door-card p { margin: 0; font-size: .98rem; color: var(--ink-soft); line-height: 1.35; }
.door-card .count {
  margin-top: 8px; font-size: .85rem; font-weight: 800;
  background: var(--card-soft, #eee); color: var(--card-accent, var(--purple));
  padding: 4px 12px; border-radius: 999px;
}
.door-card .soon-tag {
  margin-top: 8px; font-size: .82rem; font-weight: 800;
  background: #fff3cf; color: #8a6d00; padding: 4px 12px; border-radius: 999px;
}

/* ---------- Project detail ---------- */
.project-page { background: var(--card); border-radius: 28px; box-shadow: var(--shadow); overflow: hidden; }
.project-hero { padding: 26px 26px 10px; }
.project-hero h2 { font-size: clamp(1.6rem, 4vw, 2.3rem); margin: 0 0 6px; }
.project-hero .meta { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; color: var(--ink-soft); font-weight: 700; }
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card-soft, #f0ecff); color: var(--card-accent, var(--purple));
  padding: 5px 14px; border-radius: 999px; font-size: .9rem; font-weight: 800;
}
.project-body { padding: 6px 26px 26px; }
.media-frame {
  margin: 16px 0; border-radius: 20px; overflow: hidden;
  border: 5px solid #fff; box-shadow: var(--shadow-sm);
  background: #faf6ff;
}
.media-frame img { width: 100%; height: auto; }
.project-body h3 { font-size: 1.25rem; margin: 22px 0 8px; display: flex; align-items: center; gap: 8px; }
.project-body p { font-size: 1.1rem; line-height: 1.55; }
.skill-list { display: flex; gap: 8px; flex-wrap: wrap; padding: 0; margin: 6px 0 0; list-style: none; }
.skill-list li {
  background: #fff4fb; border: 2px solid var(--pink);
  color: var(--pink-d); font-weight: 700;
  padding: 6px 14px; border-radius: 999px; font-size: .98rem;
}
.placeholder-note {
  background: #fff8e2; border: 2px dashed #f2b705; color: #8a6d00;
  border-radius: 16px; padding: 12px 16px; font-size: 1rem; line-height: 1.4;
  margin: 8px 0;
}
.reflection-box {
  background: linear-gradient(135deg,#fff0f7,#f3edff);
  border-radius: 18px; padding: 16px 20px; font-size: 1.12rem; line-height: 1.55;
  border-left: 6px solid var(--pink);
}
.project-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 22px; align-items: center; }
.link-out {
  display: inline-flex; align-items: center; gap: 8px;
  background: linear-gradient(180deg,#a9f0c6,#3fb984);
  color: #06432a; font-weight: 800; text-decoration: none;
  padding: 13px 22px; border-radius: 999px; font-size: 1.1rem;
  box-shadow: 0 8px 18px rgba(63,185,132,0.4);
}
.link-out:hover { transform: translateY(-2px); }

.prevnext { display: flex; justify-content: space-between; gap: 10px; margin-top: 26px; }
.prevnext .pill { max-width: 48%; }
.prevnext .pill span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Achievements ---------- */
.trophy-grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(230px,1fr)); }
.trophy {
  background: linear-gradient(180deg,#fffdf4,#fff2c9);
  border: 3px solid var(--yellow); border-radius: 22px;
  padding: 22px; text-align: center; box-shadow: var(--shadow-sm);
  transition: transform .15s ease;
}
.trophy:hover { transform: translateY(-4px) rotate(-1deg); }
.trophy .ic { font-size: 3.4rem; filter: drop-shadow(0 4px 6px rgba(180,140,0,0.3)); }
.trophy h3 { margin: 8px 0 4px; }
.trophy p { margin: 0; color: var(--ink-soft); font-size: 1rem; line-height: 1.4; }
.trophy .date { display: inline-block; margin-top: 8px; font-weight: 800; color: #a67c00; }

/* ---------- Olivia's room ---------- */
.about-card {
  background: var(--card); border-radius: 28px; box-shadow: var(--shadow);
  padding: 26px; display: grid; gap: 20px;
  grid-template-columns: 220px 1fr;
}
.about-avatar {
  text-align: center;
}
.about-avatar img {
  width: 200px; height: 200px; object-fit: cover; margin: 0 auto;
  border-radius: 50%; border: 6px solid var(--pink); background: #fff4fb;
  box-shadow: var(--shadow-sm);
}
.about-avatar .crown { font-size: 2rem; margin-top: 8px; }
.about-info h2 { margin: 0 0 4px; font-size: 2rem; }
.about-info .age { color: var(--ink-soft); font-weight: 800; font-size: 1.1rem; }
.about-block { margin-top: 16px; }
.about-block h3 { margin: 0 0 6px; font-size: 1.2rem; display: flex; gap: 8px; align-items: center; }
.about-block p { margin: 0; font-size: 1.1rem; line-height: 1.5; }
.chip-list { display: flex; gap: 8px; flex-wrap: wrap; padding: 0; margin: 0; list-style: none; }
.chip-list li { background: #eef0ff; color: var(--purple); font-weight: 700; padding: 6px 14px; border-radius: 999px; }
.message-bubble {
  background: linear-gradient(135deg,#fff0f7,#f3edff);
  border-radius: 18px; padding: 16px 20px; font-size: 1.15rem; line-height: 1.5;
  border: 2px dashed var(--pink);
}

/* ---------- Coming soon room ---------- */
.coming-soon {
  text-align: center; background: var(--card); border-radius: 28px;
  padding: 46px 26px; box-shadow: var(--shadow); max-width: 620px; margin: 0 auto;
}
.coming-soon .big { font-size: 4rem; }
.coming-soon h2 { font-size: 1.8rem; margin: 10px 0; }
.coming-soon p { font-size: 1.15rem; color: var(--ink-soft); line-height: 1.5; }

/* ---------- Map ---------- */
.map-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); }
.map-cell {
  background: var(--card); border-radius: 18px; padding: 16px 10px; text-align: center;
  cursor: pointer; box-shadow: var(--shadow-sm); border: 3px solid transparent; font: inherit; color: inherit;
}
.map-cell:hover, .map-cell:focus-visible { border-color: var(--purple); transform: translateY(-3px); }
.map-cell .e { font-size: 2.2rem; }
.map-cell .n { display: block; margin-top: 6px; font-weight: 800; font-size: .98rem; }

/* ---------- Modal / panels ---------- */
.modal-backdrop {
  position: absolute; inset: 0; z-index: 20;
  background: rgba(60,40,110,0.4);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-backdrop.active { display: flex; }
.modal {
  background: var(--card); border-radius: 26px; box-shadow: var(--shadow);
  max-width: 520px; width: 100%; max-height: 86vh; overflow-y: auto; padding: 26px;
}
.modal h2 { margin: 0 0 6px; }
.modal .close-x {
  float: right; background: #f0ecff; border: none; border-radius: 50%;
  width: 40px; height: 40px; font-size: 1.4rem; cursor: pointer; color: var(--ink);
}
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 0; border-bottom: 1px solid #eee6ff;
}
.setting-row:last-child { border-bottom: none; }
.setting-row .label { font-weight: 700; font-size: 1.05rem; }
.setting-row .desc { font-size: .9rem; color: var(--ink-soft); font-weight: 500; }
.switch {
  position: relative; width: 62px; height: 34px; flex: none;
  background: #d9d2f2; border-radius: 999px; border: none; cursor: pointer; transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 4px; left: 4px; width: 26px; height: 26px;
  background: #fff; border-radius: 50%; transition: left .2s; box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.switch[aria-checked="true"] { background: #6fce9c; }
.switch[aria-checked="true"]::after { left: 32px; }
.parent-box { background: #fff8e2; border: 2px dashed #f2b705; border-radius: 16px; padding: 12px 16px; margin-top: 12px; }
.parent-box h3 { margin: 0 0 4px; color: #8a6d00; }
.credits { margin-top: 14px; font-size: 0.82rem; color: var(--ink-soft); line-height: 1.5; text-align: center; }
.credits a { color: var(--purple); font-weight: 700; }

/* ---------- Loading ---------- */
#loading {
  position: absolute; inset: 0; z-index: 40; display: flex;
  flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: linear-gradient(160deg, #bfe3ff, #ffe0ee);
}
#loading .castle-emoji { font-size: 4.5rem; animation: bob 1.6s ease-in-out infinite; }
#loading p { font-size: 1.3rem; font-weight: 800; color: var(--pink-d); }
@keyframes bob { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-12px)} }

/* Toast */
#toast {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(120%);
  background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 999px;
  font-weight: 700; z-index: 50; transition: transform .3s ease; box-shadow: var(--shadow);
  max-width: 90vw; text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); }

/* Hall on-screen navigation arrows (explore mode) */
.hall-controls {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 12px; z-index: 5; flex-wrap: wrap; justify-content: center;
  max-width: 96vw;
}
@media (max-width: 720px) {
  /* on touch you drag to look and use "Map" in the top bar, so these are hidden
     (!important overrides the inline display:flex set in JS) */
  .hall-controls { display: none !important; }
  .hall-hint { bottom: 22px; }
}
.hall-hint {
  position: absolute; bottom: 84px; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,0.85); padding: 8px 18px; border-radius: 999px;
  font-weight: 700; color: var(--ink-soft); z-index: 5; box-shadow: var(--shadow-sm);
  text-align: center; max-width: 92vw; font-size: 0.98rem;
}
@media (max-width: 720px) {
  .hall-hint { font-size: 0.78rem; padding: 5px 12px; bottom: 72px; white-space: nowrap; }
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .about-card { grid-template-columns: 1fr; }
  .about-avatar img { width: 150px; height: 150px; }
  .breadcrumb { max-width: 100%; order: 3; width: 100%; }
  .topbar { padding: 8px 10px; gap: 6px; }
  .pill { padding: 9px 13px; font-size: .95rem; }
  .screen { padding-top: 120px; }
  .prevnext .pill { max-width: 100%; }
  .prevnext { flex-direction: column; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
body.reduced-motion * { animation: none !important; transition: none !important; }

/* Utility */
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: -999px; top: 8px; z-index: 100;
  background: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 800; color: var(--ink);
}
.skip-link:focus { left: 8px; }
