:root {
  --bg-dark: #0b0f17;
  --bg-card: #131b29;
  --bg-card-alt: #192336;
  --border: #26354d;
  --text-main: #e6edf7;
  --text-muted: #8ea0bc;
  --emerald: #10b981;
  --emerald-dim: rgba(16, 185, 129, 0.16);
  --cyan: #06b6d4;
  --amber: #f59e0b;
  --rose: #f43f5e;
  --indigo: #6366f1;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, sans-serif;
  min-height: 100vh;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #0f1623;
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 12px var(--emerald);
}

.brand h1 {
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.scoreboard {
  display: flex;
  align-items: center;
  gap: 12px;
}

.score-pill {
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.score-pill.team-us {
  border-color: var(--emerald);
}

.score-pill.team-them {
  border-color: var(--amber);
}

.score-pill .label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
}

.score-pill .value {
  font-size: 1.25rem;
  font-weight: 800;
}

.score-pill .target {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.turn-badge {
  padding: 6px 12px;
  border-radius: 6px;
  background: var(--indigo);
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.control-group label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

select {
  background: var(--bg-card-alt);
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
}

.hw-pill {
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--emerald-dim);
  border: 1px solid var(--emerald);
  color: var(--emerald);
  font-size: 0.75rem;
  font-weight: 600;
}

/* Callout Banner */
.callout-banner {
  background: linear-gradient(90deg, rgba(16,185,129,0.18), rgba(6,182,212,0.12));
  border-bottom: 1px solid var(--border);
  padding: 8px 20px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #a7f3d0;
  text-align: center;
}

.callout-banner.alert-locked {
  background: linear-gradient(90deg, rgba(244,63,94,0.28), rgba(245,158,11,0.24));
  border-bottom-color: var(--amber);
  color: #fde68a;
}

.callout-banner.alert-scored {
  background: linear-gradient(90deg, rgba(99,102,241,0.28), rgba(16,185,129,0.22));
  border-bottom-color: var(--emerald);
  color: #d1fae5;
}

/* Main Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 16px;
  padding: 16px 20px;
}

@media (max-width: 1180px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

.left-col,
.right-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.card-header h2 {
  font-size: 0.88rem;
  letter-spacing: 0.05em;
  color: #cbd5e1;
}

.meta-text {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.board-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.board-scroll-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.open-ends-bar {
  display: flex;
  gap: 8px;
}

.end-chip {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  background: var(--bg-card-alt);
  border: 1px solid var(--cyan);
  color: #67e8f9;
}

/* Hand Locked / End-of-Hand Banner */
.hand-end-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid var(--amber);
}

.hand-end-banner.scored {
  background: rgba(16, 185, 129, 0.14);
  border-color: var(--emerald);
}

.hand-end-banner.hidden,
.board-scroll-hint.hidden,
.hidden {
  display: none !important;
}

.hand-end-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.82rem;
}

.hand-end-info strong {
  color: #fde68a;
  letter-spacing: 0.03em;
}

.hand-end-banner.scored .hand-end-info strong {
  color: #6ee7b7;
}

.hand-end-info span {
  color: var(--text-main);
  font-size: 0.76rem;
}

.hand-end-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Virtual Board Canvas (Horizontally Scrollable & Pannable) */
.canvas-wrapper {
  width: 100%;
  background: #143321;
  border: 2px solid #235337;
  border-radius: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  display: block;
  cursor: grab;
  user-select: none;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #2f7a4f #0e2418;
}

.canvas-wrapper.dragging {
  cursor: grabbing;
}

.canvas-wrapper::-webkit-scrollbar {
  height: 10px;
}

.canvas-wrapper::-webkit-scrollbar-track {
  background: #0e2418;
  border-radius: 0 0 6px 6px;
}

.canvas-wrapper::-webkit-scrollbar-thumb {
  background: #2f7a4f;
  border-radius: 5px;
  border: 2px solid #0e2418;
}

.canvas-wrapper::-webkit-scrollbar-thumb:hover {
  background: #3fa068;
}

#boardCanvas {
  display: block;
  margin: 0 auto;
}

.board-scroll-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
}

/* 7-Slot Rack */
.slots-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
}

.slot-box {
  background: var(--bg-card-alt);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.slot-box.playable {
  border-color: var(--emerald);
  background: rgba(16, 185, 129, 0.09);
  cursor: pointer;
}

.slot-box.playable:hover {
  transform: translateY(-3px);
}

.slot-box.recommended {
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.35);
}

