/* Math King - Fantasy Math Battle Game */
:root {
  --blue-dark: #1a237e;
  --blue-mid: #283593;
  --blue-bright: #42a5f5;
  --gold: #ffd700;
  --gold-dark: #f59e0b;
  --orange: #ff6f00;
  --red: #c62828;
  --purple-dark: #1a0a2e;
  --purple-mid: #311b92;
  --green: #2e7d32;
  --white: #ffffff;
  --slot-size: clamp(52px, 12vw, 88px);
  --card-w: clamp(72px, 20vw, 100px);
  --card-h: calc(var(--card-w) * 1.45);
  --game-board-max: 1200px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  font-family: 'Nunito', sans-serif;
  background: var(--purple-dark);
  color: var(--white);
  touch-action: manipulation;
  user-select: none;
}

/* Screens */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.screen.active {
  display: flex;
}

.screen.overlay {
  background: rgba(0, 0, 0, 0.75);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.screen.overlay[hidden] {
  display: none !important;
}

/* ===== MENU ===== */
#screen-menu {
  align-items: center;
  justify-content: flex-start;
  min-height: 0;
}

.btn-menu-refresh {
  position: relative;
  top: auto;
  right: auto;
  left: auto;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid rgba(255, 215, 0, 0.55);
  border-radius: 50%;
  background: linear-gradient(165deg, rgba(74, 20, 140, 0.55) 0%, rgba(26, 10, 46, 0.85) 100%);
  color: #fff8e1;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(74, 20, 140, 0.7), 0 5px 14px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-menu-refresh-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255, 235, 59, 0.35) 0%, rgba(245, 158, 11, 0.3) 100%);
  color: var(--gold);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn-menu-refresh:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(74, 20, 140, 0.7);
}

.btn-menu-refresh:active .btn-menu-refresh-icon svg {
  transform: rotate(-180deg);
}

.btn-menu-refresh-icon svg {
  display: block;
  transition: transform 0.35s ease;
}

.menu-country-flag-wrap {
  position: absolute;
  top: calc(var(--safe-top) + 0.55rem);
  left: max(0.65rem, env(safe-area-inset-left, 0px));
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid rgba(255, 215, 0, 0.55);
  border-radius: 50%;
  background: linear-gradient(165deg, rgba(74, 20, 140, 0.55) 0%, rgba(26, 10, 46, 0.85) 100%);
  box-shadow: 0 4px 0 rgba(74, 20, 140, 0.7), 0 5px 14px rgba(0, 0, 0, 0.35);
}

.menu-country-flag-wrap.hidden {
  display: none;
}

.menu-country-flag {
  width: 28px;
  height: 21px;
  object-fit: cover;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25);
}

@media (hover: hover) {
  .btn-menu-refresh:hover {
    border-color: rgba(255, 235, 59, 0.85);
    box-shadow: 0 5px 0 rgba(74, 20, 140, 0.7), 0 8px 18px rgba(255, 215, 0, 0.25);
    transform: translateY(-1px);
  }

  .btn-menu-refresh:hover .btn-menu-refresh-icon {
    background: linear-gradient(180deg, rgba(255, 235, 59, 0.55) 0%, rgba(245, 158, 11, 0.45) 100%);
  }
}

.menu-top-actions {
  position: absolute;
  top: calc(var(--safe-top) + 0.55rem);
  right: max(0.65rem, env(safe-area-inset-right, 0px));
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.menu-online-pts {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 44px;
  padding: 0.35rem 0.65rem;
  border: 2px solid rgba(255, 215, 0, 0.55);
  border-radius: 999px;
  background: linear-gradient(165deg, rgba(74, 20, 140, 0.55) 0%, rgba(26, 10, 46, 0.85) 100%);
  box-shadow: 0 4px 0 rgba(74, 20, 140, 0.7), 0 5px 14px rgba(0, 0, 0, 0.35);
  color: #fff8e1;
}

.menu-online-pts.hidden {
  display: none;
}

.menu-online-pts-icon {
  font-size: 0.95rem;
  line-height: 1;
}

.menu-online-pts-value {
  font-family: 'Bangers', cursive;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  color: var(--gold);
  line-height: 1;
}

.menu-online-pts-label {
  font-family: 'Nunito', sans-serif;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.82);
  line-height: 1;
}

#screen-howto,
#screen-legend,
#screen-settings,
#screen-register,
#screen-account,
#screen-login,
#screen-leaderboard,
#screen-match-history,
#screen-friends,
#screen-privacy,
#screen-terms,
#screen-campaign,
#screen-support {
  align-items: center;
  justify-content: center;
  z-index: 1;
}

#screen-menu.active,
#screen-howto.active,
#screen-legend.active,
#screen-settings.active,
#screen-register.active,
#screen-account.active,
#screen-login.active,
#screen-leaderboard.active,
#screen-match-history.active,
#screen-friends.active,
#screen-privacy.active,
#screen-terms.active,
#screen-campaign.active,
#screen-support.active {
  z-index: 60;
}

#screen-howto,
#screen-legend,
#screen-settings,
#screen-register,
#screen-account,
#screen-login,
#screen-leaderboard,
#screen-match-history,
#screen-friends,
#screen-privacy,
#screen-terms,
#screen-support {
  background: #1a0a2e;
}

.menu-legal-links {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  width: 100%;
  max-width: min(100%, 360px);
  margin: 0.65rem auto 0;
  padding-top: 0.35rem;
}

.menu-legal-link {
  background: none;
  border: none;
  padding: 0.35rem 0.25rem;
  font-family: 'Nunito', sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.72);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.menu-legal-link:active {
  color: var(--gold);
}

.menu-legal-sep {
  color: rgba(255, 255, 255, 0.35);
  font-size: 0.75rem;
  line-height: 1;
}

.legal-page-content {
  text-align: left;
}

.legal-updated {
  font-size: 0.75rem;
  text-align: center;
  color: rgba(255, 255, 255, 0.72);
  margin: -0.35rem 0 1rem;
}

.legal-section {
  margin-bottom: 0.85rem;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  background: linear-gradient(
    135deg,
    rgba(74, 20, 140, 0.88) 0%,
    rgba(49, 27, 146, 0.82) 50%,
    rgba(13, 27, 62, 0.92) 100%
  );
  border: 2px solid rgba(255, 215, 0, 0.35);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
}

.legal-section h2 {
  font-family: 'Bangers', cursive;
  font-size: 1.1rem;
  color: #fff9c4;
  letter-spacing: 0.04em;
  margin-bottom: 0.45rem;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.legal-section p,
.legal-section li {
  font-size: clamp(0.78rem, 3vw, 0.88rem);
  line-height: 1.55;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.legal-section ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.legal-section li {
  position: relative;
  padding-left: 1rem;
  margin-bottom: 0.35rem;
}

.legal-section li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--gold);
  font-weight: 800;
}

.legal-section strong {
  color: #ffe082;
}

.legal-contact-btn {
  margin-top: 0.75rem;
  width: 100%;
  max-width: 280px;
}

.support-page-content {
  text-align: center;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 auto;
}

#screen-support .menu-bg {
  z-index: 0;
}

#screen-support .support-panel,
#screen-support .support-guest-fields,
#screen-support .support-ticket-picker {
  position: relative;
  z-index: 1;
  pointer-events: auto;
}

.support-panel {
  text-align: left;
  margin: 0.75rem auto 0;
  padding: 1rem 1.1rem 1.05rem;
  border-radius: 16px;
  background: linear-gradient(
    135deg,
    rgba(74, 20, 140, 0.92) 0%,
    rgba(106, 27, 154, 0.85) 42%,
    rgba(26, 35, 126, 0.94) 100%
  );
  border: 2px solid rgba(255, 215, 0, 0.5);
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

#support-new-panel {
  padding: 1.05rem 1.15rem 1.1rem;
}

.support-panel .register-label {
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.support-panel .register-input,
.support-panel .support-select,
.support-panel .support-textarea {
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(255, 215, 0, 0.4);
  color: #263238;
}

.support-panel .register-input::placeholder,
.support-panel .support-textarea::placeholder {
  color: rgba(38, 50, 56, 0.55);
}

.support-panel .register-input:focus,
.support-panel .support-select:focus,
.support-panel .support-textarea:focus {
  border-color: rgba(255, 215, 0, 0.75);
  box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.28);
}

.support-panel-title {
  font-family: 'Bangers', cursive;
  font-size: 1.15rem;
  color: #fff9c4;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.55);
  margin: 0 0 0.65rem;
}

.support-select,
.support-textarea {
  width: 100%;
  margin-bottom: 0.55rem;
}

.support-textarea {
  resize: vertical;
  min-height: 4.5rem;
}

.support-guest-fields {
  text-align: left;
  margin: 0.5rem auto 0;
  max-width: 100%;
}

.support-chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.support-chat-status {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.72);
  margin: 0;
}

.support-new-chat-btn {
  flex-shrink: 0;
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.support-messages {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-height: min(42vh, 320px);
  overflow-y: auto;
  padding: 0.35rem 0.15rem;
  margin-bottom: 0.65rem;
}

.support-message {
  display: flex;
  flex-direction: column;
  max-width: 88%;
}

.support-message--player {
  align-self: flex-end;
  align-items: flex-end;
}

.support-message--admin {
  align-self: flex-start;
  align-items: flex-start;
}

.support-message-bubble {
  padding: 0.55rem 0.75rem;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.45;
  word-break: break-word;
}

.support-message--player .support-message-bubble {
  background: linear-gradient(135deg, rgba(66, 165, 245, 0.35), rgba(21, 101, 192, 0.45));
  border: 1px solid rgba(100, 181, 246, 0.5);
}

.support-message--admin .support-message-bubble {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 215, 0, 0.35);
}

.support-message-meta {
  font-size: 0.68rem;
  opacity: 0.65;
  margin-top: 0.15rem;
}

.support-reply-form {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.support-ticket-picker {
  text-align: left;
  margin-top: 0.75rem;
}

.menu-nav-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.55rem;
  width: 100%;
  max-width: min(100%, 360px);
  margin: auto 0 0;
  padding-top: 0.85rem;
  flex-shrink: 0;
}

.btn-menu-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 5.5rem;
  padding: 0.65rem 0.4rem 0.55rem;
  border: 2px solid transparent;
  border-radius: 16px;
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  text-align: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-menu-nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1.45rem;
  line-height: 1;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.btn-menu-nav-label {
  font-size: clamp(0.62rem, 2.8vw, 0.72rem);
  line-height: 1.15;
  letter-spacing: 0.02em;
  color: inherit;
}

.btn-menu-nav--leaderboard {
  color: #fff8e1;
  background: linear-gradient(165deg, rgba(255, 193, 7, 0.35) 0%, rgba(255, 152, 0, 0.22) 100%);
  border-color: rgba(255, 215, 0, 0.55);
  box-shadow: 0 4px 0 rgba(191, 136, 0, 0.55), 0 6px 14px rgba(255, 193, 7, 0.2);
}

.btn-menu-nav--leaderboard .btn-menu-nav-icon {
  background: linear-gradient(180deg, rgba(255, 235, 59, 0.45) 0%, rgba(245, 158, 11, 0.35) 100%);
}

.btn-menu-nav--howto {
  color: #e8eaf6;
  background: linear-gradient(165deg, rgba(126, 87, 194, 0.4) 0%, rgba(49, 27, 146, 0.35) 100%);
  border-color: rgba(171, 71, 188, 0.5);
  box-shadow: 0 4px 0 rgba(74, 20, 140, 0.65), 0 6px 14px rgba(126, 87, 194, 0.25);
}

.btn-menu-nav--howto .btn-menu-nav-icon {
  background: linear-gradient(180deg, rgba(186, 104, 200, 0.45) 0%, rgba(106, 27, 154, 0.4) 100%);
}

.btn-menu-nav--settings {
  color: #e3f2fd;
  background: linear-gradient(165deg, rgba(66, 165, 245, 0.35) 0%, rgba(21, 101, 192, 0.3) 100%);
  border-color: rgba(66, 165, 245, 0.55);
  box-shadow: 0 4px 0 rgba(13, 71, 161, 0.65), 0 6px 14px rgba(66, 165, 245, 0.22);
}

.btn-menu-nav--settings .btn-menu-nav-icon {
  background: linear-gradient(180deg, rgba(100, 181, 246, 0.45) 0%, rgba(25, 118, 210, 0.4) 100%);
}

.btn-menu-nav--history {
  color: #f3e5f5;
  background: linear-gradient(165deg, rgba(171, 71, 188, 0.35) 0%, rgba(106, 27, 154, 0.28) 100%);
  border-color: rgba(186, 104, 200, 0.55);
  box-shadow: 0 4px 0 rgba(74, 20, 140, 0.55), 0 6px 14px rgba(171, 71, 188, 0.22);
}

.btn-menu-nav--history .btn-menu-nav-icon {
  background: linear-gradient(180deg, rgba(206, 147, 216, 0.45) 0%, rgba(142, 36, 170, 0.35) 100%);
}

.btn-menu-nav--legend {
  color: #fff8e1;
  background: linear-gradient(165deg, rgba(255, 152, 0, 0.38) 0%, rgba(183, 28, 28, 0.32) 100%);
  border-color: rgba(255, 193, 7, 0.6);
  box-shadow: 0 4px 0 rgba(191, 54, 12, 0.6), 0 6px 14px rgba(255, 152, 0, 0.25);
}

.btn-menu-nav--legend .btn-menu-nav-icon {
  background: linear-gradient(180deg, rgba(255, 224, 130, 0.5) 0%, rgba(230, 81, 0, 0.4) 100%);
}

.menu-nav-span-full {
  grid-column: 1 / -1;
  flex-direction: row;
  justify-content: center;
  gap: 0.65rem;
  min-height: 4.35rem;
  padding: 0.55rem 0.85rem;
}

.menu-nav-span-full .btn-menu-nav-label {
  font-size: clamp(0.7rem, 3.1vw, 0.82rem);
  max-width: 14rem;
}

.btn-menu-nav:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

.btn-menu-nav--leaderboard:active {
  box-shadow: 0 1px 0 rgba(191, 136, 0, 0.55);
}

.btn-menu-nav--howto:active {
  box-shadow: 0 1px 0 rgba(74, 20, 140, 0.65);
}

.btn-menu-nav--legend:active {
  box-shadow: 0 1px 0 rgba(191, 54, 12, 0.6);
}

.btn-menu-nav--settings:active {
  box-shadow: 0 1px 0 rgba(13, 71, 161, 0.65);
}

@media (hover: hover) {
  .btn-menu-nav:hover {
    transform: translateY(-2px);
  }

  .btn-menu-nav--leaderboard:hover {
    border-color: rgba(255, 235, 59, 0.85);
    box-shadow: 0 5px 0 rgba(191, 136, 0, 0.55), 0 8px 18px rgba(255, 193, 7, 0.35);
  }

  .btn-menu-nav--howto:hover {
    border-color: rgba(206, 147, 216, 0.75);
    box-shadow: 0 5px 0 rgba(74, 20, 140, 0.65), 0 8px 18px rgba(126, 87, 194, 0.35);
  }

  .btn-menu-nav--settings:hover {
    border-color: rgba(144, 202, 249, 0.85);
    box-shadow: 0 5px 0 rgba(13, 71, 161, 0.65), 0 8px 18px rgba(66, 165, 245, 0.35);
  }
}

.settings-page-content,
.register-page-content,
.account-page-content,
.howto-content,
.legend-content,
.legal-page-content,
.leaderboard-content,
.campaign-content,
.support-page-content {
  position: relative;
  z-index: 2;
  pointer-events: auto;
  width: min(100%, 420px);
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: calc(var(--safe-top) + 0.75rem) 1.25rem calc(var(--safe-bottom) + 1rem);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.settings-page-content::-webkit-scrollbar,
.register-page-content::-webkit-scrollbar,
.howto-content::-webkit-scrollbar,
.legend-content::-webkit-scrollbar,
.legal-page-content::-webkit-scrollbar,
.campaign-content::-webkit-scrollbar,
.support-page-content::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.register-page-title {
  font-family: 'Bangers', cursive;
  font-size: clamp(2rem, 8vw, 2.75rem);
  color: var(--gold);
  text-align: center;
  margin-bottom: 0.5rem;
  letter-spacing: 0.05em;
  text-shadow: 0 2px 0 #5d4037;
}

.account-details-panel .btn-register {
  width: 100%;
  margin-top: 0.5rem;
}

.account-details-panel .btn-register-new {
  margin-top: 0.5rem;
}

.account-avatar-field {
  margin-bottom: 0.75rem;
}

.account-avatar-picker {
  margin-bottom: 0.15rem;
}

.register-page-lead {
  font-size: 0.85rem;
  line-height: 1.5;
  text-align: center;
  color: rgba(255, 255, 255, 0.88);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  margin-bottom: 1rem;
}

.register-page-panel {
  margin-bottom: 0;
}

.register-avatar-field {
  margin-bottom: 0.25rem;
  text-align: center;
}

.register-avatar-field > .register-label {
  display: block;
  text-align: center;
}

.register-avatar-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.register-avatar-preview {
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, rgba(74, 20, 140, 0.35), rgba(255, 152, 0, 0.25));
  border: 2px solid rgba(255, 215, 0, 0.45);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.register-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.register-avatar-img.hidden {
  display: none;
}

.register-avatar-initial {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: #5d4037;
}

.register-avatar-initial.hidden {
  display: none;
}

.register-avatar-icon {
  display: block;
  width: 52%;
  height: 52%;
}

.register-avatar-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: center;
}

.btn-register-avatar,
.btn-register-avatar-remove {
  font-size: 0.8rem;
  padding: 0.45rem 0.75rem;
}

.register-avatar-field > .register-hint {
  display: block;
  text-align: center;
}

.register-success-avatar-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.register-success-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 215, 0, 0.5);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.menu-register.register-page-panel .register-avatar-preview {
  background: rgba(0, 0, 0, 0.25);
  border-color: rgba(255, 215, 0, 0.5);
}

.menu-register.register-page-panel .register-avatar-initial {
  color: #fff9c4;
}

.login-switch {
  margin: 1rem 0 0;
  font-size: 0.85rem;
  text-align: center;
  color: rgba(255, 255, 255, 0.82);
}

