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

:root {
  --bg-darkest: #060610;
  --bg-dark: #0a0a1a;
  --bg-medium: #12122a;
  --bg-light: #1a1a3e;
  --wall: #0b0b1e;
  --path: #2d2845;
  --path-lit: #3d3560;
  --path-reachable: #4a3f7a;
  --accent: #c9a227;
  --accent-glow: #ffd700;
  --accent-dim: #8a7020;
  --text: #e0d8c8;
  --text-dim: #7a7a8a;
  --text-bright: #fff;
  --danger: #e74c3c;
  --success: #2ecc71;
  --tile-size: 62px;
  --arrow-size: 32px;
  --font-display: 'Cinzel', Georgia, serif;
  --font-body: 'Inter', system-ui, sans-serif;
}

@media (max-width: 600px) {
  :root { --tile-size: 46px; --arrow-size: 26px; }
}

html, body {
  height: 100%;
  background: var(--bg-darkest);
  color: var(--text);
  font-family: var(--font-body);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

body { display: flex; justify-content: center; }

#app { width: 100%; max-width: 900px; min-height: 100vh; }

.screen { display: none; padding: 20px; }
.screen.active { display: flex; flex-direction: column; align-items: center; }

.hidden { display: none !important; }

/* ── Lobby ── */

.game-title {
  font-family: var(--font-display);
  font-size: 3rem;
  color: var(--accent);
  text-shadow: 0 0 30px rgba(201, 162, 39, 0.4), 0 0 60px rgba(201, 162, 39, 0.15);
  margin-top: 60px;
  letter-spacing: 0.1em;
}

.subtitle {
  font-family: var(--font-display);
  color: var(--text-dim);
  font-size: 1rem;
  margin-top: 8px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

#menu-view, #waiting-view { margin-top: 40px; width: 100%; max-width: 360px; }

.input-group { margin-bottom: 20px; }
.input-group label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 6px; }

input[type="text"] {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-medium);
  border: 1px solid var(--bg-light);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus { border-color: var(--accent-dim); }

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #b8921f);
  color: #1a1a1a;
}
.btn-primary:hover { filter: brightness(1.15); transform: translateY(-1px); }

.btn-secondary {
  background: var(--bg-light);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
}
.btn-secondary:hover { background: #252555; }

.btn-small { padding: 8px 16px; font-size: 0.9rem; }

.btn-row { display: flex; flex-direction: column; gap: 12px; }

.join-row { display: flex; gap: 8px; }
.join-row input { width: 100px; text-align: center; text-transform: uppercase; font-weight: 600; letter-spacing: 0.15em; }
.join-row .btn { flex: 1; }

.room-code-display {
  text-align: center;
  margin-bottom: 24px;
  padding: 20px;
  background: var(--bg-medium);
  border-radius: 12px;
  border: 1px solid var(--bg-light);
}
.room-code-display .label { display: block; font-size: 0.8rem; color: var(--text-dim); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.15em; }
.room-code-display .code {
  font-family: var(--font-display);
  font-size: 2.5rem;
  color: var(--accent);
  letter-spacing: 0.3em;
  text-shadow: 0 0 20px rgba(201, 162, 39, 0.3);
}

#player-list { margin-bottom: 20px; }

.lobby-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 6px;
  background: var(--bg-medium);
  border-radius: 8px;
  border-left: 3px solid;
}
.lobby-player .dot { width: 10px; height: 10px; border-radius: 50%; }
.lobby-player .name { flex: 1; font-weight: 500; }
.lobby-player .host-badge { font-size: 0.75rem; color: var(--accent); text-transform: uppercase; letter-spacing: 0.1em; }

.dim-text { color: var(--text-dim); font-size: 0.9rem; text-align: center; }

/* ── Game ── */

#game-screen.active { align-items: stretch; }

#game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px;
  margin-bottom: 8px;
}

.turn-info { font-weight: 600; font-size: 1rem; }
.phase-info { font-size: 0.85rem; color: var(--text-dim); }

#game-layout {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
}

#board-area { flex-shrink: 0; }

#board-container {
  display: grid;
  grid-template-columns: var(--arrow-size) repeat(7, var(--tile-size)) var(--arrow-size);
  grid-template-rows: var(--arrow-size) repeat(7, var(--tile-size)) var(--arrow-size);
  gap: 2px;
  background: rgba(201, 162, 39, 0.35);
  border: 2px solid var(--bg-light);
  border-radius: 4px;
}

.edge-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-darkest);
}

#action-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

.slide-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--accent);
  font-size: 1.1rem;
  opacity: 0.8;
  transition: all 0.2s;
  border-radius: 4px;
  user-select: none;
  background: var(--bg-darkest);
}
.slide-arrow:hover { opacity: 1; background: rgba(201, 162, 39, 0.15); transform: scale(1.1); }
.slide-arrow.blocked { opacity: 0.2; cursor: not-allowed; color: var(--text-dim); }
.slide-arrow.blocked:hover { background: none; transform: none; }
.slide-arrow.inactive { opacity: 0; pointer-events: none; }

