@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Playfair+Display:wght@700&display=swap');

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

:root {
  --wood-dark: #1c110a;
  --wood-base: #2a1810;
  --wood-mid: #3d2517;
  --wood-light: #52362a;
  --wood-highlight: #6b4a38;
  --wood-border: #5a3d2a;
  --gold: #d4a54a;
  --gold-light: #e8c06a;
  --gold-dim: #a07830;
  --text: #ede4d4;
  --text-dim: #9a8a70;
  --text-faint: #6a5a4a;
  --green: #7ab868;
  --red: #d45a4a;
  --red-dim: #8b3a2a;
  --canvas-shadow: rgba(0,0,0,0.6);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--wood-dark);
  background-image:
    repeating-linear-gradient(
      87deg,
      transparent,
      transparent 60px,
      rgba(255,200,120,0.015) 60px,
      rgba(255,200,120,0.015) 61px
    ),
    repeating-linear-gradient(
      87deg,
      transparent,
      transparent 120px,
      rgba(0,0,0,0.04) 120px,
      rgba(0,0,0,0.04) 121px
    ),
    radial-gradient(ellipse at 50% 0%, rgba(80,50,20,0.3) 0%, transparent 70%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ==================== Auth Page ==================== */

.page-auth {
  justify-content: center;
  min-height: 100vh;
  padding: 40px 20px;
}

.auth-hero {
  text-align: center;
  margin-bottom: 8px;
}

.auth-logo {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  margin-bottom: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}

.auth-hero h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2.2rem;
  color: var(--gold);
  letter-spacing: 1px;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  margin: 0;
}

.auth-subtitle {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin-top: 4px;
  letter-spacing: 3px;
  text-transform: uppercase;
  font-weight: 500;
}

.container {
  width: 100%;
  max-width: 420px;
  padding: 0 20px;
}

.auth-box {
  background: linear-gradient(160deg, var(--wood-mid) 0%, var(--wood-base) 100%);
  border-radius: 16px;
  padding: 28px;
  margin-top: 24px;
  border: 1px solid var(--wood-border);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.04) inset,
    0 12px 40px rgba(0,0,0,0.5),
    0 2px 8px rgba(0,0,0,0.3);
}

.auth-box input {
  display: block;
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 12px;
  border: 1px solid var(--wood-border);
  border-radius: 10px;
  background: var(--wood-dark);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.auth-box input::placeholder {
  color: var(--text-faint);
}

.auth-box input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212,165,74,0.15);
}

/* ==================== Buttons ==================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 22px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  text-decoration: none;
  gap: 8px;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, var(--gold-light), var(--gold), var(--gold-dim));
  color: var(--wood-dark);
  box-shadow: 0 2px 12px rgba(212,165,74,0.3), 0 1px 2px rgba(0,0,0,0.2);
}

.btn-primary:hover {
  box-shadow: 0 4px 20px rgba(212,165,74,0.4), 0 1px 2px rgba(0,0,0,0.2);
}

.btn-secondary {
  background: linear-gradient(135deg, var(--wood-highlight), var(--wood-light));
  color: var(--text);
  border: 1px solid var(--wood-border);
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.btn-danger {
  background: linear-gradient(135deg, var(--red), var(--red-dim));
  color: var(--text);
  box-shadow: 0 2px 8px rgba(212,90,74,0.2);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--wood-border);
  padding: 8px 16px;
}

.btn-ghost:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text);
  border-color: var(--wood-highlight);
}

.btn-small {
  padding: 7px 14px;
  font-size: 13px;
  border-radius: 8px;
}

.btn-google {
  width: 100%;
  padding: 13px 20px;
  background: #fff;
  color: #333;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.btn-google:hover {
  background: #f8f8f8;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.btn-google svg {
  flex-shrink: 0;
}

.auth-divider {
  display: flex;
  align-items: center;
  margin: 20px 0 16px;
  color: var(--text-faint);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--wood-border);
}

.auth-divider span {
  padding: 0 14px;
  white-space: nowrap;
}

.error-msg {
  color: var(--red);
  margin: 6px 0 10px;
  font-size: 13px;
  min-height: 0;
}

.success-msg {
  color: var(--green);
  margin: 6px 0 10px;
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--wood-dark);
  border-radius: 10px;
  padding: 4px;
}

.tab {
  flex: 1;
  padding: 9px 16px;
  border-radius: 8px;
  cursor: pointer;
  background: transparent;
  color: var(--text-dim);
  border: none;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: var(--wood-light);
  color: var(--gold);
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

/* ==================== Lobby ==================== */