.login-switch-link {
  font-family: inherit;
  font-size: inherit;
  font-weight: 800;
  color: #90caf9;
  background: none;
  border: none;
  padding: 0;
  margin: 0 0 0 0.25rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

@media (hover: hover) {
  .login-switch-link:hover {
    color: #bbdefb;
  }
}

.menu-player-bar {
  width: 100%;
  margin-bottom: 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.menu-player-status {
  font-size: 0.8rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  margin: 0;
}

.menu-player-status.hidden {
  display: none;
}

.menu-player-actions {
  width: 100%;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.4rem;
}

.btn-sign-out {
  font-family: 'Bangers', cursive;
  font-size: 1.15rem;
  letter-spacing: 0.05em;
  width: 100%;
  padding: 0.7rem 1.35rem;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  background: linear-gradient(180deg, #ef5350 0%, #c62828 100%);
  color: #fff;
  box-shadow: 0 4px 0 #b71c1c, 0 6px 16px rgba(198, 40, 40, 0.45);
  transition: transform 0.15s;
}

.btn-sign-out.hidden {
  display: none;
}

.btn-sign-out:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #b71c1c;
}

@media (hover: hover) {
  .btn-sign-out:hover {
    filter: brightness(1.06);
  }
}

.btn-menu-support {
  position: relative;
  font-family: 'Bangers', cursive;
  font-size: 1.15rem;
  letter-spacing: 0.05em;
  width: 100%;
  max-width: 280px;
  padding: 0.7rem 1.35rem;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  background: linear-gradient(180deg, #ffb74d 0%, #ef6c00 100%);
  color: #fff;
  box-shadow: 0 4px 0 #e65100, 0 6px 16px rgba(239, 108, 0, 0.45);
  transition: transform 0.15s;
}

.btn-menu-support-badge {
  position: absolute;
  top: -0.35rem;
  right: -0.35rem;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: #d32f2f;
  color: #fff;
  font-family: 'Nunito', sans-serif;
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 1.35rem;
  text-align: center;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.btn-menu-support-badge.hidden {
  display: none;
}

.btn-menu-support:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #e65100;
}

@media (hover: hover) {
  .btn-menu-support:hover {
    filter: brightness(1.06);
  }
}

.btn-login {
  font-family: 'Bangers', cursive;
  font-size: 1.15rem;
  letter-spacing: 0.05em;
  width: 100%;
  max-width: 280px;
  padding: 0.7rem 1.35rem;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  background: linear-gradient(180deg, #81c784 0%, #2e7d32 100%);
  color: #fff;
  box-shadow: 0 4px 0 #1b5e20, 0 6px 16px rgba(46, 125, 50, 0.45);
  transition: transform 0.15s;
}

.btn-login.hidden {
  display: none;
}

.btn-login:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #1b5e20;
}

@media (hover: hover) {
  .btn-login:hover {
    filter: brightness(1.06);
  }
}

.btn-signup {
  font-family: 'Bangers', cursive;
  font-size: 1.15rem;
  letter-spacing: 0.05em;
  width: 100%;
  max-width: 280px;
  padding: 0.7rem 1.35rem;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  background: linear-gradient(180deg, #64b5f6 0%, #1565c0 100%);
  color: #fff;
  box-shadow: 0 4px 0 #0d47a1, 0 6px 16px rgba(21, 101, 192, 0.45);
  transition: transform 0.15s;
}

.btn-signup:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #0d47a1;
}

.settings-page-panel {
  width: 100%;
  margin-bottom: 0;
}

.howto-content {
  text-align: left;
}

.legend-content {
  width: min(100%, 520px);
  text-align: center;
}

.legend-tagline {
  font-family: 'Nunito', sans-serif;
  font-size: 0.88rem;
  font-weight: 700;
  color: rgba(255, 235, 59, 0.9);
  margin: -0.2rem 0 0.85rem;
  letter-spacing: 0.03em;
}

.legend-comic-wrap {
  margin: 0 0 0.65rem;
  border-radius: 14px;
  overflow: hidden;
  border: 3px solid rgba(255, 215, 0, 0.45);
  box-shadow:
    0 8px 28px rgba(0, 0, 0, 0.5),
    0 0 24px rgba(255, 193, 7, 0.15);
  background: rgba(0, 0, 0, 0.25);
  touch-action: pan-y pinch-zoom;
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
}

.legend-comic-wrap.is-swiping {
  cursor: grabbing;
}

.legend-comic-img {
  display: block;
  width: 100%;
  height: auto;
  vertical-align: top;
  transition: opacity 0.2s ease;
  pointer-events: none;
  -webkit-user-drag: none;
  user-drag: none;
}

.legend-comic-img.legend-slide-fade {
  opacity: 0.35;
}

.legend-slideshow-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  margin: 0 0 1rem;
  flex-wrap: wrap;
}

.btn-legend-nav {
  font-family: 'Nunito', sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.45rem 0.75rem;
  border-radius: 10px;
  border: 2px solid rgba(255, 215, 0, 0.65);
  background: linear-gradient(180deg, rgba(74, 20, 140, 0.95) 0%, rgba(26, 10, 46, 0.98) 100%);
  color: #fff9c4;
  cursor: pointer;
  touch-action: manipulation;
  min-width: 5.5rem;
}

.btn-legend-nav:hover:not(:disabled) {
  border-color: #ffeb3b;
  box-shadow: 0 0 12px rgba(255, 235, 59, 0.35);
}

.btn-legend-nav:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-legend-nav:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.legend-slide-counter {
  font-family: 'Bangers', cursive;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  color: var(--gold);
  min-width: 3.5rem;
  text-align: center;
}

.legend-footer {
  font-family: 'Bangers', cursive;
  font-size: clamp(1rem, 4.5vw, 1.2rem);
  color: var(--gold);
  letter-spacing: 0.06em;
  text-shadow: 0 2px 0 #5d4037;
  margin-bottom: 0.5rem;
}

.leaderboard-content {
  text-align: center;
}

.leaderboard-subtitle {
  font-size: 0.85rem;
  opacity: 0.8;
  margin: -0.5rem 0 1rem;
}

.leaderboard-status {
  font-size: 0.9rem;
  margin: 0.5rem 0 1rem;
  color: rgba(255, 255, 255, 0.75);
}

.leaderboard-status.hidden {
  display: none;
}

.leaderboard-error {
  color: #ff8a80;
}

.leaderboard-list {
  list-style: none;
  width: 100%;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: min(52vh, 420px);
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.leaderboard-list::-webkit-scrollbar {
  display: none;
}

.leaderboard-item {
  display: grid;
  grid-template-columns: 2.25rem 2.5rem 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 215, 0, 0.25);
  border-radius: 12px;
  text-align: left;
}

.leaderboard-avatar {
  flex-shrink: 0;
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Nunito', sans-serif;
  font-size: 0.95rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #7c4dff, #512da8);
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.leaderboard-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.leaderboard-item.is-me .leaderboard-avatar {
  border-color: rgba(144, 202, 249, 0.85);
  box-shadow: 0 0 10px rgba(66, 165, 245, 0.45);
}

.leaderboard-item.rank-1 .leaderboard-avatar {
  border-color: rgba(255, 215, 0, 0.85);
}

.leaderboard-item.is-me {
  border-color: rgba(66, 165, 245, 0.75);
  background: rgba(66, 165, 245, 0.15);
  box-shadow: 0 0 12px rgba(66, 165, 245, 0.35);
}

.leaderboard-item.rank-1 {
  border-color: rgba(255, 215, 0, 0.85);
  background: linear-gradient(90deg, rgba(255, 215, 0, 0.2), rgba(255, 255, 255, 0.06));
}

.leaderboard-item.rank-2 {
  border-color: rgba(192, 192, 192, 0.7);
}

.leaderboard-item.rank-3 {
  border-color: rgba(205, 127, 50, 0.75);
}

.leaderboard-rank {
  font-family: 'Bangers', cursive;
  font-size: 1.35rem;
  color: var(--gold);
  text-align: center;
  line-height: 1;
}

.leaderboard-name {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 800;
  font-size: 0.95rem;
  min-width: 0;
}

.leaderboard-name-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.leaderboard-flag {
  flex-shrink: 0;
  width: 1.35rem;
  height: 1rem;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.leaderboard-meta {
  font-size: 0.65rem;
  opacity: 0.7;
  margin-top: 0.1rem;
}

.leaderboard-points {
  font-family: 'Bangers', cursive;
  font-size: 1.35rem;
  color: #fff9c4;
  text-shadow: 0 2px 0 #5d4037;
  white-space: nowrap;
}

.howto-title {
  font-family: 'Bangers', cursive;
  font-size: clamp(2rem, 8vw, 2.75rem);
  color: var(--gold);
  text-align: center;
  margin-bottom: 1rem;
  letter-spacing: 0.05em;
  text-shadow: 0 2px 0 #5d4037;
}

.menu-rules.howto-rules {
  margin-bottom: 1rem;
  background: linear-gradient(
    135deg,
    rgba(74, 20, 140, 0.9) 0%,
    rgba(49, 27, 146, 0.88) 45%,
    rgba(13, 27, 62, 0.94) 100%
  );
  border: 2px solid rgba(255, 215, 0, 0.45);
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.howto-content > .howto-rules:nth-of-type(1) {
  background: linear-gradient(
    135deg,
    rgba(74, 20, 140, 0.92) 0%,
    rgba(106, 27, 154, 0.85) 42%,
    rgba(26, 35, 126, 0.94) 100%
  );
  border-color: rgba(255, 215, 0, 0.5);
}

.howto-content > .howto-rules:nth-of-type(2) {
  background: linear-gradient(
    135deg,
    rgba(21, 101, 192, 0.9) 0%,
    rgba(49, 27, 146, 0.86) 48%,
    rgba(13, 27, 62, 0.94) 100%
  );
  border-color: rgba(100, 181, 246, 0.5);
}

.howto-content > .howto-rules:nth-of-type(3) {
  background: linear-gradient(
    135deg,
    rgba(183, 28, 28, 0.82) 0%,
    rgba(106, 27, 154, 0.86) 45%,
    rgba(26, 35, 126, 0.94) 100%
  );
  border-color: rgba(255, 152, 0, 0.55);
}

.howto-content > .howto-rules:nth-of-type(4) {
  background: linear-gradient(
    135deg,
    rgba(0, 105, 92, 0.88) 0%,
    rgba(46, 125, 50, 0.78) 40%,
    rgba(26, 35, 126, 0.92) 100%
  );
  border-color: rgba(105, 240, 174, 0.45);
}

.howto-special-intro {
  margin: 0 0 0.85rem;
  font-family: 'Nunito', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.92);
}

.howto-powerup-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.howto-powerup-list li::before {
  display: none;
}

.howto-powerup-item {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.55rem 0.6rem;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.howto-powerup-steal {
  border-color: rgba(244, 67, 54, 0.35);
}

.howto-powerup-any-number {
  border-color: rgba(255, 193, 7, 0.35);
}

.howto-powerup-targeted {
  border-color: rgba(255, 87, 34, 0.35);
}

.howto-powerup-insight {
  border-color: rgba(186, 104, 200, 0.35);
}

.howto-powerup-attack {
  border-color: rgba(229, 57, 53, 0.4);
}

.howto-powerup-any-special {
  border-color: rgba(255, 193, 7, 0.5);
}

.howto-powerup-greedy {
  border-color: rgba(255, 196, 0, 0.45);
}

.howto-powerup-img {
  flex-shrink: 0;
  width: clamp(52px, 14vw, 64px);
  height: auto;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}

.howto-powerup-img.howto-zoomable {
  cursor: zoom-in;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.howto-powerup-img.howto-zoomable:hover,
.howto-powerup-img.howto-zoomable:focus-visible {
  transform: scale(1.06);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  outline: none;
}

.howto-powerup-body {
  min-width: 0;
}

.howto-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(4, 8, 20, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.howto-lightbox.open {
  display: flex;
  animation: howtoLightboxFade 0.18s ease;
}

@keyframes howtoLightboxFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.howto-lightbox-figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: howtoLightboxPop 0.2s ease;
}

@keyframes howtoLightboxPop {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.howto-lightbox-img {
  max-width: min(78vw, 360px);
  max-height: 72vh;
  width: auto;
  height: auto;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
}

.howto-lightbox-caption {
  color: #fff;
  font-weight: 700;
  font-size: clamp(1rem, 4vw, 1.3rem);
  letter-spacing: 0.02em;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

.howto-lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.15s ease;
}

.howto-lightbox-close:hover,
.howto-lightbox-close:focus-visible {
  background: rgba(255, 255, 255, 0.28);
  transform: scale(1.08);
  outline: none;
}

.howto-powerup-name {
  display: block;
  font-family: 'Bangers', cursive;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  color: #ffe082;
  margin-bottom: 0.2rem;
}

.howto-powerup-body p {
  margin: 0;
  font-family: 'Nunito', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.42;
  color: rgba(255, 255, 255, 0.88);
}

.howto-powerup-body p strong {
  color: #fff9c4;
}

.menu-rules.howto-rules h2 {
  font-size: 1.2rem;
  color: #fff9c4;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.55);
  margin-bottom: 0.65rem;
}

.menu-rules.howto-rules ul {
  color: rgba(255, 255, 255, 0.92);
}

.menu-rules.howto-rules li {
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.menu-rules.howto-rules strong {
  color: #ffe082;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.btn-howto {
  font-family: 'Bangers', cursive;
  font-size: 1.1rem;
  letter-spacing: 0.05em;
  width: 100%;
  max-width: 280px;
  margin: 0 auto 1rem;
  padding: 0.65rem 1.25rem;
  border-radius: 50px;
  border: 2px solid rgba(255, 215, 0, 0.5);
  background: rgba(255, 255, 255, 0.1);
  color: var(--gold);
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}

.btn-howto:active {
  transform: scale(0.98);
  background: rgba(255, 215, 0, 0.15);
}

.btn-back {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: fit-content;
  max-width: 100%;
  align-self: flex-start;
  min-height: 44px;
  padding: 0.45rem 1rem 0.45rem 0.5rem;
  margin: 0 0 0.85rem;
  margin-right: auto;
  border: 2px solid rgba(255, 215, 0, 0.55);
  border-radius: 50px;
  background: linear-gradient(165deg, rgba(74, 20, 140, 0.55) 0%, rgba(26, 10, 46, 0.85) 100%);
  color: #fff8e1;
  font-family: 'Bangers', cursive;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(74, 20, 140, 0.7), 0 5px 14px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-back-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255, 235, 59, 0.35) 0%, rgba(245, 158, 11, 0.3) 100%);
  color: var(--gold);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn-back-icon svg {
  display: block;
  margin-left: -2px;
}

.btn-back-label {
  padding-right: 0.15rem;
  line-height: 1;
}

.btn-back:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(74, 20, 140, 0.7);
}

@media (hover: hover) {
  .btn-back:hover {
    border-color: rgba(255, 235, 59, 0.85);
    box-shadow: 0 5px 0 rgba(74, 20, 140, 0.7), 0 8px 18px rgba(255, 215, 0, 0.25);
    transform: translateY(-1px);
  }

  .btn-back:hover .btn-back-icon {
    background: linear-gradient(180deg, rgba(255, 235, 59, 0.55) 0%, rgba(245, 158, 11, 0.45) 100%);
  }
}

.menu-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: url('../assets/ui/menu-bg-art.png') center / cover no-repeat;
  opacity: 0.38;
}

.menu-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(var(--safe-top) + 1rem) 1.25rem calc(var(--safe-bottom) + 0.5rem);
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  width: min(100%, 420px);
  text-align: center;
  flex: 1 1 auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.menu-content::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.menu-logo-wrap {
  margin: 0 0 0.5rem;
  padding: 0;
  line-height: 0;
  width: clamp(200px, 72vw, 320px);
  overflow: visible;
}

.menu-logo-stage {
  position: relative;
  display: block;
  width: 100%;
  line-height: 0;
}

.logo-volt-fx {
  position: absolute;
  inset: -8% -12%;
  z-index: 2;
  pointer-events: none;
  overflow: visible;
}

.logo-bolt {
  position: absolute;
  color: #e0f7ff;
  filter: drop-shadow(0 0 6px #00e5ff) drop-shadow(0 0 14px #fff59d);
  opacity: 0;
  transform-origin: center center;
}

.logo-bolt--left {
  left: -4%;
  top: 18%;
  width: 22%;
  height: auto;
  transform: rotate(-12deg) scale(0.85);
  animation: bolt-strike-left 2.8s ease-in-out infinite;
}

.logo-bolt--right {
  right: -4%;
  top: 22%;
  width: 22%;
  height: auto;
  transform: rotate(12deg) scaleX(-1) scale(0.9);
  animation: bolt-strike-right 3.1s ease-in-out infinite;
  animation-delay: 0.9s;
}

.logo-bolt--top {
  left: 50%;
  top: -2%;
  width: 28%;
  height: auto;
  transform: translateX(-50%) rotate(8deg);
  animation: bolt-strike-top 3.4s ease-in-out infinite;
  animation-delay: 1.6s;
}

.logo-spark {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, #80deea 45%, transparent 70%);
  box-shadow: 0 0 8px #00e5ff, 0 0 16px #fff59d;
  opacity: 0;
  animation: spark-pop 2.4s ease-out infinite;
}

.logo-spark--1 { left: 8%; top: 35%; animation-delay: 0.2s; }
.logo-spark--2 { right: 10%; top: 42%; animation-delay: 1.1s; }
.logo-spark--3 { left: 42%; top: 8%; animation-delay: 1.9s; }
.logo-spark--4 { right: 28%; bottom: 18%; animation-delay: 2.5s; }

.logo-thunder-flash {
  position: absolute;
  inset: 5%;
  z-index: 1;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle, rgba(224, 247, 255, 0.55) 0%, rgba(0, 229, 255, 0.2) 35%, transparent 65%);
  opacity: 0;
  animation: thunder-flash 2.8s ease-out infinite;
}

.menu-logo {
  position: relative;
  z-index: 3;
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 10px 28px rgba(255, 215, 0, 0.45));
  animation: float 3s ease-in-out infinite, logo-volt-glow 2.8s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes logo-volt-glow {
  0%, 88%, 100% {
    filter: drop-shadow(0 10px 28px rgba(255, 215, 0, 0.45));
  }
  90%, 94% {
    filter:
      drop-shadow(0 0 18px rgba(0, 229, 255, 0.95))
      drop-shadow(0 0 32px rgba(255, 241, 118, 0.85))
      drop-shadow(0 12px 28px rgba(255, 215, 0, 0.55));
  }
  92% {
    filter:
      drop-shadow(0 0 28px rgba(255, 255, 255, 1))
      drop-shadow(0 0 40px rgba(0, 229, 255, 0.9))
      drop-shadow(0 12px 28px rgba(255, 215, 0, 0.6));
  }
}

@keyframes bolt-strike-left {
  0%, 82%, 100% { opacity: 0; transform: rotate(-12deg) scale(0.85); }
  83% { opacity: 0.15; }
  84%, 86% { opacity: 1; transform: rotate(-8deg) scale(1); }
  87% { opacity: 0.35; }
  88%, 100% { opacity: 0; transform: rotate(-12deg) scale(0.85); }
}

@keyframes bolt-strike-right {
  0%, 78%, 100% { opacity: 0; }
  79% { opacity: 0.2; }
  80%, 82% { opacity: 1; transform: rotate(12deg) scaleX(-1) scale(1.05); }
  83% { opacity: 0.4; }
  84%, 100% { opacity: 0; transform: rotate(12deg) scaleX(-1) scale(0.9); }
}

@keyframes bolt-strike-top {
  0%, 85%, 100% { opacity: 0; transform: translateX(-50%) rotate(8deg) scale(0.9); }
  86%, 88% { opacity: 1; transform: translateX(-50%) rotate(4deg) scale(1.08); }
  89% { opacity: 0.25; }
  90%, 100% { opacity: 0; transform: translateX(-50%) rotate(8deg) scale(0.9); }
}

@keyframes spark-pop {
  0%, 90%, 100% { opacity: 0; transform: scale(0); }
  91% { opacity: 1; transform: scale(1.4); }
  93% { opacity: 0.6; transform: scale(0.6); }
  95%, 100% { opacity: 0; transform: scale(0); }
}

@keyframes thunder-flash {
  0%, 88%, 100% { opacity: 0; }
  89% { opacity: 0.85; }
  90% { opacity: 0.35; }
  91% { opacity: 0.7; }
  92%, 100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .menu-logo {
    animation: float 3s ease-in-out infinite;
  }

  .logo-bolt,
  .logo-spark,
  .logo-thunder-flash {
    animation: none;
    opacity: 0;
  }
}

.menu-tagline {
  font-size: clamp(0.85rem, 3.5vw, 1rem);
  opacity: 0.85;
  margin-bottom: 1rem;
}

.menu-rules {
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 215, 0, 0.35);
  border-radius: 16px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  text-align: left;
  width: 100%;
}

.menu-rules h2 {
  font-family: 'Bangers', cursive;
  font-size: 1.4rem;
  color: var(--gold);
  margin-bottom: 0.5rem;
  letter-spacing: 1px;
}

.menu-rules ul {
  list-style: none;
  font-size: clamp(0.8rem, 3vw, 0.9rem);
  line-height: 1.6;
}

.menu-rules li {
  padding-left: 1.2rem;
  position: relative;
  margin-bottom: 0.35rem;
}

.menu-rules li::before {
  content: '⭐';
  position: absolute;
  left: 0;
  font-size: 0.7rem;
}

.menu-rules strong {
  color: var(--gold);
}

/* Buttons */
.btn-primary, .btn-secondary {
  font-family: 'Bangers', cursive;
  font-size: clamp(1.2rem, 5vw, 1.6rem);
  letter-spacing: 1px;
  border: none;
  border-radius: 50px;
  padding: 0.85rem 2rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  width: 100%;
  max-width: 280px;
  margin-bottom: 0.6rem;
}

.btn-primary {
  background: linear-gradient(180deg, #ffeb3b 0%, var(--gold-dark) 50%, #e65100 100%);
  color: #4a148c;
  box-shadow: 0 6px 0 #bf360c, 0 8px 20px rgba(255, 111, 0, 0.5);
}

.btn-primary:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #bf360c;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.12);
  color: var(--white);
  border: 2px solid rgba(255, 255, 255, 0.3);
  font-size: 1rem;
  padding: 0.6rem 1.5rem;
}

.menu-sound-toggle {
  width: 100%;
  max-width: 280px;
  margin-bottom: 0.4rem;
}

.menu-bottom-actions {
  width: 100%;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.menu-bottom-actions.hidden {
  display: none;
}

.menu-bottom-actions .btn-menu-support,
.menu-bottom-actions .btn-sign-out {
  max-width: none;
}

.btn-menu-support.hidden {
  display: none;
}

.btn-icon {
  margin-right: 0.3rem;
}

/* Menu play modes */
.menu-play-modes {
  width: 100%;
  margin-bottom: 0.75rem;
}

.menu-mode-hint {
  font-size: 0.72rem;
  opacity: 0.7;
  margin-top: 0.35rem;
  line-height: 1.4;
}

.btn-mode {
  font-family: 'Bangers', cursive;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  border: none;
  border-radius: 50px;
  padding: 0.75rem 1.25rem;
  cursor: pointer;
  width: 100%;
  max-width: 280px;
  margin: 0 auto 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: transform 0.15s;
}

.btn-mode:active {
  transform: translateY(3px);
}

.btn-mode-ai {
  background: linear-gradient(180deg, #ce93d8 0%, #7b1fa2 100%);
  color: #fff;
  box-shadow: 0 4px 0 #4a148c;
}

.btn-mode-lobby {
  background: linear-gradient(180deg, #80deea 0%, #00838f 100%);
  color: #fff;
  box-shadow: 0 4px 0 #006064;
}

.btn-mode-friends {
  background: linear-gradient(180deg, #ff8a80 0%, #c62828 100%);
  color: #fff;
  box-shadow: 0 4px 0 #8e0000;
}

.btn-mode-campaign {
  background: linear-gradient(180deg, #ffd54f 0%, #ef6c00 100%);
  color: #4a148c;
  box-shadow: 0 4px 0 #b53d00;
}

/* ===== CAMPAIGN SCREEN (level-map style) ===== */
.campaign-content {
  text-align: center;
}

.campaign-subtitle {
  font-size: 0.85rem;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.82);
  margin: -0.4rem 0 0.85rem;
}

.campaign-tiers {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.9rem;
}

.campaign-tier-chip {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.45rem 0.3rem;
  border-radius: 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 0.62rem;
  line-height: 1.2;
  color: rgba(255, 255, 255, 0.9);
}

.campaign-tier-chip strong {
  font-size: 0.72rem;
}

.campaign-tier-chip.campaign-tier-1 {
  background: linear-gradient(160deg, rgba(66, 165, 245, 0.3), rgba(21, 101, 192, 0.18));
  border-color: rgba(100, 181, 246, 0.5);
}

.campaign-tier-chip.campaign-tier-2 {
  background: linear-gradient(160deg, rgba(102, 187, 106, 0.3), rgba(46, 125, 50, 0.18));
  border-color: rgba(129, 199, 132, 0.5);
}

.campaign-tier-chip.campaign-tier-3 {
  background: linear-gradient(160deg, rgba(186, 104, 200, 0.32), rgba(123, 31, 162, 0.2));
  border-color: rgba(206, 147, 216, 0.55);
}

/* The map area: warm "ground" with a winding stone trail and diamond nodes. */
.campaign-levels {
  position: relative;
  width: 100%;
  border-radius: 18px;
  overflow: hidden;
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 236, 200, 0.5), transparent 42%),
    radial-gradient(circle at 78% 72%, rgba(255, 184, 168, 0.4), transparent 46%),
    linear-gradient(165deg, #f0d9b1 0%, #e7b58f 48%, #d98c8c 100%);
  box-shadow: inset 0 0 0 4px rgba(120, 72, 48, 0.45), inset 0 0 40px rgba(120, 60, 40, 0.25);
}

/* Faded artwork behind the trail & nodes. */
.campaign-levels::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: url('../assets/backgrounds/campaign-map.png') top center / cover no-repeat;
  opacity: 0.3;
}

/* SVG trail */
.campaign-trail {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.campaign-trail-edge {
  stroke: rgba(90, 60, 40, 0.45);
}

.campaign-trail-fill {
  stroke: #c9b08a;
}

.campaign-trail-dots {
  stroke: rgba(255, 255, 255, 0.45);
  stroke-linecap: round;
}

/* Diamond level node — positioned by JS (left/top = its centre). */
.campaign-level {
  --node: 58px;
  --gem-h: 210;
  --gem-light: hsl(var(--gem-h, 210), 92%, 80%);
  --gem: hsl(var(--gem-h, 210), 82%, 60%);
  --gem-dark: hsl(var(--gem-h, 210), 72%, 45%);
  --gem-frame: hsl(var(--gem-h, 210), 66%, 35%);
  --clip: none;
  --round: 24%;
  position: absolute;
  width: var(--node);
  height: var(--node);
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  color: #1f1430;
  font-family: 'Bangers', cursive;
  letter-spacing: 0.02em;
}

/* Per-level shape: clip-path silhouette (+ corner rounding for circle/square). */
.campaign-level[data-shape="diamond"]  { --clip: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); --round: 0; }
.campaign-level[data-shape="circle"]   { --clip: none; --round: 50%; }
.campaign-level[data-shape="square"]   { --clip: none; --round: 26%; }
.campaign-level[data-shape="hexagon"]  { --clip: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%); --round: 0; }
.campaign-level[data-shape="pentagon"] { --clip: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%); --round: 0; }
.campaign-level[data-shape="octagon"]  { --clip: polygon(30% 0%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%); --round: 0; }
.campaign-level[data-shape="star"]     { --clip: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); --round: 0; }
.campaign-level[data-shape="triangle"] { --clip: polygon(50% 4%, 100% 100%, 0% 100%); --round: 0; }

/* The gem face. Shape comes from --clip / --round, colour from --gem-* vars. */
.campaign-diamond {
  position: absolute;
  inset: 0;
  border-radius: var(--round, 24%);
  clip-path: var(--clip, none);
  background: linear-gradient(150deg,
    var(--gem-light, #fff4d6) 0%,
    var(--gem, #ffe7a8) 52%,
    var(--gem-dark, #f4cf86) 100%);
  transition: transform 0.12s ease, filter 0.12s ease;
}

/* Glossy highlight that follows whatever shape the level uses. */
.campaign-diamond::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  clip-path: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 55%);
  pointer-events: none;
}

/* Coloured outer frame: a slightly larger copy of the shape behind the face. */
.campaign-level::before {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: var(--round, 24%);
  clip-path: var(--clip, none);
  z-index: -1;
  background: var(--gem-frame, #2d6fd6);
  filter: drop-shadow(0 5px 9px rgba(0, 0, 0, 0.38));
}

.campaign-level-inner {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  pointer-events: none;
}

.campaign-level-num {
  font-size: calc(var(--node, 58px) * 0.46);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}

.campaign-level-time {
  font-family: 'Nunito', sans-serif;
  font-size: calc(var(--node, 58px) * 0.17);
  font-weight: 800;
  margin-top: 1px;
  opacity: 0.7;
}

/* Three stars beneath cleared levels. */
.campaign-level-stars {
  position: absolute;
  bottom: calc(var(--node, 58px) * -0.3);
  left: 50%;
  transform: translateX(-50%);
  font-size: calc(var(--node, 58px) * 0.2);
  letter-spacing: -1px;
  white-space: nowrap;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.45));
  pointer-events: none;
}

/* Locked levels: keep the level's own shape & hue, but muted, with a padlock. */
.campaign-level.is-locked {
  cursor: not-allowed;
  color: rgba(30, 25, 45, 0.78);
}

.campaign-level.is-locked .campaign-diamond {
  filter: grayscale(0.5) brightness(0.92);
  opacity: 0.82;
}

.campaign-level.is-locked::before {
  filter: grayscale(0.55) brightness(0.78) drop-shadow(0 4px 7px rgba(0, 0, 0, 0.35));
  opacity: 0.85;
}

.campaign-level.is-locked .campaign-level-num {
  font-size: calc(var(--node, 58px) * 0.38);
}

.campaign-level:not(:disabled):hover .campaign-diamond {
  transform: scale(1.09);
  filter: brightness(1.08);
}

.campaign-level:not(:disabled):active .campaign-diamond {
  transform: scale(0.95);
}

/* Current level: pulsing gold rim around its shape. */
.campaign-level.is-current::before {
  background: linear-gradient(150deg, #ffe98a, #f5b301);
  inset: -6px;
  animation: campaign-current-pulse 1.7s ease-in-out infinite;
}

@keyframes campaign-current-pulse {
  0%, 100% {
    filter: drop-shadow(0 0 4px rgba(255, 215, 0, 0.55)) drop-shadow(0 5px 9px rgba(0, 0, 0, 0.38));
  }
  50% {
    filter: drop-shadow(0 0 15px rgba(255, 215, 0, 0.95)) drop-shadow(0 5px 9px rgba(0, 0, 0, 0.38));
  }
}

/* Avatar marker hovering above the current level (like the reference map). */
.campaign-marker {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  pointer-events: none;
  animation: campaign-marker-bob 2s ease-in-out infinite;
}

.campaign-marker-frame {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(34px, calc(var(--node, 58px) * 0.82), 50px);
  height: clamp(34px, calc(var(--node, 58px) * 0.82), 50px);
  border-radius: 10px;
  background: linear-gradient(160deg, #fff0c0, #f3c969);
  border: 3px solid #d8a23a;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.35);
  overflow: visible;
  font-size: 1.4rem;
}

.campaign-marker-frame::after {
  content: "";
  position: absolute;
  bottom: -9px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 9px solid #d8a23a;
}

.campaign-marker-avatar {
  width: 100%;
  height: 100%;
  border-radius: 7px;
  object-fit: cover;
}

.campaign-marker-heart {
  position: absolute;
  right: -8px;
  bottom: -6px;
  font-size: 0.85rem;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4));
}

@keyframes campaign-marker-bob {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-4px); }
}

@media (prefers-reduced-motion: reduce) {
  .campaign-level.is-current::before,
  .campaign-marker {
    animation: none;
  }
}

.btn-mode-local {
  background: linear-gradient(180deg, #ffeb3b 0%, var(--gold-dark) 50%, #e65100 100%);
  color: #4a148c;
  box-shadow: 0 4px 0 #bf360c;
}

.btn-continue {
  background: linear-gradient(180deg, #69f0ae 0%, #00c853 50%, #1b5e20 100%);
  color: #1b5e20;
  box-shadow: 0 4px 0 #2e7d32;
  margin-top: 0.35rem;
}

.btn-continue.hidden {
  display: none;
}

.menu-continue-hint {
  font-size: 0.72rem;
  text-align: center;
  color: rgba(255, 255, 255, 0.75);
  margin: 0.25rem 0 0;
}

.menu-continue-hint.hidden {
  display: none;
}

.match-history-list {
  gap: 0.65rem;
  max-height: min(58vh, 480px);
}

.match-history-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.75rem 0.85rem;
  background: linear-gradient(135deg, rgba(26, 14, 46, 0.95) 0%, rgba(13, 27, 62, 0.92) 100%);
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  text-align: left;
  list-style: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.match-history-item.match-won {
  border-color: rgba(105, 240, 174, 0.55);
  background: linear-gradient(
    135deg,
    rgba(27, 94, 32, 0.92) 0%,
    rgba(46, 125, 50, 0.78) 38%,
    rgba(26, 35, 126, 0.88) 100%
  );
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(185, 246, 202, 0.2);
}

.match-history-item.match-lost {
  border-color: rgba(255, 138, 128, 0.5);
  background: linear-gradient(
    135deg,
    rgba(136, 14, 79, 0.9) 0%,
    rgba(183, 28, 28, 0.78) 42%,
    rgba(26, 35, 126, 0.9) 100%
  );
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 205, 210, 0.15);
}

.match-history-result {
  flex: 0 0 3.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  padding: 0.35rem 0.2rem;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0.62));
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.match-won .match-history-result {
  background: linear-gradient(180deg, rgba(27, 94, 32, 0.75), rgba(0, 0, 0, 0.55));
  border-color: rgba(185, 246, 202, 0.35);
}

.match-lost .match-history-result {
  background: linear-gradient(180deg, rgba(183, 28, 28, 0.72), rgba(0, 0, 0, 0.55));
  border-color: rgba(255, 138, 128, 0.35);
}

.match-history-result-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.match-lost .match-history-result-icon {
  font-size: 1rem;
  font-weight: 800;
  color: #ff8a80;
}

.match-history-result-label {
  font-family: 'Bangers', cursive;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1;
  color: #ffffff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}

.match-won .match-history-result-label {
  color: #e8f5e9;
}

.match-lost .match-history-result-label {
  color: #ffcdd2;
}

.match-history-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
}

.match-history-players {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
  width: 100%;
  min-width: 0;
}

.match-history-player-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  min-width: 0;
  flex: 1 1 0;
  max-width: 44%;
}

button.match-history-player-chip-btn {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  border-radius: 12px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

button.match-history-player-chip-btn:hover,
button.match-history-player-chip-btn:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 0 0 2px rgba(255, 183, 77, 0.55);
  outline: none;
}

button.match-history-player-chip-btn:active {
  transform: translateY(0);
}

.match-history-vs {
  flex: 0 0 auto;
  align-self: center;
  margin-bottom: 1.15rem;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.72);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.match-history-avatar {
  flex-shrink: 0;
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Nunito', sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #7c4dff, #512da8);
  border: 2px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.28);
}

