/* youknObtainium - colorblind-accessible element card game */

:root {
  --bg-dark: #1a1b26;
  --bg-card: #24283b;
  --bg-board: #16161e;
  --text: #c0caf5;
  --text-muted: #565f89;
  --accent: #7aa2f7;
  --success: #9ece6a;
  --warning: #e0af68;
  --error: #f7768e;
  /* Family colors (plus shape icons for accessibility) */
  --family-s: #7aa2f7;   /* s-block: blue, circle */
  --family-p: #9ece6a;   /* p-block: green, triangle */
  --family-d: #e0af68;   /* d-block: amber, square */
  --family-f: #bb9af7;   /* f-block: purple, diamond */
  --card-radius: 8px;
  --card-shadow: 0 2px 8px rgba(0,0,0,0.3);
  --transition: 0.2s ease;
}

* {
  box-sizing: border-box;
}

.winner-banner {
  flex-shrink: 0;
  text-align: center;
  padding: 1rem;
  margin: 0.35rem 0;
  font-size: clamp(1.25rem, 4vw, 2.25rem);
  font-weight: 800;
  color: var(--success);
  background: rgba(158, 206, 106, 0.15);
  border-radius: var(--card-radius);
  border: 2px solid var(--success);
  letter-spacing: 0.02em;
}

.winner-banner-event-horizon {
  color: #2ac3de;
  background: rgba(42, 195, 222, 0.2);
  border-color: #2ac3de;
  animation: event-horizon-pulse 1s ease-in-out infinite alternate;
  box-shadow: 0 0 24px rgba(42, 195, 222, 0.5);
}

.winner-card-reason {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.winner-card-reason-label {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.winner-cards-display {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.winner-cards-display .card {
  transform: scale(1.15);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.winner-explanation {
  font-size: clamp(0.95rem, 2.5vw, 1.1rem);
  font-weight: 600;
  color: var(--text);
  margin: 0;
  line-height: 1.4;
}

@keyframes event-horizon-pulse {
  from { box-shadow: 0 0 16px rgba(42, 195, 222, 0.4); transform: scale(1); }
  to   { box-shadow: 0 0 32px rgba(42, 195, 222, 0.8); transform: scale(1.02); }
}

/* Event Horizon win: James Webb black hole image as full-page background */
body.event-horizon-bg {
  background-image: url('james-webb-first-supermassive-black-hole-runaway-home.webp');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}
body.event-horizon-bg .app {
  background: transparent;
}

.game-over-panel {
  flex-shrink: 0;
  background: var(--bg-card);
  border-radius: 12px;
  padding: 1rem;
  margin: 0.5rem 0;
  border: 1px solid var(--text-muted);
}
.game-over-panel-title { margin: 0 0 0.75rem; font-size: 1.1rem; color: var(--accent); }
.game-over-panel label { display: block; margin-bottom: 0.25rem; font-size: 0.9rem; color: var(--text-muted); }
.game-over-panel input[type="text"] {
  width: 100%;
  max-width: 240px;
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--text-muted);
  background: var(--bg-dark);
  color: var(--text);
  margin-bottom: 0.5rem;
}
.game-over-panel-meta { font-size: 0.9rem; color: var(--text-muted); margin: 0.5rem 0 0.75rem; }
.game-over-panel-why { font-size: 0.9rem; color: var(--text-muted); margin: 0.25rem 0 0.75rem; }
.game-over-panel-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.game-over-panel-actions button {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: var(--accent);
  color: var(--bg-dark);
}
.game-over-panel-actions .btn-scoreboard {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-weight: 600;
  text-decoration: none;
  background: var(--bg-dark);
  color: var(--text);
  border: 1px solid var(--text-muted);
}
.score-submitted-msg { color: var(--success); font-weight: 600; margin-top: 0.5rem; }

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "DM Sans", "Segoe UI", system-ui, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  line-height: 1.4;
}

.app {
  height: 100vh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.5rem;
  overflow: hidden;
}

/* Header - fixed height, buttons don't move */
.header-wrap { flex-shrink: 0; position: relative; }
.header {
  flex-shrink: 0;
  text-align: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--text-muted);
  transition: transform 0.25s ease-out;
}
.header-reveal-bar {
  display: none;
  padding: 0.5rem 1rem;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--bg-dark);
  border-bottom: 1px solid var(--text-muted);
  cursor: pointer;
}
/* In game: hide top menu, show only exit bar */
body.header-hidden .header-wrap .header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  transform: translateY(-100%);
  pointer-events: none;
  z-index: 5;
}
body.header-hidden .header-reveal-bar {
  display: block;
}
/* In game (playtest): hide session log so only exit bar and game show */
body.header-hidden .playtest-panel {
  display: none;
}