.lobby-top-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: rgba(0,0,0,0.25);
  border-bottom: 1px solid rgba(255,255,255,0.04);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.lobby-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lobby-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.lobby-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.2rem;
  color: var(--gold);
  letter-spacing: 1px;
}

.lobby-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.lobby-username {
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
}

.lobby-container {
  max-width: 560px;
  padding-top: 28px;
}

.create-game-card {
  background: linear-gradient(160deg, var(--wood-mid) 0%, var(--wood-base) 100%);
  border: 1px solid var(--wood-border);
  border-radius: 14px;
  padding: 22px;
  margin-bottom: 28px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.create-game-card h3 {
  color: var(--gold);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  letter-spacing: 0.5px;
}

.create-game {
  display: flex;
  gap: 10px;
}

.create-game input {
  flex: 1;
  padding: 11px 16px;
  border: 1px solid var(--wood-border);
  border-radius: 10px;
  background: var(--wood-dark);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.create-game input::placeholder {
  color: var(--text-faint);
}

.create-game input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212,165,74,0.15);
}

.lobby-tabs {
  display: flex;
  gap: 4px;
  background: var(--wood-dark);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 18px;
}

.lobby-tab {
  flex: 1;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  background: transparent;
  color: var(--text-dim);
  border: none;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.15s;
  text-align: center;
}

.lobby-tab:hover {
  color: var(--text);
}