.match-history-avatar.is-you {
  border-color: rgba(144, 202, 249, 0.78);
  box-shadow: 0 0 8px rgba(66, 165, 245, 0.35);
}

.match-history-avatar.is-opponent {
  border-color: rgba(255, 183, 77, 0.78);
  box-shadow: 0 0 8px rgba(255, 152, 0, 0.28);
}

.match-history-avatar-ai {
  font-size: 1rem;
  line-height: 1;
  background: linear-gradient(135deg, #546e7a, #263238);
}

.match-history-avatar-default {
  color: #5d4037;
  background: #efebe9;
}

.match-history-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.match-history-avatar-icon {
  display: block;
  width: 58%;
  height: 58%;
}

.match-history-player-name {
  width: 100%;
  font-size: 0.58rem;
  font-weight: 800;
  line-height: 1.15;
  color: rgba(255, 255, 255, 0.92);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.match-history-opponent-panel .match-history-opponent-profile {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin: 0.5rem 0 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.match-history-opponent-profile-avatar {
  flex: 0 0 3rem;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #7c4dff, #512da8);
  border: 2px solid rgba(255, 183, 77, 0.65);
}

.match-history-opponent-profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.match-history-opponent-profile-name {
  margin: 0;
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
}

.match-history-opponent-profile-meta {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.78);
}

.match-history-opponent-lead {
  margin-top: 0;
}

.match-history-opponent-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin: 0.75rem 0 0.35rem;
}

.match-history-opponent-add-btn {
  min-width: 9rem;
}

.match-history-opponent-loading {
  margin: 0;
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.75);
  text-align: center;
}

.match-history-opponent {
  font-weight: 800;
  font-size: 0.92rem;
  line-height: 1.2;
  color: #ffffff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.match-history-mode-pill {
  display: inline-flex;
  align-items: center;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #f5f5f5;
}

.match-history-meta {
  font-size: 0.62rem;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.82);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.match-history-scores {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.05rem;
  min-width: 3.25rem;
  padding: 0.35rem 0.45rem;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.42), rgba(0, 0, 0, 0.62));
  border: 1px solid rgba(255, 215, 0, 0.28);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.match-won .match-history-scores {
  border-color: rgba(185, 246, 202, 0.45);
  background: linear-gradient(180deg, rgba(27, 94, 32, 0.55), rgba(0, 0, 0, 0.58));
}

.match-lost .match-history-scores {
  border-color: rgba(255, 171, 145, 0.45);
  background: linear-gradient(180deg, rgba(136, 14, 79, 0.5), rgba(0, 0, 0, 0.58));
}

.match-history-score-you,
.match-history-score-opp {
  font-family: 'Bangers', cursive;
  font-size: 1.25rem;
  line-height: 1;
}

.match-history-score-you {
  color: #ffe082;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.match-won .match-history-score-you {
  color: #e8f5e9;
}

.match-lost .match-history-score-you {
  color: #ffccbc;
}

.match-history-score-opp {
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.78);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.match-history-score-sep {
  font-size: unset;
  font-weight: 800;
  letter-spacing: 0.08em;
  opacity: 0.45;
  line-height: 1;
}

.match-history-score-sep * {
  font-size: unset;
}

.match-history-content .leaderboard-subtitle {
  margin-bottom: 0.55rem;
}

.match-history-filters {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  width: 100%;
  max-width: min(100%, 360px);
  margin: 0 auto 0.85rem;
}

.match-history-filter-btn {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.28);
  color: rgba(255, 255, 255, 0.82);
  font-family: 'Nunito', sans-serif;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.match-history-filter-btn.is-active {
  border-color: rgba(255, 215, 0, 0.75);
  background: linear-gradient(180deg, rgba(255, 215, 0, 0.28) 0%, rgba(255, 152, 0, 0.22) 100%);
  color: #fff8e1;
  box-shadow: 0 3px 10px rgba(255, 193, 7, 0.22);
}

.match-history-filter-btn:active {
  transform: translateY(1px);
}

@media (hover: hover) {
  .match-history-filter-btn:hover:not(.is-active) {
    border-color: rgba(255, 215, 0, 0.45);
    color: #fff;
  }
}

.btn-match-review {
  flex: 0 0 auto;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  border: 2px solid rgba(255, 215, 0, 0.55);
  background: linear-gradient(180deg, rgba(255, 215, 0, 0.22) 0%, rgba(255, 152, 0, 0.18) 100%);
  color: #fff8e1;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-match-review:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(255, 193, 7, 0.25);
}

.match-detail-panel {
  position: fixed;
  inset: 0;
  z-index: 220;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(8, 6, 18, 0.72);
  backdrop-filter: blur(4px);
}

.match-detail-panel.hidden {
  display: none;
}

.match-detail-card {
  position: relative;
  width: min(100%, 520px);
  max-height: min(82vh, 640px);
  overflow: auto;
  padding: 1.15rem 1rem 1rem;
  border-radius: 18px;
  border: 2px solid rgba(255, 255, 255, 0.16);
  background: linear-gradient(160deg, rgba(26, 14, 46, 0.98) 0%, rgba(13, 27, 62, 0.96) 100%);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
}

.btn-match-detail-close {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.match-detail-title {
  margin: 0 2rem 0.35rem 0;
  font-size: 1.15rem;
  color: #ffd54f;
}

.match-detail-summary {
  margin: 0 0 0.85rem;
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.72);
  line-height: 1.45;
}

.match-detail-players {
  margin: 0 0 0.85rem;
}

.match-detail-players .match-history-players {
  justify-content: center;
}

.match-detail-players .match-history-player-name {
  max-width: 7.5rem;
}

.match-play-item.match-play-by-opponent {
  border-color: rgba(100, 181, 246, 0.42);
  background: rgba(21, 101, 192, 0.16);
}

.match-play-item.match-play-by-you {
  border-color: rgba(255, 215, 0, 0.28);
}

.match-detail-plays {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.match-play-item {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
}

.match-play-item.match-play-correct {
  border-color: rgba(105, 240, 174, 0.45);
  background: rgba(46, 125, 50, 0.18);
}

.match-play-item.match-play-wrong {
  border-color: rgba(255, 138, 128, 0.42);
  background: rgba(183, 28, 28, 0.16);
}

.match-play-status {
  flex: 0 0 1.35rem;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.35;
}

.match-play-correct .match-play-status {
  color: #69f0ae;
}

.match-play-wrong .match-play-status {
  color: #ff8a80;
}

.match-play-body {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.match-play-equation {
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.02em;
}

.match-play-detail {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.72);
  line-height: 1.35;
}

.match-play-empty {
  padding: 0.75rem;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.65);
  list-style: none;
}

.btn-mode-icon {
  font-size: 1.2rem;
}

/* AI level picker */
.ai-level-panel {
  z-index: 175;
}

.ai-level-panel-inner {
  max-height: 90vh;
  overflow-y: auto;
}

.ai-level-header {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 1.1rem;
}

.ai-level-header-icon {
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.06));
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.ai-level-header-text {
  flex: 1;
  min-width: 0;
}

.ai-level-title {
  margin-bottom: 0.25rem;
  font-size: 1.45rem;
  line-height: 1.1;
}

.ai-level-subtitle {
  font-family: 'Nunito', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.78);
  margin: 0;
}

.ai-level-cards {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  width: 100%;
  margin: 0 0 1rem;
}

.ai-level-card {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.85rem 0.9rem 0.85rem 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.04) 100%);
  color: #fff;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.ai-level-card-accent {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: 14px 0 0 14px;
}

.ai-level-card--easy .ai-level-card-accent {
  background: linear-gradient(180deg, #81c784, #2e7d32);
}

.ai-level-card--medium .ai-level-card-accent {
  background: linear-gradient(180deg, #ffd54f, #f57f17);
}

.ai-level-card--hard .ai-level-card-accent {
  background: linear-gradient(180deg, #ff8a65, #bf360c);
}

.ai-level-card-icon {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  margin-left: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.ai-level-card-body {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}

.ai-level-card-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.ai-level-card-name {
  font-family: 'Bangers', cursive;
  font-size: 1.2rem;
  letter-spacing: 0.04em;
  line-height: 1;
}

.ai-level-badge {
  font-family: 'Nunito', sans-serif;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.18rem 0.45rem;
  border-radius: 999px;
}

.ai-level-badge--easy {
  background: rgba(46, 125, 50, 0.35);
  color: #c8e6c9;
  border: 1px solid rgba(129, 199, 132, 0.45);
}

.ai-level-badge--medium {
  background: rgba(245, 127, 23, 0.28);
  color: #ffe082;
  border: 1px solid rgba(255, 213, 79, 0.4);
}

.ai-level-badge--hard {
  background: rgba(191, 54, 12, 0.32);
  color: #ffccbc;
  border: 1px solid rgba(255, 138, 101, 0.45);
}

.ai-level-card-desc {
  font-family: 'Nunito', sans-serif;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.72);
}

.ai-level-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.15rem;
}

.ai-level-tag {
  font-family: 'Nunito', sans-serif;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.88);
  letter-spacing: 0.02em;
}

.ai-level-card-chevron {
  flex-shrink: 0;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  color: rgba(255, 255, 255, 0.35);
  padding-right: 0.15rem;
  transition: transform 0.15s ease, color 0.15s ease;
}

.ai-level-card:hover,
.ai-level-card:focus-visible {
  border-color: rgba(255, 255, 255, 0.28);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.16) 0%, rgba(255, 255, 255, 0.07) 100%);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}

.ai-level-card:hover .ai-level-card-chevron,
.ai-level-card:focus-visible .ai-level-card-chevron {
  color: rgba(255, 255, 255, 0.75);
  transform: translateX(2px);
}

.ai-level-card:active {
  transform: scale(0.985);
}

.ai-level-card--easy:hover,
.ai-level-card--easy:focus-visible {
  border-color: rgba(129, 199, 132, 0.45);
}

.ai-level-card--medium:hover,
.ai-level-card--medium:focus-visible {
  border-color: rgba(255, 213, 79, 0.4);
}

.ai-level-card--hard:hover,
.ai-level-card--hard:focus-visible {
  border-color: rgba(255, 138, 101, 0.45);
}

.btn-ai-level-cancel {
  margin-top: 0.15rem;
  opacity: 0.92;
}

/* Lobby panel */
.lobby-panel {
  z-index: 180;
}

.lobby-panel-inner {
  max-height: 90vh;
  overflow-y: auto;
  text-align: left;
}

.lobby-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.lobby-tab {
  flex: 1;
  font-family: 'Bangers', cursive;
  font-size: 1rem;
  padding: 0.45rem;
  border-radius: 8px;
  border: 2px solid rgba(255, 215, 0, 0.35);
  background: rgba(0, 0, 0, 0.25);
  color: var(--white);
  cursor: pointer;
}

.lobby-tab.active {
  background: rgba(255, 215, 0, 0.25);
  border-color: var(--gold);
  color: var(--gold);
}

.lobby-view.hidden {
  display: none;
}

.lobby-register-required {
  background: rgba(255, 152, 0, 0.2);
  border: 1px solid rgba(255, 193, 7, 0.6);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  color: #ffe082;
}

.lobby-register-required.hidden {
  display: none;
}

.lobby-desc {
  font-size: 0.85rem;
  line-height: 1.45;
  margin-bottom: 0.75rem;
  opacity: 0.9;
}

/* Lobby waiting — status alert */
.lobby-status {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  width: 100%;
  margin: 0 0 1rem;
  padding: 0.75rem 0.85rem;
  border-radius: 14px;
  border: 2px solid rgba(255, 215, 0, 0.35);
  background: rgba(0, 0, 0, 0.28);
  overflow: hidden;
  transition: border-color 0.35s ease, background 0.35s ease, box-shadow 0.35s ease;
}

.lobby-status--waiting {
  border-color: rgba(66, 165, 245, 0.45);
  background: linear-gradient(135deg, rgba(21, 101, 192, 0.22), rgba(0, 0, 0, 0.3));
}

.lobby-status--ready {
  border-color: rgba(105, 240, 174, 0.75);
  background: linear-gradient(135deg, rgba(46, 125, 50, 0.35), rgba(27, 94, 32, 0.25));
  box-shadow: 0 0 20px rgba(105, 240, 174, 0.25);
}

.lobby-status--alert {
  animation: lobby-status-pop 0.65s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.lobby-status-ring {
  position: absolute;
  inset: -2px;
  border-radius: 14px;
  pointer-events: none;
  opacity: 0;
}

.lobby-status--ready .lobby-status-ring {
  opacity: 1;
  border: 2px solid rgba(105, 240, 174, 0.6);
  animation: lobby-status-ring-pulse 1.4s ease-out 2;
}

.lobby-status--alert .lobby-status-ring {
  animation: lobby-status-ring-burst 0.8s ease-out;
}

.lobby-status-icon {
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 1.15rem;
  line-height: 1;
  background: rgba(0, 0, 0, 0.35);
}

.lobby-status--waiting .lobby-status-icon {
  animation: lobby-status-wait-bob 2s ease-in-out infinite;
}

.lobby-status-icon-wait,
.lobby-status-icon-ready {
  display: none;
}

.lobby-status--waiting .lobby-status-icon-wait {
  display: block;
}

.lobby-status--ready .lobby-status-icon-ready {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-family: 'Bangers', cursive;
  font-size: 1.35rem;
  color: #b9f6ca;
  animation: lobby-status-check-pop 0.5s ease 0.15s both;
}

.lobby-status-body {
  flex: 1 1 auto;
  min-width: 0;
  text-align: left;
}

.lobby-status-title {
  font-family: 'Bangers', cursive;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  line-height: 1.15;
  margin: 0 0 0.2rem;
  color: var(--gold);
}

.lobby-status--ready .lobby-status-title {
  color: #b9f6ca;
  text-shadow: 0 0 12px rgba(105, 240, 174, 0.45);
}

.lobby-status-detail {
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.4;
  margin: 0;
  opacity: 0.92;
}

.lobby-guest-name {
  font-family: 'Bangers', cursive;
  font-size: 1.05rem;
  letter-spacing: 0.03em;
  color: #fff9c4;
  text-shadow: 0 0 10px rgba(255, 235, 59, 0.5);
}

@keyframes lobby-status-pop {
  0% { transform: scale(0.92); opacity: 0.7; }
  45% { transform: scale(1.03); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes lobby-status-ring-pulse {
  0% { transform: scale(1); opacity: 0.85; }
  100% { transform: scale(1.12); opacity: 0; }
}

@keyframes lobby-status-ring-burst {
  0% { transform: scale(0.95); opacity: 1; box-shadow: 0 0 0 0 rgba(105, 240, 174, 0.8); }
  100% { transform: scale(1.15); opacity: 0; box-shadow: 0 0 24px 8px rgba(105, 240, 174, 0); }
}

@keyframes lobby-status-wait-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

@keyframes lobby-status-check-pop {
  0% { transform: scale(0); opacity: 0; }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .lobby-status--waiting .lobby-status-icon,
  .lobby-status--ready .lobby-status-ring,
  .lobby-status--alert,
  .lobby-status-icon-ready {
    animation: none;
  }
}

.lobby-visibility {
  border: none;
  margin-bottom: 0.75rem;
}

.lobby-visibility legend {
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}

.lobby-visibility label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
  cursor: pointer;
}

.lobby-match-settings {
  border: none;
  margin: 0 0 0.85rem;
  padding: 0;
}

.lobby-match-settings legend {
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.lobby-setting-row {
  margin-bottom: 0.65rem;
}

.lobby-setting-row:last-child {
  margin-bottom: 0;
}

.lobby-match-presets {
  margin-top: 0.35rem;
}

.lobby-match-presets .timer-preset-btn.is-active {
  border-color: var(--gold);
  background: rgba(255, 215, 0, 0.28);
  color: #fff9c4;
}

.lobby-match-summary {
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff9c4;
  margin: 0 0 0.75rem;
  padding: 0.45rem 0.65rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 215, 0, 0.28);
}

.lobby-pin-row {
  margin-bottom: 0.75rem;
}

.lobby-subtitle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 1rem 0 0.5rem;
}

.lobby-subtitle-row .lobby-subtitle {
  margin: 0;
  flex: 1 1 auto;
}

.btn-lobby-refresh {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 2px solid rgba(255, 215, 0, 0.45);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--gold);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-lobby-refresh:active:not(:disabled) {
  transform: scale(0.94);
}

.btn-lobby-refresh:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-lobby-refresh.is-spinning {
  animation: lobby-refresh-spin 0.65s linear infinite;
}

@keyframes lobby-refresh-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.lobby-subtitle {
  font-family: 'Bangers', cursive;
  color: var(--gold);
  font-size: 1.1rem;
  margin: 1rem 0 0.5rem;
}

.lobby-public-list {
  list-style: none;
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.15rem;
  margin: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 215, 0, 0.4) transparent;
}

.lobby-public-list::-webkit-scrollbar {
  width: 6px;
}

.lobby-public-list::-webkit-scrollbar-thumb {
  background: rgba(255, 215, 0, 0.4);
  border-radius: 6px;
}

/* ── Lobby card ── */
.lobby-card {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.65rem;
  background: linear-gradient(165deg, rgba(74, 20, 140, 0.45) 0%, rgba(26, 10, 46, 0.6) 100%);
  border: 1px solid rgba(255, 215, 0, 0.22);
  border-radius: 14px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}

.lobby-card:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 215, 0, 0.5);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.lobby-card-avatar {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(255, 215, 0, 0.55);
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

.lobby-card-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.lobby-card-avatar.is-initial {
  font-family: 'Bangers', cursive;
  font-size: 1.4rem;
  color: var(--gold);
  background: linear-gradient(165deg, #5e35b1 0%, #311b92 100%);
}

.lobby-card-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.lobby-card-top {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  min-width: 0;
}

.lobby-card-name {
  font-weight: 800;
  font-size: 0.92rem;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lobby-card-user {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.6);
  flex-shrink: 0;
}

.lobby-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.lobby-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.66rem;
  font-weight: 700;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  color: rgba(255, 255, 255, 0.85);
  white-space: nowrap;
}

.lobby-chip-code {
  font-family: monospace;
  color: var(--gold);
  background: rgba(255, 215, 0, 0.14);
  letter-spacing: 0.03em;
}

.lobby-chip-age {
  color: rgba(255, 255, 255, 0.55);
  background: transparent;
  padding-left: 0.1rem;
}

.btn-lobby-join-card {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 0.82rem;
  padding: 0.5rem 0.85rem;
  border-radius: 999px;
  border: none;
  background: linear-gradient(180deg, #ffd54f 0%, #ffb300 100%);
  color: #4a148c;
  cursor: pointer;
  box-shadow: 0 3px 0 #b28704;
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.1s ease;
}

.btn-lobby-join-card:hover {
  filter: brightness(1.05);
}

.btn-lobby-join-card:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #b28704;
}

.btn-lobby-join-arrow {
  font-size: 0.9rem;
  line-height: 1;
}

/* ── List states (loading / empty / error) ── */
.lobby-list-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  text-align: center;
  padding: 1.4rem 1rem;
  background: rgba(0, 0, 0, 0.2);
  border: 1px dashed rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  color: rgba(255, 255, 255, 0.7);
}

.lobby-list-state-icon {
  font-size: 1.6rem;
  line-height: 1;
}

.lobby-list-state-title {
  font-weight: 800;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.85);
}

.lobby-list-state-hint {
  font-size: 0.74rem;
  opacity: 0.7;
}

.lobby-list-loading {
  flex-direction: row;
  justify-content: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.lobby-list-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 215, 0, 0.3);
  border-top-color: var(--gold);
  animation: lobby-refresh-spin 0.7s linear infinite;
}

.lobby-toast {
  margin-top: 0.75rem;
  padding: 0.5rem;
  border-radius: 8px;
  font-size: 0.85rem;
  text-align: center;
}

.lobby-toast.show.success {
  background: rgba(46, 125, 50, 0.5);
}

.lobby-toast.show.error {
  background: rgba(198, 40, 40, 0.5);
}

.lobby-toast.show.info {
  background: rgba(21, 101, 192, 0.45);
}

