html,
body {
  height: 100%;
}
body {
  overflow: hidden;
}
:root {
  --brand: #6c63ff;
  --accent: #ff9f1c;
  --good: #2ecc71;
  --bad: #ff4d4f;
  --ink: #24324b;
  --soft: #f7f7fb;
  --sky: #e8f3ff;

  --chip1: #ffe6d0;
  --chip1b: #ffc190;
  --chip2: #e7f5ff;
  --chip2b: #bde1ff;
  --chip3: #fde7f2;
  --chip3b: #ffc5e5;
  --chip4: #eaf7e9;
  --chip4b: #c8edc5;
}
* {
  box-sizing: border-box;
}
html {
  font-size: 62.5%;
}
body {
  margin: 0;
  font-family: "Poppins", system-ui, -apple-system, Segoe UI, Roboto, Arial,
    sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #eaf6ff 0%, #fff8f0 100%);
  min-height: calc(var(--vh, 1vh) * 100);
}
.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: calc(var(--vh, 1vh) * 100);
  margin: 0 auto;
  width: min(96rem, 100%);
  background: #fff;
  border-radius: 2rem;
  box-shadow: 0 12px 28px rgba(16, 24, 40, 0.12);
  overflow: hidden;
  border: 4px solid #fff;
  position: relative;
}
.header {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  padding: 1.2rem 1.6rem;
  background: linear-gradient(90deg, var(--brand), #8a85ff);
  color: #fff;
}
.logo {
  width: 4.4rem;
  height: 4.4rem;
  border-radius: 1.2rem;
  background: #fff3;
  display: grid;
  place-items: center;
}
.logo i {
  font-size: 2.2rem;
}
.title-wrap {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.title {
  font-size: 1.9rem;
  font-weight: 700;
}
.subtitle {
  font-size: 1.2rem;
  opacity: 0.9;
}

.toolbar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.8rem;
}
.tbtn {
  border: none;
  background: #fff;
  color: var(--brand);
  border-radius: 999px;
  width: 3.6rem;
  height: 3.6rem;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.tbtn:active {
  transform: translateY(1px);
}

.content {
  overflow: auto;
  min-height: 0;
  overscroll-behavior: contain;
  padding: 1.6rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.6rem;
}
@media (min-width: 720px) {
  .content {
    overflow: auto;
    min-height: 0;
    overscroll-behavior: contain;
    grid-template-columns: 1fr 1fr;
  }
}

.card {
  background: var(--soft);
  border-radius: 1.6rem;
  padding: 1.2rem;
  box-shadow: inset 0 0 0 2px #fff;
}

.image-wrap {
  display: grid;
  place-items: center;
  padding: 1rem;
  background: #fff;
  border-radius: 1.2rem;
  position: relative;
}
.image-wrap img {
  display: block;
  max-width: 100%;
  height: auto;
  max-height: clamp(160px, 32dvh, 360px);
  object-fit: contain;
  border-radius: 1.2rem;
  border: 4px solid var(--sky);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.08);
}
/* floating speaker on image */
.speak-fab {
  position: absolute;
  right: 1.2rem;
  top: 1.2rem;
  width: 3.8rem;
  height: 3.8rem;
  border-radius: 999px;
  border: none;
  background: #ffffff;
  color: var(--brand);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}
.speak-fab:active {
  transform: translateY(1px);
}

.progress {
  height: 1.2rem;
  background: #e9eef6;
  border-radius: 999px;
  overflow: hidden;
}
.bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffcc00, #ff66cc);
  transition: width 0.5s ease;
}
.counter {
  font-size: 1.3rem;
  margin-top: 0.6rem;
  opacity: 0.75;
}

.placeholder {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: clamp(64px, 8vw, 96px);
  gap: clamp(8px, 1.4vw, 14px);
  padding: 12px;
  background: #eaf3ff;
  border-radius: 12px;
  align-content: start;
  justify-content: start;
  min-height: unset;
  overflow: visible;
}
.slot {
  display: grid;
  place-items: center;
  width: clamp(64px, 8vw, 96px);
  height: clamp(56px, 7dvh, 72px);
  border: 2px dashed #bbd0ff;
  border-radius: 12px;
  background: #fff;
  font-size: clamp(22px, 4.6vw, 30px);
  font-weight: 700;
}

