:root {
  /* Gold Premium Design Tokens */
  --bg-base: #000000;
  --bg-table: #0A0907;
  --bg-table-spot: #1A150B;
  --surface-1: #121009;
  --surface-2: #1B170C;
  --gold-100: #FFF0A0;
  --gold-300: #F7D774;
  --gold-500: #F5C518;
  --gold-600: #D4A017;
  --gold-700: #B8860B;
  --gold-900: #5E4307;
  --text-primary: #F3E9C6;
  --text-secondary: #B5A77A;
  --text-muted: #7C714F;
  --tile-body: #0B0B0B;
  --tile-body-highlight: #1A1A1A;
  --tile-pip: #F5C518;
  --state-danger: #C2554A;
  --state-success: #C9B458;

  /* Theme mappings */
  --color-felt: #0A0907;
  --color-felt-deep: #000000;
  --color-felt-border: #5E4307;
  --color-ivory: #0B0B0B;
  --color-ivory-edge: #D4A017;
  --color-ivory-shadow: #000000;
  --color-pip: #F5C518;
  --color-brass: #F5C518;
  --color-brass-glow: rgba(245, 197, 24, 0.4);
  --color-playable: #F5C518;
  --color-text-light: #F3E9C6;
  --color-text-muted: #B5A77A;
  --color-error: #C2554A;
  --color-success: #C9B458;
  --font-main: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Bodoni Moda', 'Didot', 'Georgia', serif;
}

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

body {
  font-family: var(--font-main);
  background-color: var(--color-felt-deep);
  color: var(--color-text-light);
  height: 100vh;
  overflow: hidden;
}

#game-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
.game-header {
  background: rgba(13, 36, 32, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-felt-border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
}

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

.brand-link {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--color-brass);
}

.brand-badge {
  background: var(--color-brass);
  color: #171A19;
  font-weight: 700;
  font-size: 13px;
  padding: 3px 7px;
  border-radius: 6px;
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.badge-pill {
  font-size: 12px;
  background: rgba(255, 255, 255, 0.08);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--color-text-light);
}

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

.player-card {
  display: flex;
  flex-direction: column;
  min-width: 100px;
}

.player-card.me {
  text-align: right;
}

.player-role {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--color-brass);
}

.player-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.player-score {
  font-size: 14px;
  color: var(--color-text-muted);
}

.match-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.target-pill, .round-pill {
  font-size: 11px;
  background: rgba(210, 169, 74, 0.15);
  color: var(--color-brass);
  padding: 2px 8px;
  border-radius: 12px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--color-felt-border);
  color: var(--color-text-light);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--color-brass);
}

/* Playing Table */
.table-felt {
  flex: 1;
  background: radial-gradient(circle at center, #1b443c 0%, #12302a 70%, #0d2420 100%);
  display: flex;
  flex-direction: column;
  padding: 12px;
  overflow: hidden;
  position: relative;
}

.table-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: rgba(13, 36, 32, 0.4);
  border-radius: 10px;
  margin-bottom: 8px;
}

.boneyard-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.3);
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.boneyard-label {
  font-size: 11px;
  color: var(--color-text-muted);
  letter-spacing: 0.5px;
}

.boneyard-val {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-brass);
}

.turn-banner {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-brass);
  text-align: center;
  padding: 4px 16px;
  background: rgba(210, 169, 74, 0.1);
  border-radius: 20px;
  border: 1px solid rgba(210, 169, 74, 0.2);
  animation: pulseGlow 2.5s infinite;
}

@keyframes pulseGlow {
  0%, 100% { border-color: rgba(210, 169, 74, 0.2); }
  50% { border-color: rgba(210, 169, 74, 0.6); box-shadow: 0 0 12px rgba(210, 169, 74, 0.2); }
}

.opp-tiles-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.opp-tiles-label {
  font-size: 11px;
  color: var(--color-text-muted);
}

.mini-rack {
  display: flex;
  gap: 3px;
}

.mini-tile-back {
  width: 14px;
  height: 24px;
  background: #2C5E55;
  border: 1px solid #1F4A43;
  border-radius: 3px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Board Container */
.board-container {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.08);
  padding: 20px;
}

.empty-board-prompt {
  text-align: center;
  color: var(--color-text-muted);
}

.empty-icon {
  font-size: 42px;
  margin-bottom: 8px;
  opacity: 0.6;
}

.board-chain {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 100%;
  justify-content: center;
}

/* Domino Tile Style */
.domino-tile {
  width: 44px;
  height: 84px;
  background-color: var(--color-ivory);
  border: 1px solid var(--color-ivory-edge);
  border-radius: 6px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  display: flex;
  flex-direction: column;
  position: relative;
  cursor: default;
  transition: transform 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28), box-shadow 0.2s;
  flex-shrink: 0;
}