/* Hidden opponent / AI cards */
.card.card-back {
  background: linear-gradient(145deg, #311b92 0%, #1a237e 100%);
  border: 2px solid rgba(255, 215, 0, 0.35);
  cursor: default;
  pointer-events: none;
}

.card-back-pattern {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-family: 'Bangers', cursive;
  font-size: 2rem;
  color: rgba(255, 215, 0, 0.5);
}

/* Online / AI: opponent hand is hidden (count shown in header); steal mode reveals cards */
.mode-online .player-zone:not(.my-zone) .hand-scroll-wrap:not(.steal-mode-active),
.mode-ai .player-zone:not(.my-zone) .hand-scroll-wrap:not(.steal-mode-active) {
  display: none;
}

/* Player register */
.menu-register {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(66, 165, 245, 0.45);
  border-radius: 16px;
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
  text-align: left;
}

.menu-register.register-page-panel {
  background: linear-gradient(
    135deg,
    rgba(74, 20, 140, 0.92) 0%,
    rgba(106, 27, 154, 0.85) 42%,
    rgba(26, 35, 126, 0.94) 100%
  );
  border: 2px solid rgba(255, 215, 0, 0.5);
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.menu-register.register-page-panel .settings-title {
  color: #fff9c4;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.55);
}

.menu-register.register-page-panel .register-label {
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.menu-register.register-page-panel .register-hint {
  color: rgba(255, 255, 255, 0.72);
  opacity: 1;
  text-shadow: none;
}

.menu-register.register-page-panel .register-input {
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(255, 215, 0, 0.4);
  color: #263238;
}

.menu-register.register-page-panel .register-input::placeholder {
  color: rgba(38, 50, 56, 0.55);
}

.menu-register.register-page-panel .register-input:focus {
  border-color: rgba(255, 215, 0, 0.75);
  box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.28);
}

.menu-register.register-page-panel .register-welcome {
  color: #fff9c4;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

.menu-register.register-page-panel .register-account-summary {
  background: rgba(0, 0, 0, 0.22);
  border-color: rgba(255, 215, 0, 0.35);
}

.menu-register.register-page-panel .register-account-summary dt {
  color: rgba(255, 255, 255, 0.7);
  opacity: 1;
}

.menu-register.register-page-panel .register-account-summary dd {
  color: #fff;
}

.menu-register.register-page-panel .network-id {
  background: rgba(0, 0, 0, 0.28);
  border-color: rgba(255, 215, 0, 0.45);
  color: #fff9c4;
}

.menu-register.register-page-panel .login-switch {
  color: rgba(255, 255, 255, 0.88);
}

.menu-register.register-page-panel .login-switch-link {
  color: #90caf9;
}

@media (hover: hover) {
  .menu-register.register-page-panel .login-switch-link:hover {
    color: #bbdefb;
  }
}

.menu-register.register-page-panel.login-page-panel {
  background: linear-gradient(
    155deg,
    #0d1b3e 0%,
    #1a237e 28%,
    #311b92 58%,
    #4a148c 82%,
    #6a1b9a 100%
  );
  border: 2px solid rgba(186, 104, 200, 0.45);
  box-shadow:
    0 6px 24px rgba(74, 20, 140, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.menu-register.register-page-panel.login-page-panel .settings-title {
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

.menu-register.register-page-panel.login-page-panel .register-label {
  color: #e1bee7;
}

.menu-register.register-page-panel.login-page-panel .register-hint {
  color: rgba(225, 190, 231, 0.85);
}

.menu-register.register-page-panel.login-page-panel .register-input {
  background: rgba(255, 255, 255, 0.96);
  border-color: rgba(126, 87, 194, 0.45);
  color: #263238;
}

.menu-register.register-page-panel.login-page-panel .register-input::placeholder {
  color: rgba(38, 50, 56, 0.55);
}

.menu-register.register-page-panel.login-page-panel .register-input:focus {
  border-color: #ba68c8;
  box-shadow: 0 0 0 3px rgba(186, 104, 200, 0.45);
}

.menu-register.register-page-panel.login-page-panel .login-switch {
  color: rgba(255, 255, 255, 0.9);
}

.menu-register.register-page-panel.login-page-panel .login-switch-link {
  color: #ffd700;
}

@media (hover: hover) {
  .menu-register.register-page-panel.login-page-panel .login-switch-link:hover {
    color: #ffeb3b;
  }
}

.login-remember-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.15rem 0 0.2rem;
}

.login-remember-checkbox {
  width: 1.05rem;
  height: 1.05rem;
  flex-shrink: 0;
  margin: 0;
  accent-color: #ffd700;
  cursor: default;
}

.login-remember-label {
  font-size: 0.88rem;
  font-weight: 700;
  color: #e1bee7;
  cursor: default;
  user-select: none;
}

.login-page-panel .login-remember-hint {
  display: block;
  margin-top: 0;
  margin-bottom: 0.5rem;
}

.register-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.register-avatar-field > .register-hint {
  text-align: center;
}

.register-country-wrap {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.register-country-flag {
  width: 28px;
  height: 21px;
  object-fit: cover;
  border-radius: 3px;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.2);
}

.register-country-flag.hidden {
  display: none;
}

.register-country-select {
  flex: 1;
  min-width: 0;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: none;
}

.register-country-select option {
  color: #1a0a2e;
  background: #fff;
}

.menu-register.register-page-panel .register-country-select {
  color: #000;
  background-color: rgba(255, 255, 255, 0.94);
  background-image: none;
}

.register-country-field > .register-hint {
  display: block;
  margin-top: 0.35rem;
}

.register-account-summary .register-summary-country {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.register-account-summary .register-summary-flag {
  width: 22px;
  height: 16px;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.register-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.register-hint {
  font-size: 0.68rem;
  line-height: 1.35;
  opacity: 0.62;
  font-weight: 600;
}

.register-form-error {
  font-size: 0.8rem;
  font-weight: 800;
  color: #ff8a80;
  background: rgba(198, 40, 40, 0.2);
  border: 1px solid rgba(255, 138, 128, 0.45);
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
  margin: 0;
}

.register-form-error.hidden {
  display: none;
}

.register-label {
  font-size: 0.85rem;
  font-weight: 700;
  opacity: 0.9;
}

.register-input.field-error {
  border-color: #ef5350;
  box-shadow: 0 0 0 3px rgba(239, 83, 80, 0.25);
}

.register-input {
  width: 100%;
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  border: 2px solid rgba(255, 215, 0, 0.4);
  background: rgba(0, 0, 0, 0.35);
  color: var(--white);
  outline: none;
}

.register-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.25);
}

.register-input::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

.btn-register {
  font-family: 'Bangers', cursive;
  font-size: 1.15rem;
  letter-spacing: 0.05em;
  border: none;
  border-radius: 50px;
  padding: 0.7rem 1.25rem;
  cursor: pointer;
  width: 100%;
  margin-top: 0.25rem;
  background: linear-gradient(180deg, #64b5f6 0%, #1565c0 100%);
  color: #fff;
  box-shadow: 0 4px 0 #0d47a1, 0 6px 16px rgba(21, 101, 192, 0.45);
  transition: transform 0.15s;
}

.btn-register:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #0d47a1;
}

.register-form.hidden,
.register-success.hidden {
  display: none;
}

.register-current-password-wrap.hidden {
  display: none;
}

.register-welcome {
  font-family: 'Bangers', cursive;
  font-size: 1.2rem;
  color: var(--gold);
  margin-bottom: 0.5rem;
}

.register-account-summary {
  width: 100%;
  margin: 0 0 0.75rem;
  padding: 0.65rem 0.75rem;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 215, 0, 0.28);
  border-radius: 12px;
  display: grid;
  grid-template-columns: minmax(5.5rem, 38%) 1fr;
  gap: 0.35rem 0.5rem;
  font-size: 0.78rem;
}

.register-account-summary dt {
  font-weight: 800;
  opacity: 0.75;
  margin: 0;
}

.register-account-summary dd {
  margin: 0;
  font-weight: 700;
  word-break: break-word;
}

.network-id {
  font-family: 'Nunito', monospace;
  font-size: clamp(0.75rem, 3.2vw, 0.95rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  word-break: break-all;
  background: rgba(0, 0, 0, 0.4);
  border: 2px dashed rgba(255, 215, 0, 0.5);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  margin: 0.35rem 0 0.65rem;
  color: #fff9c4;
  user-select: all;
}

.btn-copy-id {
  max-width: none;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.btn-register-new {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.4rem;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.65);
  font-size: 0.8rem;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

.btn-register-new:hover {
  color: var(--gold);
}

/* Settings */
.menu-settings {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 215, 0, 0.35);
  border-radius: 16px;
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
  text-align: left;
}

.menu-settings.settings-page-panel {
  background: linear-gradient(
    135deg,
    rgba(74, 20, 140, 0.92) 0%,
    rgba(106, 27, 154, 0.85) 42%,
    rgba(26, 35, 126, 0.94) 100%
  );
  border: 2px solid rgba(255, 215, 0, 0.5);
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.settings-title {
  font-family: 'Bangers', cursive;
  font-size: 1.35rem;
  color: var(--gold);
  margin-bottom: 0.75rem;
  letter-spacing: 0.05em;
}

.setting-row label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: rgba(255, 255, 255, 0.85);
}

.setting-timer-control {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.timer-slider {
  flex: 1;
  height: 8px;
  accent-color: var(--gold);
  cursor: pointer;
}

.timer-setting-value {
  font-family: 'Bangers', cursive;
  font-size: 1.25rem;
  color: var(--gold);
  min-width: 4.5rem;
  text-align: right;
}

.timer-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.timer-preset-btn {
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 0.8rem;
  padding: 0.4rem 0.65rem;
  border-radius: 8px;
  border: 2px solid rgba(255, 215, 0, 0.45);
  background: rgba(0, 0, 0, 0.25);
  color: var(--white);
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.timer-preset-btn:hover,
.timer-preset-btn.active {
  background: rgba(255, 215, 0, 0.25);
  border-color: var(--gold);
}

.timer-preset-btn:active {
  transform: scale(0.95);
}

.settings-panel {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  pointer-events: auto;
}

.settings-panel[hidden] {
  display: none !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

.settings-panel.panel-open:not([hidden]) {
  display: flex !important;
  pointer-events: auto;
  visibility: visible;
}

.settings-panel-inner {
  pointer-events: auto;
  position: relative;
  z-index: 1;
  background: linear-gradient(160deg, #4a148c 0%, #1a237e 100%);
  border: 3px solid var(--gold);
  border-radius: 20px;
  padding: 1.25rem 1.5rem;
  width: min(100%, 340px);
  text-align: left;
}

.settings-note {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
  margin: 0.75rem 0;
}

.setting-divider {
  height: 1px;
  margin: 1rem 0 0.75rem;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 215, 0, 0.35),
    transparent
  );
}

.settings-subtitle {
  font-family: 'Bangers', cursive;
  font-size: 1.1rem;
  letter-spacing: 0.04em;
  color: var(--gold);
  margin: 0 0 0.5rem;
  text-align: center;
}

.settings-panel-inner .btn-secondary {
  width: 100%;
  max-width: none;
}

/* Board background template picker */
.board-bg-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  width: 100%;
}

.board-bg-option {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 0.55rem;
  border: 2px solid rgba(255, 255, 255, 0.18);
  background-color: rgba(10, 14, 40, 0.6);
  background-size: cover;
  background-position: center;
  cursor: pointer;
  overflow: hidden;
  padding: 0;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.board-bg-option:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 215, 0, 0.5);
}

.board-bg-option.is-active {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.35), 0 4px 12px rgba(0, 0, 0, 0.45);
}

.board-bg-option.is-active::after {
  content: "✓";
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #0b1020;
  background: var(--gold);
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 50%;
}

.board-bg-option-none {
  display: flex;
  align-items: center;
  justify-content: center;
  background-image:
    repeating-linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.06) 0,
      rgba(255, 255, 255, 0.06) 6px,
      transparent 6px,
      transparent 12px
    );
}

.board-bg-option-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 2px 3px;
  font-size: 0.6rem;
  font-weight: 600;
  text-align: center;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.78));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.board-bg-option-none .board-bg-option-label {
  background: none;
  position: static;
  font-size: 0.7rem;
}

.confirm-panel,
.name-taken-panel {
  z-index: 500;
}

.confirm-panel.panel-open {
  z-index: 550;
}

.confirm-panel-inner {
  text-align: center;
}

.confirm-surrender-art {
  display: block;
  width: min(100%, 280px);
  height: auto;
  margin: 0 auto 0.65rem;
  object-fit: contain;
  background: transparent;
  filter: drop-shadow(0 10px 22px rgba(255, 215, 0, 0.35));
  animation: surrender-art-float 3s ease-in-out infinite;
  will-change: transform;
}

@keyframes surrender-art-float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-12px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .confirm-surrender-art {
    animation: none;
    transform: none;
  }
}

.confirm-surrender-title {
  margin-bottom: 0.35rem;
}

.confirm-message {
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 0.5rem 0 1.25rem;
  color: rgba(255, 255, 255, 0.9);
}

.confirm-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.confirm-actions .btn-primary,
.confirm-actions .btn-secondary {
  width: 100%;
  max-width: none;
  margin-bottom: 0;
}

.confirm-surrender-panel .btn-confirm-surrender-yes {
  background: linear-gradient(180deg, #ef5350 0%, #c62828 100%);
  box-shadow: 0 4px 0 #8e0000, 0 6px 16px rgba(198, 40, 40, 0.45);
}

.confirm-surrender-panel .btn-confirm-surrender-yes:active {
  box-shadow: 0 1px 0 #8e0000;
}

.settings-panel-inner .btn-leave-game {
  width: 100%;
  max-width: none;
  margin-top: 0.5rem;
  border-color: rgba(244, 67, 54, 0.65);
  color: #ff8a80;
  position: relative;
  z-index: 2;
  pointer-events: auto;
  touch-action: manipulation;
  cursor: pointer;
}

.settings-panel-inner .btn-leave-game:hover,
.settings-panel-inner .btn-leave-game:focus-visible {
  background: rgba(244, 67, 54, 0.2);
  border-color: #f44336;
}

.game-hud-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  position: relative;
  z-index: 200;
  pointer-events: auto;
  isolation: isolate;
}

.btn-hud-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  font-size: 1.1rem;
  cursor: pointer;
  touch-action: manipulation;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.btn-hud-icon:active {
  transform: scale(0.95);
}

/* ===== GAME SCREEN ===== */
#screen-game {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  max-height: 100dvh;
  display: none;
  flex-direction: column;
  align-items: stretch;
  background:
    radial-gradient(ellipse at 50% 50%, rgba(233, 30, 99, 0.25) 0%, transparent 55%),
    linear-gradient(180deg, #1a0a2e 0%, #311b92 40%, #1a237e 100%);
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

#screen-game.active {
  display: flex;
}

.online-connection-banner {
  position: absolute;
  top: calc(var(--safe-top) + 3.25rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: min(96%, 360px);
  padding: 0.45rem 0.55rem 0.45rem 0.65rem;
  border-radius: 12px;
  border: 2px solid rgba(255, 152, 0, 0.75);
  background: linear-gradient(165deg, rgba(74, 20, 140, 0.95) 0%, rgba(26, 10, 46, 0.98) 100%);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
}

.online-connection-banner.hidden {
  display: none !important;
}

.online-connection-icon {
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}

.online-connection-text {
  flex: 1 1 auto;
  font-family: 'Nunito', sans-serif;
  font-size: 0.72rem;
  font-weight: 800;
  color: #ffe0b2;
  line-height: 1.25;
  text-align: left;
}

.btn-online-reconnect {
  flex-shrink: 0;
  font-family: 'Nunito', sans-serif;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  border: 2px solid rgba(255, 193, 7, 0.7);
  background: linear-gradient(180deg, #ffb300 0%, #f57c00 100%);
  color: #3e2723;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-online-reconnect:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-online-reconnect:active {
  transform: scale(0.96);
}

#screen-game .game-hud,
#screen-game .game-board,
#screen-game .message-bar {
  width: 100%;
  max-width: 100%;
}

#screen-game .game-board {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  z-index: 2;
}

/* Selectable board background template (opacity set in Settings). Sits behind
   all board content via a negative-z pseudo layer. */
#screen-game .game-board::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: var(--board-bg-image, none);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: var(--board-bg-opacity, 0);
  transition: opacity 0.25s ease;
  border-radius: inherit;
}

#screen-game .message-bar {
  position: relative;
  z-index: 1;
}

#screen-game .game-bottom-dock {
  flex-shrink: 0;
  width: 100%;
  max-width: 100%;
  position: relative;
  z-index: 150;
  background: transparent;
}

#screen-game .game-bottom-dock .message-bar {
  background: transparent;
  border-top: none;
}

/* HUD — top and bottom bars */
.game-hud {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0.4rem 0.6rem;
  gap: 0.5rem;
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.35);
  position: relative;
  z-index: 100;
}

.game-hud-top {
  border-bottom: 2px solid rgba(255, 215, 0, 0.25);
}

.game-hud-bottom {
  display: none;
  border-top: 2px solid rgba(255, 215, 0, 0.25);
}

/* Online: hide duplicate top bar (Opp/You scores); use compact HUD with timers only */
.mode-online .game-hud-top {
  display: none !important;
}

.mode-online .game-hud-bottom {
  display: flex;
  order: 0;
  flex-shrink: 0;
  border-top: none;
  border-bottom: 2px solid rgba(255, 215, 0, 0.25);
}

.mode-online .game-board {
  order: 1;
}

.mode-online .game-bottom-dock {
  order: 2;
}

.mode-online .game-hud-bottom .hud-left {
  display: none;
}

/* AI match: move the status message bar up below the top HUD */
.mode-ai .game-hud-top {
  order: 0;
}

.mode-ai .game-bottom-dock {
  order: 1;
}

.mode-ai .game-board {
  order: 2;
}

.mode-ai .game-hud-bottom {
  order: 3;
}

.mode-ai .game-bottom-dock .message-bar {
  border-top: none;
  border-bottom: 1px solid rgba(255, 215, 0, 0.2);
}

.mode-online .online-connection-banner:not(.hidden) {
  top: calc(var(--safe-top) + 3.35rem);
}

/* Online: opponent header on top, equation below, your hand at bottom */
.mode-online .game-board {
  grid-template-rows: auto auto minmax(0, 1fr);
  grid-template-areas:
    "zone-top"
    "center"
    "zone-bottom";
  gap: clamp(0.15rem, 0.6vh, 0.35rem);
}

.mode-online #zone-p1 {
  grid-area: zone-top;
  flex: 0 0 auto;
  min-height: 0;
}

.mode-online #zone-p1 .player-header {
  display: none !important;
}

.mode-online #zone-p1 .hand-scroll-wrap {
  display: none !important;
}

.mode-online .battle-center {
  grid-area: center;
  align-self: stretch;
  justify-content: flex-start;
  padding: 0.1rem 0 0.2rem;
  z-index: 12;
}

.mode-online .equation-visual {
  min-height: clamp(112px, 26vw, 148px);
  padding: clamp(0.55rem, 2.2vw, 0.8rem) clamp(0.3rem, 1.8vw, 0.55rem);
  gap: clamp(0.18rem, 1.1vw, 0.42rem);
  border-width: 2px;
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.45),
    0 0 24px rgba(255, 215, 0, 0.12);
}

.mode-online .eq-slot {
  width: clamp(50px, 12.5vw, 80px);
  height: clamp(62px, 15.5vw, 96px);
}

.mode-online .eq-slot-num {
  width: clamp(52px, 13vw, 84px);
  height: clamp(64px, 16vw, 100px);
}

.mode-online .eq-slot-value {
  font-size: clamp(1.55rem, 7.2vw, 2.4rem);
}

.mode-online .eq-slot-value .eq-card-img {
  width: clamp(44px, 11.5vw, 62px);
  height: clamp(60px, 15.5vw, 86px);
}

.mode-online .eq-slot-op {
  width: clamp(48px, 11.5vw, 68px);
  height: clamp(62px, 15.5vw, 96px);
}

.mode-online .eq-slot-op .eq-slot-value {
  font-size: clamp(1.9rem, 8.5vw, 2.65rem);
}

.mode-online .eq-equals {
  font-size: clamp(1.5rem, 6vw, 2.1rem);
}

.mode-online .battle-center .btn-end-turn {
  width: min(100%, 20rem);
  min-width: 0;
  min-height: 2.85rem;
  max-height: none;
  margin-top: 0.2rem;
  font-size: clamp(0.72rem, 2.8vw, 0.88rem);
}

.mode-online .player-zone:not(.my-zone) {
  min-height: 0;
}

/* Online: 2 rows × 3 cards per row (scroll if more than 6) */
.mode-online .my-zone {
  --online-hand-cols: 3;
  --online-hand-col-gap: clamp(8px, 2.2vw, 12px);
  --online-hand-row-gap: clamp(8px, 2vw, 12px);
  --card-w: min(28vw, 108px);
}

.mode-online #zone-p2.my-zone {
  position: relative;
  z-index: 160;
  overflow: visible;
}

.mode-online .my-zone .hand-scroll-wrap {
  flex: 1 1 auto;
  min-height: calc(var(--card-h) * 2 + var(--online-hand-row-gap) + 1.1rem);
  touch-action: auto;
  overflow: visible;
  position: relative;
  z-index: 1;
}

.mode-online .my-zone .card {
  position: relative;
  z-index: 1;
  overflow: visible;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  animation: none !important;
  padding: 0;
}

.mode-online .my-zone .card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  border: none;
  border-radius: 0;
  background: none !important;
  box-shadow: none;
}

.mode-online .my-zone .card.playable,
.mode-online .my-zone .card.powerup-card,
.mode-online .my-zone .card.powerup-card.selected,
.mode-online .my-zone .card.selected {
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  animation: none !important;
}

.mode-online .my-zone .card:hover,
.mode-online .my-zone .card:focus-visible {
  z-index: 10;
  border: none !important;
  box-shadow: none !important;
}

.mode-online .my-zone .card.selected {
  z-index: 11;
}

.mode-online .my-zone .card.is-drag-lift {
  z-index: 12;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45) !important;
}

.mode-online .my-zone .card.is-dragging-source {
  z-index: 0;
}

.mode-online .my-zone .hand {
  display: grid;
  grid-template-columns: repeat(3, var(--card-w));
  grid-auto-rows: var(--card-h);
  justify-content: center;
  align-content: start;
  column-gap: var(--online-hand-col-gap);
  row-gap: var(--online-hand-row-gap);
  width: min(
    100%,
    calc(var(--card-w) * 3 + var(--online-hand-col-gap) * 2 + 1rem)
  );
  max-width: 100%;
  margin: 0 auto;
  padding: 0.85rem 0.5rem 0.55rem;
  overflow-x: visible;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  min-height: calc(var(--card-h) * 2 + var(--online-hand-row-gap));
  max-height: calc(var(--card-h) * 2 + var(--online-hand-row-gap) + 0.85rem);
  touch-action: pan-y;
  scroll-snap-type: none;
  flex: 0 0 auto;
  cursor: default;
  position: relative;
  z-index: 2;
  isolation: isolate;
  -webkit-overflow-scrolling: touch;
}

.mode-online .my-zone .card.playable:not(.powerup-card) {
  touch-action: none;
}

@media (hover: none) and (pointer: coarse) {
  .mode-online .my-zone .card.playable {
    transition: transform 0.08s ease-out, box-shadow 0.08s ease-out;
  }

  .mode-online .my-zone .card.is-drag-lift {
    transform: translateY(-8px) scale(1.08);
  }
}

.mode-online .my-zone .hand::before,
.mode-online .my-zone .hand::after {
  display: none;
  content: none;
  width: 0;
}

.hud-left {
  display: flex;
  gap: 0.4rem;
}

.score-box {
  background: linear-gradient(135deg, var(--blue-mid), var(--blue-dark));
  border: 2px solid var(--gold);
  border-radius: 10px;
  padding: 0.2rem 0.5rem;
  min-width: 48px;
  text-align: center;
}

.score-box.active-player {
  box-shadow: 0 0 12px var(--gold);
  border-color: #ffeb3b;
}

.score-label {
  display: block;
  font-family: 'Bangers', cursive;
  font-size: 0.75rem;
  color: var(--gold);
  line-height: 1;
}

.score-value {
  font-family: 'Bangers', cursive;
  font-size: 1.3rem;
  line-height: 1.1;
}

/* Match clock */
.match-timer-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  padding: 0.15rem 0.35rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.88);
  border: 1px solid rgba(255, 215, 0, 0.35);
  flex-shrink: 0;
  position: relative;
  z-index: 120;
  pointer-events: auto;
}

.match-timer-hud {
  min-width: 46px;
  padding: 0.1rem 0.35rem;
}

.match-timer-hud .match-timer-label {
  font-size: 0.5rem;
}

.match-timer-hud .match-timer-text {
  font-size: 0.95rem;
  line-height: 1.05;
}

.match-timer-label {
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.75;
  line-height: 1;
}

.match-timer-text {
  font-family: 'Bangers', cursive;
  font-size: 1rem;
  color: var(--gold);
  line-height: 1.1;
}

.match-timer-wrap.warning {
  border-color: #ff9800;
}

.match-timer-wrap.warning .match-timer-text {
  color: #ff9800;
}

.match-timer-wrap.danger {
  border-color: #f44336;
  animation: pulse-timer 0.5s ease infinite;
}

.match-timer-wrap.danger .match-timer-text {
  color: #f44336;
}

/* Turn timer cluster — match clock beside turn countdown */
.hud-timer-cluster {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  z-index: 110;
  pointer-events: none;
}

.hud-timer-cluster > * {
  pointer-events: auto;
}

.online-conn-pill {
  display: flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.18rem 0.28rem 0.18rem 0.38rem;
  border-radius: 999px;
  border: 1px solid rgba(129, 199, 132, 0.55);
  background: rgba(10, 22, 12, 0.82);
  flex-shrink: 0;
  max-width: 7.5rem;
}

.online-conn-pill.hidden,
.online-conn-pill[hidden] {
  display: none !important;
}

