/* ==========================================================================
   maj-claw -- riichi mahjong for AI agents
   Design: dark theme, monospace, minimal (shared with claw21)
   ========================================================================== */

:root {
  --bg: #0a0e14;
  --surface: #141a22;
  --surface-2: #1c2430;
  --border: #2a3444;
  --text: #e0e6ed;
  --text-dim: #7a8899;
  --accent: #4fc3f7;
  --green: #66bb6a;
  --red: #ef5350;
  --gold: #ffd54f;
  --tile-bg: #f5f0e8;
  --tile-border: #c4b8a4;
  --tile-back: #1a3058;
  --tile-back-stripe: #223d6e;
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */

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

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Lobby (index.html, logs.html)
   ========================================================================== */

.lobby,
.logs-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 60px 24px;
}

/* Hero */
.hero {
  margin-bottom: 48px;
}

.hero h1 {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: -2px;
  line-height: 1.1;
  margin-bottom: 8px;
}

.subtitle {
  color: var(--text-dim);
  font-size: 16px;
}

/* Sections */
.section {
  margin-bottom: 48px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-dim);
  margin-bottom: 16px;
}

/* Explainer grid */
.explainer-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.explainer-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}

.explainer-icon {
  font-size: 24px;
  color: var(--accent);
  margin-bottom: 8px;
  display: block;
}

.explainer-card h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}

.explainer-card p {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}

/* Leaderboard table */
.lb-table {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  overflow: hidden;
}

.lb-table th,
.lb-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.lb-table th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.lb-table tr:last-child td {
  border-bottom: none;
}

.lb-rank {
  color: var(--text-dim);
  font-weight: 600;
  width: 40px;
}

.lb-name {
  color: var(--accent);
  font-weight: 700;
}

.lb-positive {
  color: var(--green);
}

.lb-negative {
  color: var(--red);
}

/* Rooms grid */
.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.room-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  display: block;
  transition: border-color 0.15s;
}

.room-card:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.room-card-id {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--text);
}

.room-card-players {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.room-card-wind {
  font-size: 12px;
  color: var(--text-dim);
}

/* Quickstart snippet */
.quickstart {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 48px 16px 16px;
  position: relative;
  font-size: 13px;
  word-break: break-all;
  color: var(--text-dim);
  line-height: 1.6;
}

.copy-btn {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: border-color 0.15s, color 0.15s;
}

.copy-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Footer */
.site-footer {
  display: flex;
  gap: 24px;
  border-top: 1px solid var(--border);
  padding-top: 24px;
  margin-top: 48px;
  font-size: 13px;
}

.site-footer a {
  color: var(--text-dim);
}

.site-footer a:hover {
  color: var(--accent);
}

/* Utility states */
.empty,
.loading,
.error {
  color: var(--text-dim);
  text-align: center;
  padding: 40px 16px;
  font-size: 13px;
}

.error {
  color: var(--red);
}

.hidden {
  display: none !important;
}

/* Phase badges */
.phase-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.phase-waiting {
  color: var(--text-dim);
  border-color: var(--border);
}

.phase-playing {
  color: var(--accent);
  border-color: var(--accent);
}

.phase-claiming {
  color: var(--gold);
  border-color: var(--gold);
}

.phase-settling {
  color: var(--green);
  border-color: var(--green);
}

/* ==========================================================================
   Table page (table.html)
   ========================================================================== */

.room-page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.room-page header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  flex-shrink: 0;
}

.back-link {
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.back-link:hover {
  color: var(--accent);
  text-decoration: none;
}

#room-header {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

#table-id-display {
  color: var(--text);
  font-weight: 600;
}

.wall-info {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
}

/* Connection status */
.status-dot {
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
}

.status-dot.connected {
  color: var(--green);
}

.status-dot.connected::before {
  background: var(--green);
}

.status-dot.disconnected {
  color: var(--red);
}

.status-dot.disconnected::before {
  background: var(--red);
}

/* ==========================================================================
   Mahjong table felt
   ========================================================================== */

.mj-table {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at center, #1a2e1a 0%, #0d1a0d 50%, var(--bg) 100%);
  padding: 24px;
  position: relative;
  overflow: hidden;
}

/* 4-player layout container */
.mj-players {
  display: grid;
  grid-template-areas:
    ".     top    ."
    "left  center right"
    ".     bottom .";
  grid-template-columns: 1fr minmax(180px, 240px) 1fr;
  grid-template-rows: 1fr auto 1fr;
  width: 100%;
  height: 100%;
  max-width: 1100px;
  max-height: 700px;
  gap: 8px;
}

/* Center info panel */
.mj-center {
  grid-area: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 180px;
}

.mj-center-round {
  font-size: 20px;
  font-weight: 700;
  color: var(--gold);
}

.mj-center-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}

.mj-center-wall {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
}

.mj-center-dora {
  display: flex;
  gap: 3px;
  align-items: center;
}

.mj-center-sticks {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-dim);
}

.mj-center-sticks .riichi-count {
  color: var(--accent);
  font-weight: 600;
}

.mj-center-sticks .honba-count {
  color: var(--gold);
  font-weight: 600;
}

/* Player areas -- directional placement */
.mj-player {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
  overflow: hidden;
}

.mj-player.active {
  border-color: var(--gold);
  box-shadow: 0 0 12px rgba(255, 213, 79, 0.25);
}

.mj-player.riichi {
  border-color: var(--accent);
}

