/* Pinoy Word Games — cozy light theme, single-screen layout */

:root {
  --bg: #fdf6ec;
  --bg-soft: #faedd8;
  --card: #fffdf8;
  --ink: #5a4632;
  --ink-soft: #8a7560;
  --line: #ecdfc8;
  --coral: #e76f51;
  --coral-soft: #fbe3da;
  --peach: #f4a261;
  --sage: #7fa86f;
  --sage-soft: #e6f0df;
  --sky: #6fa8c9;
  --locked: #d8cfc2;
  --gold: #f2b705;
  --radius: 18px;
  --shadow: 0 6px 18px rgba(122, 92, 60, 0.10);
  --shadow-lift: 0 10px 26px rgba(122, 92, 60, 0.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Quicksand", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overflow: hidden; /* single screen: the app manages its own space */
}

body {
  background:
    radial-gradient(900px 500px at 85% -10%, #fdebd2 0%, transparent 60%),
    radial-gradient(700px 420px at -10% 110%, #eef3e2 0%, transparent 55%),
    var(--bg);
}

h1, h2, h3, .btn, .lvl, .badge, .key {
  font-family: "Baloo 2", "Quicksand", system-ui, sans-serif;
}

button { touch-action: manipulation; }

/* ---------- floating cozy bits ---------- */
.floaties {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.floaty {
  position: absolute;
  font-size: 24px;
  opacity: 0.28;
  filter: saturate(0.9);
  animation: drift var(--dur, 26s) ease-in-out infinite alternate;
  animation-delay: var(--delay, 0s);
}
@keyframes drift {
  from { transform: translate(0, 0) rotate(-6deg); }
  to   { transform: translate(var(--dx, 40px), var(--dy, -60px)) rotate(8deg); }
}
@media (prefers-reduced-motion: reduce) {
  .floaty { animation: none; }
}

/* ---------- app frame: header + stage, exactly one viewport tall ---------- */
.wrap {
  position: relative;
  z-index: 1;
  /* --app-h is set from the *visible* viewport in JS; in an installed
     (standalone) PWA on Android, 100dvh can resolve taller than what's on
     screen (the bottom system bar), pushing the keyboard off-screen. The
     dvh value is the fallback before/without JS. */
  height: 100dvh;
  height: var(--app-h, 100dvh);
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}
.topbar .spacer { flex: 1; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--ink);
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  font-size: 17px;
}
.brand .tile-logo { display: inline-grid; grid-auto-flow: column; gap: 3px; }
.brand .tile-logo b {
  width: 21px; height: 21px;
  display: grid; place-items: center;
  background: var(--card);
  border: 2px solid var(--peach);
  border-radius: 6px;
  font-size: 11px;
  color: var(--coral);
  box-shadow: 0 2px 0 rgba(122,92,60,.12);
}
@media (max-width: 480px) {
  .brand .brand-name { display: none; }
  /* keep the top bar from crowding: icons only on narrow screens */
  .topbar .btn-label { display: none; }
}

/* Mute toggle */
#btn-mute { font-size: 15px; padding: 7px 10px; }
#btn-mute.muted { opacity: 0.55; }

/* Sync Up: update-available indicator */
#btn-sync { position: relative; }
.sync-dot { display: none; }
#btn-sync.has-update {
  color: var(--coral);
  box-shadow: 0 4px 0 #ecbfae, var(--shadow);
}
#btn-sync.has-update .sync-dot {
  display: block;
  position: absolute;
  top: -3px;
  right: -3px;
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: var(--coral);
  border: 2px solid var(--bg);
  animation: sync-pulse 1.4s ease-in-out infinite;
}
#btn-sync.syncing > span[aria-hidden] { display: inline-block; animation: sync-spin .8s linear infinite; }
@keyframes sync-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: .65; }
}
@keyframes sync-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .sync-dot, #btn-sync.syncing > span[aria-hidden] { animation: none; }
}