.domino-tile.crosswise {
  width: 84px;
  height: 44px;
  flex-direction: row;
}

.domino-tile.small {
  width: 32px;
  height: 60px;
}

.domino-tile.small.crosswise {
  width: 60px;
  height: 32px;
}

.tile-half {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile-divider {
  background-color: var(--color-ivory-edge);
  position: absolute;
  z-index: 2;
}

.domino-tile:not(.crosswise) .tile-divider {
  width: calc(100% - 6px);
  height: 1.5px;
  top: 50%;
  left: 3px;
  transform: translateY(-50%);
}

.domino-tile.crosswise .tile-divider {
  height: calc(100% - 6px);
  width: 1.5px;
  left: 50%;
  top: 3px;
  transform: translateX(-50%);
}

/* Brass Spinner pin */
.spinner-pin {
  width: 4px;
  height: 4px;
  background: var(--color-brass);
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* Playable highlight */
.domino-tile.playable {
  cursor: pointer;
  border-color: var(--color-playable);
  box-shadow: 0 0 14px var(--color-brass-glow), 0 4px 8px rgba(0,0,0,0.4);
}

.domino-tile.playable:hover {
  transform: translateY(-8px) scale(1.05);
}

/* Pip geometry */
.pip {
  position: absolute;
  width: 6.5px;
  height: 6.5px;
  background-color: var(--color-pip);
  border-radius: 50%;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.7);
  transform: translate(-50%, -50%);
}

.domino-tile.small .pip {
  width: 5px;
  height: 5px;
}

/* Controls */
.controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  gap: 12px;
}

.btn-action {
  background: rgba(210, 169, 74, 0.15);
  border: 1px solid var(--color-brass);
  color: var(--color-brass);
  padding: 8px 16px;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-action:hover:not(:disabled) {
  background: var(--color-brass);
  color: #171A19;
}

.btn-action:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--color-text-muted);
}

.quick-reactions {
  display: flex;
  gap: 6px;
}

.btn-reaction {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  font-size: 15px;
  padding: 4px 8px;
  cursor: pointer;
  transition: transform 0.15s;
}

.btn-reaction:hover {
  transform: scale(1.2);
}

/* Hand Rack */
.hand-rack-wrapper {
  background: rgba(13, 36, 32, 0.85);
  border-radius: 12px;
  border: 1px solid var(--color-felt-border);
  padding: 10px 16px;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
}

.rack-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

.hand-hint {
  color: var(--color-brass);
  font-weight: 500;
}

.player-hand {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 6px 2px 10px 2px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

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

.modal-card {
  background: var(--color-felt-deep);
  border: 2px solid var(--color-brass);
  border-radius: 16px;
  padding: 28px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  text-align: center;
}

.modal-card.mini {
  max-width: 340px;
}

.modal-logo {
  font-size: 36px;
  margin-bottom: 8px;
}

.modal-card h2 {
  font-size: 24px;
  color: var(--color-brass);
  margin-bottom: 8px;
}

.modal-desc {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-bottom: 20px;
  line-height: 1.4;
}

.form-group {
  text-align: left;
  margin-bottom: 16px;
}

.form-group label {
  font-size: 12px;
  color: var(--color-text-muted);
  display: block;
  margin-bottom: 6px;
}

.form-group input, .room-input-row input {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--color-felt-border);
  color: var(--color-text-light);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  outline: none;
}

.form-group input:focus, .room-input-row input:focus {
  border-color: var(--color-brass);
}

.modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.room-input-row {
  display: flex;
  gap: 8px;
}

.divider-text {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 11px;
  margin: 4px 0;
}

.divider-text::before, .divider-text::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.divider-text span {
  padding: 0 10px;
}

.btn-primary {
  background: var(--color-brass);
  color: #171A19;
  border: none;
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}

.btn-primary:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-text-light);
  border: 1px solid var(--color-felt-border);
  font-family: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
}

.btn-outline {
  background: transparent;
  color: var(--color-brass);
  border: 1px solid var(--color-brass);
  font-family: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
}

.btn-text {
  background: transparent;
  color: var(--color-text-muted);
  border: none;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  margin-top: 10px;
}

.end-choice-buttons {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.end-choice-buttons button {
  flex: 1;
}

.result-scores {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  padding: 12px;
  margin: 16px 0;
}

.score-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  padding: 4px 0;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 120px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 90;
  pointer-events: none;
}