.header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
}

.tagline {
  margin: 0.2rem 0 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.game-status {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.game-status > * {
  flex-shrink: 0;
}

.open-cards-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}
.open-cards-toggle input { cursor: pointer; }
.open-cards-toggle span { user-select: none; }

.tutorial-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}
.tutorial-toggle input { cursor: pointer; }
.tutorial-toggle span { user-select: none; }

/* Tutorial popup: rule of the moment, 7 seconds */
.tutorial-popup {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.6);
  padding: 1rem;
  animation: tutorial-fade-in 0.2s ease-out;
}
@keyframes tutorial-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.tutorial-popup-inner {
  max-width: 420px;
  max-height: 85vh;
  overflow: auto;
  background: var(--bg-card);
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.tutorial-popup-title {
  margin: 0 0 0.5rem 0;
  font-size: 1.1rem;
  color: var(--accent);
}
.tutorial-popup-body {
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--text);
}
.tutorial-popup-body strong { color: var(--accent); }
.tutorial-popup-dismiss {
  margin: 0.75rem 0 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.tutorial-popup-close {
  margin-top: 0.75rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: var(--bg-dark);
  border: none;
  border-radius: 8px;
}
.tutorial-popup-close:hover { filter: brightness(1.1); }
.tutorial-popup { cursor: pointer; }
.tutorial-popup-inner { cursor: default; pointer-events: auto; }

/* Molecule / combo info popup (name + use, close button) */
.molecule-rule-popup {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.6);
  padding: 1rem;
}
.molecule-rule-popup-inner {
  max-width: 380px;
  background: var(--bg-card);
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.molecule-rule-popup-title { margin: 0 0 0.5rem 0; font-size: 1.1rem; color: var(--accent); }
.molecule-rule-popup-body { font-size: 0.9rem; line-height: 1.45; color: var(--text); }
.molecule-rule-popup-close {
  margin-top: 0.75rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: var(--bg-dark);
  border: none;
  border-radius: 8px;
}
.molecule-rule-popup-close:hover { filter: brightness(1.1); }

/* Rules overlay (mobile): full-screen modal to view rules */
.rules-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  box-sizing: border-box;
}
.rules-overlay-inner {
  background: var(--bg-card);
  border-radius: 12px;
  border: 2px solid var(--accent);
  max-width: 100%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
.rules-overlay-title {
  margin: 0 0 0.5rem 0;
  font-size: 1.25rem;
  color: var(--accent);
  flex-shrink: 0;
}
.rules-overlay-content {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding-right: 0.25rem;
}
.rules-overlay-content .rules-list { list-style: none; padding: 0; margin: 0; }
.rules-overlay-content .rule-item { margin-bottom: 0.75rem; }
.rules-overlay-content .rule-head { font-weight: 600; color: var(--accent); display: block; margin-bottom: 0.2rem; }
.rules-overlay-content .rule-detail { font-size: 0.9rem; line-height: 1.45; color: var(--text); }
.rules-overlay-close {
  margin-top: 0.75rem;
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: var(--bg-dark);
  border: none;
  border-radius: 8px;
  flex-shrink: 0;
}
.rules-overlay-close:hover { filter: brightness(1.1); }
/* Rules button: hidden by default, shown on mobile where rules section is hidden */
#btn-rules.btn-rules-mobile { display: none; }

.btn-header {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-weight: 600;
  text-decoration: none;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--text-muted);
}
.btn-header:hover { border-color: var(--accent); color: var(--accent); }

#turn-indicator {
  font-weight: 600;
  color: var(--success);
}

#message-area {
  min-height: 1.5em;
  color: var(--text-muted);
}

#btn-new-game {
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: var(--bg-dark);
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

#btn-new-game:hover {
  filter: brightness(1.1);
}

