/* ============================================================
   style.css — Mahjong table UI
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@700;900&family=Ma+Shan+Zheng&display=swap');

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

:root {
  --table-green: #1a6b3c;
  --table-dark: #145230;
  --tile-bg: #f5f0e1;
  --tile-border: #b8a88a;
  --tile-shadow: #8a7a5e;
  --accent: #e8c547;
  --red: #c0392b;
  --blue: #2471a3;
  --gold: #f1c40f;
  --text: #ecf0f1;
  --dark-text: #2c3e50;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--table-dark);
  color: var(--text);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.hidden { display: none !important; }

/* ============ LOBBY ============ */
#lobby-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: linear-gradient(135deg, #0d3b1e 0%, #1a6b3c 50%, #0d3b1e 100%);
}

.lobby-card {
  background: rgba(0,0,0,0.5);
  border-radius: 16px;
  padding: 40px;
  text-align: center;
  min-width: 340px;
  max-width: 90vw;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1);
}

.lobby-card h1 {
  font-size: 2.2em;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--accent);
  margin-bottom: 24px;
  font-size: 1.1em;
}

.join-form {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  justify-content: center;
}

#name-input {
  padding: 10px 16px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 1em;
  outline: none;
  width: 180px;
}

#name-input::placeholder { color: rgba(255,255,255,0.5); }

#join-btn {
  padding: 10px 24px;
  background: var(--accent);
  color: var(--dark-text);
  border: none;
  border-radius: 8px;
  font-size: 1em;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}

#join-btn:hover { background: #d4b03e; }

.waiting { margin-top: 16px; }
.waiting p { margin-bottom: 8px; }

#player-list {
  list-style: none;
  margin-bottom: 12px;
}

#player-list li {
  padding: 6px 12px;
  background: rgba(255,255,255,0.1);
  border-radius: 6px;
  margin-bottom: 4px;
  font-weight: bold;
}

.hint { color: rgba(255,255,255,0.5); font-size: 0.9em; }

/* ============ GAME TABLE ============ */
#game-screen {
  position: relative;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at center, #1e7d48 0%, #145230 60%, #0d3b1e 100%);
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: auto 1fr;
  overflow: hidden;
}

/* ---- Opponents ---- */
.opponent {
  padding: 8px 12px;
  transition: background 0.3s;
  border-radius: 8px;
}

.opponent.active-turn {
  background: rgba(241, 196, 15, 0.15);
  box-shadow: inset 0 0 20px rgba(241, 196, 15, 0.1);
}

.opponent-top {
  grid-row: 1;
  grid-column: 1 / 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 10px;
}

.opponent-left {
  grid-row: 2;
  grid-column: 1;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  padding-left: 10px;
  gap: 6px;
  max-width: 200px;
}

.op-info {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 6px;
}

.op-name {
  font-weight: bold;
  font-size: 0.95em;
}

.op-money {
  color: var(--accent);
  font-weight: bold;
  font-size: 0.9em;
}

.op-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: center;
}

.opponent-left .op-hand-group {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.opponent-left .op-tiles {
  flex-direction: column;
}

.opponent-left .op-info {
  flex-direction: column;
  gap: 2px;
  text-align: center;
}

.op-melds {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  flex-wrap: wrap;
  justify-content: center;
}

.opponent-left .op-melds {
  flex-direction: column;
  align-items: center;
  margin-top: 0;
  margin-left: 4px;
}

.opponent-left .op-melds .meld {
  flex-direction: column;
  gap: 1px;
}

/* ---- Center ---- */
#center-area {
  grid-row: 2;
  grid-column: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px;
}

.center-info {
  display: flex;
  gap: 24px;
  margin-bottom: 12px;
}

.info-item {
  text-align: center;
}

.info-label {
  display: block;
  font-size: 0.75em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.5);
}

.info-value {
  display: block;
  font-size: 1.4em;
  font-weight: bold;
  color: var(--accent);
}

#discard-pile {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  max-width: 500px;
  max-height: 220px;
  overflow-y: auto;
  justify-content: center;
  padding: 8px;
  background: rgba(0,0,0,0.2);
  border-radius: 12px;
  min-height: 60px;
}

/* ---- My Area ---- */
#my-area {
  grid-row: 3;
  grid-column: 1 / 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 10px 12px;
  background: rgba(0,0,0,0.25);
  border-top: 2px solid rgba(255,255,255,0.08);
}

.my-info {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 6px;
}

#my-name {
  font-weight: bold;
  font-size: 1.1em;
}

#my-money {
  color: var(--accent);
  font-weight: bold;
  font-size: 1.1em;
}

