html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: #111;
}

*, *::before, *::after {
  box-sizing: border-box;
}

:root {
  --edge-offset: clamp(10px, 2vw, 24px);
  --shadow: 0 14px 30px rgba(0, 0, 0, 0.35);

  --slot-w: clamp(74px, min(5.5vw, 8vh), 92px);
  --slot-h: calc(var(--slot-w) * 1.5);
  --card-w: calc(var(--slot-w) * 1.5);
  --card-h: calc(var(--card-w) * 1.5);
  --opp-card-w: var(--slot-w);
  --opp-card-h: calc(var(--opp-card-w) * 1.5);

  --row-gap: 10px;
  --hand-gap: 6px;
  --stack-gap: 10px;
  --row-step-gap: clamp(10px, 2vh, 26px);
  --row-step: calc(var(--slot-h) + var(--row-step-gap));

  --opp-traps-top: calc(50vh - var(--slot-h) * 2 - var(--row-step-gap) * 1.5);
  --top-stack-top: var(--opp-traps-top);
  --bottom-stack-bottom: calc(100vh - var(--opp-traps-top) - 3 * var(--row-step) - var(--slot-h));

  --op-hand-top: clamp(-30px, -2vw, -12px);
  --player-hand-bottom: clamp(8px, 1.2vh, 16px);
}

.game-board {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background-image: url('../img/battlefield-desktop.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  isolation: isolate;
}

.board-overlay {
  position: absolute;
  inset: 0;
  background:
          linear-gradient(180deg, rgba(0,0,0,0.12), rgba(0,0,0,0.08) 30%, rgba(0,0,0,0.14)),
          radial-gradient(circle at center, rgba(255,255,255,0.04), transparent 42%);
  pointer-events: none;
  z-index: 0;
}

.player-header,
.board-pile,
.terrain-slot,
.board-row,
.hand,
.end-turn-btn {
  position: absolute;
  z-index: 2;
}

.player-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.opponent-header {
  top: clamp(10px, 2vh, 22px);
  left: var(--edge-offset);
}

.self-header {
  bottom: clamp(10px, 2vh, 22px);
  left: var(--edge-offset);
}

.nameplate,
.lp-badge {
  padding: 8px 14px;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.03em;
  background: rgba(18, 26, 34, 0.72);
  border: 1px solid rgba(255,255,255,0.16);
  box-shadow: var(--shadow);
  font-size: clamp(12px, 1vw, 15px);
}

.nameplate.enemy {
  background: rgba(125, 36, 36, 0.78);
}

.nameplate.self {
  background: rgba(35, 68, 122, 0.78);
}

.board-pile,
.terrain-slot,
.slot {
  width: var(--slot-w);
  aspect-ratio: 2 / 3;
  border-radius: 12px;
}

.board-pile {
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.24);
  box-shadow: var(--shadow);
  background:
          linear-gradient(145deg, rgba(29, 38, 48, 0.82), rgba(12, 16, 24, 0.92)),
          repeating-linear-gradient(45deg, rgba(255,255,255,0.04) 0 6px, transparent 6px 12px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px 8px;
  color: #fff;
}

.pile-title,
.terrain-title {
  font-size: clamp(9px, 0.8vw, 12px);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: 0.06em;
}

.pile-count {
  align-self: end;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(255,255,255,0.14);
  font-size: clamp(10px, 0.92vw, 13px);
  font-weight: 700;
}

.opponent-deck {
  top: var(--top-stack-top);
  left: var(--edge-offset);
}

.opponent-graveyard {
  top: var(--top-stack-top);
  right: var(--edge-offset);
}

.player-deck {
  bottom: var(--bottom-stack-bottom);
  left: var(--edge-offset);
}

.player-graveyard {
  bottom: var(--bottom-stack-bottom);
  right: var(--edge-offset);
}

.terrain-slot {
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.24);
  box-shadow: var(--shadow);
  background:
          linear-gradient(180deg, rgba(48, 70, 43, 0.88), rgba(22, 37, 24, 0.92)),
          radial-gradient(circle at top, rgba(255,255,255,0.12), transparent 55%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0;
  color: #f5edd5;
  text-align: center;
}

.terrain-art {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center top;
  z-index: 0;
}

.terrain-title,
.terrain-name {
  position: relative;
  z-index: 1;
}

.terrain-title {
  position: absolute;
  top: 4px;
  left: 0;
  right: 0;
  z-index: 1;
}

.terrain-name {
  font-size: clamp(9px, 0.82vw, 12px);
  font-weight: 700;
  line-height: 1.1;
  word-break: break-word;
  padding: 4px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
}

.opponent-terrain {
  top: calc(var(--top-stack-top) + var(--slot-h) + var(--stack-gap));
  right: var(--edge-offset);
}

.player-terrain {
  bottom: calc(var(--bottom-stack-bottom) + var(--slot-h) + var(--stack-gap));
  right: var(--edge-offset);
}

.board-row {
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, var(--slot-w));
  gap: var(--row-gap);
  justify-items: center;
  align-items: center;
}

.opponent-strategies {
  top: var(--opp-traps-top);
}

.opponent-units {
  top: calc(var(--opp-traps-top) + var(--row-step));
}

.player-units {
  top: calc(var(--opp-traps-top) + (var(--row-step) * 2));
}

.player-strategies {
  top: calc(var(--opp-traps-top) + (var(--row-step) * 3));
}

.slot {
  border: 2px dashed rgba(255,255,255,0.26);
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(3px);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: rgba(255,255,255,0.86);
  font-weight: 800;
  letter-spacing: 0.05em;
  font-size: clamp(8px, 0.7vw, 11px);
  padding: 4px;
  outline: none;
}

.slot:focus-visible,
.card:focus-visible,
.gm-btn:focus-visible,
.surrender-btn:focus-visible {
  outline: 2px solid #d4af37;
  outline-offset: 2px;
}

