/* Mahjong Online — Styles */

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

:root {
  --felt: #1a6b3c;
  --felt-dark: #145a30;
  --tile-bg: #f5f0e1;
  --tile-border: #c4b998;
  --tile-shadow: rgba(0,0,0,0.3);
  --tile-hover: #fff8e7;
  --tile-selected: #ffe066;
  --text-light: #e8e0d0;
  --text-dark: #2a2a2a;
  --accent: #e74c3c;
  --accent-green: #27ae60;
  --accent-blue: #3498db;
  --btn-primary: #e74c3c;
  --btn-secondary: #34495e;
  --overlay-bg: rgba(0,0,0,0.7);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #0d0d0d;
  color: var(--text-light);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

.screen { display: none; width: 100%; height: 100%; }
.screen.active { display: flex; }

/* ===== LOBBY ===== */
#lobby {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}

.lobby-container {
  text-align: center;
  max-width: 400px;
  width: 90%;
}

.lobby-container h1 {
  font-size: 3rem;
  margin-bottom: 0.25rem;
  text-shadow: 0 2px 10px rgba(231,76,60,0.3);
}

.subtitle {
  color: #888;
  margin-bottom: 2rem;
  font-size: 1.1rem;
}

.lobby-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.lobby-form input, .lobby-form select {
  padding: 0.75rem 1rem;
  border: 1px solid #333;
  border-radius: 8px;
  background: #1a1a2e;
  color: var(--text-light);
  font-size: 1rem;
}

.settings-row {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.settings-row label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #aaa;
}

.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn:hover { transform: translateY(-1px); filter: brightness(1.1); }
.btn:active { transform: translateY(0); }

.btn-primary { background: var(--btn-primary); color: white; }
.btn-secondary { background: var(--btn-secondary); color: white; }

.divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: #555;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #333;
}

.join-row {
  display: flex;
  gap: 0.5rem;
}
.join-row input { flex: 1; }

/* ===== GAME TABLE ===== */
.game-table {
  width: 100%;
  height: 100%;
  background: var(--felt);
  background-image:
    radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
  position: relative;
  display: grid;
  grid-template-areas:
    ". top ."
    "left center right"
    ". bottom .";
  grid-template-columns: 120px 1fr 120px;
  grid-template-rows: 140px 1fr 180px;
}

/* Player areas */
.player-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px;
  position: relative;
}

.player-top { grid-area: top; }
.player-left { grid-area: left; }
.player-right { grid-area: right; }
.player-bottom { grid-area: bottom; }

.player-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-light);
  opacity: 0.8;
}

.player-info .player-name {
  font-weight: 600;
  background: rgba(0,0,0,0.3);
  padding: 2px 10px;
  border-radius: 12px;
}

.player-area.active-turn .player-name {
  background: var(--accent);
  color: white;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231,76,60,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(231,76,60,0); }
}

/* Hands */
.hand {
  display: flex;
  gap: 2px;
  justify-content: center;
  flex-wrap: nowrap;
}

.hand-top, .hand-left .hand, .hand-right .hand {
  gap: 1px;
}

