/* ============================================================================
   Pikahans Game Runtime — fixed viewport shell, HUD, board, overlays, effects
   Loaded AFTER pikahans.redesign.css
   ========================================================================== */

html.pk-playing,
html.pk-playing body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body.pk-playing {
  overflow: hidden;
}

/* --- Game shell (fixed viewport grid) ------------------------------------ */
body.pk-themed .game-container.pk-game-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 640px;
  max-width: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: radial-gradient(circle at top, #18264f 0%, #080b1a 60%, #03050d 100%);
  z-index: 2;
}

/* --- HUD ----------------------------------------------------------------- */
body.pk-themed .pk-game-hud {
  width: min(1440px, calc(100vw - 48px));
  height: auto;
  min-height: 88px;
  margin: 24px auto 12px;
  padding: 0;
  position: relative;
  z-index: 30;
}

body.pk-themed #collapsed-bar.pk-hud-grid {
  display: grid !important;
  grid-template-columns: auto minmax(240px, 1fr) auto;
  align-items: center;
  gap: clamp(12px, 2vw, 24px);
  width: 100%;
  min-height: 88px;
  margin: 0;
  padding: 0 24px;
  position: static;
  top: auto;
  border-radius: 28px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .14);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .28);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  flex-wrap: nowrap;
  justify-content: unset;
}

body.pk-themed .pk-hud-left,
body.pk-themed .pk-hud-center,
body.pk-themed .pk-hud-right {
  display: flex;
  align-items: center;
  min-width: 0;
  position: relative;
  z-index: 2;
}

body.pk-themed .pk-hud-left {
  gap: clamp(10px, 1.4vw, 16px);
}

body.pk-themed .pk-hud-center {
  flex: 1 1 auto;
}

body.pk-themed .pk-hud-right {
  justify-content: flex-end;
  gap: 12px;
  flex-shrink: 0;
}

body.pk-themed .pk-hud-right .help-toolbar {
  position: static;
  top: auto;
  right: auto;
  display: flex;
  gap: 10px;
}

body.pk-themed .pk-hud-right .toolbar-btn {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
}

/* Timer & score pills in HUD */
body.pk-themed .pk-hud-right .timer-wrapper .timer,
body.pk-themed .pk-score-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-weight: 800;
  font-size: 15px;
  white-space: nowrap;
  flex: 0 0 auto;
}

body.pk-themed .pk-time-pill.is-warning {
  color: #f7b733 !important;
  box-shadow: 0 0 24px rgba(247, 183, 51, .25);
}

body.pk-themed .pk-time-pill.is-danger {
  color: #ff4d5e !important;
  animation: pkTimerPulse .8s infinite;
}

body.pk-themed .pk-score-pill.is-bumping {
  animation: pkScoreBump .36s ease-out;
}

@keyframes pkTimerPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

@keyframes pkScoreBump {
  0% { transform: scale(1); }
  45% { transform: scale(1.12); box-shadow: 0 0 28px rgba(247, 183, 51, .36); }
  100% { transform: scale(1); }
}

/* Pause button — fixed size, never stretch */
body.pk-themed #pause-btn,
body.pk-themed .pk-pause-btn {
  flex: 0 0 auto !important;
  width: auto !important;
  min-width: 128px;
  height: 48px !important;
  max-height: 48px !important;
  padding: 0 18px !important;
  border-radius: 999px !important;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  position: static !important;
  top: auto !important;
  right: auto !important;
  bottom: auto !important;
  left: auto !important;
  writing-mode: horizontal-tb !important;
  align-self: center !important;
  font-weight: 700;
  font-size: 14px;
  color: var(--pk-text);
  background: var(--pk-surface-2);
  border: 1px solid var(--pk-border-strong);
  cursor: pointer;
  backdrop-filter: blur(10px);
  box-shadow: var(--pk-shadow-soft);
  transition: transform var(--pk-fast), background var(--pk-fast);
}

body.pk-themed #pause-btn:hover,
body.pk-themed .pk-pause-btn:hover {
  background: var(--pk-surface-3);
  transform: translateY(-2px);
}

body.pk-themed #pk-hud-pause-slot {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}

/* --- Main / board -------------------------------------------------------- */
body.pk-themed .pk-game-main {
  min-height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px 36px 8px;
  overflow: hidden;
}

body.pk-themed .pk-board-wrap {
  width: min(1380px, 100%);
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

body.pk-themed #game-board.pk-board-host {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 0;
  overflow: hidden;
}

body.pk-themed .char-grid.pk-board {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(var(--pk-board-cols, 12), minmax(0, 1fr));
  gap: clamp(8px, .9vw, 14px);
  max-width: 100%;
  margin: 0 auto;
}