.general-slot {
  border: 2px solid rgba(215, 181, 109, 0.92);
  background:
          linear-gradient(180deg, rgba(215, 181, 109, 0.22), rgba(56, 42, 16, 0.18)),
          rgba(255,255,255,0.09);
  box-shadow: 0 0 18px rgba(215, 181, 109, 0.16);
}

.strategy-slot.face-down {
  background:
          linear-gradient(145deg, rgba(45, 32, 22, 0.9), rgba(26, 20, 12, 0.95)),
          repeating-linear-gradient(45deg, rgba(255,255,255,0.03) 0 8px, transparent 8px 16px);
  border-style: solid;
  border-color: rgba(114, 89, 60, 0.95);
}

.hand {
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: var(--hand-gap);
}

.player-hand {
  width: min(72vw, calc(var(--card-w) * 5 + var(--hand-gap) * 4 + 18px), 960px);
  bottom: var(--player-hand-bottom);
}

.opponent-hand {
  width: min(42vw, calc(var(--opp-card-w) * 5 + var(--hand-gap) * 4 + 18px), 520px);
  top: var(--op-hand-top);
}

.card {
  width: var(--card-w);
  aspect-ratio: 2 / 3;
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.22);
}

.opponent-hand .card {
  width: var(--opp-card-w);
  background:
          linear-gradient(145deg, rgba(56, 38, 24, 0.95), rgba(24, 16, 10, 1)),
          repeating-linear-gradient(45deg, rgba(255,255,255,0.04) 0 8px, transparent 8px 16px);
  transform: translateY(-24%);
}

.visible-card {
  position: relative;
  overflow: hidden;
}

.card-artwork {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-size: cover;
  background-position: center top;
}

.card-frame {
  position: absolute;
  inset: 0;
  z-index: 2;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  pointer-events: none;
}

.player-hand .visible-card:nth-child(1) { transform: rotate(-10deg) translateY(10px); }
.player-hand .visible-card:nth-child(2) { transform: rotate(-5deg) translateY(5px); }
.player-hand .visible-card:nth-child(3) { transform: rotate(0deg) translateY(0); }
.player-hand .visible-card:nth-child(4) { transform: rotate(5deg) translateY(5px); }
.player-hand .visible-card:nth-child(5) { transform: rotate(10deg) translateY(10px); }

