/* Journal bear — honey studio. One primary action, quiet secondary controls. */

@font-face {
  font-family: "Nunito";
  src: url("fonts/nunito-latin-wght-normal.woff2") format("woff2-variations");
  font-weight: 200 1000;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #fff6e4;
  --card: #ffffff;
  --ink: #3a2a1a;
  --muted: #7a6556;
  --sunshine: #ffc531;
  --blush: #ffd0c2;
  --done: #17806f;
  --tint: #f6ede3;
  --tint-pressed: #efe4d6;

  /* Per-category accents; .card[data-kind] swaps them. */
  --chip-bg: var(--tint);
  --chip-ink: var(--ink);
  --frame-bg: #fff9f0;

  /* Motion tokens. Strong custom curves; UI stays under 300ms. */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-reward: cubic-bezier(0.34, 1.3, 0.64, 1);
  --dur-press: 160ms;
  --dur-swap: 200ms;

  --card-max: 460px;
  --frame-size: min(100%, 36dvh, 320px);
}

* { box-sizing: border-box; }

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
  overflow-x: clip;
}

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Nunito", ui-rounded, "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(120% 70% at 50% 0%, #fffaf0 0%, rgba(255, 250, 240, 0) 60%),
    radial-gradient(90% 60% at 50% 100%, #ffeccc 0%, rgba(255, 236, 204, 0) 70%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overscroll-behavior: none;
  overflow-x: clip;
  padding:
    env(safe-area-inset-top, 0px)
    max(16px, env(safe-area-inset-right, 0px))
    max(16px, env(safe-area-inset-bottom, 0px))
    max(16px, env(safe-area-inset-left, 0px));
}

button, [role="button"] {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Header ---------- */

.topbar {
  width: min(100%, var(--card-max));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 4px 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand img {
  height: 40px;
  width: auto;
  display: block;
  transform-origin: 50% 90%;
}

.brand img.is-cheering {
  animation: bear-cheer 520ms var(--ease-reward);
}

@keyframes bear-cheer {
  0% { transform: rotate(0deg); }
  35% { transform: rotate(-10deg) scale(1.06); }
  100% { transform: rotate(0deg) scale(1); }
}

/* Helper chores: the bear jumps, spins and wiggles. */
.brand img.is-celebrating {
  animation: bear-celebrate 1400ms var(--ease-out);
}

@keyframes bear-celebrate {
  0% { transform: translateY(0) rotate(0deg) scale(1); }
  12% { transform: translateY(2px) scale(1.1, 0.88); }
  30% { transform: translateY(-14px) rotate(-180deg) scale(1.15); }
  48% { transform: translateY(0) rotate(-360deg) scale(1.05, 0.95); }
  60% { transform: rotate(-372deg) scale(1.08); }
  72% { transform: rotate(-348deg) scale(1.08); }
  84% { transform: rotate(-366deg) scale(1.04); }
  100% { transform: rotate(-360deg) scale(1); }
}

.brand h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--muted);
  white-space: nowrap;
}

.stars {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 14px 6px 10px;
  border-radius: 999px;
  background: var(--card);
  box-shadow:
    0 1px 2px rgba(58, 42, 26, 0.06),
    0 4px 12px rgba(58, 42, 26, 0.06);
  font-weight: 900;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
  transform-origin: center;
}

.stars-icon { font-size: 1.15rem; line-height: 1; }

.stars.is-bumping {
  animation: stars-bump 260ms var(--ease-out);
}

@keyframes stars-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* ---------- Card ---------- */

.card {
  background: var(--card);
  border-radius: 36px;
  box-shadow:
    0 1px 2px rgba(58, 42, 26, 0.05),
    0 6px 16px rgba(58, 42, 26, 0.06),
    0 24px 48px rgba(58, 42, 26, 0.06);
  padding: 20px 20px 22px;
  width: min(100%, var(--card-max));
  margin-block: auto;
  text-align: center;
  position: relative;
}

[data-kind="draw"] { --chip-bg: #ffe4dc; --chip-ink: #8a4a38; --frame-bg: #fff1ec; }
[data-kind="find"] { --chip-bg: #d7f0fc; --chip-ink: #1d6488; --frame-bg: #eef8fd; }
[data-kind="write"] { --chip-bg: #fff1c2; --chip-ink: #7a580c; --frame-bg: #fff9e4; }
[data-kind="sing"] { --chip-bg: #d7f6f1; --chip-ink: #14685c; --frame-bg: #edfbf8; }
[data-kind="move"] { --chip-bg: #ffe8d2; --chip-ink: #8a4e1c; --frame-bg: #fff4ea; }
[data-kind="help"] { --chip-bg: #ece4fb; --chip-ink: #5b3f9a; --frame-bg: #f6f1fd; }

/* ---------- Category filter: a corner pill and a small grid ---------- */

.filter-pill {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 4px 12px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  color: var(--muted);
  background: var(--tint);
  cursor: pointer;
  transition: transform var(--dur-press) var(--ease-out), background-color var(--dur-press) var(--ease-out);
}

/* Keep the tap target at least 44px without making the pill look bigger. */
.filter-pill::before {
  content: "";
  position: absolute;
  inset: -6px;
}

.filter-pill[data-kind]:not([data-kind=""]) {
  color: var(--chip-ink);
  background: var(--chip-bg);
}

.filter-pill:active { transform: scale(0.95); }

.filter-pill:focus-visible,
.filter-tile:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ink);
}

.filter-pop {
  position: absolute;
  top: 54px;
  right: 10px;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(3, 72px);
  gap: 8px;
  padding: 10px;
  border-radius: 20px;
  background: var(--card);
  box-shadow:
    0 1px 2px rgba(58, 42, 26, 0.08),
    0 8px 20px rgba(58, 42, 26, 0.12),
    0 24px 48px rgba(58, 42, 26, 0.1);
  transform-origin: top right;
  animation: filter-pop-in 160ms var(--ease-out);
}

.filter-pop[hidden] { display: none; }

@keyframes filter-pop-in {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

.filter-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 64px;
  padding: 6px 4px;
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--muted);
  background: var(--tint);
  cursor: pointer;
  transition: transform var(--dur-press) var(--ease-out), background-color var(--dur-press) var(--ease-out);
}

.filter-tile-icon {
  font-size: 1.5rem;
  line-height: 1;
  filter: grayscale(1);
  opacity: 0.5;
  transition: filter var(--dur-press) var(--ease-out), opacity var(--dur-press) var(--ease-out);
}

.filter-tile[aria-pressed="true"] {
  color: var(--chip-ink);
  background: var(--chip-bg);
}

.filter-tile[data-kind="all"][aria-pressed="true"] {
  color: var(--ink);
  background: #fff1c2;
}

.filter-tile[aria-pressed="true"] .filter-tile-icon {
  filter: none;
  opacity: 1;
}

.filter-tile:active { transform: scale(0.95); }

/* ---------- Stage (the swipeable prompt) ---------- */

.stage {
  display: grid;
  justify-items: center;
  grid-template-areas:
    "frame"
    "prompt";
  border-radius: 28px;
  cursor: pointer;
  touch-action: pan-y;
  will-change: transform, opacity;
  outline: none;
}

.stage:focus-visible {
  box-shadow: 0 0 0 3px var(--card), 0 0 0 6px var(--ink);
}

/* Portrait: frame and prompt stack; .copy only groups them side by side. */
.copy { display: contents; }

.frame {
  grid-area: frame;
  position: relative;
  width: var(--frame-size);
  aspect-ratio: 1;
  /* Clears the filter pill in the card's top-right corner. */
  margin: 34px 0 4px;
  border-radius: 32px;
  background: var(--frame-bg);
  box-shadow: inset 0 0 0 3px rgba(58, 42, 26, 0.04);
  display: grid;
  place-items: center;
  overflow: hidden;
  transition: transform var(--dur-press) var(--ease-out);
}

.stage:active .frame {
  transform: scale(0.97);
}

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

.frame-emoji {
  font-size: min(46cqw, 9rem);
  line-height: 1;
  filter: drop-shadow(0 6px 10px rgba(58, 42, 26, 0.12));
}

.frame { container-type: inline-size; }

.sticker {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--done);
  color: #fff;
  box-shadow: 0 0 0 3px var(--card), 0 4px 10px rgba(23, 128, 111, 0.3);
  opacity: 0;
  transform: scale(0.6) rotate(-20deg);
  transition:
    opacity 180ms var(--ease-out),
    transform 320ms var(--ease-reward);
  pointer-events: none;
}

.card.is-done .sticker {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

/* Helper chores earn a gold sticker. */
.card[data-kind="help"] .sticker {
  background: var(--sunshine);
  color: var(--ink);
  box-shadow: 0 0 0 3px var(--card), 0 4px 12px rgba(255, 170, 0, 0.45);
}

/* Navigating to a done prompt shows the sticker without a pop. */
.card.is-instant .sticker { transition: none; }

.prompt {
  grid-area: prompt;
  font-size: clamp(1.55rem, 1.05rem + 2.4vw, 2.4rem);
  line-height: 1.2;
  font-weight: 850;
  letter-spacing: -0.02em;
  text-wrap: balance;
  margin: 14px 0 18px;
  max-width: 22ch;
  /* Reserve four lines so the card keeps one height whatever the prompt length. */
  min-height: 4.8em;
}

.word {
  border-radius: 8px;
  padding: 0 2px;
  margin: 0 -2px;
  transition: background-color 120ms ease, color 120ms ease;
}

.word.is-reading {
  background: var(--sunshine);
  color: var(--ink);
}

/* ---------- Buttons ---------- */

.buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.secondary-row {
  display: flex;
  gap: 12px;
}

.btn {
  position: relative;
  font-family: inherit;
  font-weight: 800;
  border: none;
  cursor: pointer;
  color: var(--ink);
  transition:
    transform var(--dur-press) var(--ease-out),
    background-color var(--dur-press) ease,
    color var(--dur-press) ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn:focus-visible,
.link-btn:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

.btn-primary {
  width: 100%;
  min-height: 72px;
  border-radius: 999px;
  background: var(--sunshine);
  font-size: 1.35rem;
  letter-spacing: -0.015em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow:
    inset 0 -3px 0 rgba(58, 42, 26, 0.12),
    0 6px 16px rgba(255, 170, 0, 0.25);
}

/* A soft ring breathes while the bear is talking. */
.btn-primary::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: inherit;
  box-shadow: 0 0 0 3px var(--sunshine);
  opacity: 0;
  pointer-events: none;
}

.btn-primary.is-speaking::after {
  animation: speak-ring 1200ms var(--ease-out) infinite;
}

@keyframes speak-ring {
  0% { opacity: 0.9; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.06, 1.18); }
}

.btn-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
}

.btn-icon svg { grid-area: 1 / 1; }

.btn-primary .icon-stop { display: none; }
.btn-primary.is-speaking .icon-speak { display: none; }
.btn-primary.is-speaking .icon-stop { display: block; }

.btn-secondary {
  flex: 1;
  min-height: 60px;
  padding: 10px 12px;
  border-radius: 999px;
  background: var(--tint);
  font-size: 1.1rem;
  line-height: 1.15;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: inset 0 0 0 1px rgba(58, 42, 26, 0.06);
}

.btn-next svg {
  transition: transform var(--dur-press) var(--ease-out);
}

.btn-next:active svg {
  transform: translateX(3px);
}

/* Done: outline ring morphs into a filled check. */
.done-icon {
  overflow: visible;
  flex: none;
}

.done-ring {
  fill: transparent;
  stroke: var(--done);
  stroke-width: 2.4;
  transition: fill 160ms ease, stroke 160ms ease;
}

.done-check {
  fill: none;
  stroke: var(--done);
  stroke-width: 2.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 240ms var(--ease-out) 60ms;
}

.btn-done[aria-pressed="true"] {
  background: var(--done);
  color: #fff;
  box-shadow: none;
}

.btn-done[aria-pressed="true"] .done-ring {
  fill: #fff;
  stroke: #fff;
}

.btn-done[aria-pressed="true"] .done-check {
  stroke: var(--done);
  stroke-dashoffset: 0;
}

.card.is-instant .done-check,
.card.is-instant .btn-done,
.card.is-instant .done-ring {
  transition: none;
}

.btn-done.is-popping {
  animation: done-pop 320ms var(--ease-reward);
}

@keyframes done-pop {
  0% { transform: scale(0.97); }
  45% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.btn-label { display: inline-block; }

/* ---------- All done ---------- */

.all-done {
  margin-top: 16px;
  font-weight: 900;
  font-size: 1.2rem;
  color: var(--done);
}

.all-done[hidden] { display: none; }

.all-done p { margin: 0 0 4px; }

.link-btn {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--muted);
  background: none;
  border: none;
  padding: 8px 12px;
  border-radius: 999px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* ---------- Reward burst ---------- */

.reward {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  overflow: hidden;
}

.reward[hidden] { display: none; }

/* Surprise pieces are positioned and moved by the Web Animations API in app.js. */
.reward-item,
.reward-flyer {
  position: fixed;
  left: 0;
  top: 0;
  line-height: 1;
  margin: -0.5em 0 0 -0.5em;
  will-change: transform, opacity;
}

.reward-item {
  font-size: var(--size, 2rem);
  opacity: 0;
}

.reward-flyer { font-size: 1.6rem; }

/* Helper celebration pieces. Like the items, they sit at 0,0 and app.js moves them. */
.reward-backdrop {
  position: fixed;
  inset: 0;
  opacity: 0;
  background:
    radial-gradient(circle at var(--cx, 50%) var(--cy, 35%),
      rgba(255, 224, 130, 0.85) 0,
      rgba(255, 214, 102, 0.45) 140px,
      rgba(255, 246, 228, 0) 320px),
    rgba(58, 42, 26, 0.32);
}

.reward-ring,
.reward-rays,
.reward-banner {
  position: fixed;
  left: 0;
  top: 0;
  opacity: 0;
  will-change: transform, opacity;
}

.reward-ring {
  width: 110px;
  height: 110px;
  margin: -55px 0 0 -55px;
  border-radius: 50%;
  border: 6px solid var(--sunshine);
  box-shadow: 0 0 18px rgba(255, 197, 49, 0.7);
}

.reward-rays {
  width: 380px;
  height: 380px;
  margin: -190px 0 0 -190px;
  border-radius: 50%;
  background: repeating-conic-gradient(rgba(255, 197, 49, 0.75) 0deg 9deg, rgba(255, 255, 255, 0) 9deg 24deg);
  -webkit-mask-image: radial-gradient(circle, #000 18%, rgba(0, 0, 0, 0) 68%);
  mask-image: radial-gradient(circle, #000 18%, rgba(0, 0, 0, 0) 68%);
}

.reward-trophy {
  filter: drop-shadow(0 10px 18px rgba(160, 100, 0, 0.35));
}

.reward-banner {
  padding: 10px 26px 12px;
  border-radius: 999px;
  border: 3px solid var(--sunshine);
  background: linear-gradient(180deg, #8f63e0 0%, #6b44c4 100%);
  box-shadow:
    inset 0 -4px 0 rgba(40, 20, 90, 0.25),
    0 10px 24px rgba(91, 63, 154, 0.35);
  color: #fff;
  font-size: clamp(1.6rem, 1.1rem + 3vw, 2.4rem);
  font-weight: 950;
  letter-spacing: -0.01em;
  line-height: 1.1;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(40, 20, 90, 0.35);
}

.reward-banner:lang(zh) { letter-spacing: 0.04em; }

/* ---------- Hover (pointer devices only) ---------- */

@media (hover: hover) and (pointer: fine) {
  .btn:hover { transform: scale(1.02); }
  .btn:active { transform: scale(0.97); }
  .btn-primary:hover { background: #ffcd4d; }
  .btn-secondary:hover { background: var(--tint-pressed); }
  .btn-done[aria-pressed="true"]:hover { background: #14725f; }
  .stage:hover .frame { transform: scale(1.01); }
  .stage:active .frame { transform: scale(0.97); }
  .link-btn:hover { color: var(--ink); }
  .filter-pill:hover,
  .filter-tile[aria-pressed="false"]:hover { background: var(--tint-pressed); }
}

/* ---------- Responsive ---------- */

@media (min-width: 600px) and (orientation: portrait) {
  :root {
    --card-max: 540px;
    --frame-size: min(100%, 34dvh, 360px);
  }
  .card { padding: 28px 28px 30px; }
}

/* Side-by-side: tablets/desktops and landscape phones. */
@media (orientation: landscape) and (min-width: 640px) {
  :root {
    --card-max: 880px;
    --frame-size: min(40vw, 48dvh, 340px);
  }

  .card {
    padding: 28px 32px 28px;
    text-align: left;
  }

  .stage {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "frame copy";
    column-gap: 32px;
    align-items: center;
  }

  .copy {
    grid-area: copy;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-self: stretch;
  }

  .frame { margin: 0; }
  .prompt {
    margin: 14px 0 0;
    max-width: 18ch;
    min-height: 0;
    font-size: clamp(1.6rem, 1rem + 2.2vw, 2.8rem);
  }

  .buttons {
    flex-direction: row;
    margin-top: 24px;
  }

  .btn-primary { flex: 1.15; width: auto; }
  .secondary-row { flex: 1; }
  .all-done { text-align: center; }
}

/* Short landscape phones: compact everything so nothing scrolls. */
@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --frame-size: min(36vw, 52dvh, 260px);
  }
  .topbar { padding: 6px 4px 4px; }
  .brand img { height: 32px; }
  .card { padding: 16px 20px; border-radius: 28px; }
  .stage { column-gap: 24px; }
  .prompt { font-size: clamp(1.4rem, 0.8rem + 2vw, 2rem); }
  .buttons { margin-top: 14px; gap: 10px; }
  .secondary-row { gap: 10px; }
  .btn-primary { min-height: 56px; font-size: 1.15rem; }
  .btn-secondary { min-height: 56px; }
}

/* Very short portrait phones (iPhone SE 1st gen and similar). */
@media (orientation: portrait) and (max-height: 600px) {
  :root { --frame-size: min(100%, 30dvh, 240px); }
  .prompt { margin: 10px 0 14px; }
  .btn-primary { min-height: 64px; }
  .btn-secondary { min-height: 54px; }
}

/* ---------- Reduced motion: fewer, gentler — opacity only ---------- */

@media (prefers-reduced-motion: reduce) {
  .btn,
  .btn:hover,
  .btn:active,
  .stage:active .frame,
  .btn-next:active svg,
  .filter-pill:active,
  .filter-tile:active {
    transform: none;
  }

  .filter-pop { animation-name: star-fade-in; }

  @keyframes star-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  .btn-done.is-popping,
  .stars.is-bumping,
  .brand img.is-cheering,
  .brand img.is-celebrating {
    animation: none;
  }

  .sticker {
    transform: none;
    transition: opacity 180ms ease;
  }

  .btn-primary.is-speaking::after {
    animation: none;
    opacity: 0.6;
  }
}

/* ---------- Language switch ---------- */

.topbar-end {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lang-btn {
  min-height: 40px;
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow:
    0 1px 2px rgba(58, 42, 26, 0.06),
    0 4px 12px rgba(58, 42, 26, 0.06);
  transition: transform var(--dur-press) var(--ease-out);
}

.lang-btn:active { transform: scale(0.97); }

.lang-btn:focus-visible {
  outline: 3px solid var(--sunshine);
  outline-offset: 2px;
}

/* Chinese prompts fall back to the system CJK font (Nunito is Latin-only). */
.prompt:lang(zh) { letter-spacing: 0; }
