:root {
  --bg: #0d1a14;
  --bg-accent: #111f18;
  --panel: rgba(18, 32, 24, 0.92);
  --panel-strong: #1a2e20;
  --ink: #d6ead8;
  --muted: #7aaa86;
  --accent: #3a9e6e;
  --accent-strong: #2e7d54;
  --accent-blue: #3a7dbf;
  --accent-purple: #7a5bb5;
  --good: #4ec98a;
  --highlight-yellow: #ffe600;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --tile-size: clamp(34px, calc((100vw - 170px) / 7), 74px);
  --radius: 18px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.game-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 14px 18px 18px;
  gap: 12px;
  box-sizing: border-box;
  max-width: 100vw;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.landing-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
}

.landing-panel {
  width: min(780px, 100%);
  display: grid;
  gap: 18px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid rgba(58, 158, 110, 0.18);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.landing-panel h1 {
  margin: 0;
  font-size: 3rem;
  line-height: 1;
  color: var(--good);
}

.landing-score {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.landing-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.start-game-button {
  min-width: 180px;
}

.about-link {
  color: var(--good);
  font-weight: 800;
  text-decoration: none;
}

.quote-quest-panel {
  display: grid;
  gap: 8px;
  padding: 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(58, 158, 110, 0.18);
}

.quote-quest-title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.1;
  color: var(--ink);
}

.quote-quest-description {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.85rem;
}

.quote-line {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.quote-word {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  font-weight: 900;
  letter-spacing: 0;
}

.quote-mark {
  color: var(--muted);
}

.pending-quote-word {
  color: var(--highlight-yellow);
  text-shadow: 0 0 14px rgba(255, 230, 0, 0.65);
}

.completed-quote-word {
  color: var(--muted);
}

.hidden-quote-word {
  color: var(--muted);
}

.secondary-button {
  padding: 12px 18px;
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  background: var(--panel-strong);
  color: var(--ink);
  border: 1px solid rgba(58, 158, 110, 0.15);
}

.danger-button {
  color: #e05555;
}

.stats-card {
  max-height: min(720px, 88vh);
  display: grid;
  gap: 4px;
  overflow: auto;
}

#stats-title,
.overlay-card.stats-card h2,
.stats-card h2 {
  color: var(--ink);
  font-weight: 700;
  font-size: 1.25rem;
}

.stats-card p {
  margin: 2px 0;
}

.stats-card h3,
.completed-quotes h3 {
  margin: 0;
  color: var(--good);
  font-weight: 900;
  font-size: 1.05rem;
}

.debug-card {
  display: grid;
  gap: 12px;
}

.debug-setting {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: 900;
}

.completed-quotes {
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
  padding: 2px 0;
}

.completed-quote {
  margin: 0;
}

.hud {
  width: min(920px, 100%);
  justify-self: center;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: stretch;
  gap: 12px;
}

.hud-card,
.word-zone,
.tray-panel,
.overlay-card {
  background: var(--panel);
  border: 1px solid rgba(58, 158, 110, 0.18);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hud-card {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
}

.hud-card.time-card {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 4px 8px;
  padding: 8px 12px;
  width: auto;
}

.time-card .hud-label {
  display: block;
  grid-column: 1 / -1;
}

.time-card .hud-value {
  font-size: 1.4rem;
}

.give-up-button {
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 0.85rem;
  color: #e07070 !important;
}

.hud-card-score {
  justify-self: end;
  text-align: right;
}

.hud-label,
.word-zone-label,
.tray-label,
.overlay-kicker {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.hud-value {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  font-weight: 900;
}

.stage {
  display: grid;
  place-items: center;
}

.word-container {
  display: flex;
  justify-content: center;
}

.word-zone {
  width: min(920px, 100%);
  padding: 12px;
}

.word-zone-head,
.tray-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.word-slot,
.tile-row {
  position: relative;
  height: calc(var(--tile-size) + 22px);
  min-height: calc(var(--tile-size) + 22px);
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  padding: 10px;
  overflow: visible;
  border-radius: 14px;
  border: 2px dashed rgba(58, 158, 110, 0.22);
  background: rgba(255, 255, 255, 0.03);
  transition: border-color 140ms ease, background-color 140ms ease, transform 140ms ease;
}

.word-slot {
  width: 100%;
  font: inherit;
  color: inherit;
  text-align: left;
}

.word-slot.empty::after {
  content: "Tap or drag tiles here";
  color: var(--muted);
  font-weight: 600;
}

.word-slot.valid {
  border-color: var(--good);
  background: rgba(78, 201, 138, 0.08);
  box-shadow: inset 0 0 0 1px rgba(78, 201, 138, 0.14);
}

.word-slot.ready {
  cursor: pointer;
}

.tray-panel {
  width: min(920px, 100%);
  justify-self: center;
  padding: 12px;
}

.tile {
  position: relative;
  flex: 0 0 var(--tile-size);
  width: var(--tile-size);
  height: var(--tile-size);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 14px;
  background:
    linear-gradient(160deg, #2a4a35 0%, #1c3326 100%);
  box-shadow:
    inset 0 1px 0 rgba(78, 201, 138, 0.18),
    inset 0 -3px 0 rgba(0, 0, 0, 0.3),
    0 6px 14px rgba(0, 0, 0, 0.4);
  font-size: clamp(1.25rem, 4vw, 1.8rem);
  font-weight: 900;
  color: #c8ead4;
  user-select: none;
  touch-action: none;
  transition: transform 120ms ease, opacity 120ms ease, box-shadow 120ms ease;
}

.tile-letter {
  font: inherit;
  font-weight: inherit;
  line-height: 1;
}

.tile:active {
  transform: scale(0.96);
}

.tile.drag-source {
  visibility: hidden;
}

.tile.dragging {
  position: absolute;
  z-index: 2000;
  margin: 0;
  pointer-events: none;
  opacity: 1;
  transform: rotate(-4deg) scale(1.06);
  transition: none;
}

.tile.multiplier {
  background:
    linear-gradient(160deg, #1e3a5a 0%, #14264a 100%);
  box-shadow:
    inset 0 1px 0 rgba(58, 125, 191, 0.25),
    inset 0 -3px 0 rgba(0, 0, 0, 0.3),
    0 6px 14px rgba(0, 0, 0, 0.4);
  color: #a8d4f0;
}

.tile-placeholder {
  flex: 0 0 var(--tile-size);
  background: rgba(58, 158, 110, 0.06);
  border: 2px dashed rgba(58, 158, 110, 0.2);
  box-shadow: none;
}

.tile-score {
  position: absolute;
  left: 8px;
  bottom: 6px;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--muted);
}

.tile-bonus {
  position: absolute;
  top: 6px;
  right: 7px;
  padding: 2px 5px;
  border-radius: 999px;
  background: rgba(58, 125, 191, 0.2);
  color: #a8d4f0;
  font-size: 0.68rem;
  font-weight: 900;
}

.icon-button,
.primary-button {
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.icon-button {
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  background: var(--panel-strong);
  color: var(--ink);
  border: 1px solid rgba(58, 158, 110, 0.15);
}

.icon-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.trash-button {
  font-size: 1.15rem;
}

.primary-button {
  padding: 14px 22px;
  background: var(--accent);
  color: #fff;
}

.drag-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  min-height: 100vh;
  pointer-events: none;
  z-index: 1500;
}

.floating-letter {
  position: fixed;
  z-index: 30;
  pointer-events: none;
}

.tile-entering {
  animation: riseIn 480ms cubic-bezier(.2, .8, .2, 1) both;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
}

#round-over {
  display: grid;
  place-items: center;
  align-items: center;
  justify-content: center;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(440px, 100%);
  padding: 28px;
  text-align: center;
}

.overlay-card h2 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--good);
}

.overlay-score {
  margin: 10px 0 16px;
  font-size: clamp(3rem, 12vw, 5rem);
  font-weight: 900;
  color: var(--accent-strong);
}

.new-high-score {
  color: var(--highlight-yellow) !important;
  text-shadow: 0 0 14px rgba(255, 230, 0, 0.65);
}

.overlay-message,
.overlay-detail {
  margin: 10px 0;
  color: var(--muted);
}

.quote-completion-message {
  margin: 10px 0;
  color: var(--highlight-yellow);
  text-shadow: 0 0 14px rgba(255, 230, 0, 0.65);
  font-weight: 900;
}

.overlay-quest {
  margin-bottom: 18px;
}

.toast {
  position: fixed;
  left: 50%;
  top: 100px;
  transform: translateX(-50%);
  z-index: 2600;
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--ink);
  border: 1px solid rgba(58, 158, 110, 0.25);
  box-shadow: var(--shadow);
  font-weight: 900;
  text-align: center;
  transition: opacity 300ms ease;
  opacity: 1;
  pointer-events: none;
}

.toast.toast-hidden {
  opacity: 0;
}

.enemy-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 16px;
  gap: 8px;
}

.enemy-sprite {
  font-size: 64px;
  line-height: 1;
  transition: transform 150ms ease;
  user-select: none;
}

.enemy-hit {
  transform: scale(0.8) rotate(-10deg);
  filter: brightness(1.5) saturate(3);
}

.enemy-hp-bar {
  width: 200px;
  height: 10px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(58, 158, 110, 0.2);
}

.enemy-hp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-strong), var(--good));
  transition: width 300ms cubic-bezier(.3, .8, .3, 1);
}

.enemy-hp-text {
  font-size: 14px;
  font-weight: 800;
  color: var(--muted);
}

.score-pop {
  animation: pulse 220ms ease;
}

.zone-hover {
  border-color: var(--good);
  background: rgba(78, 201, 138, 0.07);
}

.dumping .tile {
  animation: dumpAway 2s ease forwards;
}

.launching {
  animation: launchWord 1100ms cubic-bezier(.18, .75, .22, 1) forwards;
}

@keyframes pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

@keyframes dumpAway {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(130vh) rotate(14deg); opacity: 0; }
}

@keyframes launchWord {
  0% { transform: translateY(0) rotate(0deg) scale(1); opacity: 1; }
  55% { transform: translateY(-48vh) rotate(-5deg) scale(1.03); opacity: 1; }
  100% { transform: translateY(-130vh) rotate(-9deg) scale(1.04); opacity: 1; }
}

