/* Python 勇者 —— 全局样式(暗色主题) */

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

:root {
  --bg: #12151f;
  --panel: #1b2030;
  --panel2: #222840;
  --border: #303852;
  --text: #dde3f0;
  --muted: #8b93ab;
  --accent: #ffb84d;
  --green: #57c76a;
  --red: #ff6b6b;
  --blue: #5a8dff;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  overflow: hidden;
}

button {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary {
  background: #2c6e49;
  border-color: #3a9e63;
  font-weight: bold;
}
button.primary:hover:not(:disabled) { background: #35855a; color: #fff; }

/* ---------- 头部 ---------- */
header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  height: 52px;
}
header h1 { font-size: 20px; color: var(--accent); }
#player-stats { display: flex; align-items: center; gap: 12px; flex: 1; }
.stat { font-size: 15px; }
.xp-track {
  width: 120px; height: 8px;
  background: #0d0f17;
  border-radius: 4px;
  overflow: hidden;
}
#player-xp-bar { height: 100%; width: 0; background: linear-gradient(90deg, #7bd88f, #4da3ff); }
nav { display: flex; gap: 8px; }
#btn-endless:not(:disabled) {
  border-color: #7c5cff;
  color: #c4b8ff;
  background: linear-gradient(135deg, #262347, #222840);
}

/* ---------- 主布局 ---------- */
main {
  display: flex;
  height: calc(100% - 52px);
}
#left-pane {
  flex: 1.15;
  min-width: 420px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}
#right-pane {
  flex: 1;
  min-width: 380px;
  display: flex;
  flex-direction: column;
}

/* ---------- 左侧 ---------- */
#level-banner {
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#level-banner .concept { color: var(--muted); font-size: 13px; }

#canvas-wrap { position: relative; background: #1b2035; }
#battle-canvas { display: block; width: 100%; height: auto; }
#battle-controls {
  position: absolute;
  left: 50%; bottom: 10px;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
}
#battle-controls button {
  padding: 3px 10px;
  font-size: 12px;
  background: rgba(15, 18, 30, 0.75);
}
#speed-buttons button.active { border-color: var(--accent); color: var(--accent); }

#info-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#tab-bar {
  display: flex;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 8px 16px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel {
  display: none;
  padding: 12px 16px;
  overflow-y: auto;
  flex: 1;
  font-size: 14px;
  line-height: 1.7;
}
.tab-panel.active { display: block; }

#objective-text { margin-bottom: 8px; }
#bonus-goal { margin-bottom: 8px; }
.bonus { color: var(--accent); font-size: 13px; }
.bonus.done { color: var(--green); }

#enemy-intel table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  margin: 6px 0;
}
#enemy-intel th, #enemy-intel td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
}
#enemy-intel th { color: var(--muted); font-weight: normal; background: var(--panel); }
.intel-title { font-size: 13px; color: var(--muted); margin-top: 4px; }
.hero-stats { font-size: 13px; color: var(--green); margin-top: 4px; }

.hint-item {
  background: rgba(255, 184, 77, 0.08);
  border-left: 3px solid var(--accent);
  padding: 6px 10px;
  margin: 6px 0;
  font-size: 13px;
  border-radius: 0 6px 6px 0;
}

.syntax-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.sc-title { color: var(--accent); font-weight: bold; margin-bottom: 6px; font-size: 14px; }
.syntax-card pre {
  background: #0d0f17;
  padding: 8px 10px;
  border-radius: 6px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  overflow-x: auto;
  color: #9ecbff;
  white-space: pre-wrap;
}
.sc-note { color: var(--muted); font-size: 13px; margin-top: 6px; }

#battle-log { font-size: 13px; font-family: Consolas, "Courier New", monospace; }
.log-line { padding: 1px 0; color: var(--muted); }
.log-line.win { color: var(--accent); font-weight: bold; }
.log-line.lose { color: var(--red); font-weight: bold; }

/* ---------- 右侧 ---------- */
#editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
#run-status { font-size: 13px; color: var(--muted); }

#editor-host {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #282c34;
}
#editor-host .cm-editor { height: 100%; }
#editor-fallback {
  width: 100%; height: 100%;
  background: #282c34;
  color: #dcdfe4;
  border: none;
  resize: none;
  outline: none;
  padding: 12px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 14px;
  line-height: 1.5;
  tab-size: 4;
}

#console {
  height: 170px;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  background: #0d0f17;
}
#console-title {
  font-size: 12px;
  color: var(--muted);
  padding: 4px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
