/* Head to Head — layout and screen styles.
   Relies on game.css being loaded first for all CSS custom properties. */

/* ── Screen shell ─────────────────────────────────────────────── */
.h2h-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-color);
  color: var(--text-color);
  overflow: hidden;
}

/* ── Shared topbar ─────────────────────────────────────────────── */
.h2h-topbar {
  position: relative;          /* anchor for absolute-positioned title */
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 44px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--header-border);
  padding: 0 4px;
  margin-bottom: 0;            /* override game.css header margin */
}

/* Title: flex-1 + text-align:center so it fills the middle column and stays
   visually centered regardless of the width of the flanking buttons */
.h2h-title-sm {
  flex: 1;
  width: auto;
  display: block;
  text-align: center;
  font-size: 10px;
  height: auto;
  padding: 0;
  pointer-events: none;
  white-space: nowrap;
}

/* ── Game screen topbar (fresh — no .game-title dependency) ────── */
.h2h-game-topbar {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 44px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--header-border);
  padding: 0 4px;
  margin-bottom: 0;            /* override game.css header margin */
}

.h2h-game-title {
  flex: 1;
  text-align: center;
  font-family: 'Press Start 2P', cursive;
  font-size: 14px;
  color: #f5c518;
  white-space: nowrap;
  pointer-events: none;
}

.h2h-topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Gate screens ──────────────────────────────────────────────── */
.h2h-gate-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px 24px;
  width: 90%;
  max-width: 380px;
  background: var(--modal-bg);
  border: 1px solid var(--modal-border);
  border-radius: 12px;
}

.h2h-gate-msg {
  font-family: 'Press Start 2P', cursive;
  text-align: center;
  font-size: 8px;
  line-height: 1.8;
}

.h2h-gate-submsg {
  font-family: 'Press Start 2P', cursive;
  text-align: center;
  font-size: 7px;
  line-height: 1.8;
  opacity: 0.7;
  margin-top: -8px;
}

/* ── Shared button styles ──────────────────────────────────────── */
.h2h-btn-primary {
  width: 100%;
  padding: 13px;
  background: #f5c518;
  color: #3d1f00;
  border: none;
  border-radius: 8px;
  font-family: 'Press Start 2P', cursive;
  font-size: 10px;
  cursor: pointer;
  letter-spacing: 0.02em;
  line-height: 1.6;
  touch-action: manipulation;
}
.h2h-btn-primary:hover { opacity: 0.88; }
.h2h-btn-primary:active { opacity: 0.75; }

.h2h-btn-ghost {
  width: 100%;
  padding: 11px;
  background: transparent;
  color: var(--text-color);
  border: 1px solid var(--modal-border);
  border-radius: 8px;
  font-family: 'Press Start 2P', cursive;
  font-size: 12px;
  line-height: 1.6;
  cursor: pointer;
  touch-action: manipulation;
}
.h2h-btn-ghost:hover { background: var(--modal-bg); }

/* ── Online presence indicator ─────────────────────────────────── */
.h2h-online-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1.0rem;
  opacity: 0.7;
  flex-shrink: 0;
}

.h2h-online-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e33;
  flex-shrink: 0;
  box-shadow: 0 0 4px #e33;
}

/* ── Lobby ─────────────────────────────────────────────────────── */
.h2h-lobby-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 500px;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Coin + online indicator on one row */
.h2h-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 90%;
  max-width: 420px;
  padding: 8px 0 2px;
  flex-shrink: 0;
}

.h2h-coin-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Press Start 2P', cursive;
  font-size: 16px;
  opacity: 0.85;
}

.h2h-coin-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.h2h-lobby-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px 16px 28px;
  width: 90%;
  max-width: 420px;
  background: var(--modal-bg);
  border: 1px solid var(--modal-border);
  border-radius: 12px;
  margin: 8px 0 24px;
}

