*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
:root {
  --bg: #0f1010;
  --surface: #1a1b1c;
  --surface-2: #232425;
  --border: #2e3032;
  --text: #e8e8e8;
  --text-dim: #8a8d90;
  --accent: #ce432d;
  --accent-hover: #e04e36;
  --green: #3fb950;
  --red: #f85149;
  --topbar-h: 48px;
  --footer-h: 36px;
  --radius: 6px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input {
  font: inherit;
  color: inherit;
}

/* ── Topbar ── */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 16px;
  background: #171918;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.brand-mark {
  display: inline-block;
  width: 20px;
  height: 20px;
  background: var(--accent);
  border-radius: 4px;
}

.mode-switcher {
  display: flex;
  gap: 2px;
  margin-left: auto;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2px;
}

.mode-btn {
  padding: 4px 14px;
  border-radius: calc(var(--radius) - 2px);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}

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

.mode-btn.is-active {
  background: var(--accent);
  color: #fff;
}

/* ── Workspace ── */

.workspace {
  display: flex;
  height: calc(100vh - var(--topbar-h) - var(--footer-h));
  overflow: hidden;
}

.play-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ── Game stage ── */

.game-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  overflow: hidden;
}

.game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  outline: none;
}

.game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(0, 0, 0, 0.85);
  z-index: 10;
  transition: opacity 0.3s;
}

.game-overlay.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.load-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.load-text {
  font-size: 14px;
  color: var(--text-dim);
}

.load-progress-wrap {
  width: 200px;
  height: 4px;
  background: var(--surface);
  border-radius: 2px;
  overflow: hidden;
}

.load-progress {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.2s;
}

/* ── Shadow taunt ── */

.taunt-card {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  cursor: pointer;
  outline: none;
}

.taunt-card.is-hidden,
.taunt-img.is-hidden {
  display: none;
}

.taunt-img {
  display: block;
  width: auto;
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
}

/* ── Toolbar ── */

.game-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.run-summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.summary-label {
  font-size: 13px;
  color: var(--text-dim);
}

.summary-result {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}

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

.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  height: 40px;
  padding: 0 14px;
  background: #27292a;
  border: 1px solid #424547;
  color: #d8dadd;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 1px 2px rgb(0 0 0 / 30%);
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
  white-space: nowrap;
}

.toolbar-btn:hover {
  background: #333536;
  border-color: #5a5e61;
  color: #fff;
}

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

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

.toolbar-btn.is-active:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* ── Touch controls ── */

.touch-controls {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 12px 12px;
  background: var(--surface);
}

.touch-controls button {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 56px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: background 0.1s;
}

.touch-controls button.is-pressed {
  background: var(--accent);
  border-color: var(--accent);
}

/* ── Sidebar ── */

.sidebar {
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
}

.section-head h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}

/* ── Player section ── */

.player-section {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.input-label {
  display: block;
  padding: 0 14px 4px;
  font-size: 12px;
  color: var(--text-dim);
}

.player-section input {
  display: block;
  width: calc(100% - 28px);
  margin: 0 14px;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.player-section input:focus {
  border-color: var(--accent);
}

.submit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 0;
}

.submit-btn {
  padding: 5px 14px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, opacity 0.15s;
}

.submit-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.submit-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Leaderboard section ── */

.board-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.board-head > div {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.board-mode {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 400;
}

.table-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 0 14px;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table-wrap th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-dim);
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.table-wrap td {
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.table-wrap tr:hover td {
  background: var(--surface-2);
}

.table-wrap th.col-result,
.table-wrap td.col-result {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.board-empty {
  padding: 32px 0;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

.board-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  font-size: 11px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}

.board-disclaimer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 10px;
  line-height: 1.5;
}

.board-disclaimer a {
  color: var(--text-dim);
  overflow-wrap: anywhere;
}

.board-disclaimer a:hover {
  color: var(--text);
  text-decoration: underline;
}

/* ── Site footer ── */

.site-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--footer-h);
  padding: 0 12px;
  border-top: 1px solid var(--border);
  background: #171918;
  color: var(--text-dim);
  font-size: 12px;
  letter-spacing: 0;
  text-align: center;
}

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

.site-footer a:hover {
  color: var(--text);
  text-decoration: underline;
}

/* ── Toast ── */

.toast-container {
  position: fixed;
  top: calc(var(--topbar-h) + 14px);
  left: 50%;
  width: min(440px, calc(100vw - 32px));
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  z-index: 200;
  pointer-events: none;
  transform: translateX(-50%);
}

.toast {
  width: 100%;
  min-height: 52px;
  padding: 14px 18px;
  background: #262829;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / 45%);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  overflow-wrap: anywhere;
  text-align: center;
  color: var(--text);
  pointer-events: auto;
  animation: toast-in 0.25s ease-out;
}

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

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Info dialog ── */

.info-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgb(0 0 0 / 68%);
}

.info-modal.is-hidden {
  display: none;
}

.info-dialog {
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid #4b4e50;
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgb(0 0 0 / 55%);
}

.info-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 0 14px 0 18px;
  border-bottom: 1px solid var(--border);
}

.info-dialog-head h2 {
  font-size: 17px;
  font-weight: 700;
}

.info-close {
  width: 36px;
  height: 36px;
  color: var(--text-dim);
  border-radius: var(--radius);
  font-size: 26px;
  line-height: 1;
}

.info-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.info-content {
  padding: 18px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
}

.info-content a {
  color: var(--accent);
  overflow-wrap: anywhere;
}

.info-content a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* ── Responsive ── */

@media (max-width: 980px) {
  .workspace {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .play-col {
    flex: none;
  }

  .game-stage {
    aspect-ratio: 640 / 400;
    flex: none;
  }

  .sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    overflow-y: visible;
  }

  .table-wrap {
    max-height: 400px;
  }

  .touch-controls {
    display: grid;
  }

  .site-footer {
    min-height: var(--footer-h);
    padding: 8px 12px;
  }
}

@media (max-width: 560px) {
  .toast-container {
    top: calc(var(--topbar-h) + 10px);
    width: calc(100vw - 20px);
  }

  .toast {
    min-height: 56px;
    padding: 15px 16px;
  }

  .topbar {
    padding: 0 10px;
    gap: 8px;
  }

  .mode-btn {
    padding: 4px 10px;
    font-size: 12px;
  }

  .game-toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .game-actions {
    width: 100%;
  }

  .toolbar-btn {
    flex: 1;
    min-width: 0;
  }

}
