/* ============================
   CSS Reset
   ============================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ============================
   Variables
   ============================ */
:root {
  --bg-main:      #0d1117;
  --bg-panel:     #161b22;
  --bg-card:      #1c2128;
  --border-blue:  #4a6fa5;
  --accent-gold:  #f0c040;
  --text-primary: #e6edf3;
  --text-muted:   #8b949e;
  --btn-primary:  #4a6fa5;
  --btn-hover:    #5a82be;
  --danger:       #f85149;
  --radius:       8px;
}

/* TEND page shell */
.tend-game-nav {
  position: fixed;
  inset: 0 0 auto;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 20px;
  background: rgba(13, 17, 23, 0.96);
  border-bottom: 1px solid var(--border-blue);
  color: var(--text-muted);
  font-size: 0.85rem;
}

.tend-game-nav a {
  color: var(--text-primary);
  text-decoration: none;
}

.tend-game-nav a:first-child {
  color: var(--accent-gold);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.tend-game-nav a:hover,
.tend-game-nav a:focus-visible {
  color: var(--accent-gold);
}

body {
  padding-top: 44px;
}

/* ============================
   Base
   ============================ */
html, body {
  height: 100%;
  background: var(--bg-main);
  color: var(--text-primary);
  font-family: 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

/* ============================
   Setup View
   ============================ */
#setup-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.setup-card {
  background: var(--bg-card);
  border: 1px solid var(--border-blue);
  border-radius: 16px;
  padding: 48px 56px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 8px 40px rgba(74,111,165,0.2);
}

.game-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent-gold);
  text-align: center;
  margin-bottom: 40px;
  letter-spacing: 2px;
}

.setup-section {
  margin-bottom: 28px;
}

.section-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.radio-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: 1px solid var(--border-blue);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-primary);
  font-size: 0.95rem;
  user-select: none;
}

.radio-label:hover {
  border-color: var(--accent-gold);
  background: rgba(240,192,64,0.08);
}

.radio-label input[type="radio"] {
  accent-color: var(--border-blue);
  width: 16px;
  height: 16px;
}

.radio-label:has(input:checked) {
  border-color: var(--border-blue);
  background: rgba(74,111,165,0.2);
  color: #fff;
}

#difficulty-group {
  display: none;
}

.btn-start {
  width: 100%;
  margin-top: 12px;
  padding: 14px;
  font-size: 1rem;
}

/* ============================
   Buttons
   ============================ */
.btn-primary {
  background: var(--btn-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 24px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-primary:hover {
  background: var(--btn-hover);
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-blue);
  border-radius: var(--radius);
  padding: 10px 24px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-secondary:hover {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border-blue);
  color: var(--text-primary);
  border-radius: 6px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 1rem;
}

.btn-icon:hover {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

/* ============================
   Game View
   ============================ */
#game-view {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.game-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-blue);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
}

.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent-gold);
  letter-spacing: 1px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* ============================
   Game Layout
   ============================ */
.game-layout {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: center;
  flex: 1;
  padding: 20px;
  gap: 20px;
}

/* ============================
   Panels
   ============================ */
.panel {
  width: 200px;
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-blue);
  border-radius: 12px;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-self: flex-start;
  margin-top: 10px;
}

.player-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.stone-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
}

.black-stone {
  background: radial-gradient(circle at 35% 35%, #555, #111);
  border: 2px solid #333;
  box-shadow: 2px 3px 8px rgba(0,0,0,0.6);
}

.white-stone {
  background: radial-gradient(circle at 35% 35%, #fff, #ccc);
  border: 2px solid #aaa;
  box-shadow: 2px 3px 8px rgba(0,0,0,0.4);
}

.player-name {
  font-size: 1rem;
  font-weight: 600;
}

.player-score {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-gold);
}

.player-score span {
  font-size: 2rem;
}

.turn-indicator {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding: 8px;
  border-radius: 6px;
  transition: all 0.3s;
}

.turn-indicator.active {
  color: var(--accent-gold);
  background: rgba(240,192,64,0.1);
  border: 1px solid var(--accent-gold);
  font-weight: 600;
}

.difficulty-badge {
  text-align: center;
  font-size: 0.75rem;
  color: var(--border-blue);
  background: rgba(74,111,165,0.15);
  border: 1px solid var(--border-blue);
  border-radius: 6px;
  padding: 4px 10px;
}

/* ============================
   Canvas Area
   ============================ */
.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.canvas-wrapper {
  position: relative;
  display: inline-block;
}

#board-canvas {
  display: block;
  cursor: crosshair;
  border-radius: 4px;
}

/* ============================
   AI Thinking Toast
   ============================ */
#ai-thinking-toast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(74,111,165,0.85);
  color: #fff;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  backdrop-filter: blur(4px);
  border: 1px solid var(--border-blue);
  white-space: nowrap;
  z-index: 10;
}

/* ============================
   Timer
   ============================ */
.timer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 600px;
}

.timer-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.timer-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-panel);
  border-radius: 4px;
  border: 1px solid var(--border-blue);
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  background: var(--border-blue);
  border-radius: 4px;
  transition: width 0.5s linear, background 0.3s;
  width: 100%;
}

.timer-fill.warning {
  background: var(--danger);
  animation: pulse 0.6s infinite alternate;
}

.timer-text {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  width: 30px;
  text-align: center;
}

/* ============================
   Degradation Toast
   ============================ */
#degradation-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(248,81,73,0.9);
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

/* ============================
   Game Over Modal
   ============================ */
#game-over-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
}

.modal-overlay {
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-blue);
  border-radius: 20px;
  padding: 48px 40px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

.modal-result-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent-gold);
  margin-bottom: 8px;
}

.modal-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.modal-score {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 32px;
}

.score-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.score-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.score-val {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.score-sep {
  font-size: 2rem;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-actions .btn-primary,
.modal-actions .btn-secondary {
  width: 100%;
  justify-content: center;
  padding: 13px;
}

/* ============================
   Animations
   ============================ */
@keyframes pulse {
  from { opacity: 1; }
  to   { opacity: 0.5; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================
   Responsive (Mobile < 900px)
   ============================ */
@media (max-width: 899px) {
  .game-layout {
    flex-direction: column;
    align-items: center;
    padding: 12px;
    gap: 12px;
  }

  .panel {
    width: 100%;
    max-width: 500px;
    flex-direction: row;
    align-items: center;
    margin-top: 0;
    padding: 14px 16px;
    gap: 12px;
  }

  .player-info {
    flex-direction: row;
    gap: 12px;
  }

  .stone-icon {
    width: 32px;
    height: 32px;
  }

  .player-score {
    font-size: 1.1rem;
  }

  .player-score span {
    font-size: 1.4rem;
  }

  .turn-indicator {
    margin-left: auto;
  }

  .difficulty-badge {
    margin-left: auto;
  }

  .canvas-area {
    width: 100%;
  }

  .canvas-wrapper {
    width: 100%;
  }

  #board-canvas {
    width: 100% !important;
    height: auto !important;
  }

  .timer-row {
    max-width: 100%;
    padding: 0 4px;
  }

  .setup-card {
    padding: 32px 24px;
  }

  .game-title {
    font-size: 1.6rem;
  }
}