.h2h-card-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.h2h-card-sub {
  font-family: 'Press Start 2P', cursive;
  font-size: 9px;
  opacity: 0.75;
  margin-bottom: 4px;
  line-height: 1.8;
}

.h2h-setting-label {
  font-family: 'Press Start 2P', cursive;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #f5c518;
  margin-top: 6px;
  line-height: 1.4;
}

.h2h-pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.h2h-pill {
  padding: 7px 12px;
  border-radius: 20px;
  border: 1px solid var(--modal-border);
  background: transparent;
  color: var(--text-color);
  font-family: 'Press Start 2P', cursive;
  font-size: 9px;
  line-height: 1.4;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.h2h-pill-active {
  background: #f5c518;
  border-color: #f5c518;
  color: #3d1f00;
}

.h2h-enter-btn {
  margin-top: 12px;
}

/* Coin cost amount — red highlight inside descriptions and CTA buttons */
.h2h-coin-cost {
  color: #e05252;
}

/* ── Countdown ─────────────────────────────────────────────────── */
.h2h-countdown-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 100%;
  max-width: 500px;
  height: 100dvh;
  position: relative;   /* anchor for DUEL! glow pseudo-element */
}

.h2h-countdown-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.h2h-countdown-number {
  font-family: 'Press Start 2P', cursive;
  font-size: clamp(60px, 16vw, 100px);
  color: #e05252;
  line-height: 1;
  animation: countdown-bounce-in 0.45s cubic-bezier(0.22, 1.6, 0.36, 1) both;
}

@keyframes countdown-bounce-in {
  0%   { transform: scale(0.15); opacity: 0; }
  55%  { transform: scale(1.25); opacity: 1; }
  75%  { transform: scale(0.92); }
  90%  { transform: scale(1.07); }
  100% { transform: scale(1); opacity: 1; }
}

.h2h-countdown-label {
  font-size: 1rem;
  opacity: 0.7;
  letter-spacing: 0.05em;
}


/* ── Game screen ───────────────────────────────────────────────── */
.h2h-game-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 600px;
  height: 100dvh;
  overflow: hidden;
}

.h2h-game-topbar {
  padding: 0 8px;
}

/* Timer text row: standalone below topbar in timed games */
.h2h-timer-row {
  width: 100%;
  text-align: center;
  padding: 2px 0;
  flex-shrink: 0;
}

/* Timer bar */
.h2h-timer-bar {
  width: 100%;
  height: 4px;
  background: var(--tile-border-empty);
  flex-shrink: 0;
}

.h2h-timer-bar-fill {
  height: 100%;
  background: var(--color-present);
  width: 100%;
  transition: width 1s linear;
}

.h2h-timer-bar-fill.urgent {
  background: #e55;
}

/* Timer display */
.h2h-timer {
  font-size: 0.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  min-width: 48px;
  text-align: center;
}

.h2h-timer.urgent {
  color: #e55;
}

/* Definition */
.h2h-definition {
  font-size: 0.82rem;
  text-align: center;
  padding: 4px 12px;
  line-height: 1.45;
  min-height: 2.4em;
  flex-shrink: 0;
  max-width: 600px;
  width: 100%;
}

/* Dual grid container */
.h2h-grids {
  display: flex;
  flex-direction: row;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 700px;
  gap: 0;
  align-items: stretch;
  overflow: hidden;   /* prevents tile overflow from pushing keyboard off screen */
}

.h2h-player-panel,
.h2h-opponent-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 4px 4px 0;
  overflow: hidden;
}

.h2h-divider {
  width: 1px;
  background: var(--header-border);
  flex-shrink: 0;
  margin: 4px 0;
}

.h2h-panel-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  opacity: 0.55;
  margin-bottom: 3px;
  text-transform: uppercase;
}

/* Grid: uses the same .tile rules from game.css.
   grid-template-columns is set by JS to repeat(N, tileSize px) so columns
   match tiles exactly — no inter-column gaps from oversized 1fr columns. */
