:root {
  color-scheme: light;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background: #dff7ff;
  color: #153b32;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
}

body {
  display: flex;
  justify-content: center;
  padding: 18px;
  background:
    radial-gradient(circle at 18% 8%, rgba(255, 255, 255, 0.92), transparent 13rem),
    radial-gradient(circle at 84% 18%, rgba(255, 231, 136, 0.42), transparent 11rem),
    linear-gradient(180deg, #b8ecff 0%, #dff6d2 50%, #ffe6a5 100%);
}

button {
  min-height: 58px;
  border: 0;
  border-radius: 8px;
  color: #153b32;
  font: 900 1rem/1.05 "Trebuchet MS", "Segoe UI", sans-serif;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible {
  outline: 4px solid #153b32;
  outline-offset: 3px;
}

.game-shell {
  position: relative;
  width: min(100%, 980px);
  min-height: 100vh;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #2a7b57;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 720px;
  color: #153b32;
  font-size: 2.72rem;
  line-height: 0.98;
}

.sound-toggle {
  flex: 0 0 auto;
  min-width: 130px;
  padding: 0 18px;
  background: #153b32;
  color: #fff8dc;
  box-shadow: 0 8px 0 rgba(21, 59, 50, 0.18);
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.score-tile {
  min-height: 64px;
  padding: 10px;
  border: 3px solid rgba(21, 59, 50, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 7px 0 rgba(21, 59, 50, 0.08);
}

.score-tile span {
  display: block;
  color: #557166;
  font-size: 0.75rem;
  font-weight: 900;
  text-transform: uppercase;
}

.score-tile strong {
  display: block;
  margin-top: 2px;
  font-size: 2rem;
  line-height: 1;
}

.canvas-wrap {
  width: 100%;
  border: 4px solid #153b32;
  border-radius: 8px;
  background: #bcefff;
  box-shadow: 0 12px 0 rgba(21, 59, 50, 0.13);
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 58vh;
  background: #bcefff;
  touch-action: none;
}

.word-panel {
  margin-top: 12px;
  padding: 12px;
  border: 3px solid rgba(21, 59, 50, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 7px 0 rgba(21, 59, 50, 0.08);
}

.prompt-text {
  min-height: 24px;
  margin: 0 0 10px;
  color: #153b32;
  font-weight: 900;
}

.word-slots {
  display: grid;
  grid-template-columns: repeat(3, minmax(58px, 1fr));
  gap: 8px;
}

.word-slot {
  min-height: 62px;
  display: grid;
  place-items: center;
  border: 3px dashed #8c6f40;
  border-radius: 8px;
  background: #fff8dc;
  color: #153b32;
  font-size: 2rem;
  font-weight: 900;
  text-transform: uppercase;
}

.word-slot.filled {
  border-style: solid;
  background: #ffe78b;
}

.word-slots.shake {
  animation: word-shake 0.24s linear;
}

.letter-rack,
.touch-controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(58px, 1fr));
  gap: 8px;
  margin-top: 10px;
  touch-action: none;
}

.letter-tile {
  min-height: 66px;
  padding: 0 8px;
  border: 3px solid rgba(21, 59, 50, 0.2);
  background: #fff0a8;
  box-shadow: 0 7px 0 rgba(140, 111, 64, 0.28);
  font-size: 1.9rem;
  text-transform: uppercase;
}

.letter-tile.selected {
  transform: translateY(3px);
  background: #83d47d;
  box-shadow: 0 4px 0 rgba(21, 59, 50, 0.18);
}

.letter-tile.wrong {
  animation: tile-wobble 0.24s linear;
}

.control-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.control-row button,
.result-card button {
  padding: 0 12px;
  background: #ffcf5a;
  box-shadow: 0 7px 0 rgba(21, 59, 50, 0.16);
}

#startButton {
  background: #7ee093;
}

#checkButton {
  background: #8bd9ff;
}

.status {
  min-height: 48px;
  margin: 12px 0 0;
  padding: 12px 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.8);
  color: #153b32;
  font-weight: 900;
}

.result-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(21, 59, 50, 0.52);
  z-index: 10;
}

.result-card {
  width: min(100%, 440px);
  padding: 24px;
  border: 4px solid #153b32;
  border-radius: 8px;
  background: #fff8dc;
  box-shadow: 0 14px 0 rgba(21, 59, 50, 0.22);
}

.result-card p:not(.eyebrow) {
  margin: 12px 0 18px;
  font-weight: 900;
}

@keyframes word-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  50% { transform: translateX(7px); }
  75% { transform: translateX(-4px); }
}

@keyframes tile-wobble {
  0%, 100% { transform: rotate(0deg); }
  35% { transform: rotate(-4deg); }
  70% { transform: rotate(4deg); }
}

@media (max-width: 660px) {
  body {
    padding: 8px;
  }

  .game-header {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
  }

  .game-shell {
    min-height: auto;
  }

  .eyebrow {
    font-size: 0.7rem;
  }

  .sound-toggle {
    width: 100%;
    min-height: 58px;
  }

  h1 {
    font-size: 1.42rem;
    line-height: 1;
  }

  .score-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 8px;
  }

  .score-tile {
    min-height: 50px;
    padding: 7px 8px;
  }

  .score-tile span {
    font-size: 0.68rem;
  }

  .score-tile strong {
    font-size: 1.22rem;
  }

  .canvas-wrap {
    max-width: 320px;
    margin: 0 auto;
  }

  #gameCanvas {
    max-height: 180px;
  }

  .word-panel {
    margin-top: 8px;
    padding: 8px;
  }

  .prompt-text {
    margin-bottom: 8px;
    font-size: 0.86rem;
  }

  .word-slots {
    gap: 6px;
  }

  .word-slot {
    min-height: 58px;
    font-size: 1.55rem;
  }

  .letter-rack,
  .touch-controls {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
    margin-top: 8px;
  }

  .letter-tile {
    min-width: 0;
    min-height: 58px;
    padding: 0 4px;
    font-size: 1.34rem;
  }

  .control-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-top: 8px;
  }

  .control-row button,
  .result-card button {
    min-height: 58px;
    padding: 0 6px;
    font-size: 0.84rem;
  }

  .status {
    min-height: 42px;
    margin-top: 8px;
    padding: 8px 10px;
    font-size: 0.84rem;
  }
}

@media (max-width: 360px) {
  body {
    padding: 6px 8px;
  }

  h1 {
    font-size: 1.24rem;
  }

  .canvas-wrap {
    max-width: 304px;
  }

  #gameCanvas {
    max-height: 171px;
  }

  .letter-tile {
    font-size: 1.16rem;
  }

  .control-row button,
  .result-card button {
    font-size: 0.78rem;
  }

  .status {
    min-height: 38px;
    padding: 6px 8px;
    font-size: 0.77rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