/* Game area: scrollable on desktop; short viewport uses fit-one-screen below */
.game-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.game-scroll::-webkit-scrollbar,
.play-log::-webkit-scrollbar,
.player-hand::-webkit-scrollbar {
  display: none;
}
.play-log {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.table-view .player-hand {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

/* Game board - Grid layout */
.game-board {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto 1fr auto;
  gap: 0.5rem;
  padding: 0.5rem 0;
  background: var(--bg-board);
  border-radius: 12px;
  margin: 0.5rem 0;
}

/* Table view: fixed size so layout doesn't move */
.table-view {
  grid-template-columns: minmax(0, 1fr) minmax(260px, 2fr) 100px;
  grid-template-rows: 88px 152px 32px 70px 128px;
  gap: 0.4rem;
  padding: 0.5rem;
  max-width: 100%;
  min-height: 0;
  position: relative;
}

/* Oval poker-style table: green felt, red rim, 5 seats around */
.oval-table {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr 120px;
  padding: 0.5rem;
  min-height: 420px;
  position: relative;
}

.oval-table-wrap {
  grid-row: 1;
  position: relative;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  aspect-ratio: 1.6 / 1;
  min-height: 200px;
  z-index: 0;
}

.oval-rim {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  background: linear-gradient(145deg, #8b2a2a 0%, #5c1a1a 100%);
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.15), 0 4px 12px rgba(0,0,0,0.4);
  padding: 10px;
}

.oval-felt {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: linear-gradient(160deg, #1a4d2e 0%, #0d2818 50%, #0a1f12 100%);
  box-shadow: inset 0 0 60px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Seats inside oval-felt so their % positions are relative to the oval */
.oval-felt > .seat { position: absolute; }

/* Center: play card + last played + draw — all same size as temperature card (80×112) */
.oval-table .table-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 14% 10% 10% 10%;
  grid-column: unset;
  grid-row: unset;
  min-height: 0;
  background: transparent;
}
.oval-table .table-center .discard-pile {
  width: 80px;
  min-height: 112px;
  max-height: 112px;
  background: transparent;
  border: none;
}
.oval-table .table-center .card-slot {
  min-width: 80px;
  width: 80px;
  min-height: 112px;
  max-height: 112px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.oval-table .table-center .card-slot .card {
  width: 80px !important;
  min-height: 112px;
  max-width: 80px;
  max-height: 112px;
  font-size: 0.7rem;
}
.oval-table .table-center .card-slot .card .card-symbol { font-size: 1rem; }
.oval-table .table-center .card-slot .card .card-family-name,
.oval-table .table-center .card-slot .card .card-melting { font-size: 0.5rem; }
.oval-table .table-center .last-played-wrap {
  width: 80px;
  min-height: 112px;
  max-height: 112px;
  flex-shrink: 0;
}
.oval-table .table-center .last-played-cards {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  align-content: center;
  min-height: 112px;
  max-height: 112px;
  max-width: 80px;
  overflow: hidden;
}
.oval-table .table-center .last-played-cards .card {
  width: 80px;
  min-height: 112px;
  max-width: 80px;
  max-height: 112px;
  font-size: 0.7rem;
}
.oval-table .table-center .last-played-cards .card .card-symbol { font-size: 1rem; }
.oval-table .table-center .last-played-cards .card .card-family-name,
.oval-table .table-center .last-played-cards .card .card-melting { font-size: 0.5rem; }
.oval-table .table-center .draw-pile {
  width: 80px;
  min-height: 112px;
  max-height: 112px;
  background: linear-gradient(145deg, #2a2d3a, #1e2030);
  border: 2px dashed rgba(255,255,255,0.3);
  border-radius: var(--card-radius);
}

/* Seats around the oval: absolute position */
.oval-table .seat {
  position: absolute;
  z-index: 2;
  cursor: default;
}
.oval-table .seat-opp {
  cursor: pointer;
  border: none;
  background: transparent;
  padding: 0;
  font: inherit;
  color: inherit;
  text-align: center;
}
.oval-table .seat-opp:hover { opacity: 0.95; }
.oval-table .seat-opp:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Each bot vis-à-vis a corner of the center rectangle, still on the oval table */
.oval-table .seat-top-left { top: 5%; left: 8%; }      /* opposite rectangle top-left */
.oval-table .seat-top-right { top: 5%; right: 8%; }   /* opposite rectangle top-right */
.oval-table .seat-bottom-right { bottom: 5%; right: 8%; }  /* opposite rectangle bottom-right */
.oval-table .seat-bottom-left { bottom: 5%; left: 8%; }    /* opposite rectangle bottom-left */
.oval-table .seat-you {
  position: relative;
  grid-row: 2;
  top: auto;
  left: auto;
  right: auto;
  bottom: auto;
}

.oval-table .seat-opp .ai-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem 0.5rem;
  background: var(--bg-card);
  border-radius: 12px;
  border: 2px solid transparent;
  min-width: 72px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.oval-table .seat-opp .ai-player[data-active="true"] {
  border-color: var(--success);
  box-shadow: 0 0 0 2px var(--bg-board);
}
.oval-table .seat-opp .ai-player-header { display: contents; }
.oval-table .seat-opp .ai-name { font-weight: 600; font-size: 0.85rem; }
.oval-table .seat-opp .ai-cards { font-size: 0.8rem; color: var(--text-muted); }
.oval-table .seat-opp .ai-hand {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: center;
  min-height: 28px;
  max-height: 64px;
  overflow: hidden;
}
.oval-table .seat-opp .ai-hand .card-mini {
  width: 26px;
  min-height: 36px;
  font-size: 0.5rem;
}
.oval-table .seat-opp .seat-hint {
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.9;
}
.oval-table .seat-opp[data-revealed="true"] .seat-hint { display: none; }

.oval-table .table-center .last-played-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}
.oval-table .table-center .last-played-label { font-size: 0.65rem; color: var(--text-muted); }


/* Legacy ai-section (non-oval) - keep for fallback */
.ai-section {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  z-index: 1;
}
.table-view:not(.oval-table) .ai-section.ai-top { grid-column: 1 / 3; grid-row: 1; }
.table-view:not(.oval-table) .ai-section.ai-right { grid-column: 3; grid-row: 2; }

.ai-player {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--bg-card);
  border-radius: var(--card-radius);
  border: 2px solid transparent;
  transition: var(--transition);
}

.ai-player[data-active="true"] {
  border-color: var(--success);
  box-shadow: 0 0 0 2px var(--bg-board);
}

.ai-player-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.ai-name { font-weight: 600; }
.ai-cards {
  min-width: 1.5em;
  text-align: center;
  color: var(--text-muted);
}
.ai-icon { font-size: 0.75rem; opacity: 0.8; }

.ai-hand {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  margin-top: 0.35rem;
  min-height: 36px;
}
.opponent-cards-count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Mini cards for AI hands */
.card-mini {
  width: 32px;
  min-height: 44px;
  padding: 2px 4px;
  font-size: 0.6rem;
}
.card-mini .card-symbol { font-size: 0.6rem; }
.card-mini .card-family-icon { font-size: 0.5rem; }
.card-mini .card-decay { font-size: 0.5rem; width: 0.9em; height: 0.9em; top: 1px; right: 1px; }

/* Play log */
.play-log-section {
  grid-column: 1 / -1;
  padding: 0 0.75rem;
  flex-shrink: 0;
  z-index: 1;
}

.table-view .play-log-section { grid-row: 4; max-height: 100%; overflow: hidden; }
.table-view .play-log { max-height: 52px; }
.play-log-title {
  margin: 0 0 0.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.play-log {
  max-height: 80px;
  overflow-y: auto;
  background: var(--bg-card);
  border-radius: var(--card-radius);
  padding: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.play-log-entry {
  padding: 0.2rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.play-log-entry:last-child { border-bottom: none; }
.play-log-entry .who { font-weight: 600; color: var(--text); }
.play-log-entry .explanation { color: var(--text-muted); }

/* Center: draw pile + discard pile */
.center-area {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3rem;
  padding: 1rem;
  min-height: 180px;
  z-index: 1;
}

.table-view .center-area {
  grid-column: 1 / 3;
  grid-row: 2;
  min-height: 0;
  height: 100%;
  gap: 1.5rem;
  padding: 0.5rem;
}
.table-view .draw-pile,
.table-view .discard-pile {
  width: 72px;
  min-height: 100px;
  flex-shrink: 0;
}
.table-view .card-slot { min-width: 72px; min-height: 100px; }
.table-view .last-played-cards .card { width: 40px; min-height: 56px; font-size: 0.65rem; }

.draw-pile, .discard-pile {
  width: 100px;
  min-height: 140px;
  border-radius: var(--card-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.draw-pile {
  background: linear-gradient(145deg, #2a2d3a, #1e2030);
  border: 2px dashed var(--text-muted);
}

.draw-pile:hover:not([aria-disabled="true"]) {
  border-color: var(--accent);
  transform: scale(1.02);
}

.draw-pile[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.6;
}

.pile-inner {
  text-align: center;
}

.pile-label { display: block; font-size: 0.85rem; color: var(--text-muted); }
.pile-count { display: block; font-size: 1.25rem; font-weight: 700; }

.discard-pile {
  background: transparent;
  border: none;
  cursor: default;
}

.last-played-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}
.last-played-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.last-played-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  min-height: 50px;
}
.last-played-cards .card {
  width: 48px;
  min-height: 66px;
  padding: 4px 6px;
  font-size: 0.7rem;
}
.last-played-cards .card .card-symbol { font-size: 0.75rem; }
.last-played-cards .card .card-family-icon { font-size: 0.55rem; }

/* Flash animation for cards just played */
.card-flash {
  animation: card-flash 0.5s ease-out;
}
@keyframes card-flash {
  0% {
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.9);
    transform: scale(1.08);
  }
  100% {
    box-shadow: var(--card-shadow);
    transform: scale(1);
  }
}

.replay-section {
  grid-column: 1 / -1;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.5rem;
  z-index: 1;
}

.table-view .replay-section { grid-row: 3; padding: 0.25rem; }
.replay-section button {
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--text-muted);
  background: var(--bg-card);
  color: var(--text);
}
.replay-section button:hover:not(:disabled) {
  background: var(--accent);
  color: var(--bg-dark);
  border-color: var(--accent);
}
.replay-section button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.replay-status {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.card-slot {
  min-width: 90px;
  min-height: 126px;
  position: relative;
}

/* Card component - colorblind: family color + shape icon */
.card {
  width: 90px;
  min-height: 126px;
  border-radius: var(--card-radius);
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: var(--card-shadow);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  border: 2px solid rgba(255,255,255,0.1);
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

.card:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card-symbol {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.card-family-name {
  font-size: 0.5rem;
  line-height: 1.2;
  margin-top: 2px;
  max-width: 100%;
  text-align: center;
  color: rgba(255,255,255,0.9);
  word-break: break-word;
}
.card-melting {
  font-size: 0.55rem;
  margin-top: 1px;
  color: rgba(255,255,255,0.85);
}
.card-family-icon {
  font-size: 0.7rem;
  margin-top: 2px;
  opacity: 0.95;
}
.card-mini .card-family-name,
.card-mini .card-melting {
  display: none;
}

/* Family colors and shapes (icon = second discriminator) */
.card[data-family="0"] { background: linear-gradient(145deg, var(--family-s), #5a7bc7); }
.card[data-family="0"] .card-family-icon::before { content: "●"; }

.card[data-family="1"] { background: linear-gradient(145deg, var(--family-p), #7eae4a); }
.card[data-family="1"] .card-family-icon::before { content: "▲"; }

.card[data-family="2"] { background: linear-gradient(145deg, var(--family-d), #b89250); }
.card[data-family="2"] .card-family-icon::before { content: "■"; }

.card[data-family="3"] { background: linear-gradient(145deg, var(--family-f), #8b7ab7); }
.card[data-family="3"] .card-family-icon::before { content: "◆"; }

/* Special cards: Fission, Fusion, Temperature */
.card-special {
  font-size: 0.75rem;
}
.card-special .card-symbol {
  font-size: 0.85rem;
  text-align: center;
  line-height: 1.2;
}
.card-fission {
  background: linear-gradient(145deg, #f7768e, #c45c6e);
}
.card-fission .card-family-icon::before { content: "⚛"; }
.card-fusion {
  background: linear-gradient(145deg, #7dcfff, #5a9fd4);
}
.card-fusion .card-family-icon::before { content: "☢"; }
.card-temperature {
  background: linear-gradient(145deg, #e0af68, #b89250);
}
.card-temperature .card-family-icon::before { content: "🌡"; }
.card-eventHorizon {
  background: linear-gradient(145deg, #2ac3de, #1e9bb5);
  background-image: url('james-webb-first-supermassive-black-hole-runaway-home.webp');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
.card-eventHorizon .card-symbol,
.card-eventHorizon .card-family-icon {
  position: relative;
  z-index: 1;
  color: #fff;
  text-shadow: 0 0 4px rgba(0,0,0,0.9), 0 1px 3px rgba(0,0,0,0.95);
}
.card-eventHorizon .card-family-icon::before { content: "◉"; }
.card-eventHorizon::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  pointer-events: none;
  z-index: 0;
  border-radius: inherit;
}

/* Radiation decay countdown */
.card-decay {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  background: rgba(0,0,0,0.5);
  color: #fff;
  width: 1.1em;
  height: 1.1em;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card.selected {
  outline: 3px solid #fff;
  outline-offset: 2px;
  transform: translateY(-6px);
}

.card.unplayable {
  opacity: 0.6;
  cursor: not-allowed;
  filter: grayscale(0.3);
}

/* Player hand - fixed so Draw button doesn't move */
.player-hand-section {
  grid-column: 1 / -1;
  flex-shrink: 0;
  padding: 0.5rem 1rem;
  background: var(--bg-card);
  border-radius: 12px;
  z-index: 1;
}

.table-view .player-hand-section {
  grid-row: 5;
  padding: 0.4rem 0.75rem;
  min-height: 0;
}
.table-view .player-hand {
  min-height: 90px;
  max-height: 90px;
  overflow-x: auto;
  overflow-y: hidden;
  flex-wrap: nowrap;
  justify-content: center;
  padding: 0.35rem 0;
  -webkit-overflow-scrolling: touch;
}
.table-view .player-hand .card {
  flex-shrink: 0;
}

.hand-label {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.molecule-hint {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
}

.molecule-hint.batch-shed-callout {
  display: block;
  margin: 0 0 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--bg-dark);
  background: linear-gradient(135deg, var(--accent) 0%, #e67e22 100%);
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.4);
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.molecule-hint.batch-shed-callout strong {
  color: var(--bg-dark);
}

.player-hand .card.in-molecule {
  box-shadow: 0 0 0 2px var(--accent), 0 4px 12px rgba(0,0,0,0.3);
  outline: 2px solid rgba(255,255,255,0.5);
}
.player-hand .card.in-ferro {
  box-shadow: 0 0 0 2px #e67e22, 0 4px 12px rgba(0,0,0,0.3);
  outline: 2px solid rgba(255,255,255,0.5);
}

.player-hand {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  min-height: 140px;
  padding: 0.5rem 0;
}

.hand-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.5rem;
  flex-shrink: 0;
}
.hand-actions button,
.hand-actions a {
  flex-shrink: 0;
}

#btn-draw, #btn-play-molecule {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
}

#btn-draw {
  background: var(--accent);
  color: var(--bg-dark);
}

#btn-draw:hover:not(:disabled) { filter: brightness(1.1); }
#btn-draw:disabled { opacity: 0.5; cursor: not-allowed; }

#btn-play-molecule.secondary {
  background: var(--family-p);
  color: var(--bg-dark);
}

/* Rules section: hover to expand */
.rules-section {
  margin-top: 2rem;
  padding: 1rem;
  border-top: 1px solid var(--text-muted);
}
.rules-title {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
  color: var(--accent);
}
.rules-intro {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.rules-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.rule-item {
  margin-bottom: 0.5rem;
  border-radius: var(--card-radius);
  background: var(--bg-card);
  border: 1px solid transparent;
  transition: border-color var(--transition), background var(--transition);
}
.rule-item:hover {
  border-color: var(--accent);
  background: rgba(122, 162, 247, 0.08);
}
.rule-head {
  display: block;
  padding: 0.5rem 0.75rem;
  font-weight: 600;
  cursor: default;
  color: var(--text);
}
.rule-detail {
  max-height: 0;
  overflow: hidden;
  padding: 0 0.75rem;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-muted);
  transition: max-height 0.35s ease-out;
}
.rule-item:hover .rule-detail {
  max-height: 280px;
  padding-bottom: 0.75rem;
}
.rule-detail strong { color: var(--text); }
.rules-cards-link {
  margin: 1rem 0 0;
  font-size: 0.95rem;
}
.rules-cards-link a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.rules-cards-link a:hover { text-decoration: underline; }

/* Footer */
.video-wrap {
  margin-top: 1.5rem;
  max-width: 560px;
  margin-left: auto;
  margin-right: auto;
}
.video-title {
  font-size: 1rem;
  margin: 0 0 0.5rem;
  color: var(--text-muted);
}
.video-responsive {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  border-radius: 8px;
  background: var(--bg-card);
}
.video-responsive iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.rules-guide-link { margin: 0 0 0.75rem; font-size: 0.9rem; }
.rules-guide-link a { color: var(--accent); text-decoration: none; }
.rules-guide-link a:hover { text-decoration: underline; }
/* Guide video embed: desktop only; hidden on mobile */
@media (max-width: 768px) {
  .guide-video-desktop { display: none !important; }
}

.footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--text-muted);
}

.footer p { margin: 0; }
.footer-copyright {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  opacity: 0.9;
}
.footer-copyright a {
  color: var(--accent);
  text-decoration: none;
}
.footer-copyright a:hover { text-decoration: underline; }

/* Short viewport: fit in one screen (no scroll), hide rules, board flexes to fill */
@media (max-height: 800px) {
  .game-scroll {
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  .game-scroll > main.game-board { flex: 1; min-height: 0; }
  .oval-table { min-height: 0; }
  .oval-table-wrap { min-height: 0; }
  .game-scroll .rules-section { display: none; }
  .game-scroll .footer { padding: 0.5rem; font-size: 0.75rem; }
  #btn-rules.btn-rules-mobile { display: inline-block; }
}

/* Mobile - same viewport fit, stable buttons */
@media (max-width: 768px) {
  .app { padding: 0.35rem; }
  .header { padding: 0.35rem 0; }
  .header h1 { font-size: 1.2rem; }
  .tagline { font-size: 0.8rem; margin: 0.15rem 0 0.35rem; }
  .game-status { flex-wrap: wrap; justify-content: center; gap: 0.35rem; }
  .game-status > * { min-width: 0; }
  .open-cards-toggle { font-size: 0.8rem; }
  .game-board { padding: 0.35rem; gap: 0.35rem; margin: 0.35rem 0; }
  .table-view { grid-template-rows: 72px 120px 28px 58px 100px; grid-template-columns: minmax(0, 1fr) minmax(200px, 2fr) 72px; }
  .ai-section { gap: 0.35rem; }
  .ai-player { padding: 0.25rem 0.4rem; flex-wrap: wrap; }
  .ai-hand { min-height: 26px; }
  .table-view .ai-section.ai-right .ai-hand { max-height: 72px; }
  .center-area { gap: 1rem; padding: 0.5rem; min-height: 100px; }
  .table-view .draw-pile, .table-view .discard-pile { width: 56px; min-height: 80px; }
  .table-view .player-hand { min-height: 72px; max-height: 72px; }
  .draw-pile, .discard-pile { width: 64px; min-height: 88px; }
  .player-hand-section { padding: 0.35rem 0.5rem; }
  .player-hand { min-height: 80px; gap: 4px; }
  .card { min-width: 48px; }
  .card-mini { width: 24px; min-height: 32px; font-size: 0.5rem; }
  .hand-actions { flex-wrap: nowrap; }
  .rules-section, .video-wrap { padding: 0 0.35rem; margin-top: 0.75rem; }
  .lobby-app { padding: 1rem 0.75rem; }
  .lobby-row { flex-wrap: wrap; }
  .lobby-row input { min-width: 0; }
  /* Oval table (index/playtest): all 4 bots in one row on same level for mobile */
  .oval-table .seat-opp.seat-top-left { top: 5%; left: 2%; right: auto; bottom: auto; }
  .oval-table .seat-opp.seat-top-right { top: 5%; left: 27%; right: auto; bottom: auto; }
  .oval-table .seat-opp.seat-bottom-right { top: 5%; left: 52%; right: auto; bottom: auto; }
  .oval-table .seat-opp.seat-bottom-left { top: 5%; left: 77%; right: auto; bottom: auto; }
  /* Banners overlay the view so gameplay layout does not move */
  .winner-banner {
    position: fixed;
    top: 0.5rem;
    left: 0.5rem;
    right: 0.5rem;
    z-index: 600;
    margin: 0;
  }
  .player-hand-section .molecule-hint.batch-shed-callout {
    position: fixed;
    bottom: 7rem;
    left: 0.5rem;
    right: 0.5rem;
    z-index: 550;
    margin: 0;
  }
}
@media (max-width: 480px) {
  .game-board { grid-template-columns: 1fr; }
  .table-view { grid-template-columns: 1fr 1fr 60px; grid-template-rows: 64px 100px 24px 48px 88px; }
  .center-area { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 0.75rem; min-height: auto; }
  .table-view .center-area { grid-column: 1 / 3; }
  .draw-pile, .discard-pile { width: 56px; min-height: 78px; }
  .table-view .draw-pile, .table-view .discard-pile { width: 48px; min-height: 68px; }
  .table-view .player-hand .card { min-width: 40px; }
  .player-hand .card { min-width: 44px; }
  #btn-new-game, #btn-scoreboard-header, #btn-lobby { padding: 0.4rem 0.75rem; font-size: 0.9rem; }
}

/* Portrait on small screens: show rotate prompt, hide game */
.rotate-prompt {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-dark);
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.rotate-prompt-inner { text-align: center; }
.rotate-prompt-icon { font-size: 4rem; margin: 0 0 1rem; color: var(--accent); }
.rotate-prompt-text { font-size: 1.25rem; font-weight: 600; color: var(--text); margin: 0; }
@media (orientation: portrait) and (max-height: 700px) {
  .rotate-prompt { display: flex; }
  .app { visibility: hidden; }
}
@media (orientation: portrait) and (max-width: 768px) and (min-height: 701px) {
  .rotate-prompt { display: flex; }
  .app { visibility: hidden; }
}

/* Mobile landscape: compact layout so table, center cards, hand and draw button all fit */
@media (orientation: landscape) and (max-height: 500px) {
  .rotate-prompt { display: none; }
  .app { visibility: visible; padding: 0.25rem; }
  .header-wrap { position: relative; flex-shrink: 0; }
  .header {
    padding: 0.2rem 0;
    transition: transform 0.25s ease-out;
  }
  body.header-hidden .header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    transform: translateY(-100%);
    pointer-events: none;
    z-index: 5;
  }
  .header-reveal-bar {
    display: none;
    padding: 0.35rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--bg-dark);
    border-bottom: 1px solid var(--text-muted);
    cursor: pointer;
  }
  body.header-hidden .header-reveal-bar { display: block; }
  .header h1 { font-size: 1rem; }
  .tagline { display: none; }
  .game-status { flex-wrap: wrap; gap: 0.25rem; }
  /* Banners overlay the view so gameplay layout does not move */
  .winner-banner {
    position: fixed;
    top: 2.5rem;
    left: 0.25rem;
    right: 0.25rem;
    z-index: 600;
    margin: 0;
  }
  .player-hand-section .molecule-hint.batch-shed-callout {
    position: fixed;
    bottom: 6rem;
    left: 0.25rem;
    right: 0.25rem;
    z-index: 550;
    margin: 0;
  }
  .game-status .open-cards-toggle span,
  .game-status .tutorial-toggle span { display: none; }
  .game-scroll { min-height: 0; }
  .oval-table {
    grid-template-rows: 1fr 72px;
    min-height: 0;
    padding: 0.25rem;
  }
  .oval-table-wrap { min-height: 100px; aspect-ratio: 1.5 / 1; }
  .oval-table .table-center {
    padding: 8% 6% 6% 6%;
    gap: 0.5rem;
  }
  .oval-table .table-center .discard-pile,
  .oval-table .table-center .card-slot,
  .oval-table .table-center .last-played-wrap,
  .oval-table .table-center .draw-pile {
    width: 52px;
    min-height: 72px;
    max-height: 72px;
  }
  .oval-table .table-center .card-slot .card,
  .oval-table .table-center .last-played-cards .card {
    width: 52px !important;
    min-height: 72px;
    max-width: 52px;
    max-height: 72px;
    font-size: 0.6rem;
  }
  .oval-table .table-center .card-slot .card .card-symbol,
  .oval-table .table-center .last-played-cards .card .card-symbol { font-size: 0.8rem; }
  .oval-table .table-center .card-slot .card .card-family-name,
  .oval-table .table-center .card-slot .card .card-melting,
  .oval-table .table-center .last-played-cards .card .card-family-name,
  .oval-table .table-center .last-played-cards .card .card-melting { font-size: 0.45rem; }
  .oval-table .table-center .last-played-cards { min-height: 72px; max-height: 72px; max-width: 52px; }
  .oval-table .seat-opp .ai-player { padding: 0.25rem 0.35rem; min-width: 56px; }
  .oval-table .seat-opp .ai-name { font-size: 0.7rem; }
  .oval-table .seat-opp .ai-cards { font-size: 0.65rem; }
  .oval-table .seat-opp .ai-hand .card-mini { width: 20px; min-height: 28px; }
  .oval-table .seat-you { grid-row: 2; }
  /* Bots 3 and 4: move up toward middle of screen on mobile */
  .oval-table .seat-bottom-right { bottom: 28%; right: 8%; }
  .oval-table .seat-bottom-left { bottom: 28%; left: 8%; }
  /* User's deck: full-width bottom bar (mobile landscape) */
  .player-hand-section {
    margin: 0 -0.25rem -0.25rem -0.25rem;
    padding: 0.35rem 0.5rem;
    padding-bottom: max(0.35rem, env(safe-area-inset-bottom));
    padding-left: max(0.5rem, env(safe-area-inset-left));
    padding-right: max(0.5rem, env(safe-area-inset-right));
    background: var(--bg-dark);
    border-top: 2px solid rgba(255,255,255,0.12);
    border-radius: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
  }
  .player-hand-section .hand-label {
    font-size: 0.8rem;
    margin: 0;
    color: var(--text-muted);
    flex-shrink: 0;
  }
  .player-hand-section .player-hand {
    min-height: 52px;
    max-height: 72px;
    gap: 4px;
    padding: 0.2rem 0;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch;
  }
  .oval-table .player-hand .card,
  .player-hand .card {
    min-width: 36px;
    min-height: 50px;
    max-height: 50px;
    font-size: 0.6rem;
  }
  .player-hand .card .card-symbol { font-size: 0.75rem; }
  .player-hand .card .card-family-name,
  .player-hand .card .card-melting { font-size: 0.4rem; }
  .player-hand-section .hand-actions {
    margin-top: 0;
    justify-content: center;
    flex-shrink: 0;
  }
  .hand-actions #btn-draw { padding: 0.4rem 0.75rem; font-size: 0.85rem; }
  .rules-section { display: none; }
  #btn-rules.btn-rules-mobile { display: inline-block; }
}