.h2h-grid {
  display: grid;
  gap: var(--grid-gap);
  -webkit-perspective: 1000px;
          perspective: 1000px;
  /* width: fit-content lets the grid size to its tiles and centre in the panel */
  width: fit-content;
  margin: 0 auto;
}

/* Opponent grid: tiles slightly smaller, no interaction */
.h2h-grid-opponent {
  pointer-events: none;
  opacity: 0.9;
}

/* Mobile: stack vertically — opponent compact at top */
@media (max-width: 767px) {
  .h2h-definition {
    font-size: 0.72rem;
    padding: 2px 8px 0;
    min-height: 0;
    /* Cap to 2 lines — prevents long definitions from eating tile space */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* Tighten the gap between the definition and the YOU label */
  .h2h-panel-label {
    margin-bottom: 1px;
  }

  .h2h-grids {
    flex-direction: column;
    gap: 2px;
  }

  .h2h-divider {
    width: 100%;
    height: 1px;
    margin: 0 4px;
  }

  .h2h-opponent-panel {
    flex: 0 0 auto;
    max-height: 15dvh;
    overflow: hidden;
  }

  .h2h-player-panel {
    flex: 1;
    min-height: 0;     /* allow flex child to shrink below content size */
    overflow: hidden;  /* clip grid if JS sizing still overshoots */
  }
}

/* Very small screens (≤ 480px, e.g. iPhone SE): same fixed cap. */
@media (max-width: 480px) {
  .h2h-opponent-panel {
    max-height: 15dvh;
  }
}

/* Spectate: swap prominence — opponent expands, player collapses */
.h2h-grids.spectating .h2h-opponent-panel {
  flex: 1;
  max-height: none;
}

.h2h-grids.spectating .h2h-player-panel {
  flex: 0 0 auto;
  max-height: 30dvh;
  overflow: hidden;
}

/* Keyboard: fixed at bottom of game wrap, never pushed off screen */
.h2h-keyboard {
  flex-shrink: 0;
  width: 100%;
}

/* ── Result screen ─────────────────────────────────────────────── */
.h2h-result-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 32px 24px;
  width: 90%;
  max-width: 400px;
}

.h2h-result-icon {
  font-size: 3rem;
  line-height: 1;
}

.h2h-result-title {
  font-family: 'Press Start 2P', cursive;
  font-size: clamp(13px, 4vw, 18px);
  color: var(--color-correct);
  text-align: center;
  line-height: 1.4;
}

.h2h-result-title.loss {
  color: var(--color-absent);
}

.h2h-result-title.timeout {
  color: var(--color-present);
}

.h2h-result-body {
  text-align: center;
  font-size: 0.92rem;
  line-height: 1.55;
  opacity: 0.85;
}

.h2h-result-body .word-reveal {
  font-weight: bold;
  font-size: 1.1em;
  color: var(--color-correct);
}

.h2h-result-coins {
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
}

.h2h-result-coins.positive { color: var(--color-correct); }
.h2h-result-coins.neutral  { color: var(--color-present); }
.h2h-result-coins.negative { color: var(--color-absent); }

/* Phonetic line inside result body */
.h2h-result-phonetic {
  font-size: 0.88rem;
  opacity: 0.65;
  margin-top: 2px;
}

/* Audio playback button inside result body */
.h2h-audio-btn {
  display: block;
  background: var(--button-bg);
  color: var(--button-text);
  border: none;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  margin: 6px auto 0;
  touch-action: manipulation;
}
.h2h-audio-btn:hover { opacity: 0.8; }

/* ── Board review bar ──────────────────────────────────────────── */
.h2h-review-bar {
  width: 100%;
  padding: 6px 12px;
  background: var(--color-present);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.h2h-review-close-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Spectating banner */
.h2h-spectate-banner {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-present);
  text-align: center;
  padding: 2px 0;
  flex-shrink: 0;
}

/* Opponent finish overlay on their panel */
.h2h-opponent-finish {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-correct);
  margin-top: 2px;
}