/* stage hosts the views; views never push the page taller */
#stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- views ---------- */
.view { display: none; flex: 1; min-height: 0; flex-direction: column; }
.view.active { display: flex; animation: pop-in .25s ease; }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- home ---------- */
#view-home { justify-content: center; text-align: center; gap: clamp(6px, 1.8vh, 16px); }
.word-demo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.word-demo b {
  width: clamp(26px, 4.5vh, 34px);
  height: clamp(30px, 5vh, 38px);
  display: grid; place-items: center;
  background: var(--card);
  border: 2px solid var(--line);
  border-bottom-width: 4px;
  border-radius: 10px;
  font-family: "Baloo 2", sans-serif;
  font-size: clamp(14px, 2.6vh, 18px);
  animation: tile-bob 3.2s ease-in-out infinite;
}
.word-demo b:nth-child(2) { animation-delay: .15s; border-color: #f3cdb4; }
.word-demo b:nth-child(3) { animation-delay: .3s; }
.word-demo b:nth-child(4) { animation-delay: .45s; border-color: #cfe0c0; }
.word-demo b.plus { border: none; background: none; box-shadow: none; color: var(--coral); }
@keyframes tile-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}
@media (prefers-reduced-motion: reduce) {
  .word-demo b { animation: none; }
}

.hero-title {
  font-size: clamp(28px, 6.5vh, 48px);
  margin: 0;
  line-height: 1.1;
  letter-spacing: .5px;
}
.hero-title .hl { color: var(--coral); }
.hero-sub {
  color: var(--ink-soft);
  margin: 0 auto;
  max-width: 420px;
  font-size: clamp(13px, 2vh, 15.5px);
}
@media (max-height: 560px) {
  .hero-sub, .word-demo { display: none; }
}

.menu {
  display: grid;
  gap: clamp(8px, 1.6vh, 12px);
  width: min(330px, 86%);
  margin: 0 auto;
}

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius);
  padding: clamp(10px, 1.9vh, 14px) 20px;
  font-size: clamp(15px, 2.4vh, 18px);
  font-weight: 700;
  color: #fff;
  background: var(--coral);
  box-shadow: 0 4px 0 #c4583e, var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 #c4583e, var(--shadow-lift); }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #c4583e, var(--shadow); }
.btn.secondary {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--line), var(--shadow);
}
.btn.secondary:hover { box-shadow: 0 6px 0 var(--line), var(--shadow-lift); }
.btn.secondary:active { box-shadow: 0 2px 0 var(--line), var(--shadow); }
.btn.small { padding: 7px 13px; font-size: 14px; border-radius: 12px; }

.btn.disabled,
.btn:disabled {
  background: var(--locked);
  color: #9a8d7c;
  box-shadow: 0 4px 0 #c9bfb0;
  cursor: not-allowed;
  transform: none;
  filter: grayscale(.35);
}
.btn .soon-tag {
  font-size: 10px;
  background: #b7ab9b;
  color: #fff;
  border-radius: 999px;
  padding: 2px 7px;
  letter-spacing: .4px;
}

.home-progress {
  color: var(--ink-soft);
  font-size: clamp(12px, 1.9vh, 14px);
  margin: 0;
}
.home-foot {
  color: var(--ink-soft);
  font-size: 12px;
  margin: 0;
}
.home-foot a { color: var(--coral); text-decoration: none; }

/* ---------- shared compact view head ---------- */
.view-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 8px;
  flex-wrap: nowrap;
  min-width: 0;
}
.view-head h2 { margin: 0; font-size: clamp(18px, 3vh, 24px); white-space: nowrap; }
.view-head .meta { color: var(--ink-soft); font-size: 13px; white-space: nowrap; }
.view-head .spacer { flex: 1; }

/* ---------- levels grid: scrollable for any number of levels ---------- */
#view-levels { min-height: 0; }
.level-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-auto-rows: clamp(26px, 3.6vh, 46px);
  gap: clamp(3px, 0.8vh, 8px);
  overflow-y: auto;
  align-content: start;
}
.lvl {
  position: relative;
  border: none;
  border-radius: clamp(7px, 1.2vh, 12px);
  background: var(--card);
  box-shadow: 0 2px 0 var(--line);
  font-size: clamp(10px, 1.7vh, 15px);
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform .12s ease;
}
.lvl:hover { transform: translateY(-2px); }
.lvl.solved {
  background: var(--sage-soft);
  box-shadow: 0 2px 0 #c4d8b4;
}
.lvl.solved::after {
  content: "★";
  position: absolute;
  top: 0; right: 3px;
  font-size: 9px;
  color: var(--gold);
}
.lvl.current {
  background: var(--coral-soft);
  box-shadow: 0 2px 0 #ecbfae;
  outline: 2px solid var(--coral);
  outline-offset: 1px;
}
.lvl.locked {
  background: #f1eadf;
  color: #c2b5a3;
  box-shadow: 0 2px 0 #e0d6c6;
  cursor: not-allowed;
  font-size: clamp(9px, 1.6vh, 13px);
}
.lvl.locked:hover { transform: none; }

/* ---------- play: column that always fits ---------- */
#view-play {
  min-height: 0;
  gap: clamp(6px, 1.4vh, 12px);
  overflow-y: auto; /* last-resort: scroll instead of clipping the keyboard */
}