/* Game control voting buttons */
.game-ctrl-btn {
  padding: 4px 12px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.7);
  font-size: 0.75em;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  margin-left: 8px;
}
.game-ctrl-btn:hover {
  background: rgba(255,255,255,0.18);
  color: #fff;
}
.game-ctrl-btn.voted {
  background: rgba(241, 196, 15, 0.25);
  border-color: var(--accent);
  color: var(--accent);
}

/* Vote alert banner */
#vote-alert {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: var(--accent);
  padding: 10px 24px;
  border-radius: 10px;
  font-size: 0.95em;
  font-weight: bold;
  z-index: 200;
  border: 1px solid var(--accent);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
#vote-alert.show {
  opacity: 1;
}

#my-hand {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  margin-bottom: 4px;
}

#my-melds {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.meld {
  display: flex;
  gap: 2px;
  align-items: center;
  background: rgba(0,0,0,0.15);
  padding: 2px 4px;
  border-radius: 6px;
}

.meld-type {
  font-size: 0.65em;
  color: var(--accent);
  text-transform: uppercase;
  margin-left: 4px;
}

/* ---- Tiles ---- */
.tile {
  width: 48px;
  height: 64px;
  background: linear-gradient(170deg, #faf6ee 0%, #f0e8d4 40%, #e8ddc4 100%);
  border: 2px solid #c8b890;
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 3px 6px rgba(0,0,0,0.35),
    inset 0 1px 0 rgba(255,255,255,0.7),
    inset 0 -1px 2px rgba(0,0,0,0.06);
  position: relative;
  transition: transform 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
}

.tile-char {
  font-size: 1.8em;
  line-height: 1;
  font-weight: 900;
  font-family: 'Ma Shan Zheng', 'Noto Serif SC', 'KaiTi', 'STKaiti', serif;
  text-shadow: 0 1px 1px rgba(0,0,0,0.08);
}

.tile-label {
  font-size: 0.6em;
  color: #c0392b;
  font-weight: 900;
  font-family: 'Ma Shan Zheng', 'Noto Serif SC', 'KaiTi', 'STKaiti', serif;
  line-height: 1;
  margin-top: 2px;
}

.tile-back {
  background: linear-gradient(135deg, #1a7a3a 0%, #0e5c28 50%, #1a7a3a 100%);
  border-color: #0e5c28;
  color: #fff;
}

.tile-back .tile-char { font-size: 2em; }

.tile.clickable {
  cursor: pointer;
}

.tile.clickable:hover {
  transform: translateY(-10px);
  box-shadow:
    0 10px 20px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.7);
  border-color: var(--gold);
}

.tile.drawn-tile {
  border-color: var(--gold);
  box-shadow:
    0 0 12px rgba(241, 196, 15, 0.6),
    inset 0 1px 0 rgba(255,255,255,0.7);
}

.tile.discarded { opacity: 0.9; }

/* Suit colors — matching real mahjong tiles */
.tile.dots .tile-char { color: #1a7a6a; }
.tile.characters .tile-char {
  color: #c0392b;
  font-size: 1.6em;
  font-weight: 900;
}
.tile.characters .tile-label {
  font-size: 0.7em;
  color: #c0392b;
  font-weight: 900;
}
.tile.wind .tile-char {
  color: #1a2d5a;
  font-size: 1.7em;
  font-weight: 900;
  text-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.tile.dragon .tile-char {
  color: #c0392b;
  font-size: 1.9em;
  font-weight: 900;
}
.tile.dragon[data-value="green"] .tile-char {
  color: #1a7a3a;
  font-weight: 900;
}
.tile.dragon[data-value="white"] .tile-char {
  color: transparent;
}

/* Flower tile colors — plants are blue, seasons are red */
.tile.flower .tile-char {
  font-size: 1.6em;
  font-weight: 900;
}
.tile.flower[data-value="plum"] .tile-char,
.tile.flower[data-value="orchid"] .tile-char,
.tile.flower[data-value="chrysanthemum"] .tile-char,
.tile.flower[data-value="bamboo"] .tile-char {
  color: #2471a3;
}
.tile.flower[data-value="spring"] .tile-char,
.tile.flower[data-value="summer"] .tile-char,
.tile.flower[data-value="autumn"] .tile-char,
.tile.flower[data-value="winter"] .tile-char {
  color: #c0392b;
}

/* Flower display areas */
#my-flowers {
  display: flex;
  gap: 3px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.op-flowers {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 4px;
}

.opponent-left .op-flowers {
  flex-direction: column;
  margin-top: 0;
  margin-left: 4px;
}

.summary-flowers {
  margin: 10px 0;
}

/* ---- Dots grid pattern (like real tiles) ---- */
.dots-grid {
  display: grid;
  gap: 2px;
  padding: 3px;
  justify-items: center;
  align-items: center;
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.4);
}
.dot-green {
  background: radial-gradient(circle at 35% 35%, #5ac4a0, #1a7a3a);
}
.dot-red {
  background: radial-gradient(circle at 35% 35%, #f08080, #c04040);
}
.dot-1-special {
  background: radial-gradient(circle,
    #c83030 0%, #c83030 22%,
    #fff 23%, #fff 28%,
    #1a7a3a 29%, #1a7a3a 48%,
    #fff 49%, #fff 53%,
    #1a7a3a 54%, #1a7a3a 100%);
  box-shadow: inset 0 1px 3px rgba(255,255,255,0.3);
}

/* White dragon blue frame */
.white-dragon-frame {
  display: inline-block;
  width: 20px;
  height: 28px;
  border: 3px solid #2471a3;
  border-radius: 3px;
  background: transparent;
}

.dots-1 { grid-template-columns: 1fr; }
.dots-1 .dot { width: 22px; height: 22px; }

.dots-2 { grid-template-columns: 1fr; gap: 3px; }
.dots-2 .dot { width: 12px; height: 12px; }

.dots-3 { grid-template-columns: 1fr; gap: 2px; }
.dots-3 .dot { width: 10px; height: 10px; }

.dots-4 { grid-template-columns: 1fr 1fr; gap: 3px; }
.dots-4 .dot { width: 10px; height: 10px; }

.dots-5 { grid-template-columns: 1fr 1fr; gap: 2px; }
.dots-5 .dot { width: 8px; height: 8px; }
.dots-5 .dot:nth-child(5) { grid-column: 1 / 3; justify-self: center; }

.dots-6 { grid-template-columns: 1fr 1fr; gap: 2px; }
.dots-6 .dot { width: 8px; height: 8px; }

.dots-7 { grid-template-columns: 1fr 1fr 1fr; gap: 1px; }
.dots-7 .dot { width: 7px; height: 7px; }
.dots-7 .dot:nth-child(7) { grid-column: 2; justify-self: center; }

.dots-8 { grid-template-columns: 1fr 1fr 1fr; gap: 1px; }
.dots-8 .dot { width: 7px; height: 7px; }
.dots-8 .dot:nth-child(7) { grid-column: 1 / 2; }
.dots-8 .dot:nth-child(8) { grid-column: 3; }

.dots-9 { grid-template-columns: 1fr 1fr 1fr; gap: 1px; }
.dots-9 .dot { width: 7px; height: 7px; }

/* Tile back pattern */
.tile-back-pattern {
  display: block;
  width: 28px;
  height: 38px;
  border-radius: 3px;
  background:
    repeating-linear-gradient(45deg, transparent, transparent 3px, rgba(255,255,255,0.08) 3px, rgba(255,255,255,0.08) 6px);
  border: 1px solid rgba(255,255,255,0.15);
}

/* ---- Smaller dots for opponent tiles ---- */
.op-tiles .dots-grid,
.op-melds .dots-grid { padding: 1px; gap: 1px; }
.op-tiles .dot,
.op-melds .dot { width: 4px; height: 4px; }
.op-tiles .dots-1 .dot,
.op-melds .dots-1 .dot { width: 10px; height: 10px; }
.op-tiles .dots-2 .dot,
.op-melds .dots-2 .dot { width: 5px; height: 5px; }
.op-tiles .dots-3 .dot,
.op-melds .dots-3 .dot { width: 5px; height: 5px; }
.op-tiles .tile-back-pattern,
.op-melds .tile-back-pattern { width: 16px; height: 24px; }

/* Smaller white dragon frame for opponents */
.op-tiles .white-dragon-frame,
.op-melds .white-dragon-frame {
  width: 12px;
  height: 16px;
  border-width: 2px;
}

/* Smaller tiles for opponents */
.op-tiles .tile,
.op-melds .tile {
  width: 28px;
  height: 38px;
}

.op-tiles .tile-char { font-size: 1.1em; }
.op-tiles .tile-label { display: none; }
.op-melds .tile-char { font-size: 1.1em; }
.op-melds .tile-label { display: none; }

/* ---- Action bar ---- */
#action-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 40px;
}

.action-btn {
  padding: 8px 20px;
  border: none;
  border-radius: 8px;
  font-size: 1em;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
}

.action-btn:hover {
  transform: scale(1.05);
}

.action-btn:active {
  transform: scale(0.97);
}

.btn-win {
  background: linear-gradient(135deg, #f1c40f, #e67e22);
  color: #2c3e50;
}

.btn-kong { background: #8e44ad; color: #fff; }
.btn-pong { background: #2471a3; color: #fff; }
.btn-chow { background: #27ae60; color: #fff; }
.btn-pass { background: rgba(255,255,255,0.15); color: #fff; }
.btn-play { background: #27ae60; color: #fff; }
.btn-restart { background: var(--red); color: #fff; }

/* ---- Message log ---- */
#message-log {
  position: absolute;
  top: 0;
  right: 0;
  width: 260px;
  max-height: 160px;
  overflow-y: auto;
  padding: 8px;
  background: rgba(0,0,0,0.4);
  border-radius: 0 0 0 8px;
  font-size: 0.8em;
  pointer-events: none;
  z-index: 10;
}

.msg {
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  color: rgba(255,255,255,0.7);
}

/* ---- Summary Modal ---- */
#summary-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(5px);
}

#summary-content {
  background: #1c2833;
  border-radius: 16px;
  padding: 30px;
  max-width: 520px;
  width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  text-align: center;
}

#summary-content h2 {
  color: var(--gold);
  margin-bottom: 16px;
}

#summary-content h3 {
  color: var(--accent);
  margin: 12px 0 6px;
  font-size: 1em;
}

.summary-hand {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  justify-content: center;
  margin: 10px 0;
}

.summary-melds {
  margin: 10px 0;
}

.fan-breakdown ul,
.money-changes ul,
.balances ul {
  list-style: none;
  text-align: left;
  padding: 0 20px;
}

.fan-breakdown li,
.money-changes li,
.balances li {
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.summary-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
}

.summary-actions .action-btn {
  padding: 12px 28px;
  font-size: 1.05em;
}

/* ============ MOBILE ============ */
@media (max-width: 768px) {
  /* 3-sided layout: top, left+center, bottom */
  #game-screen {
    grid-template-rows: auto 1fr auto;
    grid-template-columns: 70px 1fr;
  }

  .opponent-top {
    grid-row: 1;
    grid-column: 1 / 3;
  }

  .opponent-left {
    grid-row: 2;
    grid-column: 1;
    flex-direction: column;
    max-width: 70px;
    padding: 4px;
    justify-content: flex-start;
    gap: 4px;
    overflow-y: auto;
  }

  .opponent-left .op-hand-group {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .opponent-left .op-info {
    flex-direction: column;
    gap: 2px;
    text-align: center;
  }

  .opponent-left .op-name { font-size: 0.7em; }
  .opponent-left .op-money { font-size: 0.7em; }

  .opponent-left .op-tiles {
    flex-direction: column;
    gap: 1px;
  }

  .opponent-left .op-melds {
    flex-direction: column;
    align-items: center;
    gap: 4px;
  }

  .opponent-left .op-melds .meld {
    flex-direction: column;
    gap: 1px;
  }

  #center-area {
    grid-row: 2;
    grid-column: 2;
  }

  #my-area {
    grid-row: 3;
    grid-column: 1 / 3;
  }

  .tile {
    width: 42px;
    height: 56px;
  }

  .tile-char { font-size: 1.5em; }
  .tile-label { font-size: 0.55em; }

  .op-tiles .tile,
  .op-melds .tile {
    width: 22px;
    height: 30px;
  }

  .op-tiles .tile-char { font-size: 0.85em; }
  .op-melds .tile-char { font-size: 0.85em; }

  /* Dots on mobile player tiles */
  .dots-grid { padding: 2px; }
  .dot { width: 8px; height: 8px; }
  .dots-1 .dot { width: 18px; height: 18px; }
  .dots-2 .dot { width: 10px; height: 10px; }
  .dots-3 .dot { width: 9px; height: 9px; }
  .dots-4 .dot { width: 8px; height: 8px; }
  .dots-5 .dot, .dots-6 .dot { width: 7px; height: 7px; }
  .dots-7 .dot, .dots-8 .dot, .dots-9 .dot { width: 6px; height: 6px; }

  #discard-pile {
    max-width: 85vw;
    max-height: 140px;
  }

  #message-log {
    width: 180px;
    max-height: 100px;
    font-size: 0.7em;
  }

  .center-info { gap: 14px; }
  .info-value { font-size: 1.1em; }

  .lobby-card { padding: 24px; }
  .lobby-card h1 { font-size: 1.6em; }
}

@media (max-width: 480px) {
  #game-screen {
    grid-template-columns: 58px 1fr;
  }

  .opponent-left {
    max-width: 58px;
  }

  .tile {
    width: 36px;
    height: 50px;
  }

  .tile-char { font-size: 1.35em; }
  .tile-label { font-size: 0.5em; }

  .op-tiles .tile,
  .op-melds .tile {
    width: 20px;
    height: 28px;
  }

  .op-tiles .tile-char { font-size: 0.75em; }

  .action-btn {
    padding: 6px 14px;
    font-size: 0.9em;
  }

  #discard-pile {
    max-height: 100px;
  }
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }
