/* game.css — the gameplay screen: HUD, board surface, hint panel. */

.screen--game {
  display: none;
  /* Both tracks must be able to shrink. An auto column sizes to the widest
     item's max-content — here the level title — which pushed the star display
     off the right edge on narrow screens. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  min-height: 0;
}

.screen--game.is-active {
  display: grid;
}

.hud {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
  padding: 0.6rem 0.8rem;
  background: rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(10px);
  z-index: 2;
}

.hud--top {
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.hud--bottom {
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  flex-direction: column;
  gap: 0.5rem;
  padding-bottom: calc(0.6rem + env(safe-area-inset-bottom) * 0.5);
}

.hud__title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.hud__level {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud__world {
  color: var(--text-dim);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.hud__stars {
  display: flex;
  flex: none;
  gap: 0.15rem;
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.2);
}

.hud__stars .on {
  color: #ffd76a;
  text-shadow: 0 0 12px rgba(255, 215, 106, 0.55);
}

.hud__stats {
  display: flex;
  gap: 1.4rem;
  justify-content: center;
  min-width: 0;
}

.stat {
  text-align: center;
  min-width: 48px;
}

.stat b {
  display: block;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.stat small {
  color: var(--text-dim);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.hud__tools {
  display: flex;
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
}

.tool {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--tap);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font: 600 0.72rem var(--font);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  cursor: pointer;
  position: relative;
  transition: background 0.18s ease, transform 0.12s ease;
}

.tool span {
  font-size: 1.05rem;
  line-height: 1;
}

.tool:hover:not(:disabled) {
  background: rgba(var(--accent-rgb), 0.16);
}

.tool:active:not(:disabled) {
  transform: scale(0.96);
}

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

.tool--hint {
  border-color: rgba(var(--accent-rgb), 0.4);
}

.tool .badge {
  position: absolute;
  top: 4px;
  right: 8px;
  font-style: normal;
  font-size: 0.62rem;
  background: var(--accent);
  color: #04131a;
  border-radius: 999px;
  padding: 0 5px;
  font-weight: 700;
  min-width: 16px;
  text-align: center;
}

/* ---- board ------------------------------------------------------------ */

.board-wrap {
  position: relative;
  min-height: 0;
  display: grid;
}

#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: pointer;
}

.board__intro {
  position: absolute;
  left: 50%;
  bottom: 1.1rem;
  transform: translateX(-50%);
  width: min(430px, 90%);
  background: rgba(8, 14, 28, 0.92);
  border: 1px solid rgba(var(--accent-rgb), 0.3);
  border-radius: 14px;
  padding: 0.75rem 1rem;
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--text);
  text-align: center;
  box-shadow: var(--shadow);
  animation: intro-in 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes intro-in {
  from {
    opacity: 0;
    transform: translate(-50%, 14px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.board__solved {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(34, 197, 94, 0.16);
  border: 1px solid rgba(34, 197, 94, 0.5);
  color: #8ef0b4;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  animation: toast-in 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---- hint panel ------------------------------------------------------- */

.hint-panel {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 130px);
  transform: translateX(-50%);
  width: min(420px, 92vw);
  background: rgba(8, 14, 28, 0.96);
  border: 1px solid rgba(var(--accent-rgb), 0.4);
  border-radius: 16px;
  padding: 0.9rem 1rem;
  z-index: 5;
  box-shadow: var(--shadow);
  animation: intro-in 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.hint-panel[hidden] {
  display: none;
}

.hint-panel p {
  margin: 0 0 0.7rem;
  font-size: 0.88rem;
  line-height: 1.5;
}

.hint-panel__actions {
  display: flex;
  gap: 0.5rem;
}

/* ---- landscape / desktop --------------------------------------------- */

@media (min-width: 700px) and (orientation: landscape) {
  .hud--bottom {
    flex-direction: row;
    justify-content: space-between;
    padding: 0.7rem 1.4rem;
  }

  .hud__tools {
    width: auto;
    max-width: 460px;
  }

  .tool {
    min-width: 92px;
    flex-direction: row;
    gap: 0.4rem;
  }

  .hud__stats {
    gap: 2rem;
  }
}

/* Larger hit areas for players who ask for them. */
html[data-large-targets='true'] {
  --tap: 58px;
}

html[data-large-targets='true'] .tool {
  font-size: 0.8rem;
}


/* ---- short frames -----------------------------------------------------
   An embedded player can be much shorter than a phone screen. Below this
   height the HUD collapses to a single compact row so the board keeps the
   space it needs to stay readable. */

@media (max-height: 560px) {
  .hud {
    padding: 0.35rem 0.6rem;
  }

  .hud--bottom {
    padding-bottom: calc(0.35rem + env(safe-area-inset-bottom) * 0.5);
  }

  /* Single row only where it actually fits; below this the stacked HUD stays. */
  @media (min-width: 520px) {
    .hud--bottom {
      flex-direction: row;
      justify-content: space-between;
      gap: 0.6rem;
    }

    .hud__tools {
      width: auto;
      flex: 1;
      max-width: 380px;
    }
  }

  .hud__stats {
    gap: 0.9rem;
  }

  .stat b {
    font-size: 0.95rem;
  }

  .stat small {
    font-size: 0.52rem;
  }

  .tool {
    min-height: 40px;
    font-size: 0.64rem;
    flex-direction: row;
    gap: 0.3rem;
  }

  .tool span {
    font-size: 0.9rem;
  }

  .hud__level {
    font-size: 0.85rem;
  }

  .hud__world {
    font-size: 0.6rem;
  }

  .icon-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    font-size: 1rem;
  }

  .board__intro {
    bottom: 0.5rem;
    padding: 0.5rem 0.8rem;
    font-size: 0.76rem;
  }

  .hint-panel {
    bottom: calc(env(safe-area-inset-bottom) + 64px);
    padding: 0.7rem 0.8rem;
  }
}