.card-name,
.card-stats {
  position: relative;
  z-index: 3;
  padding: 4px 12%;
  font-size: clamp(8px, 0.65vw, 11px);
  font-weight: 800;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.card-name {
  color: #f0e8d0;
  margin-top: 4%;
  background: linear-gradient(180deg, rgba(0,0,0,0.5), transparent);
  padding-top: 6%;
  padding-bottom: 4%;
}

.visible-card:has(.card-frame) .card-name {
  background: none;
}

.card-stats {
  position: absolute;
  bottom: 4%;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  padding: 0 14% 0 22%;
  font-size: clamp(8px, 0.6vw, 10px);
  font-weight: 900;
  color: #f0e8d0;
  background: linear-gradient(transparent, rgba(0,0,0,0.6));
}

.visible-card:has(.card-frame) .card-stats {
  background: none;
}

.card-type-label {
  position: absolute;
  bottom: 16%;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  font-size: clamp(8px, 0.6vw, 10px);
  font-weight: 800;
  color: #111;
  line-height: 1.2;
  text-align: center;
}

.visible-card:has(.card-frame) .card-type-label {
  background: none;
}

.art-1 { background: linear-gradient(160deg, #8b5a3d, #cfa272); }
.art-2 { background: linear-gradient(160deg, #557750, #9cc080); }
.art-3 { background: linear-gradient(160deg, #4b3a68, #9f89d6); }
.art-4 { background: linear-gradient(160deg, #7b7f8f, #d6d8dd); }
.art-5 { background: linear-gradient(160deg, #63513b, #b99965); }

.end-turn-btn {
  right: calc(var(--edge-offset) + var(--slot-w) + 14px);
  bottom: clamp(12px, 2.4vh, 24px);
  min-width: 128px;
  padding: 11px 16px;
  font-weight: 800;
  letter-spacing: 0.03em;
  box-shadow: var(--shadow);
}

@media (min-width: 1024px) and (max-height: 820px) {
  :root {
    --row-step-gap: clamp(6px, 1.2vh, 14px);
    --op-hand-top: clamp(-20px, -1.4vw, -8px);
    --player-hand-bottom: 4px;
  }

  .player-hand .visible-card:nth-child(1) { transform: rotate(-7deg) translateY(7px); }
  .player-hand .visible-card:nth-child(2) { transform: rotate(-3.5deg) translateY(4px); }
  .player-hand .visible-card:nth-child(4) { transform: rotate(3.5deg) translateY(4px); }
  .player-hand .visible-card:nth-child(5) { transform: rotate(7deg) translateY(7px); }

  .board-row {
    transform: translateX(-50%) translateY(-4vh);
  }

  .end-turn-btn {
    min-width: 112px;
    padding: 9px 13px;
    font-size: 13px;
  }
}

@media (max-width: 900px), (orientation: portrait) {
  :root {
    --slot-w: clamp(48px, min(14vw, 8.2vh), 72px);
    --card-w: calc(var(--slot-w) * 1.5);
    --opp-card-w: var(--slot-w);
    --row-gap: clamp(4px, 1.2vw, 8px);
    --row-step-gap: clamp(8px, 1.3vh, 16px);
    --op-hand-top: clamp(-18px, -2vw, -8px);
    --player-hand-bottom: clamp(8px, 1.5vh, 14px);
  }

  .game-board {
    background-image: url('../img/battlefield-mobile.png');
    background-position: center;
  }

  .nameplate,
  .lp-badge {
    padding: 7px 12px;
    font-size: 12px;
  }

  .hand {
    width: min(82vw, calc(var(--card-w) * 5 + var(--hand-gap) * 4 + 12px));
  }

  .board-pile,
  .terrain-slot,
  .slot,
  .card {
    border-radius: 10px;
  }

  .terrain-slot {
    padding: 8px 6px;
  }

  .player-hand .visible-card:nth-child(1) { transform: rotate(-7deg) translateY(7px); }
  .player-hand .visible-card:nth-child(2) { transform: rotate(-3.5deg) translateY(4px); }
  .player-hand .visible-card:nth-child(4) { transform: rotate(3.5deg) translateY(4px); }
  .player-hand .visible-card:nth-child(5) { transform: rotate(7deg) translateY(7px); }

  .end-turn-btn {
    right: var(--edge-offset);
    bottom: calc(var(--bottom-stack-bottom) - 8px);
    min-width: 104px;
    padding: 9px 12px;
    font-size: 13px;
  }
}

@media (max-width: 430px) {
  :root {
    --slot-w: clamp(44px, min(13vw, 7.2vh), 62px);
    --card-w: calc(var(--slot-w) * 1.5);
    --opp-card-w: var(--slot-w);
    --row-step-gap: clamp(6px, 1vh, 12px);
  }

  .player-header {
    gap: 8px;
  }

  .nameplate,
  .lp-badge {
    padding: 6px 10px;
    font-size: 11px;
  }

  .pile-title,
  .terrain-title,
  .terrain-name,
  .slot,
  .card-name,
  .card-stats {
    font-size: 8px;
  }

  .end-turn-btn {
    min-width: 96px;
    padding: 8px 10px;
    font-size: 12px;
  }
}

/* ================================================================== */
/*  Bootstrap dark-theme overrides (non-game pages)                    */
/* ================================================================== */

.page-lobby .form-control,
.page-decks .form-control,
.page-leaderboard .form-control,
.page-history .form-control,
.page-lobby .form-select,
.page-decks .form-select,
.page-leaderboard .form-select,
.page-history .form-select {
  background-color: #1e1a28;
  border-color: #444;
  color: #e0dcd4;
}
.page-lobby .form-control:focus,
.page-decks .form-control:focus,
.page-lobby .form-select:focus,
.page-decks .form-select:focus {
  background-color: #252035;
  border-color: #b8962e;
  color: #e0dcd4;
  box-shadow: 0 0 0 0.2rem rgba(184, 150, 46, 0.25);
}
.form-control::placeholder {
  color: #888;
  opacity: 1;
  font-weight: 400;
  font-size: 13px;
}

/* ================================================================== */
/*  Lobby                                                              */
/* ================================================================== */

html.has-lobby, .page-lobby {
  overflow: auto !important;
}
.page-lobby {
  background: #0c0e13 !important;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
}
.lobby-bg {
  position: fixed;
  inset: 0;
  background: url('../img/battlefield-desktop.png') center / cover no-repeat;
  z-index: 0;
}
.lobby-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(6, 8, 14, 0.55);
}
.lobby-wrap {
  position: relative;
  z-index: 1;
}
@media (max-width: 600px) {
  .lobby-bg { background-image: url('../img/battlefield-mobile.png'); }
}

.lang-switcher {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 8px;
}
.lang-switcher button {
  background: none;
  border: none;
  color: rgba(255,255,255,0.5);
  font-size: 13px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}
.lang-switcher button:hover { color: #fff; }
.lang-switcher button.active {
  color: #fff;
  background: rgba(255,255,255,0.15);
}

.game-lang-switcher {
  position: absolute;
  top: 6px;
  right: 12px;
  z-index: 200;
  display: flex;
  gap: 4px;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(6px);
  border-radius: 6px;
  padding: 2px 4px;
}
.game-lang-switcher button {
  background: none;
  border: none;
  color: rgba(255,255,255,0.45);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  letter-spacing: 0.5px;
}
.game-lang-switcher button:hover { color: #fff; }
.game-lang-switcher button.active {
  color: #fff;
  background: rgba(255,255,255,0.18);
}

.lobby-card {
  background: linear-gradient(160deg, rgba(24,28,36,0.96), rgba(14,16,22,0.98));
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 20px;
  padding: clamp(28px,4vw,48px);
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}

.lobby-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(28px, 5vw, 42px);
  font-weight: 900;
  color: #d4af37;
  text-align: center;
  margin: 0 0 4px;
  letter-spacing: 0.04em;
}

.lobby-sub {
  text-align: center;
  color: rgba(255,255,255,0.5);
  font-size: 14px;
  margin: 0 0 16px;
}

.lobby-nav-links {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 28px;
}
.lobby-nav-links a {
  color: #b8a472;
  text-decoration: none;
  font-size: 14px;
  padding: 6px 14px;
  border: 1px solid #b8a47244;
  border-radius: 6px;
  transition: background .15s, border-color .15s;
}
.lobby-nav-links a:hover {
  background: rgba(184,164,114,0.1);
  border-color: #b8a472;
}

.lobby-player-name {
  margin: 0 auto 18px;
  max-width: 300px;
  text-align: center;
}

.lobby-game-modes {
  margin-top: 4px;
  padding: 22px 0 10px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.lobby-game-modes-title {
  font-family: 'Cinzel', serif;
  font-size: 18px;
  font-weight: 700;
  color: #d4af37;
  margin: 0 0 22px;
  text-align: center;
  letter-spacing: 0.05em;
}
.lobby-mode-btn {
  padding: 12px;
  font-weight: 700;
  font-size: 15px;
  border-radius: 10px;
  border: none;
  color: #fff;
  transition: opacity 0.2s;
}
.lobby-mode-btn:hover { opacity: 0.85; color: #fff; }

.lobby-btn-find {
  background: linear-gradient(135deg, #1a6b3c, #d4af37);
}
.lobby-btn-practice {
  background: linear-gradient(135deg, #2a4a6e, #6b8cae);
}
.lobby-btn-create {
  background: linear-gradient(135deg, #8C1C13, #b8893c);
}
.lobby-btn-join {
  background: linear-gradient(135deg, #3d2468, #8b5ccf);
  color: #f4ecff;
}
.lobby-btn-join:hover { color: #f4ecff; }

.lobby-result { margin-top: 12px; color: #d4af37; font-size: 14px; }
.lobby-result a { color: #e8c44a; text-decoration: underline; }

.lobby-divider-sm { display: flex; align-items: center; justify-content: center; color: rgba(255,255,255,0.25); font-weight: 700; }

.matchmaking-waiting {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 0;
  font-size: 14px;
  color: #e8e0d0;
}
.matchmaking-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(212,175,55,0.3);
  border-top-color: #d4af37;
  border-radius: 50%;
  animation: mm-spin 0.8s linear infinite;
}
@keyframes mm-spin { to { transform: rotate(360deg); } }

.matchmaking-waiting .btn-link {
  background: none;
  border: none;
  color: #b8a472;
  cursor: pointer;
  text-decoration: underline;
  font-size: 13px;
  padding: 0;
}
.matchmaking-waiting .btn-link:hover { color: #e8c44a; }

@media (max-width: 580px) {
  .lobby-divider { padding: 8px 0; }
  .lobby-divider-sm { padding: 8px 0; }
}

/* ================================================================== */
/*  Faction picker                                                     */
/* ================================================================== */

.faction-picker {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.85);
}

.fp-inner {
  max-width: 900px; width: 90%;
  max-height: 90vh; overflow-y: auto;
  padding: 32px;
}

.fp-inner h2 {
  font-family: 'Cinzel', serif;
  color: #d4af37;
  text-align: center;
  margin: 0 0 24px;
  font-size: 24px;
}

.fp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.fp-card {
  background: rgba(20,24,32,0.95);
  border: 2px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  padding: 18px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s;
}
.fp-card:hover { transform: translateY(-4px); border-color: #d4af37; }
.fp-card.fp-locked { opacity: 0.5; cursor: default; }
.fp-card.fp-locked:hover { transform: none; border-color: #444; }
.fp-lock-msg { color: rgba(255,255,255,0.4) !important; font-style: italic; }
.fp-card h3 { margin: 0 0 8px; font-family: 'Cinzel', serif; font-size: 16px; }
.fp-card p { font-size: 13px; color: rgba(255,255,255,0.7); margin: 0 0 6px; }
.fp-card small { font-size: 11px; color: rgba(255,255,255,0.45); }

.fp-deck-select {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 6px 8px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  background: rgba(0,0,0,0.4);
  color: #e0dcd4;
  font-size: 12px;
}
.fp-deck-select:focus { border-color: #b8962e; outline: none; }

.fp-pick-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 8px;
  border: 1px solid #b8962e;
  border-radius: 6px;
  background: linear-gradient(135deg, #7b6530, #b8962e);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}
.fp-pick-btn:hover { background: linear-gradient(135deg, #8b7540, #c8a63e); }

/* ================================================================== */
/*  Waiting screen                                                     */
/* ================================================================== */

.waiting-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.85);
}
.ws-inner { text-align: center; color: #e8e0d0; }
.ws-inner h2 { font-family: 'Cinzel', serif; color: #d4af37; margin-bottom: 12px; }
.ws-inner strong { font-size: 28px; letter-spacing: 0.12em; color: #fff; }
.ws-hint { color: rgba(255,255,255,0.45); font-size: 13px; margin-top: 8px; }

/* ================================================================== */
/*  Phase bar                                                          */
/* ================================================================== */

.phase-bar {
  position: absolute; z-index: 10;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  display: flex; gap: 2px;
  background: rgba(12,14,20,0.82);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 999px;
  padding: 3px;
}

.phase-item {
  padding: 5px 12px;
  font-size: clamp(9px, 0.8vw, 12px);
  font-weight: 700;
  color: rgba(255,255,255,0.4);
  border: none;
  background: transparent;
  border-radius: 999px;
  cursor: default;
  transition: all 0.2s;
  letter-spacing: 0.03em;
}

.phase-item.active {
  background: rgba(212,175,55,0.22);
  color: #d4af37;
  box-shadow: 0 0 12px rgba(212,175,55,0.15);
}

.phase-item.my-turn.active { background: rgba(55,120,212,0.3); color: #7ab4ff; }
.phase-item.inert { opacity: 0.35; pointer-events: none; }

/* ================================================================== */
/*  Turn banner                                                        */
/* ================================================================== */

.turn-banner {
  position: absolute;
  z-index: 8;
  top: calc(50% + 24px);
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(10px, 0.9vw, 13px);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: rgba(255,255,255,0.4);
  white-space: nowrap;
}
.turn-banner.my-turn { color: #7ab4ff; }
.turn-banner.opp-turn { color: rgba(255,100,100,0.6); }

/* ================================================================== */
/*  Field cards                                                        */
/* ================================================================== */

.slot.occupied { border-style: solid; cursor: pointer; padding: 0; }

.field-card {
  width: 100%; height: 100%;
  position: relative;
  border-radius: 10px; overflow: hidden;
}

.fc-artwork {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-size: cover;
  background-position: center top;
  border-radius: 8px;
}

.fc-frame {
  position: absolute;
  inset: 0;
  z-index: 2;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  pointer-events: none;
}

.fc-name {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  padding: 4% 10% 2%;
  font-size: clamp(5px, 0.45vw, 8px);
  font-weight: 800;
  color: #f0e8d0;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  background: linear-gradient(180deg, rgba(0,0,0,0.5), transparent);
}

.field-card:has(.fc-frame) .fc-name {
  background: none;
}

.field-card:has(.fc-frame) .fc-stats {
  background: none;
}

.field-card.pos-def { transform: rotate(90deg); transform-origin: center; }

.fc-stats {
  position: absolute; bottom: 0; left: 0; right: 0;
  z-index: 3;
  display: flex; justify-content: space-between;
  padding: 2% 12%;
  font-size: clamp(6px, 0.5vw, 9px);
  font-weight: 900;
  color: #f0e8d0;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
  background: linear-gradient(transparent, rgba(0,0,0,0.6));
}

.card-back-sm {
  width: 100%; height: 100%;
  border-radius: 8px;
  background:
          linear-gradient(145deg, rgba(56,38,24,0.95), rgba(24,16,10,1)),
          repeating-linear-gradient(45deg, rgba(255,255,255,0.04) 0 8px, transparent 8px 16px);
}

/* ================================================================== */
/*  Highlights                                                         */
/* ================================================================== */

.highlight-tribute { box-shadow: 0 0 16px 4px rgba(255,180,50,0.5) !important; border-color: #d4af37 !important; }
.highlight-slot    { box-shadow: 0 0 16px 4px rgba(80,180,255,0.4) !important; border-color: #5ab4ff !important; animation: pulse-slot 1s infinite; }
.highlight-target  { box-shadow: 0 0 16px 4px rgba(255,70,70,0.5) !important;  border-color: #ff5555 !important; }

@keyframes pulse-slot {
  0%, 100% { box-shadow: 0 0 16px 4px rgba(80,180,255,0.4); }
  50%      { box-shadow: 0 0 24px 8px rgba(80,180,255,0.6); }
}

/* ================================================================== */
/*  Modal                                                              */
/* ================================================================== */

.gm-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.7);
}

.gm-box {
  background: linear-gradient(160deg, #1c2028, #12141a);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 16px;
  padding: 24px 28px;
  min-width: 260px;
  max-width: 520px;
  width: 90%;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.gm-title {
  font-family: 'Cinzel', serif;
  color: #d4af37;
  font-size: 18px;
  margin: 0 0 16px;
  text-align: center;
}

.gm-body { color: rgba(255,255,255,0.7); font-size: 13px; margin-bottom: 16px; }

.gm-actions { display: flex; flex-direction: column; gap: 8px; }

.gm-btn {
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.08);
  color: #e8e0d0;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
  text-align: center;
}
.gm-btn:hover { background: rgba(255,255,255,0.14); }

.gm-cancel { color: rgba(255,255,255,0.4); border-color: rgba(255,255,255,0.08); }

/* ================================================================== */
/*  Toast                                                              */
/* ================================================================== */

.game-toast {
  position: fixed; bottom: 100px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(12,14,20,0.92);
  color: #d4af37;
  font-weight: 700;
  font-size: 13px;
  padding: 10px 22px;
  border-radius: 999px;
  border: 1px solid rgba(212,175,55,0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 300;
  white-space: nowrap;
}
.game-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ================================================================== */
/*  Card detail tooltip                                                */
/* ================================================================== */

.card-detail-tip {
  position: fixed; z-index: 250;
  top: 50%;
  transform: translateY(-50%);
  width: 200px;
  max-width: calc(100vw - 24px);
  background: #1a1c22;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 14px 40px rgba(0,0,0,0.5);
}
.card-detail-tip img { width: 100%; display: block; }
#cdtInfo { padding: 10px; color: #e8e0d0; font-size: 11px; }

/* ================================================================== */
/*  Discard modal grid                                                 */
/* ================================================================== */

.discard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.discard-option {
  cursor: pointer;
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(255,255,255,0.04);
  transition: border-color 0.15s, transform 0.15s;
  text-align: center;
}
.discard-option:hover,
.discard-option:focus-visible {
  border-color: #ff5555;
  transform: translateY(-3px);
  outline: 2px solid #ff5555;
  outline-offset: 2px;
}
.discard-option img {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
}
.discard-option span {
  display: block;
  padding: 4px;
  font-size: 9px;
  font-weight: 700;
  color: #e8e0d0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ================================================================== */
/*  Graveyard viewer cards                                             */
/* ================================================================== */

.board-pile.graveyard { cursor: pointer; }
.board-pile.graveyard:hover {
  border-color: rgba(255,255,255,0.5);
  box-shadow: 0 0 14px rgba(255,255,255,0.12);
}

.gy-card {
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(255,255,255,0.04);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s;
}
.gy-card:hover,
.gy-card:focus-visible {
  border-color: rgba(212,175,55,0.6);
  outline: 2px solid rgba(212,175,55,0.6);
  outline-offset: 2px;
}
.gy-card img {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
}
.gy-card span {
  display: block;
  padding: 3px 4px;
  font-size: 9px;
  font-weight: 700;
  color: #e8e0d0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gy-stats {
  color: rgba(255,255,255,0.45) !important;
  font-size: 8px !important;
  padding-top: 0 !important;
}

/* ================================================================== */
/*  Effect badge (OPT activatable effects)                             */
/* ================================================================== */

.effect-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  background: #d4af37;
  border-radius: 50%;
  font-size: 10px;
  line-height: 18px;
  text-align: center;
  color: #1a1400;
  font-weight: 700;
  z-index: 5;
  box-shadow: 0 0 6px rgba(212,175,55,0.6);
  cursor: pointer;
  animation: pulse-badge 2s ease-in-out infinite;
}
@keyframes pulse-badge {
  0%, 100% { box-shadow: 0 0 6px rgba(212,175,55,0.4); }
  50% { box-shadow: 0 0 12px rgba(212,175,55,0.9); }
}

/* ================================================================== */
/*  Response mode (trap chain prompt)                                  */
/* ================================================================== */

.response-trap {
  cursor: pointer;
  border: 2px solid rgba(180,50,50,0.3);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(180,50,50,0.08);
  text-align: center;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.response-trap:hover,
.response-trap:focus-visible {
  border-color: rgba(220,80,80,0.8);
  box-shadow: 0 0 12px rgba(220,80,80,0.4);
  outline: 2px solid rgba(220,80,80,0.8);
  outline-offset: 2px;
}
.response-trap img {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
}
.response-trap span {
  display: block;
  padding: 4px 6px;
  font-size: 10px;
  font-weight: 700;
  color: #f0d0d0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.turn-banner.respond-turn {
  background: linear-gradient(135deg, #8b2020 0%, #c04040 100%);
  color: #fff;
}

/* ================================================================== */
/*  Surrender button                                                   */
/* ================================================================== */

.surrender-btn {
  position: absolute;
  z-index: 20;
  top: clamp(10px, 2vh, 22px);
  right: calc(var(--edge-offset) + 80px);
  padding: 6px 14px;
  border: 1px solid rgba(180,50,50,0.4);
  border-radius: 999px;
  background: rgba(120,30,30,0.55);
  backdrop-filter: blur(4px);
  color: rgba(255,200,200,0.8);
  font-weight: 700;
  font-size: clamp(10px, 0.8vw, 12px);
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.surrender-btn:hover {
  background: rgba(160,40,40,0.75);
  border-color: rgba(220,70,70,0.7);
  color: #fff;
}

/* ================================================================== */
/*  Animations                                                         */
/* ================================================================== */

@keyframes deploy-glow {
  0% { box-shadow: 0 0 0 rgba(212,175,55,0); transform: scale(1); }
  30% { box-shadow: 0 0 20px rgba(212,175,55,0.8); transform: scale(1.06); }
  100% { box-shadow: 0 0 0 rgba(212,175,55,0); transform: scale(1); }
}
.anim-deploy {
  animation: deploy-glow 0.6s ease-out;
}

@keyframes destroy-fade {
  0% { opacity: 1; filter: brightness(1); }
  30% { opacity: 1; filter: brightness(2); }
  100% { opacity: 0.2; filter: brightness(0.5); }
}
.anim-destroy {
  animation: destroy-fade 0.6s ease-out;
}

@keyframes damage-shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-6px); }
  30% { transform: translateX(6px); }
  45% { transform: translateX(-4px); }
  60% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}
.anim-damage {
  animation: damage-shake 0.5s ease-out;
  color: #ff4444 !important;
}

@keyframes float-up {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-40px); }
}
.damage-float {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 18px;
  font-weight: 900;
  color: #ff3333;
  text-shadow: 0 0 6px rgba(255,0,0,0.6);
  pointer-events: none;
  animation: float-up 1.2s ease-out forwards;
  z-index: 100;
}

@keyframes attack-lunge {
  0% { transform: translateY(0); }
  40% { transform: translateY(-18px) scale(1.08); }
  70% { transform: translateY(4px) scale(0.98); }
  100% { transform: translateY(0) scale(1); }
}
.anim-attack-lunge {
  animation: attack-lunge 0.4s ease-out;
  z-index: 10;
}

@keyframes flip-reveal {
  0% { transform: scaleX(0); filter: brightness(2); }
  50% { transform: scaleX(0.1); filter: brightness(1.8); }
  100% { transform: scaleX(1); filter: brightness(1); }
}
.anim-flip {
  animation: flip-reveal 0.5s ease-out;
}

@keyframes draw-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(0.9); box-shadow: 0 0 12px rgba(90,180,255,0.5); }
  100% { transform: scale(1); box-shadow: none; }
}
.anim-draw-pulse {
  animation: draw-pulse 0.4s ease-out;
}

@keyframes negate-flash {
  0% { filter: brightness(1); }
  25% { filter: brightness(0.4) saturate(0); }
  50% { filter: brightness(1.2); }
  100% { filter: brightness(1); }
}
.anim-negate {
  animation: negate-flash 0.5s ease-out;
}

@keyframes effect-glow {
  0% { box-shadow: 0 0 0 rgba(100,200,255,0); }
  30% { box-shadow: 0 0 18px rgba(100,200,255,0.8); }
  100% { box-shadow: 0 0 0 rgba(100,200,255,0); }
}
.anim-effect-glow {
  animation: effect-glow 0.6s ease-out;
}

/* ================================================================== */
/*  Equip links                                                        */
/* ================================================================== */

.equip-link {
  position: fixed;
  height: 2px;
  background: linear-gradient(90deg, rgba(212,175,55,0.7), rgba(212,175,55,0.2));
  transform-origin: 0 50%;
  pointer-events: none;
  z-index: 6;
}

/* ================================================================== */
/*  Mobile small-screen enhancements                                   */
/* ================================================================== */

@media (max-width: 360px) {
  :root {
    --slot-w: clamp(38px, min(12vw, 6.5vh), 54px);
    --card-w: calc(var(--slot-w) * 1.5);
    --opp-card-w: var(--slot-w);
    --row-gap: 3px;
    --hand-gap: 3px;
    --row-step-gap: clamp(4px, 0.8vh, 8px);
    --edge-offset: 6px;
  }

  .player-header { gap: 4px; }

  .nameplate,
  .lp-badge {
    padding: 4px 8px;
    font-size: 10px;
  }

  .pile-title,
  .terrain-title,
  .terrain-name {
    font-size: 7px;
  }

  .pile-count { font-size: 9px; padding: 2px 5px; }

  .surrender-btn {
    padding: 4px 10px;
    font-size: 9px;
    right: calc(var(--edge-offset) + 60px);
  }

  .phase-bar {
    padding: 2px;
    gap: 1px;
  }
  .phase-item {
    padding: 3px 6px;
    font-size: 8px;
  }

  .end-turn-btn {
    min-width: 80px;
    padding: 6px 8px;
    font-size: 11px;
  }
}

@media (max-height: 600px) and (orientation: landscape) {
  :root {
    --slot-w: clamp(40px, min(5vw, 8vh), 64px);
    --card-w: calc(var(--slot-w) * 1.5);
    --opp-card-w: var(--slot-w);
    --row-step-gap: clamp(2px, 0.6vh, 6px);
    --op-hand-top: -6px;
    --player-hand-bottom: 2px;
  }

  .nameplate,
  .lp-badge {
    padding: 4px 10px;
    font-size: 11px;
  }

  .end-turn-btn {
    min-width: 100px;
    padding: 6px 10px;
    font-size: 12px;
  }
}

/* ================================================================== */
/*  Deck Builder page                                                  */
/* ================================================================== */

.db-page {
  min-height: 100vh;
  background: linear-gradient(160deg, #0f0d14 0%, #1a1525 50%, #0d1420 100%);
  color: #e0dcd4;
}

.db-nav-link {
  color: #b8a472;
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}
.db-nav-link:hover { color: #d4c38e; text-decoration: underline; }

.db-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(18px, 3vw, 28px);
  color: #d4c38e;
}

.db-section { margin-bottom: 32px; }

.db-btn-sm {
  padding: 4px 10px;
  border: 1px solid #555;
  border-radius: 4px;
  background: #2a2535;
  color: #e0dcd4;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
}
.db-btn-sm:hover { background: #3a3545; }
.db-btn-sm:disabled { opacity: .3; cursor: default; }

/* Deck grid */
.db-deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.db-deck-card {
  background: #1e1a28;
  border: 2px solid #333;
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  position: relative;
  transition: border-color .2s, transform .15s;
}
.db-deck-card:hover { border-color: #b8962e; transform: translateY(-2px); }
.db-deck-card.valid { border-color: #3a7a3a; }
.db-deck-card.invalid { border-color: #7a3a3a; }

.db-deck-card h3 {
  font-family: 'Cinzel', serif;
  font-size: 16px;
  color: #d4c38e;
  margin: 0 0 4px;
}

.db-deck-faction {
  color: #aaa;
  font-size: 13px;
  margin: 4px 0;
}

.db-deck-info {
  color: #888;
  font-size: 12px;
  margin: 4px 0 0;
}

.db-deck-badge {
  position: absolute;
  top: 12px;
  right: 14px;
  font-size: 20px;
}
.db-deck-card.valid .db-deck-badge { color: #5a5; }
.db-deck-card.invalid .db-deck-badge { color: #a55; }

.db-empty {
  color: #777;
  font-style: italic;
  padding: 20px;
  text-align: center;
}

/* Card count badge */
.db-card-count {
  font-family: 'Cinzel', serif;
  font-size: 18px;
  color: #b8962e;
  font-weight: 700;
}

.db-pool h3, .db-current h3 {
  font-family: 'Cinzel', serif;
  font-size: 15px;
  color: #d4c38e;
  margin: 0 0 10px;
}

.db-card-list {
  max-height: 60vh;
  overflow-y: auto;
  border: 1px solid #333;
  border-radius: 8px;
  background: #151220;
  padding: 8px;
}

/* Pool card row */
.db-pool-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  transition: background .15s;
}
.db-pool-card:hover { background: #252035; }

.db-pc-art {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  border: 1px solid #444;
}

.db-pc-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.db-pc-info strong {
  font-size: 13px;
  color: #e0dcd4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.db-pc-info span { font-size: 11px; color: #999; }
.db-pc-faction { color: #b8a472 !important; }

.db-pc-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.db-pc-qty {
  font-size: 13px;
  color: #aaa;
  min-width: 28px;
  text-align: center;
}

/* Deck contents entry */
.db-deck-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 4px;
}
.db-deck-entry:hover { background: #252035; }

.db-de-name {
  flex: 1;
  font-size: 13px;
  color: #e0dcd4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.db-de-type { font-size: 11px; color: #888; }
.db-de-qty { font-size: 13px; color: #b8a472; font-weight: 700; min-width: 24px; text-align: center; }


/* Validation */
.db-validation { margin-bottom: 12px; }
.db-valid {
  background: #1a3a1a;
  border: 1px solid #3a7a3a;
  color: #7a7;
  padding: 10px 14px;
  border-radius: 6px;
  font-weight: 600;
}
.db-invalid {
  background: #3a1a1a;
  border: 1px solid #7a3a3a;
  color: #c88;
  padding: 10px 14px;
  border-radius: 6px;
}
.db-invalid p { margin: 4px 0; font-size: 13px; }

/* ================================================================== */
/*  Leaderboard page                                                   */
/* ================================================================== */

.lb-page {
  min-height: 100vh;
  background: linear-gradient(160deg, #0f0d14 0%, #1a1525 50%, #0d1420 100%);
  color: #e0dcd4;
}

.lb-nav-link {
  color: #b8a472;
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}
.lb-nav-link:hover { color: #d4c38e; text-decoration: underline; }

.lb-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(18px, 3vw, 28px);
  color: #d4c38e;
}

/* Profile card */
.lb-profile { margin-bottom: 28px; }
.lb-profile-card {
  background: #1e1a28;
  border: 2px solid #b8962e;
  border-radius: 12px;
  padding: 20px;
  text-align: center;
}
.lb-profile-card h2 {
  font-family: 'Cinzel', serif;
  font-size: 22px;
  color: #d4c38e;
  margin: 0 0 14px;
}

.lb-profile-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
}

.lb-stat { display: flex; flex-direction: column; align-items: center; }
.lb-stat-value { font-size: 28px; font-weight: 800; color: #b8962e; }
.lb-stat-label { font-size: 12px; color: #999; text-transform: uppercase; letter-spacing: 1px; }
.lb-loading { color: #777; font-style: italic; }

/* Leaderboard table */

.lb-table th {
  font-family: 'Cinzel', serif;
  font-size: 13px;
  color: #b8a472 !important;
}
.lb-table .lb-me {
  background: #1a2a1a !important;
}
.lb-table .lb-me td { color: #d4c38e; font-weight: 600; }

/* ================================================================== */
/*  M1: Turn timer                                                     */
/* ================================================================== */

.turn-timer {
  position: fixed;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20,18,28,0.9);
  border: 1px solid #444;
  border-radius: 8px;
  padding: 4px 14px;
  font-family: 'Cinzel', serif;
  font-size: 16px;
  color: #b8a472;
  z-index: 90;
  pointer-events: none;
}
.turn-timer.timer-opponent { opacity: 0.72; font-size: 13px; }
.turn-timer.timer-warning { color: #d4a030; border-color: #d4a030; }
.turn-timer.timer-critical { color: #e04040; border-color: #e04040; animation: pulse-critical 0.6s infinite alternate; }
@keyframes pulse-critical { from { opacity: 1; } to { opacity: 0.5; } }

/* ================================================================== */
/*  L2: Game log panel                                                 */
/* ================================================================== */

.game-log-panel {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 80;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
}

.log-toggle {
  writing-mode: vertical-rl;
  padding: 8px 3px;
  background: rgba(20,18,28,0.95);
  border: 1px solid #444;
  border-right: none;
  border-radius: 8px 0 0 8px;
  color: #b8a472;
  font-size: 11px;
  cursor: pointer;
  letter-spacing: 2px;
  flex-shrink: 0;
  order: -1;
}

.log-list {
  width: 240px;
  max-height: 55vh;
  background: rgba(20,18,28,0.95);
  border: 1px solid #444;
  border-right: none;
  border-radius: 0;
  padding: 8px;
  overflow-y: auto;
  font-size: 11px;
  color: #ccc;
  transition: width .25s, opacity .25s, padding .25s;
}

.game-log-panel:not(.open) .log-list {
  width: 0;
  padding: 0;
  opacity: 0;
  overflow: hidden;
  border: none;
}
.log-entry {
  padding: 3px 0;
  border-bottom: 1px solid #333;
}
.log-entry:last-child { border-bottom: none; }

/* ================================================================== */
/*  L3: Sound toggle                                                   */
/* ================================================================== */

.sound-toggle {
  position: fixed;
  bottom: 8px;
  right: 8px;
  z-index: 85;
  width: 36px;
  height: 36px;
  border: 1px solid #555;
  border-radius: 50%;
  background: rgba(20,18,28,0.9);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

/* ================================================================== */
/*  L4: Card zoom overlay                                              */
/* ================================================================== */

.card-zoom-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.card-zoom-inner {
  display: flex;
  gap: 24px;
  max-width: 90vw;
  max-height: 85vh;
  align-items: center;
}
.card-zoom-art {
  max-height: 70vh;
  max-width: 45vw;
  border-radius: 12px;
  box-shadow: 0 0 40px rgba(184,150,46,0.3);
}
.card-zoom-info {
  color: #e0dcd4;
  max-width: 300px;
}
.card-zoom-info h2 {
  font-family: 'Cinzel', serif;
  font-size: 22px;
  color: #d4c38e;
  margin: 0 0 8px;
}
.card-zoom-info .cz-type { color: #aaa; font-size: 14px; margin: 4px 0; }
.card-zoom-info .cz-stats { font-size: 16px; font-weight: 700; color: #b8a472; margin: 4px 0; }
.card-zoom-info .cz-effect { font-size: 13px; color: rgba(255,255,255,0.7); margin: 8px 0; line-height: 1.5; }
.card-zoom-info .cz-faction { font-size: 12px; color: #888; margin: 8px 0; }

@media (max-width: 600px) {
  .card-zoom-inner { flex-direction: column; gap: 12px; }
  .card-zoom-art { max-width: 80vw; max-height: 40vh; }
  .card-zoom-info { max-width: 80vw; text-align: center; }
}

/* ================================================================== */
/*  L6: Game over board dim                                            */
/* ================================================================== */

.game-board.game-over {
  opacity: 0.4;
  pointer-events: none;
}

/* Match history */
.hist-win td:first-child { color: #6dd66d; }
.hist-loss td:first-child { color: #e06060; }

/* Account section in lobby */
/* Faction unlocks */
.lobby-unlocks {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid #333;
  text-align: center;
}
.lobby-unlocks h3 {
  font-family: 'Cinzel', serif;
  font-size: 15px;
  color: #d4af37;
  margin: 0 0 12px;
}
.unlock-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}
.unlock-faction {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 8px;
  background: rgba(212,175,55,0.12);
  border: 1px solid rgba(212,175,55,0.3);
  font-size: 13px;
  color: #e8e0d0;
}
.unlock-faction.locked {
  background: rgba(255,255,255,0.04);
  border-color: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.35);
}
.unlock-faction .uf-icon { font-size: 14px; }
.unlock-faction .uf-name { font-weight: 600; }
.unlock-faction .uf-req {
  font-size: 11px;
  color: rgba(255,255,255,0.3);
  margin-left: 4px;
}
.unlock-next {
  font-size: 13px;
  color: #b8a472;
  margin-top: 4px;
}
.unlock-next strong { color: #d4af37; }

.lobby-account {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid #333;
  text-align: center;
}
.account-badge { color: #6dd66d; font-size: 14px; }
.account-hint { color: #888; font-size: 13px; }
#accountForm h3 { font-family: 'Cinzel', serif; font-size: 16px; color: #d4c38e; margin: 8px 0; }
#authForm { display: flex; flex-direction: column; gap: 8px; max-width: 300px; margin: 0 auto; }
#joinCodeInput {
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.account-btns { display: flex; gap: 8px; align-items: center; }
.account-btns button[type="submit"] { flex: 1; padding: 8px; background: #6d3a0a; color: #f5e6c8; border: none; border-radius: 6px; cursor: pointer; font-weight: 600; }
.account-btns button[type="submit"]:hover { background: #8d4a1a; }
.btn-link { background: none; border: none; color: #888; font-size: 12px; cursor: pointer; text-decoration: underline; }
.btn-link:hover { color: #d4c38e; }
.auth-error { color: #e06060; font-size: 13px; min-height: 18px; }
.db-filter-select { padding: 6px 10px; border: 1px solid #444; border-radius: 6px; background: #181820; color: #e0dcd4; font-size: 13px; }