@keyframes riseIn {
  0% { transform: translateY(110vh) scale(0.92); opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@media (max-width: 700px) {
  :root {
    --tile-size: calc((100vw - 60px) / 7);
  }

  .game-shell {
    padding: 10px 10px 10px;
    gap: 8px;
  }

  .word-zone,
  .tray-panel {
    padding: 4px;
  }

  .word-slot,
  .tile-row {
    padding: 4px;
    gap: 4px;
    height: calc(var(--tile-size) + 10px);
    min-height: calc(var(--tile-size) + 10px);
  }

  .word-zone-head,
  .tray-head {
    margin-bottom: 4px;
  }

  /* Score card: standard flex column, right-aligned */
  .hud-card {
    padding: 8px 12px;
  }

  .hud-value {
    font-size: 1.4rem;
  }

  /* Shrink tile zone headers */
  .word-zone-label,
  .tray-label {
    font-size: 0.65rem;
  }

  /* Ensure tiles stay as rounded-rect, not circles */
  .tile {
    border-radius: 10px;
    flex: 0 0 var(--tile-size);
    min-width: var(--tile-size);
  }

  /* Keep score label from overlapping letter */
  .tile-score {
    font-size: 0.6rem;
    left: 4px;
    bottom: 3px;
  }

  .tile-letter {
    font-size: clamp(1rem, 3.5vw, 1.5rem);
    margin-bottom: 1px;
  }

  .tile-bonus {
    top: 2px;
    right: 2px;
    padding: 1px 3px;
    font-size: 0.55rem;
  }
}

/* Landing page centering on mobile */
.landing-page {
  min-height: 100svh;
  align-content: center;
}

/* Tagline and enemy title on landing */
.landing-tagline {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
  font-style: italic;
}

.landing-enemy-title {
  margin: 8px 0 0;
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--good);
  text-align: center;
}

/* Squished enemy animation (when defeated) */
.enemy-squished {
  transform: scaleY(0.18) scaleX(1.4);
  transform-origin: bottom center;
  filter: brightness(0.6) saturate(0.2);
  transition: transform 350ms cubic-bezier(.18, .75, .22, 1), filter 350ms ease;
}

/* Hit animation also initiates squish transition on defeat */
.enemy-hit {
  transform: scale(0.8) rotate(-10deg);
  filter: brightness(1.5) saturate(3);
}

/* Tile fly-to-enemy animation */
@keyframes flyToEnemy {
  0%   { transform: translate(0px, 0px) scale(1); opacity: 1; }
  60%  { opacity: 1; }
  100% { transform: translate(var(--fly-tx, 0px), var(--fly-ty, 0px)) scale(0.3); opacity: 0; }
}

.tile-flying-to-enemy {
  animation: flyToEnemy 420ms cubic-bezier(.4, 0, .6, 1) forwards;
}

.overlay-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 24px;
}

.overlay-actions #play-again,
.overlay-actions #exit-round {
  margin-top: 0;
}

/* Stats overlay: padding + scroll on mobile */
@media (max-width: 700px) {
  .overlay {
    padding: 12px;
    align-items: flex-start;
    padding-top: clamp(16px, 5vh, 40px);
    padding-bottom: clamp(16px, 5vh, 40px);
  }

  #round-over {
    align-items: center;
    justify-content: center;
    place-items: center;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .overlay-card {
    max-height: calc(100svh - clamp(32px, 10vh, 80px));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Landing panel: ensure vertically centered even on short screens */
  .landing-page {
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 16px;
  }

  .landing-panel {
    max-height: calc(100svh - 32px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Tiny screen adjustments (iPhone 11 Pro, small mobile screens) */
@media (max-width: 480px) {
  .landing-panel {
    gap: 10px;
    padding: 16px 14px;
  }

  .landing-panel h1 {
    font-size: 2.1rem;
  }
}