.slot-box.ambiguous {
  border-color: var(--amber);
}

.slot-title {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 700;
}

.domino-mini {
  width: 48px;
  height: 86px;
  background: #f8fafc;
  color: #0f172a;
  border-radius: 6px;
  border: 2px solid #334155;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  font-weight: 800;
  font-size: 1.25rem;
}

.domino-mini.empty {
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed var(--border);
  color: var(--text-muted);
  font-size: 0.7rem;
}

.domino-mini .divider {
  width: 80%;
  height: 2px;
  background: #475569;
}

.slot-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.slot-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Gantry Linear Rail */
.gantry-rail-container {
  background: #0d131f;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}

.rail-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.rail-track {
  height: 16px;
  background: #1e293b;
  border-radius: 8px;
  position: relative;
}

.carriage-head {
  position: absolute;
  top: -3px;
  width: 34px;
  height: 22px;
  background: var(--cyan);
  color: #042f2e;
  font-weight: 800;
  font-size: 0.7rem;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: left 0.25s ease;
}

.strategy-strip {
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid var(--indigo);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.8rem;
}

/* Telepresence Video Grid */
.video-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.video-box {
  background: #090d14;
  border: 1px solid var(--border);
  border-radius: 8px;
  position: relative;
  height: 135px;
  overflow: hidden;
}

.video-box video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-tag {
  position: absolute;
  bottom: 6px;
  left: 8px;
  background: rgba(0, 0, 0, 0.65);
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.68rem;
}

/* Camera Viewport + SVG BBox Overlay */
.camera-viewport {
  position: relative;
  width: 100%;
  height: 210px;
  background: #090d14;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.camera-viewport img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
}

.camera-viewport svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.camera-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.harvest-badges {
  display: flex;
  gap: 8px;
}

.badge {
  padding: 4px 8px;
  border-radius: 5px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-emerald {
  background: var(--emerald-dim);
  color: var(--emerald);
}

.badge-amber {
  background: rgba(245, 158, 11, 0.16);
  color: var(--amber);
}

/* Suit Table & Move Log */
.suit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.76rem;
}

.suit-table th,
.suit-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.suit-table th {
  color: var(--text-muted);
}

.move-log {
  max-height: 120px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.76rem;
}

.move-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card-alt);
  padding: 5px 8px;
  border-radius: 5px;
}

/* Buttons */
.action-buttons,
.tab-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid var(--border);
  background: var(--bg-card-alt);
  color: var(--text-main);
  padding: 6px 11px;
  border-radius: 6px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.12);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--emerald);
  border-color: var(--emerald);
  color: #042f2e;
}

.btn-secondary {
  background: var(--cyan);
  border-color: var(--cyan);
  color: #042f2e;
}

.btn-warn {
  background: var(--amber);
  border-color: var(--amber);
  color: #271701;
}

.btn-sm {
  padding: 4px 8px;
  font-size: 0.7rem;
}

.btn.active {
  border-color: var(--cyan);
  color: var(--cyan);
}

.btn-link {
  background: none;
  border: none;
  color: var(--cyan);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  width: 400px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal.modal-wide {
  width: 500px;
}

.modal-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.modal p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row label {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-weight: 600;
}

.form-row input[type="number"],
.form-row input[type="text"] {
  background: var(--bg-card-alt);
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.88rem;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.label-with-action {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pip-summary-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.pip-stat {
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pip-stat .label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.pip-stat strong {
  font-size: 1.05rem;
  color: var(--cyan);
}

.camera-score-box {
  background: rgba(6, 182, 212, 0.08);
  border: 1px dashed rgba(6, 182, 212, 0.45);
  border-radius: 8px;
  padding: 10px 12px;
}

.camera-score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.camera-score-row strong {
  font-size: 0.8rem;
  color: #67e8f9;
}

.winner-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr 0.75fr;
  gap: 8px;
}

.winner-btn {
  text-align: center;
  padding: 8px 10px;
}

.winner-btn.active[data-winner="US"] {
  background: var(--emerald-dim);
  border-color: var(--emerald);
  color: #6ee7b7;
}

.winner-btn.active[data-winner="THEM"] {
  background: rgba(245, 158, 11, 0.18);
  border-color: var(--amber);
  color: #fde68a;
}

.winner-btn.active[data-winner="TIE"] {
  background: rgba(99, 102, 241, 0.22);
  border-color: var(--indigo);
  color: #c7d2fe;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