.online-conn-pill[data-level='slow'] {
  border-color: rgba(255, 193, 7, 0.65);
  background: rgba(40, 28, 4, 0.88);
}

.online-conn-pill[data-level='offline'] {
  border-color: rgba(239, 83, 80, 0.75);
  background: rgba(36, 10, 10, 0.9);
}

.online-conn-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 0.72rem;
}

.online-conn-bar {
  display: block;
  width: 3px;
  border-radius: 1px;
  background: rgba(255, 255, 255, 0.25);
}

.online-conn-bar:nth-child(1) {
  height: 35%;
}

.online-conn-bar:nth-child(2) {
  height: 65%;
}

.online-conn-bar:nth-child(3) {
  height: 100%;
}

.online-conn-pill[data-level='live'] .online-conn-bar {
  background: #81c784;
}

.online-conn-pill[data-level='slow'] .online-conn-bar:nth-child(1),
.online-conn-pill[data-level='slow'] .online-conn-bar:nth-child(2) {
  background: #ffd54f;
}

.online-conn-pill[data-level='offline'] .online-conn-bar:nth-child(1) {
  background: #ef5350;
}

.online-conn-label {
  font-family: 'Nunito', sans-serif;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #c8e6c9;
  line-height: 1;
  white-space: nowrap;
}

.online-conn-pill[data-level='slow'] .online-conn-label {
  color: #ffe082;
}

.online-conn-pill[data-level='offline'] .online-conn-label {
  color: #ffcdd2;
}

.btn-online-sync {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  border: 1px solid rgba(255, 215, 0, 0.45);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffd54f;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  flex-shrink: 0;
}

.btn-online-sync:active {
  transform: scale(0.94);
}

.mode-online .hud-timer-cluster {
  gap: 0.28rem;
  flex-wrap: nowrap;
}

.mode-online .online-conn-pill {
  order: -1;
}

.match-timer-wrap--bottom-hud {
  min-width: 46px;
  padding: 0.1rem 0.3rem;
}

/* Turn timer */
.timer-wrap {
  position: relative;
  width: 52px;
  height: 52px;
  flex-shrink: 0;
}

.timer-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer-ring-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.15);
  stroke-width: 3;
}

.timer-ring-fill {
  fill: none;
  stroke: var(--gold);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.3s linear, stroke 0.3s;
}

.timer-wrap.warning .timer-ring-fill {
  stroke: #ff9800;
}

.timer-wrap.danger .timer-ring-fill {
  stroke: #f44336;
  animation: pulse-timer 0.5s ease infinite;
}

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

.timer-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Bangers', cursive;
  font-size: 1.2rem;
}

.turn-indicator {
  text-align: right;
  min-width: 70px;
  margin-left: auto;
  flex-shrink: 0;
}

.turn-label {
  display: block;
  font-size: 0.65rem;
  opacity: 0.7;
  text-transform: uppercase;
}

.turn-player {
  font-family: 'Bangers', cursive;
  font-size: 1rem;
  color: var(--gold);
}

/* Game Board — portrait / narrow: stacked rows */
.game-board {
  flex: 1 1 auto;
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-columns: 1fr;
  grid-template-areas:
    "zone-top"
    "center"
    "zone-bottom";
  min-height: 0;
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0.25rem clamp(0.35rem, 2vw, 1.25rem);
  gap: clamp(0.2rem, 1vh, 0.5rem);
  align-content: stretch;
  overflow-x: visible;
  overflow-y: hidden;
}

.battle-center {
  grid-area: center;
  min-width: 0;
  overflow: visible;
  position: relative;
  z-index: 6;
}

/* The centre column (equation + End Turn button) stays above the hands so the
   button is always fully visible and tappable, never hidden behind a card. */
#zone-p1 {
  grid-area: zone-top;
  position: relative;
  z-index: 3;
}

#zone-p2 {
  grid-area: zone-bottom;
  position: relative;
  z-index: 3;
}

.battle-center .equation-visual,
.battle-center .btn-end-turn {
  position: relative;
  z-index: 2;
}

/* AI mode portrait: opponent top, you bottom */
.mode-ai #zone-p2 {
  grid-area: zone-top;
}

.mode-ai #zone-p1 {
  grid-area: zone-bottom;
}

.mode-ai #zone-p2 .player-header {
  order: 1;
}

.mode-ai #zone-p2 .hand-scroll-wrap {
  order: 2;
}

.mode-ai #zone-p1 .hand-scroll-wrap {
  order: 1;
}

.mode-ai #zone-p1 .player-header {
  order: 2;
}

.player-zone {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.hand-scroll-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: calc(var(--card-h) + 1.25rem);
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  touch-action: pan-x;
}

.hand-scroll-wrap.hand-has-overflow .hand-scroll-hint {
  color: var(--gold);
}

.hand-scroll-wrap::before,
.hand-scroll-wrap::after {
  display: none;
}

.hand-scroll-hint {
  display: none;
  text-align: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: rgba(255, 215, 0, 0.55);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.15rem 0 0.25rem;
  flex-shrink: 0;
}

.hand-scroll-wrap.hand-has-overflow .hand-scroll-hint {
  display: block;
}

/* Previous / Next card navigation arrows (overlay the hand edges). */
.hand-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 6;
  width: 30px;
  height: 30px;
  padding: 0;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255, 215, 0, 0.7);
  border-radius: 50%;
  background: rgba(22, 14, 44, 0.78);
  color: var(--gold, #ffd700);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, transform 0.12s ease, opacity 0.15s ease;
}
.hand-nav svg { display: block; }
.hand-nav-prev { left: 2px; }
.hand-nav-next { right: 2px; }
.hand-nav:hover { background: rgba(46, 28, 90, 0.92); }
.hand-nav:active { transform: translateY(-50%) scale(0.9); }
.hand-nav:disabled {
  opacity: 0.32;
  cursor: default;
  box-shadow: none;
}

/* Only show the arrows when the hand actually overflows horizontally. */
.hand-scroll-wrap.hand-has-overflow .hand-nav {
  display: flex;
}

/* Online "my zone" hand scrolls vertically as a grid — arrows don't apply. */
.mode-online .my-zone .hand-nav {
  display: none !important;
}

/* Local PvP phone portrait: flip each player’s UI toward them (table-style) */
@media (max-width: 719px) and (orientation: portrait) {
  /* Top player (P1) */
  .mode-local .player-1 .player-header,
  .mode-local .player-1 .hand-scroll-hint {
    transform: rotate(180deg);
    transform-origin: center center;
  }

  .mode-local .player-1 .card {
    transform: rotate(180deg);
  }

  /* Keep the prev/next arrows oriented for the top (upside-down) player. */
  .mode-local .player-1 .hand-nav {
    transform: translateY(-50%) rotate(180deg);
  }
  .mode-local .player-1 .hand-nav:active {
    transform: translateY(-50%) rotate(180deg) scale(0.9);
  }

  .mode-local .player-1 .card:hover,
  .mode-local .player-1 .card:focus-visible {
    transform: rotate(180deg) translateY(-6px) scale(1.05);
  }

  .mode-local .player-1 .card.selected {
    transform: rotate(180deg) translateY(-16px) scale(1.28);
  }

  /* Top HUD faces Player 1 (top of device) */
  .mode-local .game-hud-top {
    transform: rotate(180deg);
    transform-origin: center center;
  }

  /* Bottom HUD + Player 2 hand: no rotation (readable from bottom edge) */
  .mode-local .game-hud-bottom {
    transform: none;
  }
}

/* Local PvP portrait: equation + hint face the active player */
@media (orientation: portrait) {
  .mode-local.eq-face-top .equation-hint,
  .mode-local.eq-face-top .equation-visual,
  .mode-local .equation-hint.eq-facing-p1,
  .mode-local .equation-visual.eq-facing-p1 {
    transform: rotate(180deg);
    transform-origin: center center;
    transition: transform 0.4s ease;
    overflow: visible;
  }

  .mode-local.eq-face-bottom .equation-hint,
  .mode-local.eq-face-bottom .equation-visual,
  .mode-local .equation-hint.eq-facing-p2,
  .mode-local .equation-visual.eq-facing-p2 {
    transform: none;
    transform-origin: center center;
    transition: transform 0.4s ease;
    overflow: visible;
  }

  .mode-local.eq-face-top .equation-visual .eq-card-img,
  .mode-local .equation-visual.eq-facing-p1 .eq-card-img {
    transform: none;
  }

  .mode-local.eq-face-top .equation-visual .eq-slot.drop-target,
  .mode-local .equation-visual.eq-facing-p1 .eq-slot.drop-target {
    transform: scale(1.05);
  }

  .mode-local.eq-face-top .equation-visual .eq-slot:active,
  .mode-local .equation-visual.eq-facing-p1 .eq-slot:active {
    transform: scale(0.96);
  }
}

.player-1 {
  flex-direction: column;
}

.player-1 .player-header {
  order: 1;
}

.player-1 .hand-scroll-wrap {
  order: 2;
}

.player-1 .play-slot {
  order: 3;
  align-self: center;
}

.player-2 .play-slot {
  order: 1;
  align-self: center;
}

.player-2 .hand-scroll-wrap {
  order: 2;
}

.player-2 .player-header {
  order: 3;
}

@media (max-width: 900px) {
  .player-header-main .player-info {
    flex: 0 1 auto;
  }
}

.player-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.2rem 0.35rem;
  flex-shrink: 0;
  width: 100%;
  min-width: 0;
  position: relative;
  z-index: 100;
  overflow: visible;
}

.player-header-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex: 0 1 auto;
  min-width: 0;
  max-width: calc(100% - 5.5rem);
}

.player-header-leading {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  order: 0;
}

.player-header-main > .player-avatar {
  order: 1;
  flex-shrink: 0;
}

.player-header-main > .player-info {
  order: 2;
}

.btn-draw-header {
  padding: 0.2rem 0.32rem;
  border-radius: 10px;
  background: rgba(66, 165, 245, 0.15);
  border-color: rgba(66, 165, 245, 0.55);
  min-width: auto;
}

/* "Show All Cards" button — sits to the left of the Draw button. */
.btn-show-cards {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.08rem;
  margin-right: 0.4rem;
  padding: 0.26rem 0.38rem;
  border-radius: 10px;
  background: rgba(255, 193, 7, 0.16);
  border: 1.5px solid rgba(255, 213, 79, 0.6);
  color: #fff8e1;
  cursor: pointer;
  flex-shrink: 0;
  min-width: auto;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn-show-cards:hover {
  background: rgba(255, 193, 7, 0.28);
  border-color: rgba(255, 213, 79, 0.95);
}

.btn-show-cards:active {
  transform: scale(0.94);
}

.btn-show-cards.hidden {
  display: none;
}

.btn-show-cards-icon {
  font-size: clamp(1rem, 4vw, 1.25rem);
  line-height: 1;
}

.btn-show-cards-label {
  font-size: clamp(0.44rem, 1.85vw, 0.54rem);
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Show-all-cards overview popup. */
.all-cards-modal {
  position: absolute;
  inset: 0;
  z-index: 185;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.all-cards-modal.panel-open,
.all-cards-modal:not([hidden]) {
  display: flex;
}

.all-cards-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 5, 30, 0.78);
  backdrop-filter: blur(2px);
}

.all-cards-panel {
  position: relative;
  z-index: 2;
  width: min(100%, 560px);
  max-height: min(86vh, 620px);
  display: flex;
  flex-direction: column;
  padding: 0.85rem 1rem 1rem;
  border-radius: 18px;
  border: 3px solid rgba(255, 193, 7, 0.65);
  background: linear-gradient(165deg, #4a148c 0%, #1a0a2e 55%, #311b92 100%);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}

/* Local play: face the picker toward the top player when it's their turn. */
.all-cards-modal.all-cards-flip .all-cards-panel {
  transform: rotate(180deg);
}

.all-cards-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.all-cards-title {
  margin: 0;
  font-family: 'Bangers', cursive;
  font-size: clamp(1.15rem, 5vw, 1.65rem);
  letter-spacing: 0.03em;
  color: var(--gold, #ffd54f);
}

.all-cards-close {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
  line-height: 1;
}

.all-cards-close:hover {
  background: rgba(0, 0, 0, 0.55);
}

.all-cards-sub {
  margin: 0.15rem 0 0.7rem;
  font-size: clamp(0.68rem, 3vw, 0.8rem);
  color: rgba(255, 255, 255, 0.78);
}

.all-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
  gap: 0.55rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 0.25rem;
  justify-items: center;
  align-content: start;
}

.all-cards-grid .card {
  width: 100%;
  max-width: 92px;
  margin: 0;
}

/* Cards in this popup are tap-only (no drag handlers), so let a swipe that
   starts on a card scroll the grid instead of being swallowed by the
   drag-gesture `touch-action: none` used in the hand. The `#all-cards-grid`
   ID gives this higher specificity than `.card.playable:not(.powerup-card)`,
   which otherwise wins on source order and blocks the swipe. */
#all-cards-grid .card,
#all-cards-grid .card.playable,
#all-cards-grid .card.steal-target,
#all-cards-grid .card img {
  touch-action: pan-y !important;
}

.all-cards-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: rgba(255, 255, 255, 0.75);
  padding: 1.5rem 0;
}

/* Multi-select footer (slot picker: build a multi-digit number) */
.all-cards-foot {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.7rem;
  padding-top: 0.7rem;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

.all-cards-preview {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  min-height: 46px;
}

.all-cards-preview .preview-card {
  width: 32px;
  height: 44px;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  flex: 0 0 auto;
}

.all-cards-preview .preview-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.all-cards-preview .preview-eq {
  margin-left: 0.3rem;
  font-size: clamp(1.2rem, 5.5vw, 1.6rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #ffe27a;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}

.all-cards-preview-empty {
  color: rgba(255, 255, 255, 0.6);
  font-size: clamp(0.72rem, 3vw, 0.85rem);
}

.all-cards-foot-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
}

.all-cards-done {
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  padding: 0.6rem 1.1rem;
  border-radius: 0.7rem;
  font-weight: 700;
  font-size: clamp(0.8rem, 3.4vw, 0.95rem);
  transition: transform 0.12s ease, background 0.12s ease;
}

.all-cards-done:active {
  transform: scale(0.96);
}

.all-cards-place {
  flex: 0 0 auto;
  border: none;
  cursor: pointer;
  padding: 0.6rem 1.1rem;
  border-radius: 0.7rem;
  font-weight: 800;
  font-size: clamp(0.8rem, 3.4vw, 0.95rem);
  color: #1c1330;
  background: linear-gradient(180deg, #ffe27a, #ffb938);
  box-shadow: 0 4px 14px rgba(255, 170, 40, 0.35);
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.all-cards-place:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.all-cards-place:not(:disabled):active {
  transform: scale(0.96);
}

/* Selected (picked) cards in the multi-select grid + order badge */
.all-cards-grid .card.picked {
  outline: 3px solid #ffd24a;
  outline-offset: 2px;
  border-radius: 0.55rem;
  box-shadow: 0 0 0 3px rgba(255, 210, 74, 0.25), 0 6px 16px rgba(0, 0, 0, 0.4);
}

.all-cards-grid .card {
  position: relative;
}

.all-cards-grid .card .pick-order {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ff5d8f;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  z-index: 3;
}

.btn-draw-header .draw-pile {
  width: clamp(28px, 7vw, 36px);
  height: clamp(36px, 9vw, 46px);
}

.btn-draw-header .draw-label {
  font-size: clamp(0.48rem, 1.9vw, 0.58rem);
  letter-spacing: 0.04em;
}

.btn-draw-header:not(.btn-draw-active) {
  opacity: 0.38;
  cursor: default;
}

.btn-draw-header.btn-draw-active:not(:disabled) {
  opacity: 1;
  cursor: pointer;
}

/* Shining glow when the top of the draw pile is a special card. */
.btn-draw-special {
  border-color: rgba(255, 213, 79, 0.95) !important;
  animation: draw-special-glow 1.2s ease-in-out infinite;
}

.btn-draw-special .draw-pile {
  border-color: #ffd54f;
}

.draw-pile-special::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(
    120deg,
    transparent 30%,
    rgba(255, 255, 255, 0.75) 48%,
    rgba(255, 235, 120, 0.4) 54%,
    transparent 70%
  );
  background-size: 220% 100%;
  animation: draw-special-shine 1.5s linear infinite;
  mix-blend-mode: screen;
}

@keyframes draw-special-glow {
  0%, 100% {
    box-shadow:
      0 0 6px rgba(255, 213, 79, 0.55),
      0 0 14px rgba(255, 193, 7, 0.45);
  }
  50% {
    box-shadow:
      0 0 12px rgba(255, 235, 120, 0.9),
      0 0 26px rgba(255, 193, 7, 0.75);
  }
}

@keyframes draw-special-shine {
  0% { background-position: 160% 0; }
  100% { background-position: -60% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .btn-draw-special,
  .draw-pile-special::after {
    animation: none;
  }
}

.btn-draw-header:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.player-header-leading.hidden {
  display: none;
}

.player-header .player-info {
  flex: 0 1 auto;
  min-width: 0;
  text-align: center;
}

.player-header-trailing {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  position: absolute;
  right: 0.35rem;
  top: 50%;
  transform: translateY(-50%);
}

.player-header .match-timer-wrap {
  margin-left: 0;
  flex-shrink: 0;
}

.btn-surrender {
  font-family: 'Nunito', sans-serif;
  font-size: 0.95rem;
  line-height: 1;
  min-width: 2.1rem;
  min-height: 2.1rem;
  padding: 0.3rem 0.45rem;
  border-radius: 10px;
  border: 2px solid rgba(239, 83, 80, 0.7);
  background: rgba(198, 40, 40, 0.38);
  color: #ffcdd2;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn-surrender.hidden {
  display: none;
}

.btn-surrender:active {
  transform: scale(0.94);
}

@media (hover: hover) {
  .btn-surrender:hover {
    background: rgba(198, 40, 40, 0.55);
    border-color: #ef5350;
  }
}

/* Match clock dock — always above the message bar */
.match-timer-float {
  display: flex;
  flex-shrink: 0;
  justify-content: flex-end;
  align-items: center;
  min-height: 2rem;
  padding: 0.2rem 0.65rem 0.1rem;
  pointer-events: none;
}

.match-timer-float .match-timer-wrap {
  pointer-events: auto;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

@media (max-width: 900px) {
  .player-header .match-timer-wrap {
    display: none;
  }

  .match-timer-wrap--bottom-hud {
    display: flex;
  }
}

@media (min-width: 901px) {
  .match-timer-wrap--bottom-hud {
    display: none;
  }
}

.player-avatar {
  width: clamp(36px, 10vw, 48px);
  height: clamp(36px, 10vw, 48px);
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--gold);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.player-name {
  font-family: 'Bangers', cursive;
  font-size: clamp(1rem, 4vw, 1.25rem);
  color: var(--gold);
  line-height: 1;
}

.card-count {
  font-size: 0.7rem;
  opacity: 0.75;
}

/* Hands — slide left/right when cards overflow */
.hand {
  display: flex;
  flex-wrap: nowrap;
  gap: clamp(10px, 3vw, 16px);
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.5rem 1rem 0.35rem;
  justify-content: flex-start;
  align-items: center;
  flex: 1 1 auto;
  width: 100%;
  min-height: var(--card-h);
  max-height: calc(var(--card-h) + 1.25rem);
  scroll-snap-type: x proximity;
  scroll-padding-inline: 1rem;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  touch-action: pan-x;
  cursor: grab;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.hand::before,
.hand::after {
  content: '';
  flex-shrink: 0;
  width: 0.35rem;
}

.hand.is-dragging {
  cursor: grabbing;
  scroll-snap-type: none;
}

.hand.was-scrolling .card {
  pointer-events: none;
}

.hand::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

/* Cards in hand */
.card {
  flex-shrink: 0;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  scroll-snap-align: center;
  position: relative;
  border: 2px solid transparent;
  background: none;
  padding: 0;
  overflow: hidden;
  touch-action: inherit;
  box-shadow: none;
}

/* Draggable number/op cards: JS owns both hand-scroll and drag-to-slot gestures.
   Power-up cards are tap-only, so they keep native scrolling (inherit pan-x/pan-y)
   and let the user slide the hand even when the swipe starts on them. */
.card.playable:not(.powerup-card),
.card.steal-target:not(.powerup-card) {
  touch-action: none;
}

.card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  pointer-events: none;
  filter: none;
}

.card.op-card img {
  object-fit: contain;
  background: linear-gradient(180deg, #c62828 0%, #b71c1c 100%);
}

.card:hover, .card:focus-visible {
  transform: translateY(-6px) scale(1.05);
  border-color: var(--gold);
  outline: none;
  box-shadow: none;
}

.card.selected {
  transform: translateY(-16px) scale(1.28);
  border-color: #ffeb3b;
  box-shadow: none;
  z-index: 5;
}

.card.disabled {
  opacity: 0.4;
  pointer-events: none;
  transform: none;
}

.card.playable {
  border-color: rgba(255, 215, 0, 0.75);
  animation: card-playable-pulse 1.5s ease infinite;
}

@keyframes card-playable-pulse {
  0%, 100% { border-color: rgba(255, 215, 0, 0.45); }
  50% { border-color: rgba(255, 235, 59, 0.95); }
}

.card.powerup-card {
  border-color: rgba(244, 67, 54, 0.65);
  background: linear-gradient(165deg, rgba(183, 28, 28, 0.35) 0%, rgba(74, 20, 140, 0.25) 100%);
}

.card.powerup-card img {
  object-fit: cover;
  background: #1a0a2e;
}

.card.powerup-card.selected {
  border-color: #ff5252;
  box-shadow: 0 0 14px rgba(244, 67, 54, 0.65);
}

.card.powerup-card-any-number {
  border-color: rgba(255, 193, 7, 0.75);
  background: linear-gradient(165deg, rgba(255, 152, 0, 0.32) 0%, rgba(183, 28, 28, 0.28) 100%);
}

.card.powerup-card-any-number.selected {
  border-color: #ffeb3b;
  box-shadow: 0 0 14px rgba(255, 235, 59, 0.75);
}

.card.powerup-card-targeted-attack {
  border-color: rgba(255, 87, 34, 0.85);
  background: linear-gradient(165deg, rgba(183, 28, 28, 0.42) 0%, rgba(255, 111, 0, 0.28) 100%);
}

.card.powerup-card-targeted-attack.selected {
  border-color: #ff9800;
  box-shadow: 0 0 16px rgba(255, 87, 34, 0.75);
}

.card.powerup-card-insight {
  border-color: rgba(156, 39, 176, 0.85);
  background: linear-gradient(165deg, rgba(74, 20, 140, 0.42) 0%, rgba(63, 81, 181, 0.32) 100%);
}

.card.powerup-card-insight.selected {
  border-color: #ce93d8;
  box-shadow: 0 0 16px rgba(156, 39, 176, 0.75);
}

.card.powerup-card-attack {
  border-color: rgba(229, 57, 53, 0.9);
  background: linear-gradient(165deg, rgba(183, 28, 28, 0.5) 0%, rgba(120, 120, 130, 0.3) 100%);
}

.card.powerup-card-attack.selected {
  border-color: #ff5252;
  box-shadow: 0 0 16px rgba(229, 57, 53, 0.8);
}

.card.powerup-card-any-special {
  border-color: rgba(255, 193, 7, 0.95);
  background: linear-gradient(165deg, rgba(183, 28, 28, 0.55) 0%, rgba(255, 152, 0, 0.35) 45%, rgba(74, 20, 140, 0.45) 100%);
}

.card.powerup-card-any-special.selected {
  border-color: #ffd54f;
  box-shadow: 0 0 18px rgba(255, 193, 7, 0.85);
}

.card.powerup-card-greedy {
  border-color: rgba(255, 196, 0, 0.95);
  background: linear-gradient(165deg, rgba(198, 40, 40, 0.5) 0%, rgba(255, 179, 0, 0.4) 100%);
}

.card.powerup-card-greedy.selected {
  border-color: #ffd700;
  box-shadow: 0 0 16px rgba(255, 196, 0, 0.85);
}

#screen-game.any-number-place-mode .equation-visual {
  outline: 2px dashed rgba(255, 235, 59, 0.85);
  outline-offset: 4px;
  border-radius: 14px;
}

.any-number-picker {
  position: absolute;
  inset: 0;
  z-index: 180;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.any-number-picker.panel-open,
.any-number-picker:not([hidden]) {
  display: flex;
}

.any-number-picker-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 5, 30, 0.72);
}

.any-number-picker-panel {
  position: relative;
  z-index: 2;
  width: min(100%, 340px);
  max-height: min(85vh, 520px);
  overflow-y: auto;
  padding: 1.1rem 1rem 1rem;
  border-radius: 18px;
  border: 3px solid rgba(255, 193, 7, 0.65);
  background: linear-gradient(165deg, #4a148c 0%, #1a0a2e 55%, #311b92 100%);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  text-align: center;
}

/* Local play: orient the picker toward the top player (Player 1) on their turn. */
.any-number-picker.picker-flip .any-number-picker-panel {
  transform: rotate(180deg);
}

.any-number-picker-title {
  font-family: 'Bangers', cursive;
  font-size: clamp(1.6rem, 7vw, 2rem);
  color: #fff9c4;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}

.any-number-picker-sub {
  font-size: 0.78rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: 0.85rem;
  line-height: 1.35;
}

.any-number-picker-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.45rem;
  margin-bottom: 0.85rem;
}

.any-number-pick-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.25rem;
  border: 2px solid rgba(255, 215, 0, 0.55);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  cursor: pointer;
  touch-action: manipulation;
}

.any-number-pick-btn img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 6px;
  pointer-events: none;
}

.any-number-pick-label {
  font-family: 'Nunito', sans-serif;
  font-size: 0.62rem;
  font-weight: 800;
  color: #ffe082;
}

.any-number-picker-empty {
  grid-column: 1 / -1;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.8);
  padding: 0.5rem;
}

.any-number-picker-cancel {
  width: 100%;
}

/* Any Special Card picker */
.any-special-picker {
  position: absolute;
  inset: 0;
  z-index: 180;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.any-special-picker.panel-open,
.any-special-picker:not([hidden]) {
  display: flex;
}

.any-special-picker-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 5, 30, 0.74);
}

.any-special-picker-panel {
  position: relative;
  z-index: 2;
  width: min(100%, 360px);
  max-height: min(86vh, 560px);
  overflow-y: auto;
  padding: 1.1rem 1rem 1rem;
  border-radius: 18px;
  border: 3px solid rgba(255, 193, 7, 0.7);
  background: linear-gradient(165deg, #b71c1c 0%, #4a148c 55%, #311b92 100%);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  text-align: center;
}

/* Local play: orient the picker toward the top player (Player 1) on their turn. */
.any-special-picker.picker-flip .any-special-picker-panel {
  transform: rotate(180deg);
}

.any-special-picker-title {
  font-family: 'Bangers', cursive;
  font-size: clamp(1.5rem, 6.5vw, 1.95rem);
  color: #fff9c4;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}

.any-special-picker-sub {
  font-size: 0.78rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.88);
  margin-bottom: 0.9rem;
  line-height: 1.35;
}

.any-special-picker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.any-special-pick-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.3rem;
  border: 2px solid rgba(255, 215, 0, 0.55);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.any-special-pick-btn:active {
  transform: scale(0.96);
}

.any-special-pick-btn:hover:not(.is-disabled),
.any-special-pick-btn:focus-visible:not(.is-disabled) {
  border-color: #ffd54f;
  box-shadow: 0 0 14px rgba(255, 193, 7, 0.6);
  outline: none;
}

.any-special-pick-btn img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 8px;
  pointer-events: none;
}

.any-special-pick-label {
  font-family: 'Nunito', sans-serif;
  font-size: 0.66rem;
  font-weight: 800;
  color: #ffe082;
}

.any-special-pick-btn.is-disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.7);
}