.lobby-tab.active {
  background: var(--wood-light);
  color: var(--gold);
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.history-item .game-info {
  flex: 1;
  min-width: 0;
}

.history-result {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.history-outcome {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.3px;
}

.outcome-win {
  background: rgba(122,184,104,0.15);
  color: var(--green);
  border: 1px solid rgba(122,184,104,0.3);
}

.outcome-loss {
  background: rgba(212,90,74,0.15);
  color: var(--red);
  border: 1px solid rgba(212,90,74,0.3);
}

.outcome-draw {
  background: rgba(255,255,255,0.05);
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.1);
}

.history-time {
  font-size: 11px;
  color: var(--text-faint);
}

.game-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.game-item {
  background: linear-gradient(160deg, var(--wood-mid) 0%, var(--wood-base) 100%);
  border: 1px solid var(--wood-border);
  border-radius: 12px;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.game-item:hover {
  border-color: var(--wood-highlight);
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
}

.game-item .game-info {
  flex: 1;
  min-width: 0;
}

.game-item .game-name {
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game-item .game-players {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

.game-item .game-status {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  margin-right: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.status-waiting {
  background: rgba(212,165,74,0.15);
  color: var(--gold);
  border: 1px solid rgba(212,165,74,0.3);
}

.status-playing {
  background: rgba(122,184,104,0.15);
  color: var(--green);
  border: 1px solid rgba(122,184,104,0.3);
}

.status-finished {
  background: rgba(255,255,255,0.05);
  color: var(--text-faint);
  border: 1px solid rgba(255,255,255,0.08);
}

.btn-delete {
  background: none;
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-delete:hover {
  background: rgba(233,69,96,0.15);
  color: #e94560;
  border-color: rgba(233,69,96,0.3);
}

.empty-msg {
  text-align: center;
  color: var(--text-faint);
  padding: 48px 0;
  font-style: italic;
  font-size: 14px;
}

/* ==================== Game Page ==================== */

.game-page {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.game-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: rgba(0,0,0,0.3);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.game-back-link {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  transition: color 0.15s;
}

.game-back-link:hover {
  color: var(--gold);
}

.game-title {
  font-family: 'Playfair Display', Georgia, serif;
  color: var(--gold);
  font-size: 1.1rem;
  letter-spacing: 1px;
}

.game-id-label {
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 600;
}

.game-layout {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 20px;
}

.game-sidebar {
  width: 160px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}

.game-center {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Player Cards */
.player-card {
  background: linear-gradient(160deg, var(--wood-mid) 0%, var(--wood-base) 100%);
  border: 1px solid var(--wood-border);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: all 0.3s ease;
  position: relative;
  opacity: 0.5;
}

.player-card.active-turn {
  opacity: 1;
  border-color: var(--gold-dim);
  box-shadow: 0 0 20px rgba(212,165,74,0.15), 0 4px 16px rgba(0,0,0,0.3);
}

.player-card-stone {
  position: relative;
}

.stone-indicator {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4), inset 0 1px 2px rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.stone-black {
  background: radial-gradient(circle at 35% 30%, #555, #1a1a1a);
  border: 1px solid #000;
}

.stone-white {
  background: radial-gradient(circle at 35% 30%, #fff, #c8c8c8);
  border: 1px solid #aaa;
}

.player-card-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.player-card-label {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

.player-card-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.player-card-turn {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 8px rgba(212,165,74,0.5);
  opacity: 0;
  transition: opacity 0.3s;
}

.player-card-turn.visible {
  opacity: 1;
  animation: pulse 1.5s ease-in-out infinite;
}

/* Score Box */
.game-score-box {
  background: linear-gradient(160deg, var(--wood-mid) 0%, var(--wood-base) 100%);
  border: 1px solid var(--wood-border);
  border-radius: 14px;
  padding: 14px;
  text-align: center;
}

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

.score-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--gold);
  font-family: 'Playfair Display', Georgia, serif;
}

/* Turn Indicator */
.turn-indicator {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  padding: 10px 28px;
  border-radius: 24px;
  background: rgba(255,255,255,0.04);
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.06);
  transition: all 0.3s;
}

.turn-indicator.turn-yours {
  background: rgba(212,165,74,0.12);
  color: var(--gold);
  border-color: rgba(212,165,74,0.2);
  box-shadow: 0 0 16px rgba(212,165,74,0.08);
}

.turn-indicator.turn-waiting {
  background: rgba(255,255,255,0.04);
  color: var(--text-dim);
}

.turn-indicator.turn-finished {
  background: rgba(212,165,74,0.12);
  color: var(--gold);
  border-color: rgba(212,165,74,0.2);
}

/* Canvas */
.canvas-wrapper {
  border-radius: 6px;
  overflow: hidden;
  box-shadow:
    0 0 0 4px var(--wood-light),
    0 0 0 6px var(--wood-border),
    0 12px 40px var(--canvas-shadow);
}

#game-canvas {
  display: block;
  cursor: pointer;
}

.game-actions {
  margin-top: 16px;
}

/* ==================== Game Over Overlay ==================== */

.overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.overlay.visible {
  display: flex;
}

.overlay-box {
  background: linear-gradient(160deg, var(--wood-mid) 0%, var(--wood-base) 100%);
  border: 1px solid var(--wood-border);
  border-radius: 24px;
  padding: 44px 52px;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0,0,0,0.7);
  min-width: 300px;
  max-width: 380px;
}

.overlay-icon {
  font-size: 52px;
  margin-bottom: 8px;
  line-height: 1;
}

.overlay-box h2 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.8rem;
  color: var(--text);
  margin-bottom: 8px;
}

.overlay-sub {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 28px;
  line-height: 1.4;
}

.overlay-actions {
  display: flex;
  justify-content: center;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.overlay-actions .btn {
  min-width: 200px;
}

.rematch-status {
  color: var(--gold);
  font-size: 13px;
  margin-top: 14px;
  min-height: 18px;
  animation: pulse 1.5s ease-in-out infinite;
}

.rematch-status:empty {
  display: none;
}

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

@media (max-width: 960px) {
  .game-sidebar {
    display: none;
  }
  .game-layout {
    padding: 12px;
  }
  .game-center {
    width: 100%;
  }
  /* Show compact player bar on mobile */
  .game-center::before {
    content: none;
  }
}

@media (max-width: 680px) {
  .canvas-wrapper {
    width: calc(100vw - 48px);
    box-shadow:
      0 0 0 3px var(--wood-light),
      0 0 0 5px var(--wood-border),
      0 8px 24px var(--canvas-shadow);
  }
  #game-canvas {
    width: 100%;
    height: auto;
  }
  .lobby-top-bar {
    padding: 12px 16px;
  }
  .lobby-container {
    padding-top: 20px;
  }
  .game-top-bar {
    padding: 10px 16px;
  }
  .turn-indicator {
    font-size: 13px;
    padding: 8px 20px;
  }
}
