* { box-sizing: border-box; }
[hidden] { display: none !important; }
:root {
  font: 17px/1.4 "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: #19324d;
  background: #7cc9f7;
}
html, body {
  width: 100%;
  overflow-x: hidden;
}
body {
  position: relative;
  margin: 0;
  min-height: 100svh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(10px, 2vh, 26px) 0 clamp(8px, 1.4vh, 16px);
  background: #7cc9f7 url("assets/treehouse-bg.webp") center bottom / cover no-repeat fixed;
}
.page-title {
  text-align: center;
  padding: 0 12px;
}
.page-title h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.25rem);
  font-weight: 900;
  line-height: 1.04;
  letter-spacing: -.04em;
}
.page-title p {
  margin: 5px 0 0;
  font-weight: 800;
  color: #435974;
}
main {
  width: 100%;
  display: grid;
  justify-items: center;
  padding: clamp(10px, 1.8vh, 20px) 14px 0;
}
.deck { width: min(100%, 485px); }
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button:focus-visible {
  outline: 3px solid #174fa0;
  outline-offset: 4px;
}
.card {
  display:block;
  width:min(100%,423px,calc((100svh - 215px)*.787));
  width:min(100%,423px,calc((100dvh - 215px)*.787));
  min-width:min(100%,210px);
  aspect-ratio:1113/1414;
  margin:auto;
  background:none;
  border:0;
  padding:0;
  border-radius:18px;
  perspective:1250px;
  container-type:inline-size;
  position:relative;
}
.turn {
  display:block;
  height:100%;
  position:relative;
  transform-style:preserve-3d;
  transition:transform .53s cubic-bezier(.22,.7,.25,1);
  border-radius:inherit;
  box-shadow:0 13px 35px #07030ca6;
}
.card[aria-pressed=true] .turn {
  transform:rotateY(180deg);
}
.card.instant .turn {
  transition:none;
}
.face {
  display:block;
  position:absolute;
  inset:0;
  border-radius:inherit;
  overflow:hidden;
  backface-visibility:hidden;
  isolation:isolate;
}
.face {
  --pale: hsl(var(--card-hue, 214) 88% 91%);
  --bright: hsl(var(--card-hue, 214) 86% 62%);
  --deep: hsl(var(--card-hue, 214) 62% 29%);
  --paper: #fffcf5;
  border: 1.5cqi solid var(--paper);
  background: radial-gradient(circle, #ffffffb0 0 1px, transparent 2px) 0 0 / 20px 20px, var(--pale);
  color: #18354c;
}
.turn { box-shadow: 0 13px 28px #273d4840; }
.face.face.back { transform: rotateY(180deg); }
.side-label {
  position: absolute;
  inset: 6% 0 auto;
  margin-inline: auto;
  width: max-content;
  padding: .36em .9em;
  color: var(--deep);
  background: var(--paper);
  border-radius: 2em;
  font-size: 4.1cqi;
  font-weight: 850;
}
.letter-stage {
  position: absolute;
  inset: 20% 16% 31%;
  display: grid;
  place-items: center;
  border-radius: 48% 52% 58% 42% / 53% 49% 51% 47%;
  background: var(--paper);
  border: 2cqi solid var(--bright);
  box-shadow: 0 2cqi 0 var(--bright);
}
.letter-stage::before, .letter-stage::after {
  content: '✦';
  position: absolute;
  color: var(--deep);
  font-size: 8cqi;
}
.letter-stage::before { top: 4%; left: -15%; }
.letter-stage::after { right: -15%; bottom: 4%; color: #b46b00; }
#front-letter {
  font: 900 43cqi / 1 "Arial Rounded MT Bold", "Trebuchet MS", sans-serif;
  color: var(--deep);
}
.clue, .activity {
  position: absolute;
  inset: auto 6% 9%;
  min-height: 12%;
  display: grid;
  place-content: center;
  padding: 1.5cqi 3cqi;
  background: var(--paper);
  border-radius: 4cqi;
  font-size: 4.6cqi;
  font-weight: 800;
  text-wrap: balance;
}
.tap-hint {
  position: absolute;
  inset: auto 0 3%;
  color: var(--deep);
  font-size: 3.6cqi;
  font-weight: 800;
}
#badge {
  position: absolute;
  top: 4%;
  left: 5%;
  width: 12%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 32%;
  background: var(--deep);
  color: white;
  font-size: 6.7cqi;
  font-weight: 900;
}
.art-window {
  position: absolute;
  inset: 16% 6% 31%;
  border: 1.4cqi solid var(--bright);
  border-radius: 7cqi;
  background: white;
  overflow: hidden;
}
.art-window img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
#word {
  position: absolute;
  inset: 70% 5% auto;
  font-size: 9cqi;
  color: var(--deep);
  line-height: 1.1;
}
.activity { bottom: 4%; min-height: 13%; font-size: 4.2cqi; }
.activity strong { color: var(--deep); font-size: 3.6cqi; }
.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 170px));
  justify-content: center;
  gap: clamp(8px, 2.2vw, 16px);
  margin-top: clamp(12px, 2.5vh, 24px);
  width: 100%;
}
.controls button {
  min-width: 0;
  min-height: 44px;
  padding: 8px 14px 9px;
  border-radius: 999px;
  font-family: 'Fredoka', 'Manrope', sans-serif;
  font-size: clamp(12.5px, 1.32vw, 17px);
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  color: #ffffff;
  text-shadow: 0 1.5px 2px rgba(0, 0, 0, 0.28);
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}
.controls #prev {
  background: linear-gradient(180deg, #9b3cf8 0%, #731de0 58%, #5711b5 100%);
  border: 1.5px solid #bc85ff;
  border-bottom: 4.5px solid #3c0982;
  box-shadow: 0 7px 15px rgba(72, 14, 145, 0.32), inset 0 2px 3px rgba(255, 255, 255, 0.34);
}
.controls #flip {
  color: #ffffff;
  background: linear-gradient(180deg, #2b9bf9 0%, #0d74e7 58%, #0758bd 100%);
  border: 1.5px solid #7ec5ff;
  border-bottom: 4.5px solid #053d87;
  box-shadow: 0 7px 15px rgba(8, 72, 160, 0.32), inset 0 2px 3px rgba(255, 255, 255, 0.34);
}
.controls #next {
  color: #ffffff;
  background: linear-gradient(180deg, #fc9526 0%, #e4690c 58%, #bf4e06 100%);
  border: 1.5px solid #fdbe72;
  border-bottom: 4.5px solid #8c3503;
  box-shadow: 0 7px 15px rgba(155, 58, 4, 0.32), inset 0 2px 3px rgba(255, 255, 255, 0.34);
}
.controls button:disabled {
  opacity: .52;
  cursor: default;
}
.controls button:not(:disabled):hover {
  transform: translateY(-2px);
  filter: brightness(1.06);
}
.controls button:not(:disabled):active { transform: translateY(2px); }
.view-controls {
  display: flex;
  justify-content: center;
  margin-top: 17px;
}
#full {
  min-height: 42px;
  padding: 5px 14px;
  background: #fffbef;
  border: 1px solid #b9a77e;
  border-radius: 10px;
  font-size: .79rem;
  font-weight: 750;
}
.sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
@media (max-width: 580px) {
  .deck { width: min(100%, 370px); }
}
@media (prefers-reduced-motion: reduce) {
  .turn { transition: none !important; }
}
.face { border: 0; background: #240d45; }
.classic-frame { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.back .side-label, .activity strong { display: none; }
#badge {
  left: 9.82%;
  top: 2.67%;
  width: 16.3%;
  height: 10.33%;
  aspect-ratio: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-family: 'Fredoka', 'Manrope', sans-serif;
  font-size: 9.6cqi;
  font-weight: 700;
  color: #ffffff;
  background: none;
  text-shadow: 0 .45cqi .5cqi #180831;
  text-box: trim-both cap alphabetic;
}
.art-window { inset: 15% 11.7% 20.8%; border: 0; border-radius: 9%; background: none; }
.art-window img { position: absolute; inset: 2%; width: 96%; height: 96%; object-fit: contain; mix-blend-mode: multiply; }
#word { inset: 79.83% 27% auto; height: 8.35%; display: flex; align-items: center; justify-content: center; line-height: 1; color: #2a1450; font-size: 7.8cqi; text-shadow: 0 1px white; }
.activity { inset: 84.4% 15.2% auto; min-height: 5.9%; color: white; background: none; padding: 0; font-size: 4.05cqi; }
.classic-frame { filter: hue-rotate(var(--frame-shift, 0deg)); }

.page-title {
  --title-accent: #48266d;
  font-family: 'Manrope', "Nirmala UI", sans-serif;
  position: relative;
  max-width: 960px;
  width: min(960px, calc(100% - 40px));
  min-height: 44px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0;
}
.page-title-inner {
  grid-column: 2;
  text-align: center;
  min-width: 0;
}
.page-title .header-back-btn {
  grid-column: 1;
  justify-self: start;
  position: relative;
  inset: auto;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 20px 10px;
  font: 700 13.5px/1 'DM Sans', 'Manrope', "Nirmala UI", sans-serif;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  background: linear-gradient(180deg, #9b3cf8 0%, #731de0 58%, #5711b5 100%);
  border: 1.5px solid #bc85ff;
  border-bottom: 4.5px solid #3c0982;
  border-radius: 999px;
  color: #ffffff;
  box-shadow: 0 7px 15px rgba(72, 14, 145, 0.32), inset 0 2px 3px rgba(255, 255, 255, 0.34);
  text-shadow: 0 1.5px 2px rgba(0, 0, 0, 0.28);
  transform: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.page-title .header-back-btn:hover {
  background: linear-gradient(180deg, #a855f7 0%, #7e22ce 58%, #5b13bd 100%);
  border-color: #d8b4fe;
  border-bottom-color: #3c0982;
  color: #ffffff;
  transform: translateY(-2px);
}
.page-title h1 {
  font: 800 clamp(20px, 2.4vw, 32px)/1.2 'Manrope', "Nirmala UI", sans-serif;
  color: #103b4d;
  letter-spacing: -0.3px;
  text-shadow: 0 2px 10px rgba(255, 255, 255, 0.95), 0 0 4px #ffffff;
  text-wrap: balance;
}
.page-title p {
  display: inline-block;
  margin-top: .55rem;
  padding: .2rem .85rem;
  border-radius: 999px;
  background: #fffef2;
  color: var(--title-accent);
  font-size: .79rem;
  font-weight: 850;
  letter-spacing: .035em;
}
#word, .clue, .activity {
  font-family: "Trebuchet MS", "Nirmala UI", "Segoe UI", system-ui, sans-serif;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.controls button { letter-spacing: .01em; font-family: 'Fredoka', 'Manrope', "Nirmala UI", sans-serif; }
#word { inset-inline: 25%; text-align: center; }
#word[data-long="true"] { font-size: 6.3cqi; }
#word[data-vlong="true"] { font-size: 5.0cqi; }

/* --- Top-Right Multilanguage Selector --- */
.page-title .lang-menu-wrap {
  grid-column: 3;
  justify-self: end;
  position: relative;
  inset: auto;
  z-index: 70;
  text-align: start;
  font-family: 'DM Sans', 'Manrope', "Nirmala UI", sans-serif;
}
.lang-trigger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  max-width: 195px;
  padding: 9px 16px 10px;
  font: 700 13.5px/1 'DM Sans', 'Manrope', "Nirmala UI", sans-serif;
  white-space: nowrap;
  cursor: pointer;
  background: linear-gradient(180deg, #2b9bf9 0%, #0d74e7 58%, #0758bd 100%);
  border: 1.5px solid #7ec5ff;
  border-bottom: 4.5px solid #053d87;
  border-radius: 999px;
  color: #ffffff;
  box-shadow: 0 7px 15px rgba(8, 72, 160, 0.32), inset 0 2px 3px rgba(255, 255, 255, 0.34);
  text-shadow: 0 1.5px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease, filter 0.18s ease, box-shadow 0.18s ease;
}
#lang-btn-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lang-trigger-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.06);
}
.lang-trigger-btn[aria-expanded="true"] {
  filter: brightness(1.08);
}
.lang-globe {
  font-size: 14px;
  line-height: 1;
}
.lang-caret {
  font-size: 12px;
  line-height: 1;
  opacity: 0.92;
}
.lang-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 9px);
  width: 296px;
  max-width: calc(100vw - 24px);
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.98);
  border: 2px solid #f4c86a;
  border-bottom: 5px solid #df9f36;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.26), inset 0 2px 3px #ffffff;
  backdrop-filter: blur(14px);
  color: #0f172a;
  z-index: 90;
}
.lang-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 9px;
  margin-bottom: 9px;
  border-bottom: 1.5px solid #e2e8f0;
}
.lang-panel-head h2 {
  margin: 0;
  font: 800 15px/1.2 'Manrope', "Nirmala UI", sans-serif;
  color: #0f172a;
}
.lang-close-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  font-size: 18px;
  line-height: 1;
}
.lang-close-btn:hover {
  background: #eff6ff;
  color: #0d74e7;
}
.lang-search-input {
  display: block;
  width: 100%;
  height: 38px;
  padding: 7px 12px;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  background: #f8fafc;
  color: #0f172a;
  font: 600 13px/1.2 'DM Sans', "Nirmala UI", sans-serif;
}
.lang-search-input:focus {
  outline: none;
  border-color: #2b9bf9;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(43, 155, 249, 0.18);
}
.lang-options-list {
  margin-top: 8px;
  max-height: min(300px, 44svh);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  gap: 4px;
  padding-right: 2px;
}
.lang-opt-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1.5px solid transparent;
  background: transparent;
  color: #1e293b;
  text-align: start;
}
.lang-opt-btn:hover {
  background: #f0f7ff;
  border-color: #bfdbfe;
}
.lang-opt-btn[aria-selected="true"] {
  background: linear-gradient(180deg, #eff6ff 0%, #dbeafe 100%);
  border-color: #60a5fa;
  color: #1d4ed8;
}
.lang-opt-labels {
  display: grid;
  gap: 1px;
  min-width: 0;
}
.lang-opt-native {
  font: 700 13.5px/1.25 'DM Sans', "Nirmala UI", sans-serif;
}
.lang-opt-en {
  font: 600 10.5px/1.2 'DM Sans', sans-serif;
  color: #64748b;
}
.lang-opt-check {
  font-weight: 800;
  font-size: 15px;
  color: #0d74e7;
  flex-shrink: 0;
}
.lang-status {
  margin: 7px 0 0;
  font: 700 11.5px/1.3 'DM Sans', "Nirmala UI", sans-serif;
  color: #0d74e7;
}
.lang-status:empty {
  display: none;
}
.lang-status.is-error {
  color: #be123c;
}
.activity { min-height: 5.9%; font-size: 3.9cqi; }
.sunrise-base { filter: none; }
.sunrise-colors {
  mask-image: linear-gradient(to bottom, transparent 3.5%, #000 6.5% 93.5%, transparent 96.5%), linear-gradient(to right, transparent 3.5%, #000 5.5% 94.5%, transparent 96.5%);
  mask-composite: intersect;
}
#sunrise-letter {
  position: absolute;
  inset: 28% 16% 28%;
  display: grid;
  place-items: center;
  color: #fff;
  font-family: "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  font-weight: 900;
  font-size: 44cqi;
  line-height: 1;
  -webkit-text-stroke: .5cqi #93602d;
  paint-order: stroke fill;
  text-shadow: 0 1cqi #4c1e6f, 0 1.5cqi 1.5cqi #301951a0;
}
#sunrise-clue, .activity {
  display: none !important;
}