.any-special-picker-cancel {
  width: 100%;
}

/* Steal picker — opponent cards (online) */
.steal-picker {
  position: absolute;
  inset: 0;
  z-index: 180;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.steal-picker.panel-open,
.steal-picker:not([hidden]) {
  display: flex;
}

.steal-picker-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 5, 30, 0.78);
}

.steal-picker-panel {
  position: relative;
  z-index: 2;
  width: min(100%, 360px);
  max-height: min(88vh, 560px);
  overflow-y: auto;
  padding: 1.1rem 1rem 1rem;
  border-radius: 18px;
  border: 3px solid rgba(244, 67, 54, 0.75);
  background: linear-gradient(165deg, #4a148c 0%, #1a0a2e 55%, #311b92 100%);
  box-shadow:
    0 12px 32px rgba(0, 0, 0, 0.55),
    0 0 28px rgba(244, 67, 54, 0.25);
  text-align: center;
}

/* Local play: orient the picker toward the stealing top player (Player 1). */
.steal-picker.picker-flip .steal-picker-panel {
  transform: rotate(180deg);
}

.steal-picker-title {
  font-family: 'Bangers', cursive;
  font-size: clamp(1.6rem, 7vw, 2rem);
  color: #ffcdd2;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}

.steal-picker-sub {
  font-size: 0.78rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.88);
  margin-bottom: 0.85rem;
  line-height: 1.35;
}

.steal-picker-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  margin-bottom: 0.85rem;
}

.steal-picker-card-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem;
  border: 2px solid rgba(255, 82, 82, 0.75);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.3);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.steal-picker-card-btn:hover,
.steal-picker-card-btn:focus-visible {
  transform: translateY(-4px) scale(1.03);
  border-color: #ffeb3b;
  box-shadow: 0 0 16px rgba(255, 235, 59, 0.55);
  outline: none;
}

.steal-picker-card-btn img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: contain;
  border-radius: 8px;
  pointer-events: none;
  background: linear-gradient(165deg, #1a237e 0%, #0d1642 100%);
}

.steal-picker-card-label {
  font-family: 'Nunito', sans-serif;
  font-size: 0.72rem;
  font-weight: 800;
  color: #ffe082;
}

.steal-picker-empty {
  grid-column: 1 / -1;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.8);
  padding: 0.5rem;
}

.steal-picker-note {
  margin-top: 0.65rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: rgba(255, 215, 0, 0.85);
  line-height: 1.35;
}

.card.steal-target {
  border-color: rgba(255, 82, 82, 0.95);
  animation: steal-target-pulse 0.85s ease infinite;
  cursor: pointer;
}

.card.steal-target.selected {
  border-color: #ffeb3b;
}

@keyframes steal-target-pulse {
  0%, 100% {
    transform: translateY(-4px) scale(1.03);
    box-shadow: 0 0 10px rgba(255, 82, 82, 0.45);
  }
  50% {
    transform: translateY(-8px) scale(1.06);
    box-shadow: 0 0 18px rgba(255, 82, 82, 0.85);
  }
}

.hand-scroll-wrap.steal-mode-active {
  outline: 2px dashed rgba(255, 82, 82, 0.75);
  outline-offset: 3px;
  border-radius: 12px;
}

/* Power-up lightning splash */
.powerup-splash {
  position: absolute;
  inset: 0;
  z-index: 190;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  overflow: hidden;
}

.powerup-splash:not([hidden]),
.powerup-splash.show {
  display: flex;
}

.powerup-splash-flash {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0);
  pointer-events: none;
  z-index: 1;
}

.powerup-splash.flash-1 .powerup-splash-flash,
.powerup-splash.flash-2 .powerup-splash-flash,
.powerup-splash.flash-3 .powerup-splash-flash {
  animation: thunder-flash 0.12s ease-out;
}

.powerup-thunder {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}

.powerup-splash.thunder-show .lightning-1 {
  animation: bolt-strike 0.32s ease-out 0.05s;
}

.powerup-splash.thunder-show .lightning-2 {
  animation: bolt-strike 0.36s ease-out 0.28s;
}

.powerup-splash.thunder-show .lightning-3 {
  animation: bolt-strike 0.32s ease-out 0.52s;
}

.powerup-splash-panel {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 1rem 1.35rem;
  border-radius: 16px;
  background: linear-gradient(165deg, rgba(26, 10, 46, 0.92) 0%, rgba(74, 20, 140, 0.88) 100%);
  border: 2px solid rgba(255, 235, 59, 0.85);
  box-shadow:
    0 0 24px rgba(255, 235, 59, 0.45),
    0 8px 32px rgba(0, 0, 0, 0.55);
  transform: scale(0.85);
  opacity: 0;
  animation: powerup-panel-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) 0.08s forwards;
}

.powerup-splash.powerup-steal .powerup-splash-panel {
  border-color: rgba(255, 82, 82, 0.9);
  box-shadow:
    0 0 24px rgba(255, 82, 82, 0.5),
    0 8px 32px rgba(0, 0, 0, 0.55);
}

.powerup-splash.powerup-any-number .powerup-splash-panel {
  border-color: rgba(255, 193, 7, 0.9);
  box-shadow:
    0 0 24px rgba(255, 193, 7, 0.5),
    0 8px 32px rgba(0, 0, 0, 0.55);
}

.powerup-splash.powerup-targeted-attack .powerup-splash-panel {
  border-color: rgba(255, 87, 34, 0.95);
  box-shadow:
    0 0 28px rgba(255, 87, 34, 0.55),
    0 8px 32px rgba(0, 0, 0, 0.55);
}

.powerup-splash.powerup-insight .powerup-splash-panel {
  border-color: rgba(186, 104, 200, 0.95);
  box-shadow:
    0 0 28px rgba(156, 39, 176, 0.55),
    0 8px 32px rgba(0, 0, 0, 0.55);
}

.powerup-splash.powerup-attack .powerup-splash-panel {
  border-color: rgba(229, 57, 53, 0.95);
  box-shadow:
    0 0 30px rgba(229, 57, 53, 0.6),
    0 8px 32px rgba(0, 0, 0, 0.55);
}

.powerup-splash.powerup-greedy .powerup-splash-panel {
  border-color: rgba(255, 196, 0, 0.95);
  box-shadow:
    0 0 30px rgba(255, 196, 0, 0.6),
    0 8px 32px rgba(0, 0, 0, 0.55);
}

.powerup-splash-icon {
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.powerup-splash-title {
  margin: 0;
  font-family: 'Bangers', cursive;
  font-size: 1.75rem;
  letter-spacing: 0.04em;
  color: #fff9c4;
  text-shadow: 0 0 12px rgba(255, 235, 59, 0.8);
}

.powerup-splash-sub {
  margin: 0;
  font-family: 'Nunito', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.92);
  text-align: center;
  max-width: 220px;
}

@keyframes powerup-panel-pop {
  0% {
    transform: scale(0.7);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

#screen-game.flash-powerup {
  animation: powerup-screen-flash 0.35s ease;
}

@keyframes powerup-screen-flash {
  0% { filter: brightness(2.2); }
  100% { filter: brightness(1); }
}

/* Play Slots */
.play-slot {
  width: var(--slot-size);
  height: calc(var(--slot-size) * 1.35);
  border: 3px dashed rgba(255, 215, 0, 0.45);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.play-slot .slot-label {
  font-family: 'Bangers', cursive;
  font-size: 1.4rem;
  color: rgba(255, 215, 0, 0.4);
  pointer-events: none;
}

.play-slot.has-card {
  border-style: solid;
  border-color: var(--gold);
  background: rgba(255, 255, 255, 0.05);
}

.play-slot.has-card .slot-label {
  display: none;
}

.play-slot.drop-target {
  border-color: #69f0ae;
  background: rgba(105, 240, 174, 0.15);
  box-shadow: 0 0 16px rgba(105, 240, 174, 0.5);
  animation: slot-pulse 0.8s ease infinite;
}

@keyframes slot-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.play-slot .slot-card {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 9px;
}

.play-slot.slot-op .slot-card {
  object-fit: contain;
}

.play-slot.slot-op {
  width: calc(var(--slot-size) * 1.1);
  border-color: var(--red);
}

.play-slot.slot-answer {
  border-color: var(--blue-bright);
}

/* Battle Center */
.battle-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.2rem clamp(0.1rem, 1.2vw, 0.5rem);
  flex-shrink: 0;
  width: 100%;
  max-width: 100%;
  overflow: visible;
  box-sizing: border-box;
}

.eq-sign {
  font-family: 'Bangers', cursive;
  font-size: clamp(1.35rem, 4.5vw, 1.75rem);
  color: var(--gold);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.equation-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.equation-hint {
  font-size: clamp(0.65rem, 2.4vw, 0.78rem);
  color: rgba(255, 255, 255, 0.65);
  text-align: center;
  margin: 0 auto 0.2rem;
  width: 100%;
  max-width: 100%;
  transition: color 0.2s;
}

.equation-hint.active {
  color: var(--gold);
  font-weight: 700;
}

.equation-visual {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: clamp(0.12rem, 0.8vw, 0.35rem);
  padding: clamp(0.42rem, 1.4vw, 0.55rem) clamp(0.2rem, 1.2vw, 0.4rem);
  min-height: clamp(92px, 20vw, 112px);
  background: linear-gradient(165deg, #2a1456 0%, #16082a 60%, #281466 100%);
  border: 2px solid rgba(255, 215, 0, 0.35);
  border-radius: 14px;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  overflow: visible;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
}

.equation-visual::-webkit-scrollbar {
  display: none;
}

.eq-slot {
  font-family: 'Bangers', cursive;
  display: flex;
  flex-shrink: 1;
  align-items: center;
  justify-content: center;
  width: clamp(42px, 10.5vw, 70px);
  height: clamp(54px, 13.5vw, 82px);
  padding: 0.2rem;
  border: 2px dashed rgba(255, 215, 0, 0.5);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  touch-action: manipulation;
  position: relative;
  z-index: 1;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s, background 0.2s;
  color: var(--white);
  overflow: visible;
  box-sizing: border-box;
}

.eq-slot-value,
.eq-slot-cycle,
.eq-equals {
  pointer-events: none;
}

.eq-slot-num {
  width: clamp(44px, 11vw, 72px);
  height: clamp(56px, 14vw, 86px);
}

.eq-slot-value {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: clamp(1.35rem, 6.2vw, 2.15rem);
  line-height: 1;
  padding: 0.1em 0.05em;
  color: #fff9c4;
  text-shadow:
    0 3px 0 #5d4037,
    0 0 16px rgba(255, 215, 0, 0.45);
  overflow: visible;
  white-space: nowrap;
  -webkit-font-smoothing: antialiased;
}

.eq-slot-value .eq-card-img {
  width: clamp(36px, 9.5vw, 54px);
  height: clamp(52px, 13.5vw, 78px);
  object-fit: contain;
  border-radius: 8px;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.45));
  pointer-events: none;
  user-select: none;
}

.eq-slot.has-card {
  border-style: solid;
  border-color: var(--gold);
  background: rgba(255, 215, 0, 0.12);
}

.eq-slot.eq-slot-partial {
  border-color: #69f0ae;
  border-style: dashed;
  animation: slot-pulse 1s ease infinite;
  box-shadow: 0 0 14px rgba(105, 240, 174, 0.45);
}

.eq-slot-value.two-digit {
  font-size: clamp(1.35rem, 6vw, 2rem);
  letter-spacing: -0.02em;
}

.eq-slot.can-place {
  border-color: rgba(255, 215, 0, 0.35);
}

.eq-slot.can-recall {
  border-color: #ff9800;
  box-shadow: 0 0 12px rgba(255, 152, 0, 0.55);
  cursor: pointer;
}

.eq-slot.can-recall::after {
  content: '↩';
  position: absolute;
  top: 2px;
  right: 5px;
  font-size: 0.7rem;
  font-weight: 800;
  color: #ffeb3b;
  line-height: 1;
  pointer-events: none;
}

.eq-slot.can-recall-opponent {
  border-color: #f44336;
  box-shadow: 0 0 12px rgba(244, 67, 54, 0.55);
  cursor: pointer;
}

.eq-slot.can-recall-opponent::after {
  content: '✕';
  position: absolute;
  top: 2px;
  right: 6px;
  font-size: 0.75rem;
  font-weight: 800;
  color: #ffcdd2;
  line-height: 1;
  pointer-events: none;
}

.eq-slot.drop-target {
  border-color: #69f0ae;
  background: rgba(105, 240, 174, 0.2);
  box-shadow: 0 0 16px rgba(105, 240, 174, 0.5);
  animation: slot-pulse 0.8s ease infinite;
  transform: scale(1.05);
}

.eq-slot.drag-hover {
  border-color: #b9f6ca;
  background: rgba(105, 240, 174, 0.32);
  box-shadow: 0 0 22px rgba(105, 240, 174, 0.75);
  transform: scale(1.1);
  z-index: 2;
}

body.card-drag-active .equation-visual {
  border-color: rgba(105, 240, 174, 0.55);
  box-shadow: 0 0 18px rgba(105, 240, 174, 0.25);
}

body.card-drag-pending,
body.card-drag-active {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

body.card-drag-pending .hand,
body.card-drag-active .hand {
  touch-action: none;
}

body.card-drag-active .hand .card.playable:not(.is-dragging-source) {
  opacity: 0.72;
}

.card.is-drag-lift {
  z-index: 8;
  transform: translateY(-10px) scale(1.1);
  border-color: #ffeb3b;
  box-shadow:
    0 8px 20px rgba(0, 0, 0, 0.45),
    0 0 18px rgba(255, 215, 0, 0.55);
  animation: card-drag-lift-glow 0.7s ease-in-out infinite;
}

.card.is-dragging-source {
  opacity: 0.28;
  transform: scale(0.9);
  border-color: rgba(255, 215, 0, 0.5);
  box-shadow: 0 0 14px rgba(255, 215, 0, 0.35);
  animation: none;
}

.card-drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 250;
  pointer-events: none;
  margin: 0;
  overflow: visible;
  will-change: transform;
  border: 2px solid #ffeb3b;
  border-radius: 10px;
  opacity: 1;
  transform-origin: center center;
  transition: scale 0.14s ease, border-color 0.14s ease;
  animation: card-drag-ghost-glow 0.75s ease-in-out infinite;
  filter: drop-shadow(0 12px 16px rgba(0, 0, 0, 0.5));
  backface-visibility: hidden;
}

/* While hovering the equation area the ghost shrinks toward slot size. */
.card-drag-ghost.over-equation {
  border-color: #69f0ae;
}

.card-drag-ghost img {
  filter: brightness(1.1) saturate(1.12);
}

.card-drag-ghost::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 14px;
  border: 2px solid rgba(255, 235, 59, 0.45);
  box-shadow:
    0 0 20px rgba(255, 215, 0, 0.65),
    0 0 36px rgba(255, 193, 7, 0.45);
  animation: card-drag-ghost-ring 0.9s ease-in-out infinite;
  pointer-events: none;
  z-index: -1;
}

.card-drag-ghost.selected {
  border-color: #ffeb3b;
}

@keyframes card-drag-lift-glow {
  0%, 100% {
    box-shadow:
      0 8px 20px rgba(0, 0, 0, 0.45),
      0 0 16px rgba(255, 215, 0, 0.45);
  }
  50% {
    box-shadow:
      0 10px 24px rgba(0, 0, 0, 0.5),
      0 0 28px rgba(255, 235, 59, 0.85);
  }
}

@keyframes card-drag-ghost-glow {
  0%, 100% {
    box-shadow:
      0 14px 32px rgba(0, 0, 0, 0.55),
      0 0 22px rgba(255, 215, 0, 0.55),
      0 0 40px rgba(255, 193, 7, 0.35);
  }
  50% {
    box-shadow:
      0 18px 38px rgba(0, 0, 0, 0.6),
      0 0 32px rgba(255, 235, 59, 0.95),
      0 0 52px rgba(255, 152, 0, 0.55);
  }
}

@keyframes card-drag-ghost-ring {
  0%, 100% {
    opacity: 0.55;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.04);
  }
}

.eq-slot:active {
  transform: scale(0.96);
}

.eq-slot-op {
  position: relative;
  width: clamp(40px, 10vw, 58px);
  height: clamp(54px, 13.5vw, 82px);
  border-color: rgba(198, 40, 40, 0.6);
  flex-shrink: 1;
}

.eq-slot-op .eq-slot-value {
  font-size: clamp(1.65rem, 7.2vw, 2.35rem);
}

.eq-slot-op[data-op='+'] { border-color: rgba(255, 193, 7, 0.7); }
.eq-slot-op[data-op='-'] { border-color: rgba(244, 67, 54, 0.7); }
.eq-slot-op[data-op='*'] { border-color: rgba(156, 39, 176, 0.7); }
.eq-slot-op[data-op='/'] { border-color: rgba(33, 150, 243, 0.7); }

.eq-slot-op.op-cycleable,
.eq-slot-op.can-place {
  cursor: pointer;
}

.eq-slot-op .eq-slot-cycle {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-family: 'Nunito', sans-serif;
  font-size: 0.5rem;
  font-weight: 800;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
  letter-spacing: 0.03em;
  pointer-events: none;
}

.eq-slot-op.op-cycleable {
  animation: op-glow 1.2s ease infinite;
}

@keyframes op-glow {
  0%, 100% { box-shadow: 0 0 8px rgba(255, 193, 7, 0.35); }
  50% { box-shadow: 0 0 16px rgba(255, 193, 7, 0.65); }
}

.eq-slot-answer {
  border-color: rgba(66, 165, 245, 0.65);
}

.battle-center .btn-end-turn {
  flex-shrink: 0;
  align-self: center;
  width: min(100%, 14rem);
  margin-left: 0;
  margin-top: 0.15rem;
}

.battle-match-score {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(0.35rem, 2.5vw, 0.75rem);
  width: min(100%, 22rem);
  margin-top: 0.15rem;
  padding: 0.35rem clamp(0.4rem, 2vw, 0.65rem);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 215, 0, 0.22);
  box-sizing: border-box;
}

.battle-match-score.hidden,
.battle-match-score[hidden] {
  display: none !important;
}

.battle-match-side {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.05rem;
  text-align: center;
}

.battle-match-username {
  font-size: clamp(0.62rem, 2.6vw, 0.78rem);
  font-weight: 700;
  color: var(--gold, #ffd54f);
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.battle-match-crown {
  font-size: clamp(0.85rem, 3.6vw, 1.1rem);
  line-height: 1;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.5));
  animation: battle-crown-pop 0.35s ease;
}

.battle-match-crown[hidden] {
  display: none;
}

@keyframes battle-crown-pop {
  0% { transform: scale(0.4); opacity: 0; }
  70% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

.battle-match-role {
  font-size: clamp(0.52rem, 2vw, 0.62rem);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  line-height: 1.1;
}

.battle-match-points {
  font-family: 'Bangers', cursive;
  font-size: clamp(1.05rem, 4.5vw, 1.35rem);
  color: #fff;
  line-height: 1;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}

.battle-match-vs {
  flex: 0 0 auto;
  font-family: 'Bangers', cursive;
  font-size: clamp(0.85rem, 3.5vw, 1.05rem);
  color: rgba(255, 215, 0, 0.75);
  letter-spacing: 0.06em;
  padding: 0 0.1rem;
}

.mode-online .battle-match-score {
  width: min(100%, 20rem);
  margin-top: 0.25rem;
  padding: 0.4rem clamp(0.35rem, 2vw, 0.55rem);
  background: rgba(8, 12, 28, 0.72);
  border-color: rgba(255, 145, 0, 0.28);
}

.mode-online .battle-match-username {
  font-size: clamp(0.68rem, 2.8vw, 0.82rem);
}

.mode-online .battle-match-points {
  font-size: clamp(1.15rem, 5vw, 1.45rem);
  color: #ffcc80;
}

.btn-end-turn {
  --end-turn-orange: #ff9100;
  --end-turn-orange-deep: #e65100;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: clamp(7rem, 42vw, 11rem);
  min-height: clamp(2.5rem, 10vw, 3rem);
  padding: 0.35rem 0.85rem;
  overflow: hidden;
  isolation: isolate;
  border: 2px solid #ffcc80;
  border-radius: 12px;
  background: linear-gradient(
    165deg,
    #ffb74d 0%,
    var(--end-turn-orange) 38%,
    var(--end-turn-orange-deep) 100%
  );
  color: #fffde7;
  font-family: 'Bangers', cursive;
  font-size: clamp(0.72rem, 2.8vw, 0.9rem);
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-shadow:
    0 2px 0 rgba(191, 54, 12, 0.85),
    0 0 12px rgba(255, 255, 255, 0.45);
  cursor: pointer;
  touch-action: manipulation;
  box-shadow:
    0 0 0 1px rgba(255, 224, 178, 0.35) inset,
    0 4px 0 #bf360c,
    0 6px 18px rgba(255, 111, 0, 0.55),
    0 0 22px rgba(255, 152, 0, 0.65);
  animation: end-turn-glow 2s ease-in-out infinite;
  transition: transform 0.12s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.btn-end-turn::before {
  content: '';
  position: absolute;
  inset: -40% -60%;
  background: linear-gradient(
    105deg,
    transparent 38%,
    rgba(255, 255, 255, 0.55) 48%,
    rgba(255, 255, 255, 0.15) 52%,
    transparent 62%
  );
  transform: translateX(-120%) rotate(12deg);
  animation: end-turn-shine 2.8s ease-in-out infinite;
  pointer-events: none;
  z-index: -1;
}

.btn-end-turn::after {
  content: '';
  position: absolute;
  inset: 2px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  pointer-events: none;
  z-index: -1;
}

@keyframes end-turn-glow {
  0%, 100% {
    box-shadow:
      0 0 0 1px rgba(255, 224, 178, 0.35) inset,
      0 4px 0 #bf360c,
      0 6px 16px rgba(255, 111, 0, 0.5),
      0 0 18px rgba(255, 152, 0, 0.55);
  }
  50% {
    box-shadow:
      0 0 0 1px rgba(255, 248, 225, 0.5) inset,
      0 4px 0 #bf360c,
      0 8px 22px rgba(255, 145, 0, 0.7),
      0 0 32px rgba(255, 193, 7, 0.75);
  }
}

@keyframes end-turn-shine {
  0%, 28% {
    transform: translateX(-120%) rotate(12deg);
  }
  52%, 100% {
    transform: translateX(140%) rotate(12deg);
  }
}

.btn-end-turn.hidden,
.btn-end-turn[hidden] {
  display: none !important;
}

.btn-end-turn:active:not(:disabled) {
  transform: translateY(2px) scale(0.98);
  box-shadow:
    0 0 0 1px rgba(255, 224, 178, 0.35) inset,
    0 2px 0 #bf360c,
    0 4px 12px rgba(255, 111, 0, 0.45),
    0 0 16px rgba(255, 152, 0, 0.5);
  animation: none;
}

.btn-end-turn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  filter: grayscale(0.45) brightness(0.75);
  animation: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.btn-end-turn.btn-end-turn-ready:not(:disabled) {
  animation: end-turn-glow 1.35s ease-in-out infinite;
}

/* End Turn button follows the active player's orientation (hotseat / table play).
   When the active player is at the top, move the button above the equation and
   flip it 180° so it faces them. */
#screen-game.eq-face-top .battle-center .btn-end-turn {
  order: -1;
  transform: rotate(180deg);
}

#screen-game.eq-face-top .battle-center .btn-end-turn:active:not(:disabled) {
  transform: rotate(180deg) translateY(2px) scale(0.98);
}