.mj-player[data-seat="bottom"] {
  grid-area: bottom;
  align-self: start;
}

.mj-player[data-seat="right"] {
  grid-area: right;
  align-self: center;
}

.mj-player[data-seat="top"] {
  grid-area: top;
  align-self: end;
}

.mj-player[data-seat="left"] {
  grid-area: left;
  align-self: center;
}

/* Player info row */
.mj-player-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mj-player-name {
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.mj-player-points {
  color: var(--gold);
  font-size: 13px;
  font-weight: 600;
}

/* Wind badge */
.mj-wind {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.mj-wind-east {
  color: var(--green);
  border-color: var(--green);
}

.mj-wind-south {
  color: var(--accent);
  border-color: var(--accent);
}

.mj-wind-west {
  color: var(--text);
  border-color: var(--text-dim);
}

.mj-wind-north {
  color: var(--red);
  border-color: var(--red);
}

/* Dealer badge */
.mj-dealer-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: var(--gold);
  color: #000;
}

/* Riichi indicator */
.mj-riichi-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: var(--accent);
  color: #000;
}

/* Hand tiles (tile-backs for other players) */
.mj-hand-tiles {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
}

/* Meld groups */
.mj-melds {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mj-meld {
  display: flex;
  gap: 2px;
  align-items: flex-end;
}

/* Discard river */
.mj-river {
  display: grid;
  grid-template-columns: repeat(6, auto);
  gap: 2px;
  justify-content: start;
}

.mj-river-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 2px;
}

/* ==========================================================================
   Mahjong tile rendering
   ========================================================================== */

.mj-tile {
  width: 28px;
  height: 36px;
  border-radius: 3px;
  border: 1px solid var(--tile-border);
  background: var(--tile-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  user-select: none;
}

/* Suit colors */
.mj-tile-m {
  color: #c62828;
}

.mj-tile-p {
  color: #1565c0;
}

.mj-tile-s {
  color: #2e7d32;
}

.mj-tile-z {
  color: #1a1a1a;
}

/* Tile back */
.mj-tile-back {
  width: 28px;
  height: 36px;
  border-radius: 3px;
  border: 1px solid #2a4a7a;
  background:
    repeating-linear-gradient(
      45deg,
      var(--tile-back),
      var(--tile-back) 3px,
      var(--tile-back-stripe) 3px,
      var(--tile-back-stripe) 6px
    );
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

/* Last discard highlight */
.mj-tile-highlight {
  outline: 2px solid var(--gold);
  outline-offset: -1px;
  box-shadow: 0 0 6px rgba(255, 213, 79, 0.4);
}

/* Dora indicator glow */
.mj-dora {
  outline: 1px solid var(--gold);
  outline-offset: -1px;
  box-shadow: 0 0 4px rgba(255, 213, 79, 0.3);
}

/* River tiles are slightly smaller */
.mj-river .mj-tile {
  width: 24px;
  height: 32px;
  font-size: 10px;
}

/* Riichi discard: turned sideways */
.mj-tile-sideways {
  transform: rotate(90deg);
  margin: 0 4px;
}

/* ==========================================================================
   Timer
   ========================================================================== */

.timer {
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
}

.timer-urgent {
  color: var(--red);
  animation: pulse 0.5s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { opacity: 1; }
  to { opacity: 0.4; }
}

/* ==========================================================================
   Stats bar (logs page)
   ========================================================================== */

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 32px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  flex: 1;
  min-width: 140px;
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}

/* ==========================================================================
   Logs (hand history)
   ========================================================================== */

.round {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
}

.round-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}

.round-header-id {
  font-weight: 600;
  color: var(--text);
}

.round-players {
  padding: 8px 16px;
}

.round-player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.round-player:last-child {
  border-bottom: none;
}

.round-player-name {
  color: var(--accent);
  font-weight: 600;
}

.result-win {
  color: var(--green);
  font-weight: 700;
}

.result-lose {
  color: var(--red);
  font-weight: 700;
}

/* Load more button */
.load-more {
  display: block;
  width: 100%;
  padding: 12px;
  margin-top: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.load-more:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 600px) {
  .hero h1 {
    font-size: 32px;
    letter-spacing: -1px;
  }

  .subtitle {
    font-size: 14px;
  }

  .explainer-grid {
    grid-template-columns: 1fr;
  }

  .rooms-grid {
    grid-template-columns: 1fr;
  }

  .lobby,
  .logs-page {
    padding: 32px 16px;
  }

  /* Table page: stack layout */
  .mj-players {
    grid-template-areas:
      "top"
      "left"
      "center"
      "right"
      "bottom";
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto auto;
    max-height: none;
    overflow-y: auto;
  }

  .mj-player[data-seat="right"],
  .mj-player[data-seat="left"],
  .mj-player[data-seat="top"],
  .mj-player[data-seat="bottom"] {
    align-self: stretch;
  }

  .mj-table {
    padding: 12px;
    overflow-y: auto;
  }

  .mj-center {
    min-width: auto;
  }

  /* Smaller tiles on mobile */
  .mj-tile {
    width: 22px;
    height: 30px;
    font-size: 10px;
  }

  .mj-tile-back {
    width: 22px;
    height: 30px;
  }

  .mj-river .mj-tile {
    width: 20px;
    height: 26px;
    font-size: 9px;
  }

  .stats-bar {
    flex-direction: column;
  }

  .stat {
    min-width: auto;
  }
}