.letters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 1rem;
}
@media (max-width: 420px) {
  .letters {
    grid-template-columns: repeat(4, minmax(5.2rem, 1fr));
  }
}

.chip {
  display: grid;
  place-items: center;
  height: clamp(52px, 7dvh, 64px);
  border-radius: 1.2rem;
  font-size: clamp(22px, 5vw, 32px);
  font-weight: 700;
  cursor: pointer;
  background: var(--chip1);
  border: 2px solid var(--chip1b);
  user-select: none;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
}
/* rotate chip colors for variety */
.letters .chip:nth-child(4n + 1) {
  background: var(--chip1);
  border-color: var(--chip1b);
}
.letters .chip:nth-child(4n + 2) {
  background: var(--chip2);
  border-color: var(--chip2b);
}
.letters .chip:nth-child(4n + 3) {
  background: var(--chip3);
  border-color: var(--chip3b);
}
.letters .chip:nth-child(4n + 4) {
  background: var(--chip4);
  border-color: var(--chip4b);
}

.chip:active {
  transform: translateY(1px);
}

.message {
  min-height: 2.4rem;
  font-size: 1.6rem;
  font-weight: 700;
}
.ok {
  color: var(--good);
}
.oops {
  color: var(--bad);
}

.footer {
  position: relative;
  z-index: 1;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.6rem;
  background: #fff;
}
.btn {
  background: linear-gradient(135deg, var(--accent), #ff6a3d);
  border: none;
  color: #fff;
  padding: 1.2rem 1.8rem;
  border-radius: 1.2rem;
  font-size: 1.6rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 16px rgba(255, 130, 28, 0.25);
}
.btn.secondary {
  background: #eef2ff;
  color: var(--brand);
  box-shadow: none;
  border: 2px solid var(--brand);
}
.btn[disabled] {
  opacity: 0.5;
  filter: saturate(0.5);
  cursor: not-allowed;
}

@keyframes correctGlow {
  0% {
    box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.5);
  }
  70% {
    box-shadow: 0 0 0 16px rgba(46, 204, 113, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(46, 204, 113, 0);
  }
}
@keyframes wobble {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  75% {
    transform: translateX(6px);
  }
}
.win {
  animation: correctGlow 0.9s ease;
}
.shake {
  animation: wobble 0.45s ease;
}

/* Tooltip */
[data-tip] {
  position: relative;
}
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  translate: -50% 0;
  background: #111;
  color: #fff;
  padding: 0.4rem 0.8rem;
  border-radius: 0.6rem;
  font-size: 1.1rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
[data-tip]:hover::after {
  opacity: 0.9;
}

/* Success dialog */
#dlgWin::backdrop {
  background: rgba(0, 0, 0, 0.35);
}
#dlgWin {
  border: none;
  border-radius: 1.6rem;
  padding: 0;
}
.win-card {
  padding: 1.6rem;
  min-width: min(92vw, 420px);
  text-align: center;
  background: #fff;
  border-radius: 1.6rem;
}
.trophy {
  font-size: 6rem;
  line-height: 1;
  margin: 0.2rem 0 0.6rem 0;
}
.win-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
}

/* Confetti */
.confetti {
  position: fixed;
  top: 0;
  left: 0;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  opacity: 0.95;
  will-change: transform, opacity;
  animation: confetti-fall 1200ms ease-out forwards;
}
@keyframes confetti-fall {
  to {
    transform: translate(var(--xend), 100vh) rotate(var(--rend));
    opacity: 0;
  }
}

@media (max-height: 680px) {
  .content {
    gap: 1rem;
  }
  .chip,
  .slot {
    height: clamp(44px, 6.2dvh, 58px);
    font-size: clamp(18px, 4.4vw, 28px);
  }
  .image-wrap img {
    max-height: clamp(140px, 28dvh, 300px);
  }
}
@media (min-width: 1024px) {
  .content {
    padding: 2rem;
  }
  .image-wrap img {
    max-height: clamp(280px, 40vh, 560px);
  }
}