.toast {
  background: rgba(13, 36, 32, 0.95);
  border: 1px solid var(--color-brass);
  color: var(--color-text-light);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@media (max-width: 600px) {
  .scoreboard {
    gap: 8px;
  }
  .player-name {
    max-width: 80px;
    font-size: 13px;
  }
  .domino-tile {
    width: 38px;
    height: 74px;
  }
}

/* Spectator Portal Additions */
.spectator-top-notice {
  background: #0B1C19;
  border-bottom: 1px solid rgba(210, 169, 74, 0.3);
  padding: 6px 16px;
  font-size: 13px;
}

.notice-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.notice-badge {
  background: rgba(210, 169, 74, 0.2);
  color: var(--color-brass);
  border: 1px solid var(--color-brass);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 4px;
}

.notice-text {
  color: var(--color-text-light);
}

.notice-apk-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--color-brass);
  color: #0D2420;
  padding: 4px 10px;
  border-radius: 6px;
  font-weight: 600;
  text-decoration: none;
  font-size: 12px;
  transition: opacity 0.2s;
}

.notice-apk-btn:hover {
  opacity: 0.9;
}

.spectator-live-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(229, 83, 75, 0.15);
  border: 1px solid var(--color-error);
  color: #FFA49E;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background: var(--color-error);
  border-radius: 50%;
  animation: pulseLive 1.5s infinite;
}

@keyframes pulseLive {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.8; }
}

.spectator-bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(13, 36, 32, 0.95);
  border-top: 1px solid var(--color-felt-border);
  padding: 10px 20px;
  font-size: 13px;
}

.spectator-hint {
  color: var(--color-text-muted);
}

.btn-cta-small {
  background: var(--color-brass);
  color: #0D2420;
  padding: 6px 14px;
  border-radius: 6px;
  font-weight: 600;
  text-decoration: none;
  font-size: 13px;
}

/* Turn Timer Box */
.turn-timer-box {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--color-felt-border);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
}

.turn-timer-box .timer-label {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 10px;
}

.turn-timer-box .timer-val {
  color: var(--color-brass);
  font-weight: 700;
  font-size: 13px;
}

.turn-timer-box.urgent {
  border-color: var(--color-error);
  background: rgba(229, 83, 75, 0.2);
}

.turn-timer-box.urgent .timer-val {
  color: var(--color-error);
  animation: pulseLive 0.8s infinite;
}

.player-card.active-turn {
  border-color: var(--color-playable);
  box-shadow: 0 0 12px rgba(240, 199, 94, 0.4);
}

.player-tiles-sub {
  font-size: 11px;
  color: var(--color-text-muted);
}

/* Lobby Modal Wide */
.modal-card.wide {
  max-width: 620px;
  width: 90%;
}

.modal-header-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.app-exclusive-card {
  background: linear-gradient(135deg, rgba(210, 169, 74, 0.15), rgba(13, 36, 32, 0.4));
  border: 1px solid var(--color-brass);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

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

.exclusive-icon {
  width: 28px;
  height: 28px;
  color: var(--color-brass);
  flex-shrink: 0;
}

.exclusive-left strong {
  display: block;
  font-size: 14px;
  color: var(--color-brass);
}

.exclusive-left p {
  font-size: 12px;
  color: var(--color-text-light);
  margin-top: 2px;
}

.btn-primary-action {
  background: var(--color-brass);
  color: #0D2420;
  padding: 8px 14px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}

.room-search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.room-search-bar input {
  flex: 1;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--color-felt-border);
  color: var(--color-text-light);
  padding: 10px 14px;
  border-radius: 8px;
  font-family: inherit;
}

.btn-icon-sub {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--color-felt-border);
  color: var(--color-text-light);
  width: 42px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rooms-loading {
  text-align: center;
  padding: 20px;
  color: var(--color-text-muted);
}

.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  max-height: 260px;
  overflow-y: auto;
}

.room-card {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--color-felt-border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.room-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.room-code-tag {
  font-weight: 700;
  color: var(--color-brass);
  font-size: 14px;
}

.room-status-badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
}

.status-in_progress {
  color: #43A047;
  background: rgba(67, 160, 71, 0.15);
}

.status-waiting {
  color: var(--color-brass);
  background: rgba(210, 169, 74, 0.15);
}

.room-players {
  font-size: 13px;
}

.room-p-line {
  display: flex;
  justify-content: space-between;
}

.vs-line {
  text-align: center;
  font-size: 11px;
  color: var(--color-text-muted);
  margin: 2px 0;
}

.btn-spectate-action {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--color-felt-border);
  color: var(--color-text-light);
  padding: 6px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-spectate-action:hover {
  background: var(--color-brass);
  color: #0D2420;
}

.empty-rooms-box {
  grid-column: 1 / -1;
  text-align: center;
  padding: 30px;
  color: var(--color-text-muted);
}

.empty-rooms-box .subtext {
  font-size: 12px;
  display: block;
  margin-top: 6px;
}
