/* ============================================================
   Base
   ============================================================ */

:root {
  --bg: #161512;
  --bg-light: #1e1d1a;
  --bg-card: #262522;
  --text: #bababa;
  --text-bright: #e0e0e0;
  --text-muted: #787878;
  --accent: #629924;
  --accent-hover: #78b130;
  --danger: #c33;
  --square-light: #b8b8a0;
  --square-dark: #6d8a47;
  --highlight: rgba(255, 255, 50, 0.4);
  --highlight-move: rgba(100, 200, 50, 0.5);
  --check: rgba(255, 0, 0, 0.5);
  --border: #333;
  --radius: 4px;
  --board-size: min(70vh, 70vw);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

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

.hidden { display: none !important; }
.muted { color: var(--text-muted); font-style: italic; }

/* ============================================================
   Header
   ============================================================ */

header {
  display: flex;
  align-items: center;
  padding: 8px 20px;
  background: var(--bg-light);
  border-bottom: 1px solid var(--border);
  gap: 20px;
}

header h1 {
  font-size: 18px;
  font-weight: 700;
}

header h1 a { color: var(--text-bright); }

nav { display: flex; gap: 16px; }
nav a { color: var(--text); font-size: 14px; }
nav a:hover, nav a.active { color: var(--text-bright); }

.header-right {
  margin-left: auto;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-right .username { color: var(--text-bright); font-weight: 600; }
.header-right .rating { color: var(--text-muted); }
.header-right button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}
.header-right button:hover { border-color: var(--text-muted); }

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

#auth-section {
  display: flex;
  justify-content: center;
  padding-top: 80px;
}

.auth-box {
  background: var(--bg-card);
  padding: 28px;
  border-radius: 8px;
  width: 320px;
  border: 1px solid var(--border);
}

.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
}

.tab {
  flex: 1;
  padding: 8px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}

.tab.active {
  color: var(--text-bright);
  border-bottom-color: var(--accent);
}

form input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-bright);
  font-size: 14px;
}

form input:focus {
  outline: none;
  border-color: var(--accent);
}

form button, .btn {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  display: inline-block;
}

form button:hover, .btn:hover { background: var(--accent-hover); }

.form-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
  min-height: 18px;
}

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

.lobby-grid {
  display: grid;
  grid-template-columns: 240px 1fr 240px;
  gap: 20px;
  padding: 20px;
  max-width: 1100px;
  margin: 0 auto;
}

.lobby-panel {
  background: var(--bg-card);
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.lobby-panel h2, .lobby-main h2 {
  font-size: 15px;
  margin-bottom: 12px;
  color: var(--text-bright);
}

.lobby-panel form label {
  font-size: 13px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
  margin-top: 10px;
}

.lobby-panel form label:first-of-type { margin-top: 0; }

form select {
  width: 100%;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-bright);
  font-size: 14px;
  margin-bottom: 6px;
}

.lobby-panel form button { margin-top: 14px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  padding: 6px 8px;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.compact td, .compact th { padding: 4px 6px; }

td button {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 4px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}

td button:hover { background: var(--accent-hover); }

/* ============================================================
   Game Layout
   ============================================================ */

.game-layout {
  display: grid;
  grid-template-columns: var(--board-size) 260px;
  grid-template-rows: auto auto auto;
  gap: 8px 16px;
  justify-content: center;
  padding: 12px 20px;
  max-width: 900px;
  margin: 0 auto;
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
}

.player-bar.top { grid-column: 1; grid-row: 1; }
.player-bar.bottom { grid-column: 1; grid-row: 3; }

.player-name { font-weight: 600; color: var(--text-bright); font-size: 14px; }
.player-rating { color: var(--text-muted); font-size: 13px; }

.captured-pieces {
  display: flex;
  align-items: center;
  gap: 1px;
  margin-left: 6px;
}

.captured-pieces img {
  width: 18px;
  height: 18px;
  opacity: 0.85;
}

.material-diff {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-left: 2px;
}

.clock {
  margin-left: auto;
  background: var(--bg-card);
  padding: 4px 12px;
  border-radius: var(--radius);
  font-family: 'Courier New', monospace;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-bright);
  border: 1px solid var(--border);
  min-width: 72px;
  text-align: center;
}