#console-body {
  flex: 1;
  overflow-y: auto;
  padding: 6px 12px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.6;
}
.console-line.sys { color: var(--muted); }
.console-line.out { color: #9ecbff; }
.console-line.err { color: var(--red); white-space: pre-wrap; }

/* ---------- 弹窗 ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  max-width: 640px;
  width: min(92vw, 640px);
  max-height: 84vh;
  overflow-y: auto;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
}
.modal-title { font-size: 20px; color: var(--accent); margin-bottom: 12px; }
.modal-body { font-size: 14px; line-height: 1.8; }
.modal-body pre {
  background: #0d0f17;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-family: Consolas, "Courier New", monospace;
  overflow-x: auto;
  color: #9ecbff;
  margin: 8px 0;
  white-space: pre-wrap;
}
.modal-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
  justify-content: flex-end;
}
.modal-buttons button { max-width: 100%; }
.big-stars { font-size: 42px; text-align: center; color: var(--accent); letter-spacing: 8px; }
.reward { color: var(--green); }
.muted { color: var(--muted); font-size: 13px; }

/* 关卡选择 */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}
.level-card {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.1s;
}
.level-card:hover:not(.locked) { transform: translateY(-2px); border-color: var(--accent); }
.level-card.locked { opacity: 0.45; cursor: not-allowed; }
.level-card.current { border-color: var(--green); }
.lc-order { font-size: 22px; font-weight: bold; color: var(--accent); }
.lc-title { font-size: 14px; margin: 4px 0 2px; }
.lc-concept { font-size: 11px; color: var(--muted); }
.lc-stars { color: var(--accent); font-size: 13px; min-height: 18px; }

/* 商店 */
.shop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  background: var(--panel2);
}
.shop-info { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.shop-info b { font-size: 14px; }
.shop-row button { white-space: nowrap; }

/* 无尽挑战 */
.endless-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0;
}
.endless-stat {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
}
.endless-stat b { display: block; color: var(--accent); font-size: 20px; }
.endless-rules {
  border-left: 3px solid #7c5cff;
  background: rgba(124, 92, 255, 0.08);
  padding: 8px 10px;
  margin: 10px 0;
}
.endless-upgrade { color: #c4b8ff; }
.skill-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  margin-top: 10px;
}
.skill-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px;
  background: var(--panel2);
}
.skill-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.skill-head b { color: var(--accent); }
.skill-head span { color: #9fd6ff; font-size: 12px; white-space: nowrap; }
.skill-card code {
  display: block;
  margin: 7px 0;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.22);
  color: #bce6c5;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.skill-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }

/* 无尽排行榜 */
.leaderboard-submit {
  display: grid;
  gap: 7px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel2);
}
.leaderboard-submit label { color: var(--accent); font-weight: bold; }
.leaderboard-submit input {
  width: 100%;
  padding: 9px 11px;
  color: var(--text);
  background: #0d0f17;
  border: 1px solid var(--border);
  border-radius: 7px;
  outline: none;
  font: inherit;
}
.leaderboard-submit input:focus { border-color: var(--accent); }
.leaderboard-status { min-height: 22px; color: var(--muted); }
.leaderboard-status.success { color: var(--green); }
.leaderboard-status.error { color: var(--red); }
.leaderboard-table-wrap { overflow-x: auto; }
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}
.leaderboard-table th,
.leaderboard-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
}
.leaderboard-table th { color: var(--accent); background: var(--panel2); }
.leaderboard-table td:first-child { width: 58px; text-align: center; }
.leaderboard-table th:nth-child(3),
.leaderboard-table th:nth-child(4),
.leaderboard-table td:nth-child(3),
.leaderboard-table td:nth-child(4) { text-align: right; white-space: nowrap; }
.leaderboard-empty { padding: 24px 8px; color: var(--muted); text-align: center; }

/* 存档与角色选择 */
.save-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel2);
}
.save-hero img { width: 82px; height: 82px; object-fit: contain; }
.save-hero b, .save-hero span { display: block; }
.save-hero b { color: var(--accent); font-size: 18px; }
.save-hero span { color: var(--muted); font-size: 12px; margin-top: 4px; }
.character-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}
button.character-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 210px;
  padding: 10px;
  border-radius: 10px;
  background: var(--panel2);
}
.character-card img { width: 142px; height: 142px; object-fit: contain; }
.character-card b { color: var(--accent); font-size: 15px; }
.character-card span { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- 加载遮罩 / file:// 警告 ---------- */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 22, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 200;
  font-size: 15px;
}
#loading-overlay[hidden] { display: none; }
.spinner {
  width: 42px; height: 42px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#file-warning {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 300;
  padding: 60px 24px;
  text-align: center;
  line-height: 2;
}
#file-warning pre {
  display: inline-block;
  background: #0d0f17;
  padding: 10px 24px;
  border-radius: 8px;
  color: var(--accent);
  font-size: 16px;
  margin: 12px 0;
}
#file-warning h2 { color: var(--accent); margin-bottom: 12px; }

/* 窄屏:上下布局 */
@media (max-width: 900px) {
  html, body { overflow: auto; }
  main { flex-direction: column; height: auto; }
  #left-pane, #right-pane { min-width: 0; border-right: none; }
  #editor-host { min-height: 300px; }
  #info-area { min-height: 260px; }
  .skill-list { grid-template-columns: 1fr; }
}