/* Tiles */
.tile {
  width: 42px;
  height: 58px;
  background: var(--tile-bg);
  border: 1px solid var(--tile-border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  cursor: default;
  box-shadow: 0 2px 4px var(--tile-shadow);
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  user-select: none;
}

.tile-back {
  background: linear-gradient(135deg, #2c6e49 0%, #1a5c35 100%);
  border-color: #1a5c35;
}

.tile-back::after {
  content: '🀫';
  font-size: 1.4rem;
  opacity: 0.5;
}

/* Player's clickable tiles */
.hand-bottom .tile:not(.tile-back) {
  cursor: pointer;
}

.hand-bottom .tile:not(.tile-back):hover {
  transform: translateY(-8px);
  box-shadow: 0 8px 16px var(--tile-shadow);
  background: var(--tile-hover);
}

.hand-bottom .tile.selected {
  transform: translateY(-12px);
  background: var(--tile-selected);
  box-shadow: 0 8px 20px rgba(255,224,102,0.4);
}

.hand-bottom .tile.just-drawn {
  margin-left: 12px;
  border-color: var(--accent-blue);
  box-shadow: 0 0 8px rgba(52,152,219,0.5);
}

/* Small tiles for opponents */
.hand-top .tile, .hand-left .tile, .hand-right .tile {
  width: 28px;
  height: 38px;
  font-size: 1.1rem;
}

.hand-left, .hand-right {
  flex-direction: column;
}

.hand-left .hand, .hand-right .hand {
  flex-direction: column;
}

.hand-left .tile, .hand-right .tile {
  width: 38px;
  height: 28px;
}

/* Melds */
.player-melds {
  display: flex;
  gap: 8px;
  margin: 4px 0;
}

.meld-group {
  display: flex;
  gap: 1px;
}

.meld-group .tile {
  width: 32px;
  height: 44px;
  font-size: 1.3rem;
}

/* Center area */
.center-area {
  grid-area: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.game-info {
  display: flex;
  gap: 1.5rem;
  font-size: 0.85rem;
  color: var(--text-light);
  opacity: 0.7;
  background: rgba(0,0,0,0.2);
  padding: 6px 16px;
  border-radius: 20px;
}

.discard-area {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  max-width: 400px;
  justify-content: center;
  padding: 12px;
  min-height: 120px;
  background: rgba(0,0,0,0.15);
  border-radius: 8px;
}

.discard-area .tile {
  width: 32px;
  height: 44px;
  font-size: 1.2rem;
}

.discard-area .tile.last-discard {
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(231,76,60,0.5);
}

/* Action bar */
.action-bar {
  position: fixed;
  bottom: 200px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  background: rgba(0,0,0,0.85);
  padding: 12px 20px;
  border-radius: 16px;
  z-index: 100;
  align-items: center;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

.btn-action {
  padding: 8px 20px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.95rem;
}

.btn-win { background: #e74c3c; color: white; }
.btn-kong { background: #e67e22; color: white; }
.btn-pong { background: #2ecc71; color: white; }
.btn-chi { background: #3498db; color: white; }
.btn-pass { background: #7f8c8d; color: white; }

.action-timer {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid #e74c3c;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: #e74c3c;
}

/* Game log */
.game-log {
  position: fixed;
  right: 0;
  top: 0;
  width: 250px;
  height: 100%;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transform: translateX(200px);
  transition: transform 0.3s;
}

.game-log:hover {
  transform: translateX(0);
}

.log-header {
  padding: 12px 16px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  font-size: 0.9rem;
}

.log-entries {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  font-size: 0.8rem;
}

.log-entry {
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  color: #aaa;
}

.log-entry.highlight {
  color: var(--accent);
  font-weight: 600;
}

/* Overlays */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.3s;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.win-modal {
  background: #1a1a2e;
  border-radius: 16px;
  padding: 2rem;
  max-width: 600px;
  width: 90%;
  text-align: center;
}

.win-modal h2 {
  font-size: 2rem;
  margin-bottom: 1rem;
}

.win-hand, .win-melds {
  display: flex;
  gap: 4px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 1rem 0;
}

.win-hand .tile {
  width: 48px;
  height: 64px;
  font-size: 2rem;
}

.win-scoring {
  margin: 1rem 0;
  text-align: left;
  padding: 1rem;
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
}

.fan-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.fan-total {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 2px solid var(--accent);
}

/* Flower display */
.flower-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: rgba(255,255,255,0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
}

/* Animations */
.tile-enter {
  animation: tileSlideIn 0.3s ease-out;
}

@keyframes tileSlideIn {
  from { transform: translateY(-30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.tile-discard-anim {
  animation: tileDiscard 0.4s ease-out;
}

@keyframes tileDiscard {
  from { transform: scale(1.2); opacity: 0.5; }
  to { transform: scale(1); opacity: 1; }
}

/* Chi selection modal */
.chi-select {
  position: fixed;
  bottom: 260px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.9);
  padding: 16px;
  border-radius: 12px;
  z-index: 110;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chi-option {
  display: flex;
  gap: 4px;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background 0.2s;
}

.chi-option:hover {
  background: rgba(52,152,219,0.3);
}

/* Responsive */
@media (max-width: 768px) {
  .game-table {
    grid-template-columns: 80px 1fr 80px;
    grid-template-rows: 100px 1fr 150px;
  }

  .tile {
    width: 34px;
    height: 48px;
    font-size: 1.4rem;
  }

  .hand-top .tile, .hand-left .tile, .hand-right .tile {
    width: 22px;
    height: 30px;
  }

  .game-log { width: 200px; }
}
