/* Posy's Wardrobe. The boutique's palette (linen, blush, rose, plum ink)
   and its two voices: Fredoka for the game, Cormorant Garamond italic for
   the shop. Phone first: the room on top, the wardrobe drawer under the
   thumb, every target at least 48px. On a wide screen the drawer moves to
   the side. */

@font-face {
  font-family: 'Fredoka';
  src: url('./fonts/fredoka-latin.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
}
@font-face {
  font-family: 'Cormorant Garamond';
  src: url('./fonts/cormorant-italic-latin.woff2') format('woff2');
  font-style: italic;
  font-weight: 600;
  font-display: swap;
}

:root {
  --linen: #fff8f1;
  --blush: #fce4ec;
  --rose: #f293b7;
  --deep: #d4548a;
  --ink: #b03a6f;
  --ink-dark: #8e2c58;
  --plum: #4a2c3a;
  --plum-soft: rgba(74, 44, 58, 0.7);
  --sage: #a8c3a0;
  --butter: #f6d98b;
  --card: #fffdfb;
  --glass: rgba(255, 253, 251, 0.9);
  --font: 'Fredoka', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --drawer-w: 380px;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: var(--font);
  color: var(--plum);
  background: linear-gradient(#fde7ee, var(--linen));
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
[hidden] { display: none !important; }
button { font-family: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--deep); outline-offset: 2px; }
svg { display: block; width: 100%; height: 100%; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.loading {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: linear-gradient(#fde7ee, var(--linen));
  font-size: 22px; font-weight: 500; color: var(--ink);
  transition: opacity 0.4s;
}
.loading.gone { opacity: 0; pointer-events: none; }
.loading p { text-align: center; line-height: 1.5; }
.loading small { font-size: 15px; font-weight: 400; color: var(--plum-soft); }

/* ---------------------------------------------------------------- top --- */
.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 3;
  padding: calc(var(--safe-top) + 10px) 12px 0;
  display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 8px;
  pointer-events: none;
}
.top > * { pointer-events: auto; }
.round {
  width: 48px; height: 48px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.9); background: var(--glass);
  padding: 9px; box-shadow: 0 2px 8px rgba(74, 44, 58, 0.12);
}
.title { text-align: center; pointer-events: none; }
.madeby { margin: 3px 0 0; font-size: 12px; font-weight: 500; color: var(--ink-dark); text-shadow: 0 0 6px #fff, 0 0 2px #fff; }
.wordmark {
  margin: 0; text-align: center; pointer-events: none;
  font-size: 23px; font-weight: 600; line-height: 1; color: var(--ink);
  text-shadow: 0 1px 0 #fff, 0 0 8px rgba(255, 255, 255, 0.9);
}
.wordmark span { font-family: var(--serif); font-style: italic; font-size: 27px; color: var(--ink-dark); }
/* Quiet on purpose: a grown-up can find it, a child is not drawn to it. */
.grownups {
  display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 12px 0 8px;
  border-radius: 20px; border: 1.5px solid rgba(142, 44, 88, 0.25); background: rgba(255, 253, 251, 0.75);
  font-size: 14px; font-weight: 500; color: var(--plum-soft);
}
.grownups .ico { width: 20px; height: 20px; }

/* ------------------------------------------------------------- drawer --- */
.drawer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2;
  padding: 10px 0 calc(var(--safe-bottom) + 10px);
  background: var(--glass);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -4px 20px rgba(74, 44, 58, 0.12);
  display: grid; grid-template-rows: auto auto auto;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.tabs {
  display: flex; gap: 2px; overflow-x: auto; padding: 0 8px 6px; scrollbar-width: none;
}
.tabs::-webkit-scrollbar, .items::-webkit-scrollbar { display: none; }
.tab {
  position: relative; flex: 1 1 0; min-width: 46px; max-width: 76px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px 4px; border: 0; border-radius: 16px; background: transparent;
}
.tab svg { width: 32px; height: 32px; }
.tab-name { font-size: 11px; font-weight: 500; color: var(--plum-soft); white-space: nowrap; }
.tab[aria-selected="true"] { background: var(--blush); }
.tab[aria-selected="true"] .tab-name { color: var(--ink-dark); }
.tab .dot, .item.new::after {
  position: absolute; top: 4px; right: 6px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--deep); box-shadow: 0 0 0 2px #fff; display: none;
}
.tab.has-new .dot { display: block; }
.items {
  display: flex; gap: 10px; overflow-x: auto; padding: 4px 12px 6px; scroll-snap-type: x proximity;
  height: 128px;
  /* Sideways scrolls the row; up is a drag onto Posy (ui.js). */
  touch-action: pan-x;
}
.item {
  position: relative; flex: 0 0 auto; scroll-snap-align: start;
  width: 92px; height: 116px; padding: 8px 6px 6px; border-radius: 20px;
  border: 2px solid transparent; background: var(--card);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  box-shadow: 0 1px 4px rgba(74, 44, 58, 0.1);
  transition: transform 0.12s;
}
.item:active { transform: scale(0.95); }
.item[aria-pressed="true"] { border-color: var(--deep); background: var(--blush); }
.item.new::after { content: ''; display: block; top: 6px; right: 6px; }
.item .pic { width: 58px; height: 58px; }
.item-name {
  font-size: 12px; line-height: 1.15; text-align: center; color: var(--plum);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.surprise {
  justify-self: center; margin: 4px 0 0;
  display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 18px;
  border-radius: 22px; border: 0; background: linear-gradient(#f7a8c4, var(--deep));
  color: #fff; font-size: 16px; font-weight: 600; box-shadow: 0 3px 0 var(--ink-dark);
}
.surprise .ico { width: 24px; height: 24px; }
.surprise:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink-dark); }

@media (min-aspect-ratio: 23/20) {
  .drawer {
    left: auto; top: 0; width: var(--drawer-w); border-radius: 26px 0 0 26px;
    padding: calc(var(--safe-top) + 72px) 0 calc(var(--safe-bottom) + 16px);
    grid-template-rows: auto 1fr auto; align-content: start;
  }
  .tabs { flex-wrap: wrap; row-gap: 4px; }
  .tab { flex: 0 0 calc(25% - 2px); max-width: none; }
  .tab .dot { right: calc(50% - 24px); }
  .items { height: auto; flex-wrap: wrap; overflow-y: auto; overflow-x: hidden; align-content: flex-start; touch-action: pan-y; }
  .top { right: var(--drawer-w); }
  .swipe-hint { bottom: calc(var(--safe-bottom) + 40px); left: calc((100% - var(--drawer-w)) / 2); }
  .snap { right: calc(var(--drawer-w) + 14px); }
}

/* -------------------------------------------- dragging, flying, thinking --- */
.ghost {
  position: fixed; left: 0; top: 0; z-index: 40; width: 88px; height: 88px; padding: 6px;
  border-radius: 22px; background: rgba(255, 253, 251, 0.92);
  box-shadow: 0 6px 20px rgba(74, 44, 58, 0.25); pointer-events: none;
  transition: box-shadow 0.15s, background 0.15s;
}
.ghost .pic { width: 76px; height: 76px; }
.ghost.over { background: var(--blush); box-shadow: 0 0 0 4px var(--rose), 0 8px 24px rgba(212, 84, 138, 0.35); }
.ghost.gone { transition: transform 0.25s, opacity 0.25s; opacity: 0; }
.ghost.back { transition: transform 0.3s ease-in, opacity 0.3s; opacity: 0; }
.ghost.flying { width: 76px; height: 76px; background: rgba(255, 253, 251, 0.85); }
.ghost.flying .pic { width: 64px; height: 64px; }

.bubble {
  position: fixed; left: 0; top: 0; z-index: 4; width: 78px; height: 78px; margin: -78px 0 0 -6px;
  display: grid; place-items: center; border-radius: 50%; background: #fff;
  box-shadow: 0 4px 14px rgba(74, 44, 58, 0.18); pointer-events: none;
  animation: think 0.4s ease-out;
}
.bubble::before, .bubble::after {
  content: ''; position: absolute; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 6px rgba(74, 44, 58, 0.12);
}
.bubble::before { width: 16px; height: 16px; left: 4px; bottom: -12px; }
.bubble::after { width: 9px; height: 9px; left: -6px; bottom: -24px; }
.bubble .pic { width: 56px; height: 56px; }
@keyframes think { from { opacity: 0; scale: 0.6; } }

.swipe-hint {
  position: fixed; left: 50%; bottom: calc(var(--drawer-h, 290px) + 36px); z-index: 3;
  width: 64px; height: 64px; margin-left: -32px; pointer-events: none;
  filter: drop-shadow(0 2px 6px rgba(74, 44, 58, 0.3));
  animation: swipe 1.6s ease-in-out infinite;
}
@keyframes swipe {
  0%, 100% { transform: translateX(-40px); }
  50% { transform: translateX(40px); }
}
.dream { width: 50px; height: 50px; }

/* ------------------------------------------------ camera and photo book --- */
/* Top right, under the Grown-ups button: clear of the toys on the floor. */
.snap {
  position: fixed; right: 12px; top: calc(var(--safe-top) + 64px); z-index: 3;
  display: flex; flex-direction: column; gap: 10px;
}
.snapbtn { position: relative; width: 56px; height: 56px; padding: 11px; }
.snapbtn .count {
  position: absolute; top: -4px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 11px; background: var(--deep); color: #fff; font-size: 13px; font-weight: 600;
  line-height: 22px; box-shadow: 0 0 0 2px #fff;
}
.flash { position: fixed; inset: 0; z-index: 35; background: #fff; pointer-events: none; animation: flash 0.5s ease-out forwards; }
@keyframes flash { from { opacity: 0.95; } to { opacity: 0; } }
.polaroid {
  display: inline-flex; flex-direction: column; padding: 7px 7px 22px; border: 0;
  background: #fff; border-radius: 4px; box-shadow: 0 4px 14px rgba(74, 44, 58, 0.22);
}
.polaroid canvas { display: block; width: 100%; height: auto; border-radius: 2px; }
.photo-pop {
  position: fixed; left: 50%; top: 40%; z-index: 36; width: min(58vw, 230px);
  translate: -50% -50%; rotate: -3deg; pointer-events: none; animation: develop 0.45s ease-out;
}
@keyframes develop { from { scale: 0.6; opacity: 0; } }
.book { width: min(100%, 460px); }
.book-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 6px 0 16px;
  max-height: 58vh; overflow-y: auto; padding: 6px;
}
.book-grid .polaroid { padding: 5px 5px 14px; }
.book-grid .polaroid:nth-child(odd) { rotate: -2deg; }
.book-grid .polaroid:nth-child(even) { rotate: 2deg; }
.book-grid .polaroid:active { scale: 0.96; }

/* ------------------------------------------------------------- toast --- */
.toast {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 68px); z-index: 20; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; max-width: calc(100% - 32px);
  padding: 8px 18px 8px 10px; border-radius: 24px; background: var(--card);
  box-shadow: 0 4px 18px rgba(74, 44, 58, 0.2); font-size: 17px; font-weight: 500;
  animation: pop 0.3s ease-out;
}
.toast .pic { width: 40px; height: 40px; flex: 0 0 auto; }
@keyframes pop { from { transform: translateX(-50%) scale(0.8); opacity: 0; } }

/* ------------------------------------------------------------ modals --- */
.modal {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center; padding: 20px;
  background: rgba(74, 44, 58, 0.35);
}
.card {
  width: min(100%, 380px); padding: 22px 20px; border-radius: 26px;
  background: var(--card); text-align: center;
  box-shadow: 0 10px 40px rgba(74, 44, 58, 0.25);
  animation: rise 0.28s ease-out;
}
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }
.card { position: relative; }
.card h2 { margin: 0 0 6px; font-size: 26px; color: var(--ink); }
.hear { position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; padding: 8px; }
.hello h2 { font-size: 30px; }
.hello .lede { font-size: 19px; }
.lede { margin: 0 0 14px; font-size: 17px; line-height: 1.4; }
.unboxed-items { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-bottom: 16px; }
.unboxed-item { width: 96px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; line-height: 1.2; }
.unboxed-item .pic { width: 72px; height: 72px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 52px; padding: 0 26px;
  border-radius: 26px; border: 0; font-size: 18px; font-weight: 600;
}
.btn.primary { background: linear-gradient(#f7a8c4, var(--deep)); color: #fff; box-shadow: 0 3px 0 var(--ink-dark); }
.btn.secondary { background: var(--blush); color: var(--ink-dark); }
.btn.danger { background: #fff; color: var(--ink-dark); border: 2px solid rgba(142, 44, 88, 0.35); }
.btn.slim { min-height: 44px; font-size: 16px; }

/* The gate: a grown-up question and a big keypad. */
.gate h2 { font-size: 22px; }
.gate-q { font-size: 20px; margin: 4px 0 10px; }
.gate-answer {
  min-height: 48px; margin: 0 auto 12px; width: 140px; border-radius: 14px; background: var(--blush);
  font-size: 30px; font-weight: 600; line-height: 48px; color: var(--ink-dark);
}
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.keypad button {
  height: 54px; border-radius: 16px; border: 0; background: #fff; font-size: 24px; font-weight: 500;
  box-shadow: 0 2px 0 rgba(74, 44, 58, 0.18), inset 0 0 0 1.5px rgba(142, 44, 88, 0.15);
}
.keypad button.ok { background: var(--deep); color: #fff; }
.gate-msg { min-height: 22px; margin: 0 0 8px; color: var(--ink); }

/* ------------------------------------------------------ grown-ups page --- */
.page {
  position: fixed; inset: 0; z-index: 25; display: flex; flex-direction: column;
  background: var(--linen); user-select: text; -webkit-user-select: text;
}
.page-head {
  display: flex; align-items: center; gap: 12px;
  padding: calc(var(--safe-top) + 10px) 14px 10px; border-bottom: 1px solid rgba(142, 44, 88, 0.12);
}
.page-head h2 { margin: 0; font-size: 24px; color: var(--ink); }
.page-body { flex: 1; overflow-y: auto; padding: 8px 20px calc(var(--safe-bottom) + 30px); max-width: 640px; width: 100%; margin: 0 auto; font-size: 17px; line-height: 1.5; }
.page-body h3 { margin: 26px 0 6px; font-size: 20px; color: var(--ink-dark); }
.page-body p { margin: 0 0 10px; }
.serif { font-family: var(--serif); font-style: italic; font-weight: 600; font-size: 1.12em; }
.intro { color: var(--ink-dark); }
.fine { font-size: 14px; color: var(--plum-soft); }
.foot { margin-top: 26px !important; }
.page a { color: var(--ink); }

.code-slots { display: flex; gap: 6px; justify-content: center; margin: 10px 0; }
.code-slot { width: 46px; height: 46px; padding: 5px; border-radius: 12px; background: #fff; box-shadow: inset 0 0 0 2px rgba(142, 44, 88, 0.2); }
.code-pad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; max-width: 360px; margin: 0 auto; }
.pic-key { aspect-ratio: 1; padding: 8px; border-radius: 16px; border: 0; background: #fff; box-shadow: 0 2px 0 rgba(74, 44, 58, 0.15), inset 0 0 0 1.5px rgba(142, 44, 88, 0.15); }
.pic-key.del { background: var(--blush); }
.code-msg { min-height: 26px; margin-top: 10px !important; text-align: center; font-weight: 500; }
.code-msg[data-result="ok"] { color: #3f7a45; }
.code-msg[data-result="wrong"], .code-msg[data-result="again"] { color: var(--ink); }

.wearing { display: flex; flex-direction: column; gap: 8px; }
.wearing-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 18px;
  background: var(--card); text-decoration: none; color: var(--plum) !important; box-shadow: 0 1px 4px rgba(74, 44, 58, 0.1);
}
.wearing-row .pic { width: 48px; height: 48px; flex: 0 0 auto; }
.wearing-words { flex: 1; display: flex; flex-direction: column; line-height: 1.25; }
.wearing-words .serif { font-size: 16px; color: var(--ink); }
.wearing-row.home { justify-content: space-between; font-weight: 500; color: var(--ink-dark) !important; }
.go { font-size: 28px; color: var(--ink); }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; }
.switch {
  position: relative; width: 58px; height: 34px; border-radius: 17px; border: 0; flex: 0 0 auto;
  background: rgba(74, 44, 58, 0.2); transition: background 0.2s;
}
.switch::after {
  content: ''; position: absolute; top: 4px; left: 4px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.switch[aria-checked="true"] { background: var(--deep); }
.switch[aria-checked="true"]::after { transform: translateX(24px); }
.switch:disabled { opacity: 0.45; }
.choice { display: flex; border-radius: 17px; background: rgba(74, 44, 58, 0.08); padding: 3px; }
.choice button { border: 0; background: transparent; min-height: 40px; padding: 0 12px; border-radius: 14px; font-size: 15px; }
.choice button[aria-checked="true"] { background: #fff; color: var(--ink-dark); font-weight: 600; box-shadow: 0 1px 3px rgba(74, 44, 58, 0.15); }

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