.clock.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.clock.low { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ============================================================
   Board (chessboard.js)
   ============================================================ */

.board-wrap {
  grid-column: 1;
  grid-row: 2;
  width: var(--board-size);
}

/* Square highlight classes for chessboard.js */
.highlight-selected { background-color: rgba(255, 255, 50, 0.4) !important; }
.highlight-move { background-color: rgba(210, 190, 50, 0.35) !important; }
.highlight-capture { background-color: rgba(210, 190, 50, 0.5) !important; }
.highlight-check { box-shadow: inset 0 0 14px 5px rgba(255, 0, 0, 0.6) !important; }
.highlight-explosive { box-shadow: inset 0 0 10px 4px rgba(255, 120, 0, 0.6) !important; }
.highlight-last { box-shadow: inset 0 0 0 100px rgba(155, 199, 0, 0.2) !important; }
.highlight-exploded { box-shadow: inset 0 0 0 100px rgba(255, 120, 0, 0.12) !important; }

/* Explosion animation */
/* Explosion uses box-shadow instead of background-color to override chessboard.js */
@keyframes explosion-flash {
  0%   { box-shadow: inset 0 0 0 100px rgba(255, 80, 0, 0.9); }
  30%  { box-shadow: inset 0 0 0 100px rgba(255, 200, 0, 0.6); }
  100% { box-shadow: inset 0 0 0 100px transparent; }
}

@keyframes explosion-vaporize {
  0%   { box-shadow: inset 0 0 0 100px rgba(100, 0, 255, 0.8); }
  40%  { box-shadow: inset 0 0 0 100px rgba(200, 100, 255, 0.4); }
  100% { box-shadow: inset 0 0 0 100px transparent; }
}

.anim-explosion {
  animation: explosion-flash 0.6s ease-out !important;
}

.anim-vaporize {
  animation: explosion-vaporize 0.6s ease-out !important;
}

/* ============================================================
   Side Panel
   ============================================================ */

.side-panel {
  grid-column: 2;
  grid-row: 1 / 4;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.move-list {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  flex: 1;
  overflow-y: auto;
  font-size: 13px;
  font-family: 'Courier New', monospace;
  max-height: 400px;
}

.move-list .move-row {
  display: flex;
  gap: 4px;
  padding: 2px 0;
}

.move-list .move-num { color: var(--text-muted); min-width: 28px; }
.move-list .move-white, .move-list .move-black {
  min-width: 70px;
  padding: 1px 4px;
  border-radius: 2px;
  cursor: pointer;
}
.move-list .move-white:hover, .move-list .move-black:hover {
  background: rgba(255,255,255,0.1);
}

.game-actions {
  display: flex;
  gap: 8px;
}

.game-actions button {
  flex: 1;
  padding: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}

.game-actions button:hover { border-color: var(--text-muted); }
#btn-resign:hover { border-color: var(--danger); color: var(--danger); }

.explosive-actions {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}

.explosive-actions h3 {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

#explosive-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

#explosive-buttons button {
  padding: 4px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
}

#explosive-buttons button:hover {
  border-color: orange;
  color: orange;
}

#explosive-buttons button.active {
  background: orange;
  color: #000;
  border-color: orange;
}

/* ============================================================
   Modals
   ============================================================ */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  min-width: 240px;
  text-align: center;
}

.modal-content h3 {
  margin-bottom: 14px;
  color: var(--text-bright);
  font-size: 16px;
}

.promotion-color-toggle {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 13px;
}

.promotion-pieces {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.promotion-pieces .promo-choice {
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.promotion-pieces .promo-choice img { width: 48px; height: 48px; }

.promotion-pieces .promo-choice:hover { border-color: var(--accent); }

.line-choices {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.line-choices button {
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-bright);
  cursor: pointer;
  font-size: 14px;
}

.line-choices button:hover {
  border-color: orange;
  color: orange;
}

/* ============================================================
   Game Result
   ============================================================ */

.game-result {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.game-result #result-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-bright);
  margin-bottom: 12px;
}

/* ============================================================
   Rules Page
   ============================================================ */

.rules-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 30px 20px;
  line-height: 1.7;
}

.rules-content h2 {
  font-size: 22px;
  margin-bottom: 20px;
  color: var(--text-bright);
}

.rules-content h3 {
  font-size: 17px;
  margin-top: 24px;
  margin-bottom: 8px;
  color: var(--text-bright);
}

.rules-content h4 {
  font-size: 14px;
  margin-top: 14px;
  margin-bottom: 4px;
  color: var(--accent);
}

.rules-content p { margin-bottom: 8px; }

.rules-content ul {
  padding-left: 24px;
  margin-bottom: 8px;
}

.rules-content li { margin-bottom: 4px; }

.rules-content em { color: var(--text-muted); }

.notation-table td {
  padding: 4px 12px;
  border: none;
  font-size: 14px;
}

.notation-table code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 13px;
  color: var(--accent);
}

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

/* ============================================================
   Tutorial Page
   ============================================================ */

.tutorial-layout {
  display: grid;
  grid-template-columns: 1fr;
  max-width: 700px;
  margin: 0 auto;
  padding: 16px 20px;
  gap: 16px;
}

.tutorial-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tutorial-tab {
  padding: 8px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  transition: border-color 0.15s;
}

.tutorial-tab:hover { border-color: var(--accent); color: var(--text-bright); }
.tutorial-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.tutorial-board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.tutorial-board-wrap {
  width: min(500px, 80vw);
}

.tutorial-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.tutorial-actions button {
  padding: 8px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}

.tutorial-actions button:hover { border-color: orange; color: orange; }
.tutorial-actions button.active { background: orange; color: #000; border-color: orange; }
.tutorial-actions button.btn-primary { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.tutorial-info {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}

.tutorial-info h2 {
  font-size: 18px;
  color: var(--text-bright);
  margin-bottom: 8px;
}

.tutorial-desc {
  color: var(--text);
  line-height: 1.6;
  margin-bottom: 12px;
}

.tutorial-instructions {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--accent);
  font-size: 14px;
  margin-bottom: 12px;
}

.tutorial-result {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}

.tutorial-result.success { background: rgba(98, 153, 36, 0.2); color: var(--accent); border: 1px solid var(--accent); }
.tutorial-result.info { background: rgba(200, 150, 0, 0.15); color: #dda; border: 1px solid #aa8; }

.tutorial-reset {
  width: auto;
  padding: 8px 20px;
}

@media (max-width: 700px) {
  :root { --board-size: 92vw; }

  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto var(--board-size) auto auto;
  }

  .side-panel { grid-column: 1; grid-row: 4; }

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