* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Microsoft YaHei', 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, #a8e6cf 0%, #dcedc8 100%);
  min-height: 100vh;
  color: #333;
  /* Prevent rubber-band overscroll on mobile */
  overscroll-behavior: none;
}

#app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
}

/* ============ Setup screen ============ */
#setup-screen {
  text-align: center;
  padding: 40px 20px;
  max-width: 560px;
  margin: 0 auto;
}
#setup-screen h1 {
  font-size: 3rem;
  color: #2d6a4f;
  margin-bottom: 8px;
}
#setup-screen .subtitle {
  color: #52796f;
  margin-bottom: 30px;
}
.player-input {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0;
  padding: 10px 12px;
  background: white;
  border-radius: 8px;
  flex-wrap: wrap;
}
.player-input label { font-size: 0.9rem; }
.player-input input[type="text"] {
  padding: 6px 8px;
  border: 2px solid #b7e4c7;
  border-radius: 6px;
  font-size: 0.9rem;
  width: 120px;
}
.player-input input[type="color"] {
  width: 40px;
  height: 32px;
  border: none;
  background: none;
  cursor: pointer;
}
.player-count-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 24px 0;
}
.count-buttons { display: flex; gap: 8px; }
.count-btn {
  padding: 8px 18px;
  font-size: 1rem;
  background: white;
  border: 2px solid #b7e4c7;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.count-btn.active { background: #40916c; color: white; border-color: #40916c; }
#start-game-btn {
  margin-top: 10px;
  padding: 16px 40px;
  font-size: 1.2rem;
  background: #40916c;
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(64,145,108,0.4);
  transition: transform 0.2s;
}
#start-game-btn:hover { transform: translateY(-2px); }

/* ============ Game screen header ============ */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
  padding: 12px 20px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  margin-bottom: 16px;
}
header h1 { color: #2d6a4f; font-size: 1.6rem; }
#turn-indicator { font-size: 1.1rem; font-weight: bold; color: #40916c; }
#turn-indicator span { color: #1b4332; }
#mute-btn { font-size: 1.5rem; background: none; border: none; cursor: pointer; }

/* ============ Game layout ============ */
#game-layout {
  display: grid;
  grid-template-columns: 220px 1fr 200px;
  gap: 16px;
}

/* Player list sidebar */
#player-list {
  background: white;
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  max-height: 70vh;
  overflow-y: auto;
}
.player-card {
  padding: 10px;
  margin-bottom: 8px;
  border-radius: 8px;
  border-left: 6px solid;
  background: #f8f9fa;
  transition: background 0.2s, transform 0.2s;
}
.player-card.active {
  background: #e9f5ec;
  box-shadow: 0 0 10px rgba(45,106,79,0.3);
  transform: translateX(2px);
}
.player-card.bankrupt { opacity: 0.45; }
.player-card h3 { font-size: 0.95rem; margin-bottom: 4px; }
.player-card p { font-size: 0.8rem; margin: 2px 0; color: #555; }

/* Board container */
#board-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-height: 70vh;
  background: #b7e4c7;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  overflow: hidden;
}
#board {
  width: 100%;
  height: 100%;
  position: relative;
}
.tile {
  position: absolute;
  background: #fff;
  border: 1px solid #74c69d;
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  font-size: 0.62rem;
  text-align: center;
  padding: 2px;
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
}
.tile:hover { transform: scale(1.06); z-index: 10; box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.tile-header {
  width: 100%;
  height: 10px;
  border-radius: 2px 2px 0 0;
  flex-shrink: 0;
}
.tile-name { font-weight: bold; margin: 1px 0; line-height: 1.1; }
.tile-icon { font-size: 1.1rem; margin: 2px 0; }
.tile-price { color: #666; font-size: 0.58rem; }
.tile-houses {
  display: flex;
  gap: 1px;
  margin-top: 2px;
  min-height: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.house {
  width: 6px; height: 6px;
  background: #e76f51;
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}
.hotel {
  width: 9px; height: 9px;
  background: #e63946;
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}
.tile-owner {
  width: 100%;
  height: 3px;
  margin-top: auto;
}

/* Player pieces */
#pieces {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none;
}
.piece {
  position: absolute;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  z-index: 5;
  transition: left 0.18s ease-out, top 0.18s ease-out;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}
.piece.in-jail::after {
  content: '🔒';
  position: absolute;
  top: -8px;
  right: -8px;
  font-size: 0.8rem;
}

/* Action panel */
#action-panel {
  background: white;
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#action-panel button {
  padding: 12px;
  font-size: 1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: #40916c;
  color: white;
  box-shadow: 0 2px 6px rgba(64,145,108,0.3);
  transition: transform 0.15s, box-shadow 0.15s;
}
#action-panel button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(64,145,108,0.4);
}
#action-panel button:disabled { opacity: 0.45; cursor: not-allowed; }
#tile-info {
  font-size: 0.8rem;
  color: #555;
  background: #f8f9fa;
  padding: 8px;
  border-radius: 6px;
  min-height: 20px;
}