/* Large Desktops (1600px+) */
@media (min-width: 1600px) {
  .page-title {
    max-width: 1080px;
    width: min(1080px, calc(100% - 64px));
  }
  .deck {
    width: min(100%, 510px);
  }
  .card {
    width: min(100%, 445px, calc((100dvh - 220px) * .787));
  }
}

/* Tablets & Compact Laptops (<= 991.98px) */
@media (max-width: 991.98px) {
  .page-title {
    width: calc(100% - 28px);
    gap: 10px;
  }
  .deck {
    width: min(100%, 440px);
  }
}

/* Large Phones & Small Tablets (<= 720px) */
@media (max-width: 720px) {
  body {
    padding: clamp(8px, 1.5vh, 14px) 0;
  }
  .page-title {
    width: calc(100% - 20px);
    min-height: 38px;
    gap: 8px;
  }
  .page-title .header-back-btn {
    padding: 7px 13px 8px;
    font-size: 12.5px;
    gap: 4px;
    border-bottom-width: 3.5px;
  }
  .lang-trigger-btn {
    max-width: 145px;
    padding: 7px 11px 8px;
    font-size: 12px;
    gap: 4px;
    border-bottom-width: 3.5px;
  }
  .lang-panel {
    top: calc(100% + 8px);
    right: 0;
    width: min(286px, calc(100vw - 20px));
  }
  .page-title h1 {
    font-size: clamp(17.5px, 4.4vw, 22px);
  }
  main {
    padding: clamp(8px, 1.4vh, 14px) 10px 0;
  }
  .deck {
    width: min(100%, 380px);
  }
  .card {
    width: min(86vw, 340px, calc((100svh - 190px) * .787));
    width: min(86vw, 340px, calc((100dvh - 190px) * .787));
    min-width: 0;
  }
  .controls {
    gap: clamp(6px, 2vw, 10px);
    margin-top: clamp(10px, 1.8vh, 16px);
  }
  .controls button {
    min-height: 42px;
    padding: 7px 8px 8px;
    font-size: clamp(11.5px, 3.3vw, 14px);
    line-height: 1.15;
    white-space: normal;
    text-align: center;
    border-bottom-width: 3.5px;
  }
  .view-controls {
    margin-top: clamp(8px, 1.4vh, 12px);
  }
  #full {
    min-height: 34px;
    padding: 5px 14px;
    font-size: 12px;
    border-radius: 999px;
  }
}