.btn-end-turn:disabled::before {
  animation: none;
  opacity: 0;
}

@media (hover: hover) {
  .btn-end-turn:hover:not(:disabled) {
    filter: brightness(1.08);
    box-shadow:
      0 0 0 1px rgba(255, 248, 225, 0.55) inset,
      0 4px 0 #bf360c,
      0 8px 24px rgba(255, 145, 0, 0.75),
      0 0 36px rgba(255, 214, 0, 0.85);
  }
}

/* Operation cards in hand */
.card.op-card {
  background: linear-gradient(160deg, #c62828 0%, #6a1b9a 100%);
}

.card.op-card .op-symbol {
  font-family: 'Bangers', cursive;
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  color: #fff9c4;
  text-shadow: 0 2px 0 #4a148c, 0 0 12px rgba(255, 235, 59, 0.5);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.card.op-card-mul {
  background: linear-gradient(160deg, #6a1b9a 0%, #4a148c 100%);
}

.card.op-card-div {
  background: linear-gradient(160deg, #1565c0 0%, #0d47a1 100%);
}

.eq-equals {
  font-family: 'Bangers', cursive;
  font-size: clamp(1.25rem, 4.8vw, 1.85rem);
  color: var(--gold);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  padding: 0 0.08rem;
  flex-shrink: 0;
  line-height: 1;
  align-self: center;
}

.center-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: center;
  margin-top: 0.25rem;
  width: 100%;
}

.btn-draw, .btn-pass {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 215, 0, 0.4);
  border-radius: 12px;
  padding: 0.35rem 0.6rem;
  color: var(--white);
  font-family: 'Nunito', sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
  touch-action: manipulation;
}

.btn-draw:active, .btn-pass:active {
  transform: scale(0.95);
  background: rgba(255, 215, 0, 0.2);
}

.draw-pile {
  width: 40px;
  height: 52px;
  background: linear-gradient(135deg, var(--blue-mid), var(--blue-dark));
  border: 2px solid var(--gold);
  border-radius: 6px;
  position: relative;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.3);
}

.draw-pile-face {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
  pointer-events: none;
}

.draw-pile.empty .draw-pile-face {
  opacity: 0;
  visibility: hidden;
}

.draw-pile.draw-pile-pulse {
  animation: draw-pile-pulse 0.35s ease;
}

@keyframes draw-pile-pulse {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(0.88); }
}

/* Card flying from draw pile to hand */
.draw-fly-card {
  position: fixed;
  left: var(--fly-x0);
  top: var(--fly-y0);
  width: var(--fly-w);
  height: var(--fly-h);
  z-index: 500;
  pointer-events: none;
  transform: translate(-50%, -50%);
  opacity: 0;
  will-change: left, top, transform, opacity;
}

.draw-fly-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  border: 2px solid var(--gold);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
}

.draw-fly-card.is-flying {
  animation: card-draw-fly 0.52s cubic-bezier(0.22, 0.85, 0.32, 1) forwards;
}

@keyframes card-draw-fly {
  0% {
    left: var(--fly-x0);
    top: var(--fly-y0);
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
    opacity: 1;
  }
  42% {
    left: calc((var(--fly-x0) + var(--fly-x1)) / 2);
    top: calc(var(--fly-y0) - 56px);
    transform: translate(-50%, -50%) scale(1.12) rotate(-14deg);
    opacity: 1;
  }
  100% {
    left: var(--fly-x1);
    top: var(--fly-y1);
    transform: translate(-50%, -50%) scale(0.72) rotate(8deg);
    opacity: 0.92;
  }
}

.draw-reveal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 600;
  background: radial-gradient(circle at center, rgba(8, 14, 36, 0.62), rgba(2, 4, 12, 0.78));
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
}

.draw-reveal-backdrop.show {
  opacity: 1;
}

.draw-reveal-card {
  position: fixed;
  left: 50%;
  top: 44%;
  z-index: 601;
  width: min(52vw, 220px);
  aspect-ratio: 5 / 7;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.45) rotate(-6deg);
  opacity: 0;
  transition:
    transform 0.34s cubic-bezier(0.2, 0.9, 0.3, 1.25),
    opacity 0.28s ease;
  will-change: transform, opacity;
}

.draw-reveal-card.show {
  transform: translate(-50%, -50%) scale(1) rotate(0deg);
  opacity: 1;
}

.draw-reveal-card.is-flying {
  transition:
    transform 0.48s cubic-bezier(0.5, 0, 0.4, 1),
    opacity 0.48s ease;
}

/* Local play: orient the drawn card toward the top player (Player 1). The
   container's transform is animation-driven, so rotate the art instead. */
.draw-reveal-card.draw-reveal-facing-top img {
  transform: rotate(180deg);
}

.draw-reveal-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 16px;
  border: 3px solid var(--gold);
  box-shadow:
    0 0 0 3px rgba(0, 0, 0, 0.35),
    0 22px 60px rgba(0, 0, 0, 0.6),
    0 0 36px rgba(255, 215, 0, 0.35);
}

/* Flip reveal for special cards: back face shown first, then flips to front */
.draw-reveal-flip {
  perspective: 1100px;
}

.draw-flip-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0.05, 0.2, 1);
}

.draw-reveal-flip.flipped .draw-flip-inner {
  transform: rotateY(180deg);
}

.draw-flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.draw-flip-front {
  transform: rotateY(180deg);
}

@media (prefers-reduced-motion: reduce) {
  .draw-flip-inner {
    transition-duration: 0.18s;
  }
}

/* Power-up reveal (large preview + lightning, then burst on activate) */
.powerup-reveal-backdrop {
  background: radial-gradient(circle at center, rgba(20, 40, 80, 0.55), rgba(2, 6, 18, 0.82));
}

/* Local play: face the revealed special card toward the top player (Player 1).
   Rotating this wrapper (not the <img>) keeps the card's `zap` shake animation
   intact while still flipping the art the right way up for them. */
.powerup-reveal-rot {
  position: absolute;
  inset: 0;
  transform: rotate(180deg);
}

.powerup-reveal-card.is-bursting {
  transition:
    transform 0.32s cubic-bezier(0.4, 0, 0.6, 1),
    opacity 0.32s ease;
  transform: translate(-50%, -50%) scale(1.45) rotate(3deg);
  opacity: 0;
}

.powerup-reveal-card.zap img {
  animation: powerup-zap-shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

.powerup-reveal-card.zap::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.9);
  mix-blend-mode: screen;
  animation: powerup-flash 0.42s ease forwards;
  pointer-events: none;
}

@keyframes powerup-zap-shake {
  10%, 90% { transform: translateX(-2px) rotate(-1deg); }
  20%, 80% { transform: translateX(3px) rotate(1.5deg); }
  30%, 50%, 70% { transform: translateX(-5px) rotate(-2deg); }
  40%, 60% { transform: translateX(5px) rotate(2deg); }
}

@keyframes powerup-flash {
  0% { opacity: 0; }
  18% { opacity: 0.95; }
  100% { opacity: 0; }
}

.powerup-lightning {
  position: absolute;
  inset: -40%;
  pointer-events: none;
  z-index: 2;
}

.powerup-lightning span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 150%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, #ffffff 38%, #9fd8ff 60%, rgba(126, 200, 255, 0) 100%);
  filter: drop-shadow(0 0 6px #8fd0ff) drop-shadow(0 0 14px #4aa3ff);
  clip-path: polygon(48% 0, 58% 0, 50% 30%, 64% 32%, 46% 62%, 56% 60%, 38% 100%, 50% 56%, 36% 58%, 52% 28%, 40% 30%);
  opacity: 0;
  transform-origin: center top;
}

.powerup-lightning span:nth-child(1) { transform: translate(-50%, -50%) rotate(18deg); }
.powerup-lightning span:nth-child(2) { transform: translate(-50%, -50%) rotate(-32deg); }
.powerup-lightning span:nth-child(3) { transform: translate(-50%, -50%) rotate(128deg); }
.powerup-lightning span:nth-child(4) { transform: translate(-50%, -50%) rotate(-150deg); }

.powerup-reveal-card.zap .powerup-lightning span {
  animation: powerup-bolt 0.55s steps(1, end);
}

.powerup-reveal-card.zap .powerup-lightning span:nth-child(2) { animation-delay: 0.06s; }
.powerup-reveal-card.zap .powerup-lightning span:nth-child(3) { animation-delay: 0.03s; }
.powerup-reveal-card.zap .powerup-lightning span:nth-child(4) { animation-delay: 0.09s; }

@keyframes powerup-bolt {
  0% { opacity: 0; }
  10% { opacity: 1; }
  25% { opacity: 0.2; }
  40% { opacity: 0.9; }
  60% { opacity: 0; }
  100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .draw-reveal-card,
  .draw-reveal-card.is-flying,
  .powerup-reveal-card.is-bursting {
    transition-duration: 0.12s;
  }
  .powerup-lightning span,
  .powerup-reveal-card.zap img {
    animation-duration: 0.2s;
  }
}

.hand.hand-draw-landed {
  animation: hand-draw-landed 0.35s ease 0.38s;
}

@keyframes hand-draw-landed {
  0%, 100% { filter: none; }
  50% { filter: drop-shadow(0 0 14px rgba(255, 215, 0, 0.65)); }
}

/* Message bar */
.message-bar {
  flex-shrink: 0;
  text-align: center;
  padding: 0.4rem 0.75rem;
  font-size: clamp(0.75rem, 3vw, 0.9rem);
  font-weight: 700;
  background: rgba(0, 0, 0, 0.4);
  border-top: 1px solid rgba(255, 215, 0, 0.2);
  min-height: 2rem;
  position: relative;
  z-index: 1;
}

.message-bar.success {
  color: #69f0ae;
}

.message-bar.error {
  color: #ff8a80;
}

.message-bar.info {
  color: var(--gold);
}

/* Victory Splash */
.victory-splash {
  background:
    radial-gradient(ellipse at 50% 20%, rgba(156, 39, 176, 0.55) 0%, transparent 55%),
    radial-gradient(ellipse at 20% 80%, rgba(0, 229, 255, 0.22) 0%, transparent 45%),
    radial-gradient(ellipse at 80% 75%, rgba(255, 64, 129, 0.2) 0%, transparent 45%),
    linear-gradient(180deg, #0a0218 0%, #12082a 45%, #050510 100%);
  z-index: 200;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.victory-splash.active,
.victory-splash:not([hidden]) {
  display: flex !important;
}

.victory-flash {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0);
  pointer-events: none;
  z-index: 1;
}

.victory-splash.flash-1 .victory-flash,
.victory-splash.flash-2 .victory-flash,
.victory-splash.flash-3 .victory-flash {
  animation: thunder-flash 0.15s ease-out;
}

@keyframes thunder-flash {
  0% { background: rgba(255, 255, 220, 0.85); }
  100% { background: rgba(255, 255, 255, 0); }
}

.victory-thunder {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}

.lightning {
  position: absolute;
  width: 4px;
  background: linear-gradient(180deg, transparent, #fff9c4 20%, #ffeb3b 50%, #fff 80%, transparent);
  box-shadow: 0 0 20px #ffeb3b, 0 0 40px #ff9800;
  opacity: 0;
  transform-origin: top center;
}

.lightning-1 {
  left: 15%;
  top: 5%;
  height: 45%;
  transform: rotate(12deg) skewX(-8deg);
}

.lightning-2 {
  right: 18%;
  top: 8%;
  height: 50%;
  transform: rotate(-15deg) skewX(10deg);
}

.lightning-3 {
  left: 48%;
  top: 0;
  height: 55%;
  transform: rotate(5deg);
  width: 5px;
}

.victory-splash.thunder-show .lightning-1 {
  animation: bolt-strike 0.35s ease-out 0.1s;
}

.victory-splash.thunder-show .lightning-2 {
  animation: bolt-strike 0.4s ease-out 0.45s;
}

.victory-splash.thunder-show .lightning-3 {
  animation: bolt-strike 0.35s ease-out 0.85s;
}

@keyframes bolt-strike {
  0% { opacity: 0; filter: brightness(1); }
  15% { opacity: 1; filter: brightness(3); }
  40% { opacity: 0.9; }
  100% { opacity: 0; filter: brightness(1); }
}

.victory-confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 8px;
  height: 8px;
  top: -10px;
  border-radius: 2px;
  animation: confetti-fall linear forwards;
}

/* Victory fireworks */
.victory-fireworks {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  overflow: hidden;
}

.firework-burst {
  position: absolute;
  width: 0;
  height: 0;
}

.firework-spark {
  position: absolute;
  left: 0;
  top: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  opacity: 0;
  transform: translate(0, 0) scale(1);
  animation: firework-spark-fly 1.1s ease-out forwards;
}

@keyframes firework-spark-fly {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1.2);
  }
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.4);
  }
}

@media (prefers-reduced-motion: reduce) {
  .firework-spark {
    animation-duration: 0.4s;
  }
}

@keyframes confetti-fall {
  to {
    transform: translateY(110vh) rotate(720deg);
    opacity: 0.3;
  }
}

.victory-sub {
  font-family: 'Bangers', cursive;
  font-size: 1.1rem;
  color: var(--gold);
  letter-spacing: 0.08em;
  margin: 0 0 0.75rem;
  position: relative;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.victory-panel {
  background: #4a148c;
  border: 3px solid var(--gold);
  border-radius: 22px;
  padding: 2rem 1.5rem;
  text-align: center;
  max-width: 360px;
  width: 92%;
  position: relative;
  z-index: 10;
  overflow: hidden;
  animation: victory-pop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
  box-shadow:
    0 0 40px rgba(255, 215, 0, 0.35),
    0 20px 40px rgba(0, 0, 0, 0.5);
}

@keyframes victory-panel-sheen {
  0%, 100% {
    background-position: 0 0, 0 0, 0% 50%, 100% 50%, 0 0;
  }
  50% {
    background-position: 0 0, 0 0, 100% 50%, 0% 50%, 0 0;
  }
}

@keyframes victory-pop {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.victory-burst {
  display: none;
}

.victory-burst::before {
  content: '';
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: radial-gradient(
    circle at center,
    rgba(255, 235, 59, 0.62) 0%,
    rgba(255, 152, 0, 0.35) 28%,
    rgba(156, 39, 176, 0.22) 48%,
    rgba(13, 27, 62, 0.55) 62%,
    transparent 76%
  );
  animation: burst-pulse-core 3.2s ease-in-out infinite alternate;
}

.victory-burst::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-conic-gradient(
    from 8deg,
    rgba(255, 255, 255, 0.07) 0deg 7deg,
    transparent 7deg 16deg
  );
  mix-blend-mode: screen;
  opacity: 0.65;
  animation: burst-spin 14s linear infinite reverse;
}

@keyframes burst-pulse {
  0%, 100% {
    opacity: 0.82;
  }
  50% {
    opacity: 1;
  }
}

@keyframes burst-pulse-core {
  0% {
    opacity: 0.75;
    transform: scale(0.92);
  }
  100% {
    opacity: 1;
    transform: scale(1.08);
  }
}

@keyframes burst-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.victory-winner {
  font-size: 1.3rem;
  font-weight: 800;
  margin: 0 0 0.35rem;
  position: relative;
}

.victory-title-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  max-width: min(100%, 320px);
  min-height: 8.5rem;
  margin: 0 auto 0.35rem;
}

.victory-title-wrap .victory-title-img {
  grid-area: 1 / 1;
  position: relative;
  z-index: 1;
  margin: 0;
}

.victory-title-wrap .victory-title-text {
  grid-area: 1 / 1;
  align-self: center;
  justify-self: center;
  margin: 0;
}

.victory-title-wrap::after {
  display: none;
}

.victory-title-img {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  max-width: 300px;
  height: auto;
  margin: 0 auto;
  filter:
    drop-shadow(0 0 12px rgba(255, 215, 0, 0.85))
    drop-shadow(0 0 28px rgba(255, 152, 0, 0.5))
    drop-shadow(0 10px 22px rgba(0, 0, 0, 0.5));
  animation: victory-title-img-glow 2.4s ease-in-out infinite;
}

@keyframes victory-title-glow-back {
  0%, 100% {
    opacity: 0.5;
    transform: translate(-50%, -50%) scale(0.92);
  }
  50% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1);
  }
}

@keyframes victory-title-img-glow {
  0%, 100% {
    filter:
      drop-shadow(0 0 10px rgba(255, 215, 0, 0.75))
      drop-shadow(0 0 24px rgba(255, 152, 0, 0.45))
      drop-shadow(0 10px 22px rgba(0, 0, 0, 0.5));
  }
  50% {
    filter:
      drop-shadow(0 0 20px rgba(255, 235, 59, 1))
      drop-shadow(0 0 40px rgba(255, 193, 7, 0.85))
      drop-shadow(0 0 56px rgba(255, 111, 0, 0.45))
      drop-shadow(0 10px 22px rgba(0, 0, 0, 0.5));
  }
}

@media (prefers-reduced-motion: reduce) {
  .victory-title-wrap::after {
    animation: none;
    opacity: 0.65;
  }

  .victory-title-img {
    animation: none;
  }
}

.victory-title-img.hidden {
  display: none;
}

/* Outcome-driven title art (works from the victory-defeat / victory-draw
   classes on #screen-victory, independent of any inline JS toggling). */
.victory-title-lose,
.victory-title-draw {
  display: none;
}

#screen-victory.victory-defeat .victory-title-win {
  display: none !important;
}

#screen-victory.victory-defeat .victory-title-lose {
  display: block !important;
}

#screen-victory.victory-defeat .victory-title-text {
  display: none !important;
}

#screen-victory.victory-draw .victory-title-win,
#screen-victory.victory-draw .victory-title-lose {
  display: none !important;
}

#screen-victory.victory-draw .victory-title-draw {
  display: block !important;
}

#screen-victory.victory-draw .victory-title-text {
  display: none !important;
}

.victory-title {
  font-family: 'Bangers', cursive;
  font-size: 3rem;
  color: var(--gold);
  position: relative;
  text-shadow: 0 4px 0 #e65100;
}

.victory-title-text.hidden {
  display: none;
}

.victory-defeat .victory-title {
  color: #ff8a80;
  text-shadow: 0 4px 0 #b71c1c;
}

.victory-scores {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 0.5rem;
  margin: 0.25rem 0 1.25rem;
  position: relative;
  width: 100%;
}

.victory-score-card {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.65rem 0.45rem 0.55rem;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.18);
  position: relative;
}

.victory-score-card--winner {
  background: linear-gradient(160deg, rgba(255, 215, 0, 0.18), rgba(255, 152, 0, 0.12));
  border-color: var(--gold);
  box-shadow: 0 0 18px rgba(255, 215, 0, 0.35);
}

.victory-defeat .victory-score-card--winner {
  background: linear-gradient(160deg, rgba(244, 67, 54, 0.2), rgba(183, 28, 28, 0.12));
  border-color: #ef5350;
  box-shadow: 0 0 14px rgba(244, 67, 54, 0.3);
}

.victory-score-badge {
  position: absolute;
  top: -0.55rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.1rem;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.victory-score-label {
  font-family: 'Bangers', cursive;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.75);
  line-height: 1;
  text-transform: uppercase;
}

.victory-score-card--winner .victory-score-label {
  color: var(--gold);
}

.victory-defeat .victory-score-card--winner .victory-score-label {
  color: #ff8a80;
}

.victory-score-value {
  font-family: 'Bangers', cursive;
  font-size: 2rem;
  line-height: 1;
  color: var(--white);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.45);
}

.victory-score-card--winner .victory-score-value {
  color: #fff9c4;
}

.victory-score-unit {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.65;
}

.victory-score-vs {
  flex: 0 0 auto;
  align-self: center;
  font-family: 'Bangers', cursive;
  font-size: 1rem;
  color: rgba(255, 215, 0, 0.55);
  letter-spacing: 0.04em;
  padding: 0 0.1rem;
}

.victory-score-draw {
  flex: 0 0 auto;
  align-self: center;
  font-family: 'Bangers', cursive;
  font-size: 1.15rem;
  color: var(--gold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0 0.25rem;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

.victory-score-surrender {
  flex: 0 0 auto;
  align-self: center;
  font-family: 'Bangers', cursive;
  font-size: 1.05rem;
  color: #ffcdd2;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0 0.2rem;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

.victory-draw .victory-title-wrap::after {
  width: 88%;
  height: 78%;
  background: radial-gradient(
    ellipse at center,
    rgba(186, 104, 200, 0.42) 0%,
    rgba(255, 215, 0, 0.18) 42%,
    transparent 72%
  );
}

.victory-draw .victory-title {
  color: var(--gold);
  text-shadow: 0 4px 0 #5d4037;
}

.victory-draw .victory-winner {
  color: #fff9c4;
}

.victory-draw .victory-score-card {
  border-color: rgba(255, 215, 0, 0.45);
  background: linear-gradient(160deg, rgba(255, 215, 0, 0.12), rgba(126, 87, 194, 0.18));
}

.victory-draw .victory-score-value {
  color: #fff9c4;
}

.victory-panel .btn-primary,
.victory-panel .btn-secondary {
  position: relative;
  margin: 0.4rem auto;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 4rem);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0, 0, 0, 0.85);
  border: 2px solid var(--gold);
  border-radius: 50px;
  padding: 0.6rem 1.25rem;
  font-weight: 700;
  font-size: 0.9rem;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  white-space: nowrap;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success { border-color: #69f0ae; color: #69f0ae; }
.toast.error { border-color: #ff8a80; color: #ff8a80; }

/* Effects */
.shake,
.eq-slot.shake {
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

/* Attack power-up — shaking lightning quake on the whole board */
#screen-game.attack-quake {
  animation: attack-quake 0.6s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

#screen-game.attack-quake::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 500;
  pointer-events: none;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.55), transparent 45%),
    radial-gradient(circle at 70% 60%, rgba(255, 82, 82, 0.45), transparent 50%),
    rgba(229, 57, 53, 0.12);
  animation: attack-lightning 0.6s steps(1, end) both;
}

@keyframes attack-quake {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  10% { transform: translate(-9px, 4px) rotate(-0.8deg); }
  20% { transform: translate(8px, -6px) rotate(0.8deg); }
  30% { transform: translate(-10px, -3px) rotate(-1deg); }
  40% { transform: translate(9px, 5px) rotate(0.9deg); }
  50% { transform: translate(-7px, 3px) rotate(-0.6deg); }
  60% { transform: translate(7px, -4px) rotate(0.6deg); }
  70% { transform: translate(-5px, 2px) rotate(-0.4deg); }
  80% { transform: translate(4px, -2px) rotate(0.3deg); }
  90% { transform: translate(-2px, 1px) rotate(-0.15deg); }
}

@keyframes attack-lightning {
  0% { opacity: 0; }
  8% { opacity: 1; }
  16% { opacity: 0; }
  28% { opacity: 0.9; }
  36% { opacity: 0; }
  52% { opacity: 0.8; }
  60% { opacity: 0; }
  100% { opacity: 0; }
}

.flash-correct {
  animation: flash-green 0.6s ease;
}

@keyframes flash-green {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: inset 0 0 80px rgba(105, 240, 174, 0.4); }
}

/* Correct answer splash */
.correct-splash {
  position: absolute;
  inset: 0;
  z-index: 90;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.correct-splash.show {
  display: flex;
  opacity: 1;
  visibility: visible;
}

.correct-splash[hidden] {
  display: none !important;
}

.correct-splash-flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(105, 240, 174, 0.45) 0%, transparent 65%);
  opacity: 0;
  animation: correct-flash 0.5s ease forwards;
}

