/* Kids Web Games — calm, touch-first, landscape-only */

:root{
  --bg: #f7f3ea;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #5b6673;
  --line: rgba(0,0,0,.10);
  --shadow: 0 10px 30px rgba(0,0,0,.10);
  --radius: 22px;
  --tap: 84px;
  --focus: 0 0 0 4px rgba(0,0,0,.12);
  --good: rgba(0,0,0,.08);
  --bad: rgba(0,0,0,.12);
}

*{ box-sizing: border-box; }
html, body{
  height: 100%;
  width: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  overflow: hidden; /* no scrolling */
  touch-action: manipulation;
}

.app{
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar{
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
}

.topbar-title{
  text-align: center;
  font-weight: 800;
  font-size: clamp(18px, 2.2vw, 26px);
  letter-spacing: .2px;
}

.topbar-right{
  display: flex;
  justify-content: flex-end;
}

.main{
  padding: 16px;
  overflow: hidden;
}

.btn{
  min-height: 56px;
  padding: 12px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-weight: 800;
  font-size: 18px;
  box-shadow: 0 2px 0 rgba(0,0,0,.06);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:focus-visible{ outline: none; box-shadow: var(--focus); }
.btn:active{ transform: translateY(1px); }

.btn-ghost{
  background: transparent;
  box-shadow: none;
}

.select{
  min-height: 48px;
  padding: 8px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-weight: 800;
  font-size: 16px;
}

.difficulty{
  display: grid;
  gap: 4px;
  justify-items: end;
}
.difficulty-label{
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}

/* Home grid */
.grid{
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.tile{
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  grid-template-rows: 1fr auto;
  align-items: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 220px;
}

.tile:focus-visible{ outline: none; box-shadow: var(--shadow), var(--focus); }
.tile:active{ transform: translateY(2px); }

.tile-emoji{
  font-size: clamp(44px, 5vw, 72px);
  line-height: 1;
  text-align: center;
}
.tile-title{
  margin-top: 10px;
  font-size: clamp(18px, 2.2vw, 26px);
  font-weight: 900;
  text-align: center;
}
.tile-sub{
  margin-top: 6px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

/* Game shell */
.card{
  height: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
}

.card-title{
  font-size: clamp(20px, 2.5vw, 30px);
  font-weight: 950;
  text-align: center;
}

.card-body{
  overflow: hidden;
  display: grid;
  gap: 14px;
  align-content: start;
}

.card-footer{
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.pill{
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.02);
  font-weight: 800;
  color: var(--muted);
}

/* Fill in the blank */
.sentence{
  font-size: clamp(22px, 3.0vw, 34px);
  font-weight: 900;
  text-align: center;
  padding: 12px 10px;
}
.blank{
  display: inline-block;
  min-width: 140px;
  padding: 6px 10px;
  border-radius: 12px;
  border: 2px dashed rgba(0,0,0,.18);
  background: rgba(0,0,0,.03);
}

.choices{
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.choice{
  min-height: var(--tap);
  border-radius: 20px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.02);
  font-weight: 950;
  font-size: clamp(18px, 2.2vw, 26px);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.choice:focus-visible{ outline: none; box-shadow: var(--focus); }
.choice:active{ transform: translateY(2px); }

.feedback{
  text-align: center;
  font-weight: 950;
  font-size: 18px;
  color: var(--muted);
  min-height: 28px;
}

/* Tic Tac Toe */
.board{
  width: min(78vh, 78vw);
  max-width: 640px;
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.cell{
  border-radius: 22px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.02);
  font-size: clamp(38px, 6vw, 72px);
  font-weight: 950;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.cell:focus-visible{ outline: none; box-shadow: var(--focus); }
.cell:active{ transform: translateY(2px); }

/* Word Rescue */
.word-row{
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  padding-top: 6px;
}
.letter-box{
  width: 54px;
  height: 64px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.02);
  display: grid;
  place-items: center;
  font-weight: 950;
  font-size: 28px;
}

.kbd{
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  gap: 10px;
}
.key{
  min-height: 56px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.02);
  font-weight: 950;
  font-size: 18px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.key[disabled]{
  opacity: .45;
  cursor: default;
}
.key:focus-visible{ outline: none; box-shadow: var(--focus); }
.key:active{ transform: translateY(2px); }

.meter{
  width: min(640px, 90%);
  margin: 0 auto;
  height: 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.03);
  overflow: hidden;
}
.meter-fill{
  height: 100%;
  width: 100%;
  background: rgba(0,0,0,.12);
  transform-origin: left center;
  transform: scaleX(1);
  transition: transform 200ms linear;
}

/* Transition overlay */
.transition{
  position: fixed;
  inset: 0;
  background: rgba(247,243,234,.94);
  display: grid;
  place-items: center;
  z-index: 999;
}

.transition-card{
  width: min(520px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.transition-title{
  text-align: center;
  font-weight: 950;
  font-size: 20px;
  color: var(--muted);
}

.cart-track{
  margin-top: 14px;
  position: relative;
  height: 52px;
}
.track{
  position: absolute;
  left: 10px;
  right: 10px;
  top: 26px;
  height: 4px;
  border-radius: 99px;
  background: rgba(0,0,0,.10);
}
.cart{
  position: absolute;
  left: 10px;
  top: 4px;
  font-size: 32px;
  will-change: transform;
}

/* Small shake for wrong answers */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.shake{ animation: shake 260ms ease-in-out; }

@media (orientation: portrait){
  /* Friendly message if opened in portrait */
  .main::before{
    content: "Rotate your tablet to landscape 😊";
    display: block;
    text-align: center;
    font-weight: 950;
    font-size: 22px;
    color: var(--muted);
    padding-top: 18vh;
  }
  .topbar{ opacity: .15; }
}


/* Ensure [hidden] works even with explicit display rules */
.transition[hidden]{ display:none !important; }

@keyframes pop{0%{transform:scale(1)}40%{transform:scale(1.03)}100%{transform:scale(1)}}
.pop{animation:pop 220ms ease-out}
@keyframes glow{0%{background:rgba(0,0,0,.02)}100%{background:rgba(0,0,0,.06)}}
.glow{animation:glow 180ms ease-out}


/* Word Builder */
.wb-hud{display:flex;justify-content:space-between;gap:12px;margin:10px 0 12px 0;font-weight:700;}
.wb-slots{display:flex;justify-content:center;flex-wrap:wrap;gap:10px;margin:8px 0 14px 0;}
.wb-slot{width:48px;height:54px;display:flex;align-items:center;justify-content:center;border-radius:14px;border:2px dashed rgba(0,0,0,.18);font-size:28px;font-weight:900;letter-spacing:1px;}
.wb-letters{display:flex;justify-content:center;flex-wrap:wrap;gap:10px;margin:10px 0;}
.wb-letter{min-width:56px;height:56px;border-radius:16px;border:1px solid rgba(0,0,0,.12);background:var(--panel, #fff);font-size:26px;font-weight:900;cursor:pointer;}
.wb-letter.used{opacity:.35;transform:scale(.92);}
.wb-letter.shake{animation:wbshake .22s linear;}
@keyframes wbshake{0%{transform:translateX(0);}25%{transform:translateX(-4px);}50%{transform:translateX(4px);}75%{transform:translateX(-3px);}100%{transform:translateX(0);}}
.feedback.ok{font-weight:800;}
.feedback.bad{font-weight:800;}
.wb-celebrate{height:24px;display:flex;justify-content:center;align-items:center;opacity:0;transform:translateY(6px);transition:all .22s ease;}
.wb-celebrate.show{opacity:1;transform:translateY(0);}