.play-info {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.play-info h2 { margin: 0; font-size: clamp(17px, 2.8vh, 22px); white-space: nowrap; }
.badge {
  background: var(--coral-soft);
  color: var(--coral);
  font-weight: 700;
  font-size: clamp(11px, 1.8vh, 13px);
  border-radius: 999px;
  padding: 3px 10px;
  letter-spacing: .4px;
  white-space: nowrap;
}
.badge.kind { background: var(--sage-soft); color: var(--sage); }
.badge.timer {
  background: var(--bg-soft);
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}
.badge.timer.paused { opacity: .55; }

.clue {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--bg-soft);
  border: 2px dashed #ecd3ad;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: clamp(15px, 2.6vh, 19px);
  font-weight: 600;
  text-align: center;
  overflow-y: auto;
}
.clue .q-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--peach);
}
.clue-kind {
  font-family: "Baloo 2", sans-serif;
  font-size: clamp(12px, 1.9vh, 14px);
  font-weight: 700;
  letter-spacing: 0.7px;
  color: var(--sage);
  text-transform: uppercase;
  align-self: stretch;
  text-align: center;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

/* hint area lives inside the column; shrinks/scrolls before the keyboard
   ever gets pushed past the bottom */
.hint-box {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  text-align: center;
  font-size: 13px;
  color: var(--ink-soft);
}
.hint-box:empty { display: none; }
.hint-box .hint-line { margin: 2px 0; }

/* answer field: WORD1 - WORD2 with fixed dash */
.answer-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.answer-row .dash {
  font-family: "Baloo 2", sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: var(--ink-soft);
  user-select: none;
}
.word-input {
  width: min(40vw, 220px);
  padding: clamp(8px, 1.6vh, 12px) 8px;
  font-family: "Baloo 2", sans-serif;
  font-size: clamp(16px, 2.8vh, 20px);
  font-weight: 600;
  letter-spacing: 2px;
  text-align: center;
  text-transform: uppercase;
  color: var(--ink);
  background: #fffaf2;
  border: 2px solid var(--line);
  border-bottom-width: 4px;
  border-radius: 12px;
  outline: none;
  caret-color: transparent;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.word-input.active {
  border-color: var(--peach);
  box-shadow: 0 0 0 4px rgba(244, 162, 97, 0.18);
}

.feedback {
  flex: 0 0 auto;
  min-height: 20px;
  text-align: center;
  font-weight: 700;
  font-size: clamp(13px, 2.2vh, 16px);
}
.feedback.ok { color: var(--sage); animation: cheer .45s ease; }
.feedback.no { color: var(--coral); animation: shake .35s ease; }
@keyframes cheer {
  0% { transform: scale(.7); opacity: 0; }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.shake { animation: shake .35s ease; }

/* compact bar shown when revisiting a solved level */
.solved-bar {
  flex: 0 0 auto;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--sage-soft);
  border-radius: 12px;
  padding: 8px 12px;
  font-weight: 700;
  color: var(--sage);
  font-size: 14px;
}
.solved-bar.show { display: flex; }

/* ---------- custom keyboard ---------- */
.kb {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: clamp(3px, 0.8vh, 7px);
  user-select: none;
  padding-bottom: 2px;
}
.kb-row {
  display: flex;
  justify-content: center;
  gap: clamp(3px, 0.8vw, 6px);
}
.key {
  flex: 1 1 0;
  max-width: 52px;
  height: clamp(34px, 5.4vh, 50px);
  border: none;
  border-radius: 9px;
  background: var(--card);
  box-shadow: 0 3px 0 var(--line);
  color: var(--ink);
  font-size: clamp(14px, 2.4vh, 17px);
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}
.key:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.key.fn {
  max-width: 72px;
  flex: 1.5 1 0;
  background: var(--bg-soft);
  color: var(--ink-soft);
}
.key.dash { background: var(--coral-soft); color: var(--coral); }
.key.check {
  max-width: none;
  flex: 3 1 0;
  background: var(--coral);
  color: #fff;
  box-shadow: 0 3px 0 #c4583e;
  letter-spacing: .5px;
}
.key.check:active { box-shadow: 0 1px 0 #c4583e; }
.key.hintkey { max-width: 64px; background: var(--bg-soft); }

/* typical phones (most portrait handsets): the column was fitting with only
   a couple px to spare, which real-device font metrics / browser chrome eat,
   spilling the keyboard. Trim the non-shrinking parts for breathing room. */
@media (max-height: 740px) {
  .wrap { padding-top: 8px; gap: 6px; }
  #view-play { gap: clamp(5px, 1vh, 9px); }
  .view-head { margin: 2px 0 4px; }
  .clue { padding: 8px 12px; }
  .answer-row .dash { font-size: 20px; }
}

/* very short screens (landscape phones, tiny windows): tighten everything
   so all four keyboard rows stay above the bottom edge */
@media (max-height: 540px) {
  .wrap { padding-top: 6px; gap: 4px; }
  .topbar { min-height: 30px; }
  #view-play { gap: 4px; }
  .view-head { margin: 0 0 2px; }
  .clue { padding: 5px 10px; }
  .clue .q-label { display: none; }
  .clue-kind { padding-bottom: 2px; }
  .hint-box { font-size: 12px; }
  .feedback { min-height: 0; font-size: 12px; }
  .word-input { padding: 5px 8px; font-size: 15px; }
  .answer-row .dash { font-size: 18px; }
  .kb { gap: 3px; }
  .key { height: clamp(26px, 7.5vh, 38px); font-size: clamp(12px, 4vh, 15px); }
  .toast { bottom: 6px; }
}

/* ---------- overlays (lesson / reminder / win) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(90, 70, 50, 0.35);
  backdrop-filter: blur(2px);
}
.overlay.show { display: flex; }
.sheet {
  width: min(440px, 100%);
  max-height: min(82dvh, 640px);
  overflow-y: auto;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow-lift);
  padding: 20px 18px;
  animation: sheet-in .25s ease;
}
@keyframes sheet-in {
  from { opacity: 0; transform: translateY(16px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

/* lesson sheet */
.sheet .tut-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--sage);
}
.sheet h3 { margin: 4px 0 6px; font-size: 19px; }
.sheet p { margin: 6px 0; font-size: 14.5px; }
.tut-example {
  background: var(--sage-soft);
  border-radius: 12px;
  padding: 10px 12px;
  margin-top: 10px;
}
.tut-example .tut-eq { font-weight: 600; font-size: 13px; color: var(--ink-soft); }
.tut-example .tut-ea { font-size: 14px; margin-top: 4px; }
.tut-example .tut-ea b { color: var(--sage); }
.tut-example .tut-note { font-size: 13px; color: var(--ink-soft); margin: 6px 0 0; }
.sheet-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

/* win sheet */
.sheet.win { text-align: center; }
.sheet.win .win-title { font-family: "Baloo 2", sans-serif; font-size: 22px; margin: 2px 0; }
.sheet.win .ans {
  font-family: "Baloo 2", sans-serif;
  font-size: 26px;
  color: var(--sage);
  margin: 6px 0 2px;
}
.sheet.win .win-time {
  color: var(--ink-soft);
  font-size: 13px;
  margin: 8px 0 0;
  font-variant-numeric: tabular-nums;
}
.sheet.win .win-time b { color: var(--coral); }
.sheet.win .win-sub { color: var(--ink-soft); font-size: 13.5px; margin: 4px 0 0; }

/* letter-tile mechanic visualizer (lessons + hints) */
.tiles-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  flex-wrap: wrap;
  margin: 6px 0 2px;
}
.tiles { display: inline-flex; gap: 3px; }
.tiles-arrow { font-family: "Baloo 2", sans-serif; font-weight: 700; color: var(--ink-soft); }
.tile {
  width: clamp(18px, 3vh, 24px);
  height: clamp(22px, 3.6vh, 28px);
  display: grid;
  place-items: center;
  background: #fffdf8;
  border: 2px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 7px;
  font-family: "Baloo 2", sans-serif;
  font-size: clamp(11px, 2vh, 14px);
  font-weight: 700;
  color: var(--ink);
}
.tile.add { border-color: #9dc18b; background: var(--sage-soft); color: var(--sage); }
.tile.ins { border-color: #93bcd8; background: #e3eef7; color: var(--sky); }
.tile.swap { border-color: #eebf90; background: #fdeedd; color: var(--peach); }
.tile.cut {
  border-style: dashed;
  border-color: #e7a797;
  background: var(--coral-soft);
  color: var(--coral);
  position: relative;
}
.tile.cut::after {
  content: "✕";
  position: absolute;
  font-size: 9px;
  top: -2px;
  right: -1px;
  color: var(--coral);
}

/* ---------- manual (scrolls inside itself, page stays put) ---------- */
#view-manual { min-height: 0; }
.manual {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 18px;
}
.manual h2 { margin-top: 0; font-size: 20px; }
.manual h3 { color: var(--coral); margin: 18px 0 4px; font-size: 16px; }
.manual .example {
  background: var(--bg-soft);
  border-radius: 10px;
  padding: 8px 12px;
  margin: 6px 0;
  font-size: 14px;
}
.manual .example b { color: var(--sage); }
.manual p, .manual li { font-size: 14.5px; }

/* ---------- confetti burst ---------- */
.burst {
  position: fixed;
  z-index: 70;
  pointer-events: none;
  font-size: 22px;
  animation: burst-fly .9s ease-out forwards;
}
@keyframes burst-fly {
  from { transform: translate(0, 0) scale(1); opacity: 1; }
  to   { transform: translate(var(--bx), var(--by)) scale(.6) rotate(160deg); opacity: 0; }
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff8ef;
  font-size: 13.5px;
  padding: 8px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
  z-index: 80;
  white-space: nowrap;
}
.toast.show { opacity: .92; }