.correct-splash.show .correct-splash-flash {
  animation: correct-flash 0.6s ease forwards;
}

@keyframes correct-flash {
  0% { opacity: 0; transform: scale(0.8); }
  40% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.2); }
}

.correct-confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.correct-confetti .confetti-piece {
  position: absolute;
  top: -10px;
  border-radius: 2px;
  animation: confetti-fall 2.2s ease-in forwards;
}

.correct-splash-panel {
  position: relative;
  z-index: 2;
  text-align: center;
  background: linear-gradient(165deg, #1b5e20 0%, #2e7d32 40%, #1a237e 100%);
  border: 3px solid #ffeb3b;
  border-radius: 24px;
  padding: 1.5rem 1.75rem 1.25rem;
  width: min(92%, 320px);
  box-shadow:
    0 0 40px rgba(255, 215, 0, 0.5),
    0 12px 32px rgba(0, 0, 0, 0.5);
  transform: scale(0.5);
  opacity: 0;
}

.correct-splash.show .correct-splash-panel {
  animation: correct-panel-pop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes correct-panel-pop {
  0% { transform: scale(0.4); opacity: 0; }
  70% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.correct-check-ring {
  width: 4.5rem;
  height: 4.5rem;
  margin: 0 auto 0.75rem;
  border-radius: 50%;
  background: linear-gradient(180deg, #fff9c4, #ffd700);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 24px rgba(255, 235, 59, 0.8);
  animation: correct-check-bounce 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s both;
}

.correct-check {
  font-size: 2.5rem;
  font-weight: 800;
  color: #1b5e20;
  line-height: 1;
}

@keyframes correct-check-bounce {
  0% { transform: scale(0) rotate(-30deg); }
  100% { transform: scale(1) rotate(0); }
}

.correct-splash-title {
  font-family: 'Bangers', cursive;
  font-size: clamp(1.8rem, 7vw, 2.4rem);
  color: #fff9c4;
  letter-spacing: 0.06em;
  text-shadow: 0 3px 0 #33691e;
  margin-bottom: 0.35rem;
}

.correct-splash-eq {
  font-family: 'Bangers', cursive;
  font-size: clamp(1.4rem, 5.5vw, 1.9rem);
  color: var(--white);
  margin-bottom: 0.75rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.correct-splash-points {
  font-family: 'Bangers', cursive;
  font-size: clamp(2.5rem, 12vw, 3.5rem);
  color: #ffeb3b;
  line-height: 1;
  text-shadow:
    0 0 20px rgba(255, 235, 59, 0.9),
    0 4px 0 #e65100;
  animation: correct-points-pulse 0.8s ease 0.35s 2;
}

@keyframes correct-points-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.correct-splash-sub {
  font-size: 0.85rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  margin-top: 0.35rem;
  letter-spacing: 0.05em;
}

/* Wrong answer splash */
.wrong-splash {
  position: absolute;
  inset: 0;
  z-index: 90;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.wrong-splash.show {
  display: flex;
  opacity: 1;
  visibility: visible;
}

.wrong-splash[hidden] {
  display: none !important;
}

.wrong-splash-flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(244, 67, 54, 0.5) 0%, transparent 65%);
  opacity: 0;
  animation: wrong-flash 0.5s ease forwards;
}

.wrong-splash.show .wrong-splash-flash {
  animation: wrong-flash 0.6s ease forwards;
}

@keyframes wrong-flash {
  0% { opacity: 0; transform: scale(0.8); }
  40% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.2); }
}

.wrong-splash-panel {
  position: relative;
  z-index: 2;
  text-align: center;
  background: linear-gradient(165deg, #4a0e0e 0%, #b71c1c 40%, #311b92 100%);
  border: 3px solid #ff8a80;
  border-radius: 24px;
  padding: 1.5rem 1.75rem 1.25rem;
  width: min(92%, 320px);
  box-shadow:
    0 0 40px rgba(244, 67, 54, 0.55),
    0 12px 32px rgba(0, 0, 0, 0.5);
  transform: scale(0.5);
  opacity: 0;
}

.wrong-splash.show .wrong-splash-panel {
  animation: wrong-panel-pop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes wrong-panel-pop {
  0% { transform: scale(0.4); opacity: 0; }
  70% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.wrong-x-ring {
  width: 4.5rem;
  height: 4.5rem;
  margin: 0 auto 0.75rem;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffcdd2, #ef5350);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 24px rgba(244, 67, 54, 0.85);
  animation: wrong-x-bounce 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s both;
}

.wrong-x {
  font-size: 2.5rem;
  font-weight: 800;
  color: #b71c1c;
  line-height: 1;
}

@keyframes wrong-x-bounce {
  0% { transform: scale(0) rotate(30deg); }
  100% { transform: scale(1) rotate(0); }
}

.wrong-splash-title {
  font-family: 'Bangers', cursive;
  font-size: clamp(1.8rem, 7vw, 2.4rem);
  color: #ffcdd2;
  letter-spacing: 0.06em;
  text-shadow: 0 3px 0 #7f0000;
  margin-bottom: 0.35rem;
}

.wrong-splash-eq {
  font-family: 'Bangers', cursive;
  font-size: clamp(1.35rem, 5.5vw, 1.85rem);
  color: var(--white);
  margin-bottom: 0.25rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.wrong-splash-given {
  font-family: 'Nunito', sans-serif;
  font-size: clamp(0.85rem, 3.5vw, 1rem);
  font-weight: 800;
  color: #ffab91;
  margin-bottom: 0.65rem;
}

.wrong-splash-points {
  font-family: 'Bangers', cursive;
  font-size: clamp(2.5rem, 12vw, 3.5rem);
  color: #ff5252;
  line-height: 1;
  text-shadow:
    0 0 20px rgba(244, 67, 54, 0.9),
    0 4px 0 #7f0000;
  animation: wrong-points-pulse 0.8s ease 0.35s 2;
}

@keyframes wrong-points-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.wrong-splash-sub {
  font-size: 0.85rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  margin-top: 0.35rem;
  letter-spacing: 0.05em;
}

.flash-wrong {
  animation: flash-wrong-bg 0.5s ease;
}

@keyframes flash-wrong-bg {
  0%, 100% { box-shadow: inset 0 0 0 transparent; }
  50% { box-shadow: inset 0 0 80px rgba(244, 67, 54, 0.45); }
}

.score-box.score-penalty {
  animation: score-pop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 0 20px rgba(244, 67, 54, 0.85);
}

.score-box.score-penalty .score-value {
  animation: score-value-bump 0.7s ease;
  color: #ff5252;
}

.score-box.score-pop {
  animation: score-pop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 0 20px rgba(255, 235, 59, 0.9);
}

.score-box.score-pop .score-value {
  animation: score-value-bump 0.7s ease;
  color: #ffeb3b;
}

@keyframes score-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@keyframes score-value-bump {
  0% { transform: scale(1); }
  50% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

/* Phone / small tablet landscape only — side-by-side columns */
@media (orientation: landscape) and (max-width: 719px) and (min-height: 360px) {
  :root {
    --card-w: clamp(64px, 11vh, 96px);
    --slot-size: clamp(48px, 10vh, 80px);
  }

  .game-board {
    grid-template-columns: minmax(120px, 1fr) minmax(260px, 1.45fr) minmax(120px, 1fr);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "zone-left center zone-right";
    gap: clamp(0.4rem, 1.2vw, 1rem);
    padding: 0.35rem clamp(0.5rem, 2vw, 1.5rem);
    max-width: 100%;
    height: 100%;
  }

  #zone-p1 {
    grid-area: zone-left;
  }

  #zone-p2 {
    grid-area: zone-right;
  }

  .battle-center {
    grid-area: center;
    align-self: stretch;
    justify-content: center;
    align-items: center;
    border-left: 1px solid rgba(255, 215, 0, 0.15);
    border-right: 1px solid rgba(255, 215, 0, 0.15);
    padding: 0.4rem 0.5rem;
    min-width: 0;
  }

  /* Online: opponent header on top even in phone landscape */
  .mode-online .game-board {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas:
      "zone-top"
      "center"
      "zone-bottom";
  }

  .mode-online #zone-p1 {
    grid-area: zone-top;
  }

  .mode-online #zone-p2 {
    grid-area: zone-bottom;
  }

  .mode-online .battle-center {
    grid-area: center;
    border-left: none;
    border-right: none;
    justify-content: flex-start;
  }

  /* AI: opponent left, you right */
  .mode-ai #zone-p2 {
    grid-area: zone-left;
  }

  .mode-ai #zone-p1 {
    grid-area: zone-right;
  }

  .player-zone {
    flex-direction: column;
    justify-content: center;
    max-height: 100%;
    overflow: hidden;
  }

  .player-1,
  .player-2 {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
  }

  .player-header {
    flex-shrink: 0;
  }

  .hand-scroll-wrap {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
  }

  .hand {
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: flex-start;
    max-height: calc(var(--card-h) + 1rem);
  }

  .equation-hint {
    font-size: clamp(0.6rem, 1.6vh, 0.75rem);
    max-width: 100%;
  }

  .equation-visual {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    justify-content: center;
    overflow: visible;
    min-height: clamp(92px, 16vh, 112px);
    padding: clamp(0.38rem, 1.4vh, 0.5rem) clamp(0.2rem, 1vh, 0.35rem);
  }

  .eq-slot {
    width: clamp(44px, 9.5vh, 68px);
    height: clamp(54px, 11vh, 82px);
  }

  .eq-slot-num {
    width: clamp(46px, 10vh, 72px);
    height: clamp(56px, 11.5vh, 86px);
  }

  .eq-slot-value {
    font-size: clamp(1.35rem, 5vh, 1.95rem);
  }

  .btn-draw-header .draw-pile {
    width: clamp(28px, 7vh, 34px);
    height: clamp(36px, 9vh, 44px);
  }

  .eq-slot-op {
    width: clamp(42px, 8.5vh, 58px);
    height: clamp(54px, 11vh, 82px);
  }

  .eq-slot-op .eq-slot-value {
    font-size: clamp(1.5rem, 5.5vh, 2.15rem);
  }

  .eq-equals {
    font-size: clamp(1.1rem, 3.5vh, 1.5rem);
  }
}

/* Desktop / tablet landscape: rotate entire game to portrait (mobile-style layout) */
@media (min-width: 720px) and (orientation: landscape) {
  body:has(#screen-game.active) {
    overflow: hidden;
    height: 100%;
    max-height: 100dvh;
  }

  #screen-game.active {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 100dvh;
    height: 100dvw;
    max-width: 100dvh;
    max-height: 100dvw;
    min-height: 0;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center center;
    z-index: 100;
    overflow: hidden;
  }

  #screen-game.active .game-board {
    max-width: min(560px, 100%);
    margin: 0 auto;
  }

  #screen-game.active .game-bottom-dock {
    max-width: min(560px, 100%);
    margin: 0 auto;
  }

  /* Local PvP on rotated desktop: top player + HUD face the top edge */
  .mode-local .player-1 .player-header,
  .mode-local .player-1 .hand-scroll-hint {
    transform: rotate(180deg);
    transform-origin: center center;
  }

  .mode-local .player-1 .card {
    transform: rotate(180deg);
  }

  .mode-local .player-1 .hand-nav {
    transform: translateY(-50%) rotate(180deg);
  }
  .mode-local .player-1 .hand-nav:active {
    transform: translateY(-50%) rotate(180deg) scale(0.9);
  }

  .mode-local .player-1 .card:hover,
  .mode-local .player-1 .card:focus-visible {
    transform: rotate(180deg) translateY(-6px) scale(1.05);
  }

  .mode-local .player-1 .card.selected {
    transform: rotate(180deg) translateY(-16px) scale(1.28);
  }

  .mode-local .game-hud-top {
    transform: rotate(180deg);
    transform-origin: center center;
  }

  .mode-local.eq-face-top .equation-visual,
  .mode-local .equation-visual.eq-facing-p1 {
    transform: rotate(180deg);
    transform-origin: center center;
  }
}

/* Tall portrait tablet — stay stacked but use space better */
@media (orientation: portrait) and (min-width: 600px) {
  :root {
    --card-w: clamp(72px, 11vw, 96px);
    --slot-size: clamp(52px, 10vw, 80px);
  }

  .game-board {
    max-width: min(520px, 100%);
    margin: 0 auto;
  }
}

/* Large desktop — optional cap for very wide portrait monitors */
@media (min-width: 1400px) {
  :root {
    --card-w: clamp(76px, 6vmin, 108px);
    --game-board-max: 1400px;
  }

  .menu-content {
    max-width: 480px;
  }
}

@media (min-width: 1400px) and (orientation: portrait) {
  .game-board {
    max-width: var(--game-board-max);
    margin: 0 auto;
  }
}

/* Short landscape (phones) — tighter cards */
@media (max-height: 500px) and (orientation: landscape) and (max-width: 719px) {
  :root {
    --card-w: clamp(52px, 16vh, 76px);
    --slot-size: clamp(44px, 14vh, 68px);
  }

  .game-hud {
    padding: 0.25rem 0.5rem;
  }

  .game-board {
    grid-template-columns: minmax(90px, 1fr) minmax(200px, 1.4fr) minmax(90px, 1fr);
    gap: 0.25rem;
  }

  .hand-scroll-wrap {
    max-height: calc(var(--card-h) + 0.75rem);
  }

  .turn-indicator {
    min-width: 56px;
  }

  .turn-player {
    font-size: 0.85rem;
  }
}

/* Friends screen */
#screen-friends {
  background: #1a0a2e;
}

.friends-content {
  width: min(100%, 400px);
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
  padding-bottom: 2.5rem;
  box-sizing: border-box;
}

.friends-content .btn-back {
  margin-left: 0;
  margin-right: auto;
}

.friends-header {
  text-align: center;
  margin-bottom: 1.25rem;
  width: 100%;
}

.friends-header-badge {
  width: 56px;
  height: 56px;
  margin: 0 auto 0.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.65rem;
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(255, 152, 0, 0.22), rgba(198, 40, 40, 0.28));
  border: 2px solid rgba(255, 215, 0, 0.45);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.friends-title {
  font-family: 'Bangers', cursive;
  font-size: clamp(2rem, 8vw, 2.5rem);
  color: var(--gold);
  letter-spacing: 0.05em;
  text-shadow: 0 2px 0 #5d4037;
  margin-bottom: 0.35rem;
}

.friends-header-lead {
  font-size: 0.85rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.78);
  max-width: 28rem;
  margin: 0 auto;
}

.friends-alert {
  font-size: 0.85rem;
  text-align: center;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  margin-bottom: 0.85rem;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  background: rgba(66, 165, 245, 0.12);
  border: 1px solid rgba(66, 165, 245, 0.35);
  color: #90caf9;
}

.friends-alert--error {
  background: rgba(198, 40, 40, 0.15);
  border-color: rgba(239, 83, 80, 0.45);
  color: #ef9a9a;
}

.friends-status {
  text-align: center;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.65);
  margin-bottom: 1rem;
}

.friends-stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.85rem;
  width: 100%;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.friends-panel {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  background: linear-gradient(
    155deg,
    rgba(74, 20, 140, 0.92) 0%,
    rgba(49, 27, 146, 0.85) 48%,
    rgba(13, 27, 62, 0.94) 100%
  );
  border: 2px solid rgba(255, 215, 0, 0.32);
  border-radius: 18px;
  padding: 1rem 1rem 0.85rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.32);
}

.friends-panel--invites {
  border-color: rgba(255, 152, 0, 0.45);
  background: linear-gradient(
    155deg,
    rgba(74, 20, 140, 0.88) 0%,
    rgba(230, 81, 0, 0.12) 45%,
    rgba(13, 27, 62, 0.94) 100%
  );
}

.friends-panel-head {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}

.friends-panel-icon {
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.friends-panel-head-text {
  flex: 1 1 auto;
  min-width: 0;
}

.friends-panel-title {
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
  margin: 0 0 0.15rem;
  letter-spacing: 0.01em;
}

.friends-panel-desc {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.62);
  margin: 0;
  line-height: 1.4;
}

.friends-count-badge {
  flex-shrink: 0;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 800;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffd54f, #ff8f00);
  color: #4a148c;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.friends-sub-label {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255, 215, 0, 0.85);
  margin: 0.5rem 0 0.45rem;
}

.friends-search-box {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.friends-search-input {
  flex: 1 1 auto;
  min-width: 0;
  font-family: 'Nunito', sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.28);
  color: #fff;
}

.friends-search-input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.friends-search-input:focus {
  outline: none;
  border-color: rgba(255, 215, 0, 0.55);
  box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.12);
}

.friends-search-btn {
  flex-shrink: 0;
  font-family: 'Nunito', sans-serif;
  font-size: 0.85rem;
  font-weight: 800;
  padding: 0.65rem 1rem;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  color: #4a148c;
  background: linear-gradient(180deg, #ffe082 0%, var(--gold) 55%, #e65100 100%);
  box-shadow: 0 3px 0 #bf360c;
  transition: transform 0.12s ease;
}

.friends-search-btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

.friends-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.friends-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.7rem;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.friends-item:hover {
  border-color: rgba(255, 215, 0, 0.28);
  background: rgba(0, 0, 0, 0.32);
}

.friends-item-avatar {
  flex-shrink: 0;
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Nunito', sans-serif;
  font-size: 0.95rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #7c4dff, #512da8);
  border: 2px solid rgba(255, 255, 255, 0.15);
}

.friends-item-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
}

.friends-item-name {
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 0.9rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.friends-item-meta {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.55);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.friends-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: flex-end;
  flex-shrink: 0;
}

.friends-action-btn {
  font-family: 'Nunito', sans-serif;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  border: none;
  border-radius: 999px;
  padding: 0.38rem 0.72rem;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(180deg, #42a5f5 0%, #1565c0 100%);
  box-shadow: 0 2px 0 #0d47a1;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.friends-action-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: none;
}

.friends-action-btn--accept {
  background: linear-gradient(180deg, #69f0ae 0%, #00c853 100%);
  box-shadow: 0 2px 0 #1b5e20;
  color: #1b5e20;
}

.friends-action-btn--decline,
.friends-action-btn--remove {
  background: linear-gradient(180deg, #ef5350 0%, #c62828 100%);
  box-shadow: 0 2px 0 #8e0000;
}

.friends-action-btn--challenge {
  background: linear-gradient(180deg, #ffd54f 0%, #ff8f00 100%);
  box-shadow: 0 2px 0 #e65100;
  color: #4a148c;
}

.friends-action-btn:disabled,
.friends-action-btn.friends-status-pill {
  opacity: 1;
  cursor: default;
  box-shadow: none;
  transform: none;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.friends-action-btn.friends-status-pill--friend {
  color: #a5d6a7;
  border-color: rgba(129, 199, 132, 0.35);
  background: rgba(76, 175, 80, 0.12);
}

.friends-action-btn.friends-status-pill--pending {
  color: #ffcc80;
  border-color: rgba(255, 183, 77, 0.35);
  background: rgba(255, 152, 0, 0.1);
}

.friends-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 1.1rem 0.75rem;
  margin-top: 0.15rem;
  border-radius: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.15);
  text-align: center;
}

.friends-empty-state--compact {
  padding: 0.65rem;
  margin-bottom: 0.35rem;
}

.friends-empty-icon {
  font-size: 1.35rem;
  opacity: 0.65;
}

.friends-empty-state p {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.5);
  margin: 0;
}

.friends-invite-card {
  border-color: rgba(255, 152, 0, 0.4);
  background: linear-gradient(135deg, rgba(255, 152, 0, 0.12), rgba(0, 0, 0, 0.22));
}

.friends-invite-card .friends-item-avatar {
  background: linear-gradient(135deg, #ff8f00, #e65100);
}

.friends-invite-card .friends-item-name {
  color: #ffe0b2;
}

/* ============================================================= */
/* Floating friends chat                                          */
/* ============================================================= */
.mk-chat-root {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 960;
  font-family: inherit;
}
.mk-chat-root[hidden] { display: none; }

.mk-chat-fab {
  position: relative;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #6d5dfc 0%, #4836d6 100%);
  box-shadow: 0 8px 22px rgba(72, 54, 214, 0.45), 0 2px 6px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
.mk-chat-fab:hover { transform: translateY(-2px) scale(1.04); }
.mk-chat-fab:active { transform: scale(0.96); }
.mk-chat-fab--active {
  background: linear-gradient(145deg, #4836d6 0%, #2c1f9c 100%);
}
.mk-chat-fab svg { display: block; }

.mk-chat-fab-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #ff4d6d;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(255, 77, 109, 0.5);
}
.mk-chat-fab-badge[hidden] { display: none; }

.mk-chat-panel {
  position: absolute;
  right: 0;
  bottom: 70px;
  width: min(340px, calc(100vw - 28px));
  height: min(70vh, 520px);
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 18px 48px rgba(20, 16, 60, 0.35), 0 2px 8px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(109, 93, 252, 0.18);
  animation: mkChatPop 0.18s ease;
  transform-origin: bottom right;
}
.mk-chat-panel[hidden] { display: none; }

@keyframes mkChatPop {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.mk-chat-list-view,
.mk-chat-thread-view {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
}
.mk-chat-list-view[hidden],
.mk-chat-thread-view[hidden] { display: none; }

.mk-chat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 11px;
  color: #fff;
  background: linear-gradient(135deg, #6d5dfc 0%, #4836d6 100%);
  flex: 0 0 auto;
}
.mk-chat-head-icon { font-size: 18px; }
.mk-chat-head-title {
  font-weight: 800;
  font-size: 16px;
  flex: 1 1 auto;
  letter-spacing: 0.2px;
}
.mk-chat-head-btn {
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  font-size: 16px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s ease;
}
.mk-chat-head-btn:hover { background: rgba(255, 255, 255, 0.3); }

/* Conversation list */
.mk-chat-conv-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.mk-chat-conv {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.14s ease;
}
.mk-chat-conv:hover { background: #f1f0ff; }
.mk-chat-conv--unread { background: #f5f3ff; }

.mk-chat-avatar,
.mk-chat-thread-avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(145deg, #8a7bff, #5a47e6);
  color: #fff;
  font-weight: 800;
  font-size: 17px;
}
.mk-chat-thread-avatar { width: 34px; height: 34px; font-size: 14px; }
.mk-chat-avatar-img,
.mk-chat-thread-avatar .mk-chat-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.mk-chat-conv-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.mk-chat-conv-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.mk-chat-conv-name {
  font-weight: 700;
  font-size: 14px;
  color: #1f1a3d;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mk-chat-conv-time {
  flex: 0 0 auto;
  font-size: 11px;
  color: #9a96b5;
}
.mk-chat-conv-preview {
  font-size: 12.5px;
  color: #6b6790;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mk-chat-conv--unread .mk-chat-conv-preview {
  color: #2c2358;
  font-weight: 600;
}
.mk-chat-conv-badge {
  flex: 0 0 auto;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 10px;
  background: #ff4d6d;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 19px;
  text-align: center;
}

.mk-chat-empty {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #8480a3;
  text-align: center;
  padding: 20px;
}
.mk-chat-empty[hidden] { display: none; }
.mk-chat-empty-icon { font-size: 30px; }
.mk-chat-empty p { margin: 0; font-size: 13.5px; }

/* Thread */
.mk-chat-thread-head { padding-left: 6px; }
.mk-chat-thread-name {
  flex: 1 1 auto;
  font-weight: 800;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mk-chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f7f6ff;
  -webkit-overflow-scrolling: touch;
}
.mk-chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}
.mk-chat-msg--mine { align-self: flex-end; align-items: flex-end; }
.mk-chat-msg--theirs { align-self: flex-start; align-items: flex-start; }
.mk-chat-bubble {
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.35;
  word-break: break-word;
  white-space: pre-wrap;
}
.mk-chat-msg--mine .mk-chat-bubble {
  background: linear-gradient(135deg, #6d5dfc, #4836d6);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.mk-chat-msg--theirs .mk-chat-bubble {
  background: #fff;
  color: #211c44;
  border: 1px solid #e6e3f7;
  border-bottom-left-radius: 5px;
}
.mk-chat-msg-time {
  font-size: 10px;
  color: #a7a3c2;
  margin: 2px 4px 0;
}
.mk-chat-thread-loading,
.mk-chat-thread-empty {
  margin: auto;
  color: #8480a3;
  font-size: 13px;
  text-align: center;
}

.mk-chat-compose {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 10px;
  background: #fff;
  border-top: 1px solid #ece9fb;
}
.mk-chat-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid #dcd8f3;
  border-radius: 22px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  background: #f7f6ff;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.mk-chat-input:focus { border-color: #6d5dfc; background: #fff; }
.mk-chat-send {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, #6d5dfc, #4836d6);
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.mk-chat-send:hover { transform: scale(1.06); }
.mk-chat-send:disabled { opacity: 0.5; cursor: default; transform: none; }

@media (max-width: 420px) {
  .mk-chat-fab { width: 50px; height: 50px; }
  .mk-chat-panel { bottom: 64px; height: min(68vh, 480px); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