body.pk-themed .char-cell {
  width: 100%;
  aspect-ratio: 1 / 1;
  min-width: 0;
  max-height: 96px;
  border-radius: clamp(12px, 1.1vw, 18px);
  font-size: clamp(30px, 3.1vw, 52px);
}

/* Tile effects */
body.pk-themed .char-cell.match {
  animation: pkTileCorrect .42s ease-out forwards;
}

@keyframes pkTileCorrect {
  0% { transform: scale(1); }
  45% {
    transform: scale(1.12);
    box-shadow: 0 0 34px rgba(247, 183, 51, .65);
  }
  100% {
    transform: scale(.2);
    opacity: 0;
  }
}

body.pk-themed .char-cell.wrong {
  animation: pkTileWrong .22s ease;
}

@keyframes pkTileWrong {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

body.pk-themed .char-cell.selected {
  border-color: rgba(247, 183, 51, .95);
  box-shadow:
    0 0 0 3px rgba(247, 183, 51, .16),
    0 0 28px rgba(247, 183, 51, .36);
  transform: translateY(-3px) scale(1.03);
}

/* Selection dock */
body.pk-themed #pk-selection-bar {
  position: relative;
  z-index: 20;
}

/* --- Overlays ------------------------------------------------------------ */
.pk-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at center, rgba(47, 140, 255, .12), transparent 40%),
    rgba(3, 5, 13, .58);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.pk-overlay.hidden {
  display: none !important;
}

/* Question challenge overlay */
body.pk-themed #question-popup.pk-question-overlay {
  z-index: 110;
}

body.pk-themed .pk-question-card {
  width: min(560px, calc(100vw - 32px));
  padding: 28px 24px 24px;
  border-radius: 24px;
  background:
    linear-gradient(145deg, rgba(24, 38, 79, .96), rgba(15, 22, 48, .96)),
    radial-gradient(circle at top right, rgba(109, 93, 252, .22), transparent 45%);
  border: 1px solid rgba(255, 255, 255, .16);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .45);
  text-align: center;
  position: relative;
}

body.pk-themed .pk-question-card.is-warning {
  box-shadow:
    0 0 0 1px rgba(247, 183, 51, .4),
    0 0 40px rgba(247, 183, 51, .22),
    0 24px 80px rgba(0, 0, 0, .45);
}

body.pk-themed .pk-question-card.is-danger {
  animation: pkDangerPulse .75s infinite;
}

@keyframes pkDangerPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.015); }
}

body.pk-themed .pk-question-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

body.pk-themed .pk-question-timer {
  width: 76px;
  height: 76px;
  margin: 0 auto 12px;
  position: relative;
  display: grid;
  place-items: center;
}

body.pk-themed .pk-timer-ring {
  width: 76px;
  height: 76px;
  transform: rotate(-90deg);
}

body.pk-themed .pk-timer-track {
  fill: none;
  stroke: rgba(255, 255, 255, .12);
  stroke-width: 5;
}

body.pk-themed .pk-timer-progress {
  fill: none;
  stroke: #3b82f6;
  stroke-width: 5;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s linear, stroke .3s ease;
}

body.pk-themed .pk-question-card.is-warning .pk-timer-progress {
  stroke: #f7b733;
}

body.pk-themed .pk-question-card.is-danger .pk-timer-progress {
  stroke: #ff4d5e;
}

body.pk-themed .pk-timer-text {
  position: absolute;
  font-size: 24px;
  font-weight: 900;
  color: #f8fafc;
  text-shadow: 0 0 16px rgba(255, 255, 255, .35);
}

body.pk-themed .pk-question-word {
  font-size: clamp(34px, 5vw, 52px);
  font-weight: 900;
  color: var(--pk-gold-2);
  margin-bottom: 8px;
}

body.pk-themed .pk-question-prompt {
  font-size: 16px;
  color: var(--pk-muted);
  margin-bottom: 18px;
}

body.pk-themed .pk-answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

body.pk-themed .pk-answer-grid button,
body.pk-themed #options-container button {
  padding: 14px 12px;
  border-radius: 14px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--pk-border-strong);
  background: var(--pk-surface-2);
  color: var(--pk-text);
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}

body.pk-themed .pk-answer-grid button:hover,
body.pk-themed #options-container button:hover {
  transform: translateY(-2px);
  background: var(--pk-surface-3);
}

body.pk-themed .pk-answer-btn.is-correct,
body.pk-themed #options-container button.correct {
  border-color: rgba(52, 211, 153, .9) !important;
  background: linear-gradient(180deg, rgba(52, 211, 153, .28), rgba(52, 211, 153, .12)) !important;
  box-shadow: 0 0 26px rgba(52, 211, 153, .32);
}