/* ── Tile ── */

.tile {
  position: relative;
  width: var(--tile-size);
  height: var(--tile-size);
  cursor: default;
}

.tile-inner {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
}

.tc { transition: background 0.2s; }
.tc.wall { background: var(--wall); }
.tc.path { background: var(--path); }

.tile.reachable .tc.path { background: var(--path-reachable); }
.tile.reachable { cursor: pointer; }
.tile.reachable::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid rgba(201, 162, 39, 0.4);
  border-radius: 2px;
  pointer-events: none;
  animation: pulse-border 1.5s ease-in-out infinite;
}

@keyframes pulse-border {
  0%, 100% { border-color: rgba(201, 162, 39, 0.2); }
  50% { border-color: rgba(201, 162, 39, 0.6); }
}

.tile-symbol {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: calc(var(--tile-size) * 0.38);
  z-index: 2;
  filter: drop-shadow(0 0 4px rgba(0,0,0,0.8));
  pointer-events: none;
  line-height: 1;
}

.tile.has-target .tile-symbol {
  animation: glow-symbol 2s ease-in-out infinite;
}

@keyframes glow-symbol {
  0%, 100% { filter: drop-shadow(0 0 4px rgba(201, 162, 39, 0.3)); }
  50% { filter: drop-shadow(0 0 12px rgba(201, 162, 39, 0.8)); }
}

.player-markers {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: flex-end;
  gap: 1px;
  z-index: 3;
  pointer-events: none;
}

.meeple-svg {
  width: calc(var(--tile-size) * 0.32);
  height: calc(var(--tile-size) * 0.42);
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.7));
  transition: all 0.2s ease;
}

.meeple-svg.meeple-self {
  width: calc(var(--tile-size) * 0.48);
  height: calc(var(--tile-size) * 0.62);
  filter: drop-shadow(0 0 8px var(--meeple-glow, rgba(201,162,39,0.6))) drop-shadow(0 1px 3px rgba(0,0,0,0.7));
}

.home-indicator {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  opacity: 0.5;
  z-index: 1;
  pointer-events: none;
}

/* ── Side Panel ── */

#side-panel {
  min-width: 200px;
  max-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#side-panel h3 {
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: var(--accent-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

#spare-section, #target-section, #progress-section, #players-section {
  background: var(--bg-medium);
  border-radius: 10px;
  padding: 14px;
  border: 1px solid var(--bg-light);
}

#spare-tile-display {
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
}

.spare-tile-vis {
  position: relative;
  width: calc(var(--tile-size) * 1.2);
  height: calc(var(--tile-size) * 1.2);
}

.spare-tile-vis .tile-inner {
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(201, 162, 39, 0.3);
}
.spare-tile-vis .tc.path { background: var(--path-lit); }
.spare-tile-vis .tile-symbol { font-size: calc(var(--tile-size) * 0.45); }

#current-target {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
}

.target-emoji { font-size: 1.6rem; }
.target-name { font-weight: 500; }
.target-home {
  color: var(--accent);
  font-weight: 600;
  font-family: var(--font-display);
}

#collected-display {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.collected-bar {
  height: 6px;
  background: var(--bg-dark);
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}
.collected-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-glow));
  border-radius: 3px;
  transition: width 0.5s ease;
}

.player-info-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 0.9rem;
}
.player-info-row .pip {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.player-info-row .pname { flex: 1; font-weight: 500; }
.player-info-row .pcount { color: var(--text-dim); font-size: 0.8rem; }
.player-info-row.is-current { color: var(--accent); }

/* ── Game Over Overlay ── */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 6, 16, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.4s ease;
}

.overlay-content {
  background: var(--bg-medium);
  border: 1px solid var(--accent-dim);
  border-radius: 16px;
  padding: 40px;
  text-align: center;
  max-width: 400px;
  width: 90%;
}

.overlay-content h2 {
  font-family: var(--font-display);
  color: var(--accent);
  font-size: 1.8rem;
  margin-bottom: 20px;
  text-shadow: 0 0 20px rgba(201, 162, 39, 0.4);
}

#winner-display {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 20px;
}
#winner-display .winner-emoji { font-size: 2rem; display: block; margin-bottom: 8px; }

#final-stats {
  margin-bottom: 24px;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.stat-row:last-child { border: none; }

/* ── Toast ── */

#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-light);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  border-left: 3px solid var(--accent);
  animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s;
  max-width: 300px;
}

.toast.error { border-left-color: var(--danger); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* ── Responsive ── */

@media (max-width: 700px) {
  #game-layout { flex-direction: column; align-items: center; }
  #side-panel { max-width: 100%; min-width: 0; width: 100%; flex-direction: row; flex-wrap: wrap; gap: 10px; }
  #spare-section, #target-section { flex: 1; min-width: 140px; }
  #progress-section, #players-section { flex: 1; min-width: 140px; }
  .game-title { font-size: 2.2rem; margin-top: 30px; }
  #game-header { padding: 4px; }
}
