* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #1a1d24; color: #e8eaef;
  height: 100%; overflow: hidden;
}
button { cursor: pointer; }
input, select, button {
  font: inherit; padding: 6px 10px; border-radius: 4px;
  border: 1px solid #3a4050; background: #232733; color: #e8eaef;
}
button { background: #3a5fcd; border-color: #3a5fcd; }
button:hover:not(:disabled) { background: #4a6fd8; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.hidden { display: none !important; }
.error { color: #ff6e6e; min-height: 1em; margin-top: 8px; }
.banner { background: #2c4a82; padding: 8px 12px; border-radius: 4px; margin: 8px 0; display: flex; justify-content: space-between; align-items: center; }

.screen { position: absolute; inset: 0; display: flex; }
#screen-auth { align-items: center; justify-content: center; }
.auth-card { background: #232733; padding: 24px; border-radius: 8px; min-width: 320px; }
.auth-card h1 { margin: 0 0 12px; text-align: center; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tab { flex: 1; background: #2a2f3d; border: none; }
.tab.active { background: #3a5fcd; }
.auth-form { display: flex; flex-direction: column; gap: 8px; }
.auth-divider {
  display: flex; align-items: center; text-align: center;
  margin: 14px 0 10px; opacity: 0.55; font-size: 12px;
}
.auth-divider::before, .auth-divider::after {
  content: ''; flex: 1; height: 1px; background: #3a4050; margin: 0 8px;
}
.guest-btn { width: 100%; background: #2a2f3d; border: 1px solid #3a4050; }
.guest-btn:hover { background: #353a4a; }

#screen-lobby, #screen-room { padding: 24px; flex-direction: column; overflow-y: auto; }
.lobby-card, .room-card { max-width: 800px; width: 100%; margin: 0 auto; background: #232733; padding: 24px; border-radius: 8px; }
.topbar { display: flex; justify-content: space-between; align-items: center; }
.lobby-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.panel { background: #1a1d24; padding: 16px; border-radius: 6px; display: flex; flex-direction: column; gap: 8px; }

#room-teams { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin: 16px 0; }
.team { background: #1a1d24; padding: 12px; border-radius: 6px; }
.team-1 { border-top: 4px solid #d6394a; }
.team-2 { border-top: 4px solid #4d6fd8; }
.team-none { border-top: 4px solid #555; }
.team ul { list-style: none; padding: 0; margin: 8px 0; min-height: 60px; }
.team li { padding: 4px 8px; background: #232733; border-radius: 4px; margin: 4px 0; }
.room-player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.room-player-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.remove-room-player {
  width: 24px;
  height: 24px;
  padding: 0;
  flex-shrink: 0;
  background: #3a4050;
  border-color: #3a4050;
  line-height: 1;
}
.remove-room-player:hover:not(:disabled) {
  background: #d6394a;
  border-color: #d6394a;
}
.team-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.team-actions button { flex: 1 1 120px; }
.room-actions { margin-top: 16px; display: flex; gap: 12px; align-items: center; }
#room-bot-controls {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}
.bot-difficulty-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #1a1d24;
  border: 1px solid #333948;
  border-radius: 6px;
  padding: 8px;
}
.bot-difficulty-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}
.bot-difficulty-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#room-players-flat ul { list-style: none; padding: 0; }
#room-players-flat li { padding: 6px 10px; background: #1a1d24; border-radius: 4px; margin: 4px 0; }

#screen-game { flex-direction: column; height: 100vh; padding: 0; }
.game-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: #232733;
}
#game-info {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#header-status-prompt {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  max-width: 44%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  line-height: 1.2;
}
.game-header-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
  justify-content: flex-end;
  align-items: center;
}
.settings-menu {
  position: absolute;
  top: 48px;
  right: 16px;
  z-index: 40;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  background: #232733;
  border: 1px solid #3a4050;
  border-radius: 6px;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.35);
}
.settings-menu label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #c9ceda;
  font-size: 13px;
}
.settings-menu input[type="number"] {
  width: 68px;
}
.settings-menu input[type="checkbox"] {
  width: 16px;
  height: 16px;
  padding: 0;
}

.opp-top-row {
  flex-shrink: 0;
  height: 86px;
  display: flex; gap: 4px; justify-content: center; align-items: center;
  padding: 4px 16px;
}

#game-board-wrap {
  flex: 1; position: relative; overflow: hidden;
  padding: 4px 8px;
  display: flex; align-items: center; justify-content: center;
  gap: 10px;
}
.opp-side {
  display: flex; flex-direction: column; gap: 4px;
  flex-shrink: 0; align-self: center;
  min-width: 56px;
}
.opp-side:empty { min-width: 0; }
#game-board {
  background: #1a1d24;
  border-radius: 8px;
  width: min(100%, calc(100vh - 296px));
  height: min(100%, calc(100vh - 296px));
  max-width: 900px; max-height: 900px;
  flex-shrink: 0;
}

.card-back {
  width: 32px; height: 46px;
  background: #3a4050;
  border: 1.5px solid #1a1d24;
  border-radius: 4px;
  flex-shrink: 0;
}
.dealer-stack {
  position: relative;
  width: 54px; height: 58px;
  flex-shrink: 0;
  display: flex; align-items: flex-end; justify-content: center;
  color: #e8eaef; font-size: 10px; line-height: 1.05;
  text-align: center;
}
.dealer-stack::before,
.dealer-stack::after {
  content: '';
  position: absolute;
  width: 32px; height: 46px;
  background: #3a4050;
  border: 1.5px solid #1a1d24;
  border-radius: 4px;
  top: 2px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.35);
}
.dealer-stack::before { left: 9px; transform: rotate(-5deg); }
.dealer-stack::after { left: 13px; transform: rotate(4deg); }
.dealer-stack-empty-next::before,
.dealer-stack-empty-next::after {
  background: #5a1820;
  border-color: #2b0b10;
}
.dealer-stack-label {
  position: relative; z-index: 1;
  background: rgba(26, 29, 36, 0.82);
  border: 1px solid #3a4050;
  border-radius: 4px;
  padding: 2px 4px;
  white-space: nowrap;
}
.dealer-stack-empty-next .dealer-stack-label {
  background: rgba(75, 18, 26, 0.9);
  border-color: #8a2a36;
}
.opp-seat {
  display: flex; gap: 4px; align-items: center; justify-content: center;
  color: #aeb5c4; font-size: 11px;
}
.opp-seat.top { flex-direction: column; }
.opp-seat.left, .opp-seat.right { flex-direction: column; }
.opp-hand {
  display: flex; gap: 4px; align-items: center; justify-content: center;
}
.opp-hand.left, .opp-hand.right { flex-direction: column; gap: 0; }
.opp-hand.left .card-back, .opp-hand.right .card-back { margin: -5px 0; }
.opp-hand.left .card-back { transform: rotate(90deg); }
.opp-hand.right .card-back { transform: rotate(-90deg); }
.opp-hand.top .card-back { transform: rotate(180deg); }

.played-card-ghost {
  position: fixed;
  z-index: 2000;
  pointer-events: none;
  margin: 0;
  transform-origin: center;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
}
#played-pile {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 76px; height: 106px;
  display: flex; align-items: center; justify-content: center;
  z-index: 9; pointer-events: none;
}
#played-pile .card, #played-pile .card-back {
  cursor: default;
  transform: scale(0.72);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
}

.board-center-ui {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  z-index: 10; pointer-events: none;
  width: max-content; max-width: 28%;
}
.board-center-ui > * { pointer-events: auto; }
#status-area, #action-area, #seven-banner {
  background: rgba(35, 39, 51, 0.94);
  padding: 6px 10px; border-radius: 6px;
  font-size: 13px; text-align: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
#status-area { line-height: 1.25; min-width: 180px; }
#action-area {
  display: flex; flex-wrap: wrap; gap: 4px;
  justify-content: center;
  background: transparent; box-shadow: none; padding: 0;
}
#action-area button { padding: 4px 8px; font-size: 12px; }
.seven-banner {
  background: #2c4a2a !important; color: #c8efc8;
}

.hand-bar {
  flex-shrink: 0;
  height: 132px;
  display: flex; align-items: center; justify-content: center;
  padding: 20px 16px 12px;
  background: transparent;
}
#hand-area {
  display: flex; gap: 8px;
  min-height: 0; padding: 0;
  background: transparent;
  flex-wrap: nowrap;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5));
}

.card {
  width: 70px; height: 100px; background: white; color: #222;
  border-radius: 6px; border: 2px solid transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 6px; user-select: none; transition: transform 0.15s;
  cursor: pointer;
}
.card.selected { transform: translateY(-12px); border-color: #ffd54a; }
.card.spent { opacity: 0.4; }
.card.no-moves { opacity: 0.4; cursor: not-allowed; }
.card.trade-selectable {
  border-color: #ffb347;
  box-shadow: 0 0 0 3px rgba(255, 179, 71, 0.35), 0 0 14px rgba(255, 213, 74, 0.45);
}
.card .top,
.card .bottom {
  display: flex;
  gap: 3px;
  align-items: center;
  font-size: 18px;
  font-weight: bold;
  align-self: flex-start;
  line-height: 1;
}
.card .bottom {
  align-self: flex-end;
  transform: rotate(180deg);
}
.card .suit { font-size: 32px; line-height: 1; }
.card .large-rank { display: none; }
.large-number-cards .card {
  justify-content: center;
  position: relative;
}
.large-number-cards .card .top,
.large-number-cards .card .bottom {
  position: absolute;
  font-size: 20px;
}
.large-number-cards .card .top {
  top: 8px;
  left: 8px;
}
.large-number-cards .card .bottom {
  right: 8px;
  bottom: 8px;
}
.large-number-cards .card .corner-rank,
.large-number-cards .card .suit {
  display: none;
}
.large-number-cards .card .large-rank {
  display: block;
  font-size: 44px;
  font-weight: 800;
  line-height: 1;
}
.card.red { color: #cf2d2d; }
.card.black { color: #1f1f1f; }

.marble.swap-target {
  filter: drop-shadow(0 0 8px #ff9b40);
  stroke: #ff9b40;
  stroke-width: 4;
  cursor: pointer;
}
.marble.kill-target {
  filter: drop-shadow(0 0 8px #ffe680);
  stroke: #ffd54a;
  stroke-width: 4;
  cursor: pointer;
}

#game-log { display: none; }

.win-overlay {
  position: fixed; inset: 0; z-index: 3000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.62);
}
.win-dialog {
  background: #232733;
  border: 1px solid #4a5266;
  border-radius: 8px;
  padding: 24px 28px;
  min-width: 280px;
  text-align: center;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.55);
}
.win-dialog h2 { margin: 0 0 8px; }
.win-dialog p { margin: 0 0 16px; color: #c7ccd8; }

/* Board pieces */
.space {
  fill: #d8c8a8;
  stroke: #5a4a30;
  stroke-width: 1;
}
.space.start { fill: #a8895a; }
.space.home-spot { fill: #f1f1f1; }
.space.home-seat-0 { fill: #eda8b2; }
.space.home-seat-1 { fill: #ead77e; }
.space.home-seat-2 { fill: #a8dfb3; }
.space.home-seat-3 { fill: #a9ccef; }
/* Target highlights: noticeable yellow with a glow so they don't get lost
   under the larger marble overlay. 7-split shares the same yellow as
   regular target moves. */
.space.target,
.space.target-7 {
  fill: #ffe680;
  stroke: #ffb347;
  stroke-width: 3;
  cursor: pointer;
  filter: drop-shadow(0 0 8px #ffd54a);
}
.space.target:hover,
.space.target-7:hover { fill: #fff0b0; }
.space.target-swap {
  fill: #ff9b40;
  stroke: #ff7a1a;
  stroke-width: 3;
  cursor: pointer;
  filter: drop-shadow(0 0 8px #ff9b40);
}

.island, .home {
  fill: #2c1d10; stroke: #5a4a30; stroke-width: 1;
}

/* Marbles: slightly larger than spaces with a darker outline. cx/cy
   transitions cause moves to glide A→B (no path tracing — direct line). */
.marble {
  stroke: #0a0c12;
  stroke-width: 3;
  cursor: default;
  transition: cx 0.4s ease, cy 0.4s ease;
}
/* Source candidates (own marbles that could play the selected card) — a
   soft gold halo invites clicks. Visually distinct from .selected below. */
.marble.selectable {
  cursor: pointer;
  filter: drop-shadow(0 0 6px rgba(255, 213, 74, 0.85));
}
/* The chosen source marble — bold black ring + bright double-halo so it
   reads as "this is moving" at a glance, even when surrounded by yellow
   target highlights (Jack swap fan, 7-split distance fan). */
.marble.selected {
  stroke: #000;
  stroke-width: 7;
  filter: drop-shadow(0 0 14px #ffea80) drop-shadow(0 0 5px #ffea80);
}
/* When one marble is selected, drop the gold halo on the other source
   candidates so the chosen marble alone reads as "this is moving". They
   stay clickable so the player can still switch sources. */
.has-selected .marble.selectable:not(.selected) {
  filter: none;
}

.team-color-0 { fill: #d6394a; }    /* red */
.team-color-1 { fill: #d8b730; }    /* yellow */
.team-color-2 { fill: #4ab85c; }    /* green */
.team-color-3 { fill: #4a8fd8; }    /* blue */

text.label { fill: #fff; font-size: 14px; text-anchor: middle; pointer-events: none; }

#screen-replay { flex-direction: column; height: 100vh; padding: 0; }
#replay-controls { padding: 12px 16px; background: #232733; }
#replay-hands {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}
.replay-hand {
  min-width: 0;
  background: #1a1d24;
  border: 1px solid #333948;
  border-radius: 6px;
  padding: 6px;
}
.replay-hand-label {
  color: #c9ceda;
  font-size: 11px;
  line-height: 1.2;
  margin-bottom: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.replay-hand-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 36px;
  align-items: center;
}
.replay-mini-card {
  width: 28px;
  height: 36px;
  border-radius: 4px;
  background: #f7f7f4;
  border: 1px solid #c7c9ce;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  color: #202225;
}
.replay-mini-card.red { color: #cf2d2d; }
.replay-mini-card.black { color: #202225; }
.replay-hand-empty {
  color: #8d94a4;
  font-size: 11px;
}
.replay-buttons { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.replay-buttons input[type=range] { flex: 1; }
#replay-status { font-size: 13px; opacity: 0.85; min-height: 18px; }
#replay-events {
  max-height: 140px; overflow-y: auto; font-size: 12px;
  background: #1a1d24; padding: 8px; border-radius: 4px; font-family: monospace;
}
#replay-events .evt { padding: 2px 4px; }
#replay-events .evt.current { background: #3a5fcd; color: white; }
#games-list {
  font-size: 13px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 4px;
}
#games-list .game-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  padding: 6px 8px; background: #232733; border-radius: 4px; margin: 4px 0;
}
#games-list .game-row button { padding: 4px 10px; }
#games-list .meta { opacity: 0.7; font-size: 12px; }
.games-panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.games-panel-head h3 { margin: 0; }
.games-panel-head label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #aeb5c4;
}
.games-panel-head input { width: 210px; }
.games-panel-head button {
  padding: 4px 10px;
  background: #2a2f3d;
  border-color: #3a4050;
}
.games-panel-head button.active {
  background: #3a5fcd;
  border-color: #3a5fcd;
}
.game-row-main { min-width: 0; }
.game-row-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.game-row-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.game-annotation {
  margin-top: 4px;
  color: #d5dae6;
  font-size: 12px;
}
.game-label {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 5px;
  border: 1px solid #4b5870;
  border-radius: 4px;
  background: #1a1d24;
  color: #f1d26a;
}
.game-description { opacity: 0.82; }
.game-annotation-form {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(120px, 180px) minmax(0, 1fr) auto auto;
  gap: 6px;
  margin-top: 6px;
}
.game-annotation-form input { width: 100%; min-width: 0; }
.game-annotation-form button { padding: 4px 10px; }
#replay-board {
  background: #1a1d24;
  border-radius: 8px;
  width: min(100%, 100vh - 348px);
  height: min(100%, 100vh - 348px);
  max-width: 800px; max-height: 800px;
}