body.pk-themed .pk-answer-btn.is-wrong,
body.pk-themed #options-container button.wrong {
  border-color: rgba(255, 77, 94, .9) !important;
  background: linear-gradient(180deg, rgba(255, 77, 94, .26), rgba(255, 77, 94, .1)) !important;
  animation: pkWrongShake .22s ease;
}

@keyframes pkWrongShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

body.pk-themed .pk-question-feedback {
  margin-top: 14px;
  font-weight: 700;
  min-height: 0;
}

body.pk-themed .pk-question-card.is-timing .pk-question-feedback {
  display: none !important;
  visibility: hidden;
  height: 0 !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden;
  pointer-events: none;
}

body.pk-themed #user-info {
  display: none !important;
}

/* Pause overlay */
body.pk-themed #pause-overlay.pk-pause-overlay {
  display: none;
  z-index: 120;
}

body.pk-themed #pause-overlay.pk-pause-overlay[style*="flex"] {
  display: flex !important;
}

body.pk-themed .pk-pause-card {
  width: min(620px, calc(100vw - 32px));
  padding: 34px;
  border-radius: 28px;
  background:
    linear-gradient(145deg, rgba(24, 38, 79, .94), rgba(15, 22, 48, .94)),
    radial-gradient(circle at top right, rgba(109, 93, 252, .28), transparent 45%);
  border: 1px solid rgba(255, 255, 255, .16);
  box-shadow:
    0 24px 90px rgba(0, 0, 0, .52),
    0 0 40px rgba(109, 93, 252, .18);
  text-align: center;
  color: #fff;
}

body.pk-themed .pk-pause-orb {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 900;
  background: rgba(109, 93, 252, .25);
  border: 1px solid rgba(255, 255, 255, .2);
  box-shadow: 0 0 30px rgba(109, 93, 252, .35);
}

body.pk-themed .pk-pause-card h2 {
  margin: 0 0 8px;
  font-size: 28px;
  font-weight: 900;
}

body.pk-themed .pk-pause-card > p {
  margin: 0 0 20px;
  color: rgba(255, 255, 255, .78);
  font-size: 15px;
}

body.pk-themed .pk-pause-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

body.pk-themed .pk-pause-stats > div {
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .1);
}

body.pk-themed .pk-pause-stats span {
  display: block;
  font-size: 12px;
  color: rgba(255, 255, 255, .55);
  margin-bottom: 4px;
}

body.pk-themed .pk-pause-stats strong {
  font-size: 20px;
  font-weight: 900;
}

body.pk-themed .pk-pause-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

body.pk-themed .pk-pause-actions .game-btn {
  min-width: 140px;
  padding: 12px 18px;
  border-radius: 14px;
  font-weight: 700;
  cursor: pointer;
  border: none;
}

body.pk-themed .pk-pause-actions .primary-btn {
  background: linear-gradient(135deg, #3c8dff, #2457d6);
  color: #fff;
}

body.pk-themed .pk-pause-actions .secondary-btn {
  background: rgba(255, 255, 255, .1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .2);
}

/* Floating score */
.pk-floating-score {
  position: fixed;
  z-index: 80;
  pointer-events: none;
  font-size: 28px;
  font-weight: 1000;
  color: #f7b733;
  text-shadow:
    0 0 10px rgba(247, 183, 51, .8),
    0 0 28px rgba(247, 183, 51, .45);
  animation: pkScoreFloat .9s ease-out forwards;
}

@keyframes pkScoreFloat {
  0% {
    opacity: 0;
    transform: translate(-50%, 8px) scale(.85);
  }
  18% {
    opacity: 1;
    transform: translate(-50%, -4px) scale(1.15);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -58px) scale(1);
  }
}

.pk-combo-badge {
  position: fixed;
  z-index: 81;
  pointer-events: none;
  font-size: 22px;
  font-weight: 900;
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(247, 183, 51, .9), rgba(255, 140, 0, .85));
  box-shadow: 0 0 24px rgba(247, 183, 51, .5);
  animation: pkComboFade 1s ease-out forwards;
}

@keyframes pkComboFade {
  0% { opacity: 0; transform: translate(-50%, 12px) scale(.8); }
  20% { opacity: 1; transform: translate(-50%, 0) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -40px) scale(1); }
}

/* --- Responsive ---------------------------------------------------------- */
@media (max-width: 1024px) {
  body.pk-themed #collapsed-bar.pk-hud-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    padding: 16px;
    gap: 12px;
  }

  body.pk-themed .pk-hud-left,
  body.pk-themed .pk-hud-center,
  body.pk-themed .pk-hud-right {
    width: 100%;
    justify-content: center;
  }

  body.pk-themed .pk-hud-right {
    flex-wrap: wrap;
  }
}

@media (max-width: 720px) and (orientation: portrait) {
  body.pk-playing .pk-game-shell {
    display: none;
  }

  body.pk-playing #pk-rotate-gate {
    display: flex;
  }
}