/* ── Lobby tabs ────────────────────────────────────────────────── */
.h2h-tab-bar {
  display: flex;
  width: 90%;
  max-width: 420px;
  gap: 0;
  margin: 4px 0 0;
  flex-shrink: 0;
}

.h2h-tab {
  flex: 1;
  height: 65px;
  background: no-repeat center / contain;
  border: none;
  border-radius: 10px;
  font-family: 'Press Start 2P', cursive;
  font-size: 10px;
  line-height: 1.4;
  color: #f5c518;
  text-shadow: 0 1px 4px rgba(0,0,0,0.85), 0 0 8px rgba(0,0,0,0.6);
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.15s;
  opacity: 0.6;
  padding: 0;
}

.h2h-tab:first-child {
  flex: 1.1;
}

.h2h-tab-active {
  opacity: 1;
}

/* ── Image-based CTA buttons (Enter Duel / Create Invite / Find Opponent) ── */
.h2h-img-btn {
  width: 100%;
  height: 90px;
  background: #1a1208 no-repeat center / contain;
  border: none;
  border-radius: 4px;
  font-family: 'Press Start 2P', cursive;
  font-size: 12px;
  line-height: 1.4;
  color: #f5c518;
  text-shadow: 0 1px 4px rgba(0,0,0,0.85), 0 0 8px rgba(0,0,0,0.6);
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.15s;
  padding: 0;
}
.h2h-img-btn:hover { opacity: 0.88; }
.h2h-img-btn:active { opacity: 0.75; }

/* ── vs Player action layout ───────────────────────────────────── */
.h2h-find-btn {
  margin-top: 8px;
}

/* ── Invite / Searching waiting sections ───────────────────────── */
.h2h-live-waiting {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 8px;
  width: 100%;
}

.h2h-waiting-label {
  font-family: 'Press Start 2P', cursive;
  text-align: center;
  font-size: 8px;
  line-height: 1.8;
  opacity: 0.8;
  animation: h2h-pulse 1.6s ease-in-out infinite;
}

@keyframes h2h-pulse {
  0%, 100% { opacity: 0.5; }
  50%       { opacity: 1;   }
}

.h2h-invite-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--tile-bg-empty);
  border: 1px solid var(--modal-border);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}

.h2h-invite-url {
  flex: 1;
  font-size: 0.75rem;
  word-break: break-all;
  opacity: 0.75;
  min-width: 0;
}

.h2h-copy-btn {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid #f5c518;
  background: transparent;
  color: #f5c518;
  font-family: 'Press Start 2P', cursive;
  font-size: 7px;
  line-height: 1.6;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, color 0.15s;
}

.h2h-copy-btn:hover,
.h2h-copy-btn:active {
  background: #f5c518;
  color: #3d1f00;
}


/* ── Join invite screen ─────────────────────────────────────────── */
.h2h-join-sword {
  font-size: 2.4rem;
  line-height: 1;
}

.h2h-join-title {
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.3;
}

.h2h-join-meta {
  font-size: 0.88rem;
  opacity: 0.7;
  text-align: center;
  background: var(--tile-bg-empty);
  border: 1px solid var(--modal-border);
  border-radius: 8px;
  padding: 8px 16px;
  width: 100%;
}

.h2h-join-balance {
  font-size: 0.88rem;
  opacity: 0.65;
  text-align: center;
  margin-top: -6px;
}

/* ── Live game topbar timer ─────────────────────────────────────── */
.h2h-live-topbar-timer {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(7px, 2vw, 10px);
  color: var(--text-color);
  opacity: 0.65;
  letter-spacing: 0.05em;
  min-width: 44px;
  text-align: right;
  white-space: nowrap;
}

/* ── Live result attempt meta line ──────────────────────────────── */
.h2h-live-result-meta {
  font-size: 0.78rem;
  opacity: 0.65;
  margin-top: 6px;
  text-align: center;
}
