/* peril.css — loaded only on /peril */

/* ── Page Layout ─────────────────────────────────────────────────────────── */

.peril-app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  padding: 1.5rem 1rem 3rem;
  min-height: 80vh;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

.peril-header {
  text-align: center;
}

.peril-title {
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ff6600 0%, #ffd700 50%, #ff2200 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0 0 0.3rem;
}

.peril-score-line {
  margin: 0;
  font-size: 1.1rem;
  color: #ffaa44;
  letter-spacing: 0.04em;
}

#peril-score {
  font-weight: 700;
  color: #ffd700;
}

.peril-best-line {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
  color: #cc8833;
  letter-spacing: 0.04em;
}

#peril-best {
  font-weight: 700;
  color: #ffaa44;
}

/* ── Board Wrapper ───────────────────────────────────────────────────────── */

.peril-board-wrapper {
  position: relative;
}

/* ── Board Grid ──────────────────────────────────────────────────────────── */

.peril-board {
  display: grid;
  grid-template-columns: repeat(5, 90px);
  grid-template-rows: repeat(6, 120px);
  gap: 8px;
  padding: 8px;
  border-radius: 10px;
  border: 2px solid #6a1200;
  box-shadow: 0 0 32px rgba(255, 60, 0, 0.25);
  background: url('/static/img/peril-bg.jpg') center / cover no-repeat;
}

.peril-board--win {
  animation: peril-glow 0.9s ease-in-out infinite alternate;
}

@keyframes peril-glow {
  from { box-shadow: 0 0 20px rgba(255,  80, 0, 0.35); }
  to   { box-shadow: 0 0 70px rgba(255, 200, 0, 0.75); }
}

/* ── Cards ───────────────────────────────────────────────────────────────── */

.card {
  width: 90px;
  height: 120px;
  perspective: 700px;
  cursor: pointer;
  outline: none;
}

.card:focus-visible .card-inner {
  outline: 2px solid #ffd700;
  outline-offset: 3px;
  border-radius: 6px;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.45s ease;
}

.card.revealed .card-inner {
  transform: rotateY(180deg);
}

.card.matched {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease 0.1s;
}

/* ── Card Faces ──────────────────────────────────────────────────────────── */

.card-back,
.card-front {
  position: absolute;
  inset: 0;
  border-radius: 7px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Card Back ───────────────────────────────────────────────────────────── */

.card-back {
  border: 1.5px solid #6a1a00;
  box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.4);
  background-image: url('/static/img/peril-mosaic.jpg');
  background-size: 470px 760px; /* total board width × height */
  background-repeat: no-repeat;
  /* --col and --row are set per-card in board.ts; calc() positions the mosaic slice */
  /* desktop: card 90px, gap 8px, padding 8px → step = 98px */
  background-position:
    calc(var(--col) * -98px - 8px)
    calc(var(--row) * -128px - 8px);
}

/* ── Card Front ──────────────────────────────────────────────────────────── */

.card-front {
  background: linear-gradient(160deg, #450700 0%, #7a1400 45%, #450700 100%);
  border: 1.5px solid #cc3300;
  transform: rotateY(180deg);
  font-size: 2.5rem;
  font-weight: 900;
  color: #ffd700;
  letter-spacing: -0.03em;
  text-shadow:
    0 0 10px rgba(255, 200, 0, 0.55),
    0 2px 4px rgba(0, 0, 0, 0.8);
}

/* ── Win Overlay ─────────────────────────────────────────────────────────── */

.peril-win {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 1, 0, 0.9);
  border-radius: 10px;
  z-index: 10;
}

/* Must come after .peril-win so display:none overrides display:flex */
.peril-hidden {
  display: none;
}

.peril-win-inner {
  text-align: center;
  padding: 2rem 2.5rem;
}

.peril-win-flames {
  position: relative;
  height: 44px;
  margin-bottom: 0.6rem;
}

.flame {
  position: absolute;
  bottom: 0;
  width: 13px;
  border-radius: 50% 50% 22% 22%;
  animation: flame-rise 1.1s ease-in-out infinite;
}

.flame:nth-child(1) { left:  8%; height: 36px; background: #cc2000; animation-delay: 0.00s; }
.flame:nth-child(2) { left: 28%; height: 28px; background: #ff6600; animation-delay: 0.18s; }
.flame:nth-child(3) { left: 48%; height: 42px; background: #ffd700; animation-delay: 0.07s; }
.flame:nth-child(4) { left: 68%; height: 26px; background: #ff6600; animation-delay: 0.28s; }
.flame:nth-child(5) { left: 86%; height: 34px; background: #cc2000; animation-delay: 0.14s; }

@keyframes flame-rise {
  0%, 100% { transform: scaleY(1)   scaleX(1);   opacity: 1.0; }
  50%       { transform: scaleY(1.3) scaleX(0.75); opacity: 0.75; }
}

.peril-win-heading {
  font-size: 1.9rem;
  font-weight: 800;
  background: linear-gradient(135deg, #ff6600, #ffd700);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0.4rem 0 0.5rem;
}

.peril-win-message {
  color: #ffaa44;
  font-size: 1rem;
  line-height: 1.6;
  margin: 0 0 1.5rem;
}

.peril-win-message strong {
  color: #ffd700;
  font-size: 1.25rem;
}

.peril-win-message em {
  font-style: italic;
  color: #ff8844;
}

.peril-win-best {
  color: #ffaa44;
  font-size: 0.95rem;
  margin: -0.8rem 0 1.2rem;
}

.peril-win-best--new {
  color: #ffd700;
  font-weight: 700;
  font-size: 1.05rem;
}

.peril-replay-btn {
  background: linear-gradient(135deg, #b81e00, #ff5500);
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 0.75rem 2.2rem;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.03em;
  box-shadow: 0 0 18px rgba(255, 70, 0, 0.45);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.peril-replay-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 28px rgba(255, 100, 0, 0.7);
}

.peril-replay-btn:active {
  transform: translateY(0);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 540px) {
  .peril-board {
    grid-template-columns: repeat(5, 58px);
    grid-template-rows: repeat(6, 78px);
    gap: 5px;
    padding: 5px;
  }

  .card {
    width: 58px;
    height: 78px;
  }

  .card-front {
    font-size: 1.65rem;
  }

  .card-back {
    background-size: 320px 503px; /* mobile board width × height */
    /* mobile: card 58px, gap 5px, padding 5px → step = 63px / 83px */
    background-position:
      calc(var(--col) * -63px - 5px)
      calc(var(--row) * -83px - 5px);
  }
}
