/* ===== Reset & Base ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  color: #fff8e7;
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 176, 74, 0.14), transparent 42%),
    radial-gradient(circle at 82% 82%, rgba(220, 50, 60, 0.12), transparent 45%),
    linear-gradient(145deg, #240709 0%, #4d1316 52%, #2c0a0c 100%);
  min-height: 100vh;
  padding: 16px;
  overflow-x: hidden;
}

/* ===== App Layout ===== */
#app {
  max-width: 1300px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-areas:
    "lanterns sidebar"
    "board sidebar"
    "controls sidebar";
  gap: 16px;
}
#board { grid-area: board; }
#controls { grid-area: controls; }
#sidebar { grid-area: sidebar; }

/* ===== Lantern Row (改版 A) ===== */
.lantern-row {
  grid-area: lanterns;
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  width: 100%;
  max-width: 720px;
  margin: 0 auto -8px;
  height: 56px;
  padding: 0 24px;
  pointer-events: none;
  position: relative;
  z-index: 2;
}
.lantern {
  position: relative;
  width: 32px;
  height: 40px;
  border-radius: 50% / 45%;
  background:
    radial-gradient(circle at 35% 30%, #ff6a5a 0%, #d92020 55%, #7a0b0b 100%);
  border: 1.5px solid #3a0404;
  box-shadow:
    0 0 12px #ffb04a,
    inset 0 -4px 6px rgba(0, 0, 0, 0.45),
    inset 0 3px 4px rgba(255, 220, 160, 0.3);
  transform-origin: 50% -10px;
  animation: sway 2.4s ease-in-out infinite;
}
.lantern::before {
  /* 頂部金色繫繩 */
  content: "";
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 10px;
  background: linear-gradient(to bottom, #ffd166, #b8860b);
}
.lantern::after {
  /* 下方金色垂穗 */
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 12px;
  background: linear-gradient(to bottom, #ffd166 0%, #ffb04a 55%, #8a5a10 100%);
  border-radius: 1px 1px 2px 2px;
  box-shadow: 0 0 4px rgba(255, 180, 90, 0.6);
}
.lantern:nth-child(1) { animation-delay: 0s; }
.lantern:nth-child(2) { animation-delay: -0.3s; }
.lantern:nth-child(3) { animation-delay: -0.6s; }
.lantern:nth-child(4) { animation-delay: -0.9s; }
.lantern:nth-child(5) { animation-delay: -1.2s; }
.lantern:nth-child(6) { animation-delay: -1.5s; }
@keyframes sway {
  0%, 100% { transform: rotate(-4deg); }
  50%      { transform: rotate(4deg); }
}

footer {
  text-align: center;
  padding: 16px;
  color: #ffd166aa;
  font-size: 13px;
}

/* ===== Board ===== */
#board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 720px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 4px;
  padding: 10px;
  background: linear-gradient(145deg, #240809, #4a1214);
  border: 2px solid rgba(255, 209, 102, 0.72);
  border-radius: 14px;
  box-shadow:
    0 14px 36px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 209, 102, 0.16),
    inset 0 0 24px rgba(0, 0, 0, 0.45);
}

/* ===== Tile ===== */
.tile {
  position: relative;
  background: linear-gradient(180deg, #fffdf7 0%, #f6ead0 100%);
  color: #3a1a0a;
  border: 1px solid rgba(138, 58, 26, 0.55);
  border-radius: 6px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  cursor: default;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
  transition: transform 150ms ease, box-shadow 150ms ease;
}
.tile:hover {
  transform: scale(1.04);
  z-index: 5;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
.tile-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 2px;
  font-size: 11px;
  line-height: 1.2;
}
.tile .emoji { font-size: 20px; }
.tile .name { font-weight: 700; font-size: 11px; color: #3a1a0a; }
.tile .price { font-size: 10px; color: #a04010; font-weight: 600; }
.tile .owner-badge {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
}

/* Corner tiles */
.tile.corner {
  background: linear-gradient(135deg, #ffe08a 0%, #f59e42 100%);
  border: 1.5px solid rgba(138, 58, 26, 0.72);
  box-shadow: inset 0 1px 0 rgba(255, 250, 224, 0.7);
}
.tile.corner .emoji { font-size: 28px; }
.tile.corner .name { font-size: 12px; font-weight: 800; }

/* Owned tiles – colored top bar */
.tile.owned-0 { box-shadow: inset 0 6px 0 #e63946; }
.tile.owned-1 { box-shadow: inset 0 6px 0 #3b82f6; }
.tile.owned-2 { box-shadow: inset 0 6px 0 #10b981; }
.tile.owned-3 { box-shadow: inset 0 6px 0 #f59e0b; }

/* ===== Board Center ===== */
.board-center {
  grid-area: 2 / 2 / 6 / 6;
  background:
    radial-gradient(circle at 50% 25%, rgba(255, 196, 102, 0.16), transparent 62%),
    linear-gradient(160deg, #3c0a0c, #6e161a);
  border: 1.5px solid rgba(255, 209, 102, 0.48);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
  padding: 16px;
  color: #ffe9b0;
  text-align: center;
  gap: 8px;
  box-shadow:
    inset 0 0 32px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 224, 150, 0.18);
}
.board-center h1 {
  font-size: clamp(16px, 2.2vw, 26px);
  color: #fffaf0;
  font-weight: 800;
  letter-spacing: 2px;
  line-height: 1.3;
  text-shadow:
    0 0 2px #fffaf0,
    0 0 8px #ffd166,
    0 0 18px #ff8a3d,
    0 0 32px rgba(255, 68, 88, 0.85);
  animation: neon-flicker 3s infinite;
}
@keyframes neon-flicker {
  0%, 18%, 22%, 44%, 48%, 70%, 72%, 100% { opacity: 1; }
  20%, 46%  { opacity: 0.7; }
  21%, 47%  { opacity: 0.85; }
  71%       { opacity: 0.75; }
}

/* Dice */
#dice-display {
  display: flex;
  justify-content: center;
}
.dice {
  width: clamp(60px, 10vw, 100px);
  height: clamp(60px, 10vw, 100px);
  background: linear-gradient(135deg, #fff, #f5e7c4);
  color: #3a1a0a;
  border: 3px solid #8a3a1a;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(32px, 5vw, 52px);
  font-weight: 800;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}
.dice.rolling { animation: dice-shake 0.5s ease-in-out; }
@keyframes dice-shake {
  0%, 100% { transform: rotate(0deg) scale(1); }
  20% { transform: rotate(-20deg) scale(1.1); }
  40% { transform: rotate(18deg) scale(0.95); }
  60% { transform: rotate(-14deg) scale(1.08); }
  80% { transform: rotate(10deg) scale(0.98); }
}

#game-status {
  font-size: clamp(13px, 1.5vw, 16px);
  font-weight: 600;
  color: #ffe9b0;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 6px;
}

#current-tile-info {
  font-size: 13px;
  color: #fff8e7;
  background: rgba(0, 0, 0, 0.35);
  padding: 8px 10px;
  border-radius: 6px;
  width: 100%;
  min-height: 48px;
  border: 1px solid rgba(255, 209, 102, 0.3);
}
#current-tile-info .info-name { font-weight: 700; color: #ffd166; font-size: 14px; }
#current-tile-info .info-detail { margin-top: 4px; opacity: 0.9; }

/* ===== Tokens (player pieces on tile) ===== */
.token {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  bottom: 2px;
  transition: all 180ms ease;
  z-index: 3;
}
.token.player-0 { background: radial-gradient(circle at 30% 30%, #ff6a7a, #e63946); }
.token.player-1 { background: radial-gradient(circle at 30% 30%, #60a5fa, #3b82f6); }
.token.player-2 { background: radial-gradient(circle at 30% 30%, #34d399, #10b981); }
.token.player-3 { background: radial-gradient(circle at 30% 30%, #fbbf24, #f59e0b); }

/* ===== Controls ===== */
#controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding: 8px;
}
#controls button {
  --btn-border: #9a4a12;
  --btn-shadow: #6e3109;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  padding: 10px 18px;
  border: 1.5px solid var(--btn-border);
  border-radius: 10px;
  cursor: pointer;
  color: #3a1608;
  background: linear-gradient(135deg, #ffe082, #f59e3d);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 3px 0 var(--btn-shadow),
    0 6px 14px rgba(0, 0, 0, 0.35);
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}
#controls button:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.05);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 5px 0 var(--btn-shadow),
    0 10px 18px rgba(0, 0, 0, 0.42);
}
#controls button:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 2px 0 var(--btn-shadow),
    0 3px 8px rgba(0, 0, 0, 0.3);
}
#controls button:disabled {
  background: linear-gradient(135deg, #5c4747, #443333);
  color: rgba(255, 240, 224, 0.5);
  border-color: #362626;
  box-shadow: 0 2px 0 #261919;
  cursor: not-allowed;
  opacity: 0.75;
}
#buy-btn {
  --btn-border: #0a5c42;
  --btn-shadow: #06402d;
  background: linear-gradient(135deg, #6ee7b7, #0f9b6e);
  color: #042f24;
}
#end-turn-btn {
  --btn-border: #1e468a;
  --btn-shadow: #142f5e;
  background: linear-gradient(135deg, #93c5fd, #3b76d6);
  color: #091938;
}
#restart-btn {
  --btn-border: #7f1d1d;
  --btn-shadow: #571010;
  background: linear-gradient(135deg, #ef5350, #b91c1c);
  color: #fff8f0;
}

/* ===== Sidebar ===== */
#sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
#players-panel {
  background: rgba(34, 9, 12, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff6e5;
  border: 1.5px solid rgba(255, 209, 102, 0.34);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 224, 150, 0.14);
}
.player-card {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  background: rgba(255, 248, 231, 0.06);
  border: 1.5px solid rgba(255, 209, 102, 0.12);
  border-radius: 8px;
  transition: all 200ms ease;
}
.player-card .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  border: 2px solid rgba(255, 248, 231, 0.85);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.player-card[data-player="0"] .avatar { background: #e63946; }
.player-card[data-player="1"] .avatar { background: #3b82f6; }
.player-card[data-player="2"] .avatar { background: #10b981; }
.player-card[data-player="3"] .avatar { background: #f59e0b; }
.player-card .info { display: flex; flex-direction: column; gap: 2px; }
.player-card .pname { font-weight: 700; font-size: 14px; color: #fff6e5; }
.player-card .pdetail { font-size: 12px; color: #dec1a4; }
.player-card .pmoney {
  font-weight: 800;
  font-size: 15px;
  color: #6ee7b7;
}
.player-card.active {
  border-color: rgba(255, 209, 102, 0.85);
  background: linear-gradient(135deg, rgba(255, 209, 102, 0.18), rgba(255, 138, 61, 0.12));
  animation: card-pulse 1.6s ease-in-out infinite;
}
@keyframes card-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 209, 102, 0.45); }
  50% { box-shadow: 0 0 0 7px rgba(255, 209, 102, 0); }
}
.player-card.bankrupt {
  opacity: 0.42;
  filter: grayscale(0.85);
  text-decoration: line-through;
}

/* ===== Log ===== */
#log-section {
  background: rgba(34, 9, 12, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #f7ead6;
  border: 1.5px solid rgba(255, 209, 102, 0.34);
  border-radius: 12px;
  padding: 12px;
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 224, 150, 0.14);
}
#log-section h3 {
  font-size: 14px;
  color: #ffd166;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px dashed rgba(255, 209, 102, 0.3);
}
#message-log {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column-reverse;
  gap: 5px;
  font-size: 13px;
}
#message-log .log-item {
  padding: 5px 8px;
  border-left: 3px solid rgba(255, 209, 102, 0.65);
  background: rgba(255, 248, 231, 0.06);
  border-radius: 4px;
  animation: log-in 0.3s ease;
}
#message-log .log-item:nth-child(even) { background: rgba(255, 209, 102, 0.1); }
@keyframes log-in {
  from { opacity: 0; transform: translateX(-6px); }
  to { opacity: 1; transform: translateX(0); }
}
#message-log::-webkit-scrollbar { width: 6px; }
#message-log::-webkit-scrollbar-thumb { background: rgba(255, 209, 102, 0.45); border-radius: 3px; }
#message-log::-webkit-scrollbar-track { background: rgba(255, 248, 231, 0.06); }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "lanterns"
      "board"
      "controls"
      "sidebar";
  }
  #board { max-width: 100%; }
  #sidebar { max-width: 100%; }
  .lantern-row {
    height: 44px;
    padding: 0 16px;
  }
  .lantern {
    width: 26px;
    height: 32px;
  }
  .lantern::after {
    height: 10px;
  }
}
@media (max-width: 500px) {
  body { padding: 8px; }
  .tile .name { font-size: 9px; }
  .tile .price { font-size: 9px; }
  .tile .emoji { font-size: 16px; }
  .tile.corner .emoji { font-size: 20px; }
  .token { width: 16px; height: 16px; font-size: 9px; }
  #controls button { font-size: 13px; padding: 8px 12px; }
  /* 小螢幕只留 4 顆燈籠且更小 */
  .lantern-row {
    height: 36px;
    padding: 0 10px;
  }
  .lantern {
    width: 22px;
    height: 28px;
    box-shadow:
      0 0 8px #ffb04a,
      inset 0 -3px 5px rgba(0, 0, 0, 0.45),
      inset 0 2px 3px rgba(255, 220, 160, 0.3);
  }
  .lantern:nth-child(5),
  .lantern:nth-child(6) { display: none; }
}