/* Dice */
/* Dice: floating overlay centered over the board, no layout impact */
#dice-display {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.92);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  pointer-events: none;
}
.dice {
  width: 48px;
  height: 48px;
  background: white;
  border: 3px solid #333;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
@keyframes roll {
  0% { transform: rotate(0deg) scale(1); }
  25% { transform: rotate(90deg) scale(1.1); }
  50% { transform: rotate(180deg) scale(0.9); }
  75% { transform: rotate(270deg) scale(1.1); }
  100% { transform: rotate(360deg) scale(1); }
}
.rolling .dice { animation: roll 0.6s ease-in-out; }

/* Modal */
#modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-content {
  background: white;
  padding: 28px;
  border-radius: 16px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-content h2 { color: #2d6a4f; margin-bottom: 12px; }
.modal-content p { margin: 6px 0; }
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.modal-actions button {
  flex: 1;
  min-width: 120px;
  padding: 12px;
  font-size: 1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: #40916c;
  color: white;
  transition: transform 0.15s;
}
.modal-actions button:hover { transform: translateY(-1px); }
.modal-actions button.secondary { background: #95d5b2; color: #1b4332; }
.card-display {
  background: linear-gradient(135deg, #ffd166, #ef476f);
  color: white;
  padding: 20px;
  border-radius: 12px;
  font-size: 1.1rem;
  text-align: center;
  margin: 15px 0;
  font-weight: bold;
}

/* Shop items */
.shop-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  margin: 5px 0;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.shop-item:hover { background: #f0f7f2; border-color: #40916c; }
.shop-item.disabled { opacity: 0.5; cursor: default; }
.shop-item.disabled:hover { background: white; border-color: #e0e0e0; }
.shop-item-right { text-align: right; }
.shop-item-right button {
  margin-top: 4px;
  padding: 6px 12px;
  background: #40916c;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.shop-item-right button:disabled { background: #ccc; cursor: not-allowed; }

/* Message log */
#message-log {
  background: white;
  border-radius: 12px;
  padding: 12px;
  margin-top: 16px;
  height: 140px;
  overflow-y: auto;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  font-size: 0.88rem;
}
.message { padding: 3px 0; border-bottom: 1px dashed #e0e0e0; }
.message:last-child { border-bottom: none; }

/* ============ Mobile tab bar + drawer (hidden on desktop) ============ */
#tab-bar, #tab-drawer { display: none; }
.tab-btn {
  flex: 1;
  min-height: 44px;
  padding: 8px 4px;
  background: #d8f3dc;
  border: none;
  border-top: 2px solid transparent;
  font-size: 0.8rem;
  cursor: pointer;
  color: #2d6a4f;
}
.tab-btn.active { border-top-color: #40916c; background: #b7e4c7; font-weight: bold; }
.tab-panel { padding: 10px; }
.tile-info-card { background: #f8f9fa; border-radius: 8px; padding: 12px; }
.tile-info-card h3 { color: #2d6a4f; margin-bottom: 6px; font-size: 1rem; }
.tile-info-card p { font-size: 0.85rem; margin: 3px 0; color: #555; }

/* Disable hover-scale on touch devices to avoid sticky tap highlight */
@media (hover: none) {
  .tile:hover { transform: none; box-shadow: none; }
  .shop-item:hover { background: white; border-color: #e0e0e0; }
}

/* ============ Responsive ============ */
@media (max-width: 900px) {
  #game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }
  #player-list { max-height: none; }
  #board-container { max-height: 60vh; }
}

/* ============ Mobile (<=768px): board-first, bottom tab bar ============ */
@media (max-width: 768px) {
  #app { padding: 6px; max-width: 100%; }
  #game-screen {
    display: flex !important;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    gap: 6px;
  }

  /* Compact header */
  header { padding: 8px 10px; flex-wrap: wrap; gap: 4px; }
  header h1 { font-size: 1.1rem; }
  #turn-indicator { font-size: 0.85rem; flex: 1; text-align: center; }
  #mute-btn { font-size: 1.3rem; padding: 6px 10px; min-width: 40px; min-height: 40px; }

  /* Hide desktop 3-column layout; board takes the main area */
  #game-layout {
    display: block;
    flex: 1;
    min-height: 0;
    position: relative;
  }
  /* On mobile the action-panel becomes a fixed bottom action bar */
  #action-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.15);
    background: white;
  }
  #action-panel button {
    flex: 1 1 30%;
    min-height: 44px;
    font-size: 0.85rem;
    padding: 8px 4px;
  }
  /* dice display floats as overlay (sized down on mobile) */
  #dice-display .dice { width: 40px; height: 40px; font-size: 1.4rem; margin: 0 4px; }
  /* hide the verbose tile-info on mobile (shown in drawer instead) */
  #tile-info { display: none; }

  /* Board: square, fills available space above the action bar */
  #board-container {
    aspect-ratio: 1;
    max-height: none;
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
    flex: 1;
    min-height: 0;
    /* leave room for the fixed action-panel + tab-bar (~96px) */
    margin-bottom: 96px;
  }

  /* Tile sizing: smaller fonts to fit 360px width */
  .tile { font-size: 0.46rem; border-width: 1px; padding: 1px; }
  .tile-header { height: 7px; }
  .tile-name { line-height: 1; margin: 0; }
  .tile-icon { font-size: 0.85rem; margin: 1px 0; }
  .tile-price { font-size: 0.4rem; }
  .house { width: 4px; height: 4px; }
  .hotel { width: 6px; height: 6px; }
  .tile-owner { height: 2px; }

  /* Pieces: scale with screen, avoid overlap on small tiles */
  .piece {
    width: clamp(14px, 6%, 24px);
    height: clamp(14px, 6%, 24px);
    border-width: 2px;
    font-size: 0.7rem;
  }

  /* Tab bar above the action panel */
  #tab-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 51;
    background: white;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.12);
  }
  /* When tab-bar is visible, lift the action panel above it */
  #action-panel { bottom: 44px; }

  /* Slide-up drawer */
  #tab-drawer {
    display: block;
    position: fixed;
    bottom: 88px; /* above tab-bar(44) + action-panel(44) */
    left: 0;
    right: 0;
    z-index: 52;
    background: white;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.2);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
  }
  #tab-drawer.open { max-height: 45vh; overflow-y: auto; }
  /* Inside the drawer, player list & message log fill the space */
  #tab-drawer #player-list {
    max-height: none;
    box-shadow: none;
    background: none;
    padding: 4px;
  }
  #tab-drawer #message-log {
    height: auto;
    max-height: 40vh;
    box-shadow: none;
    background: none;
    padding: 4px;
  }

  /* Modal: full-width, smaller padding */
  #modal { padding: 8px; }
  .modal-content { padding: 16px; max-width: 100%; border-radius: 12px; }
  .modal-content h2 { font-size: 1.1rem; }
  .modal-actions { gap: 8px; }
  .modal-actions button { min-width: 0; padding: 10px 8px; font-size: 0.9rem; }

  /* Setup screen: compact */
  #setup-screen { padding: 20px 10px; }
  #setup-screen h1 { font-size: 2rem; margin-bottom: 6px; }
  #setup-screen .subtitle { font-size: 0.85rem; margin-bottom: 16px; }
  .player-input { padding: 6px 8px; gap: 6px; }
  .player-input input[type="text"] { width: 90px; font-size: 0.85rem; }
  .player-input input[type="color"] { width: 34px; height: 28px; }
  .count-btn { padding: 6px 14px; font-size: 0.9rem; }
  #start-game-btn { padding: 12px 28px; font-size: 1rem; }

  /* Shop items: tighter on mobile */
  .shop-item { padding: 8px; font-size: 0.85rem; }
  .shop-item-right button { padding: 6px 10px; font-size: 0.85rem; }
}