/* All Mobile Phones (<= 540px): Two-row header so Back, Language & Title never collide */
@media (max-width: 540px) {
  body {
    justify-content: flex-start;
    padding: 10px 0 14px;
  }
  .page-title {
    display: flex;
    justify-content: space-between;
    width: calc(100% - 20px);
  }
  .page-title .header-back-btn {
    grid-column: 1;
    grid-row: 1;
  }
  .page-title .lang-menu-wrap {
    grid-column: 2;
    grid-row: 1;
  }
  .page-title-inner {
    grid-column: 1 / -1;
    grid-row: 2;
  }
  .card {
    width: min(88vw, 330px, calc((100svh - 220px) * .787));
    width: min(88vw, 330px, calc((100dvh - 220px) * .787));
  }
}

/* Compact Phones (320px - 374px) */
@media (max-width: 374px) {
  .page-title {
    width: calc(100% - 14px);
  }
  .page-title .header-back-btn {
    padding: 6px 11px 7px;
    font-size: 11.5px;
  }
  .lang-trigger-btn {
    max-width: 132px;
    padding: 6px 10px 7px;
    font-size: 11.5px;
  }
  .page-title h1 {
    font-size: clamp(16px, 4.8vw, 18.5px);
  }
  main {
    padding-inline: 8px;
  }
  .controls {
    gap: 5px;
  }
  .controls button {
    min-height: 38px;
    padding: 6px 5px 7px;
    font-size: 11px;
  }
}

/* Mobile Landscape Viewports */
@media (max-height: 540px) and (orientation: landscape) {
  body {
    justify-content: flex-start;
    padding: 8px 0 12px;
  }
  .page-title {
    display: flex;
    justify-content: space-between;
    width: calc(100% - 24px);
  }
  .page-title .header-back-btn {
    grid-column: 1;
    grid-row: 1;
  }
  .page-title-inner {
    grid-column: 2;
    grid-row: 1;
  }
  .page-title .lang-menu-wrap {
    grid-column: 3;
    grid-row: 1;
  }
  .deck {
    width: min(100%, 340px);
  }
  .card {
    width: min(42vw, 220px);
    min-width: 0;
  }
  .controls {
    margin-top: 8px;
  }
}