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

:root {
  --bg: #0f1320;
  --panel: #1a2034;
  --panel-2: #232a44;
  --border: #2d3458;
  --text: #e8ecf5;
  --dim: #8a93b0;
  --accent: #4ade80;
  --gold: #fbbf24;
  --cyan: #22d3ee;
  --red: #f87171;
  --orange: #fb923c;
}

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

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 12px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 22px;
  color: var(--accent);
  letter-spacing: 2px;
}

#header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

#player-name-tag {
  color: var(--cyan);
  font-size: 14px;
  padding: 4px 10px;
  background: var(--panel-2);
  border-radius: 12px;
}

.hidden { display: none !important; }

.mini-btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}
.mini-btn:hover { background: var(--border); }
.mini-btn.primary {
  background: var(--accent);
  color: #062b14;
  border-color: var(--accent);
  font-weight: 600;
}
.mini-btn.primary:hover { filter: brightness(1.1); }

main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 12px;
  padding: 12px 0;
  overflow: hidden;
}

#game-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

#game-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #050810;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
}

#game {
  max-width: 100%;
  max-height: 100%;
  display: block;
  image-rendering: pixelated;
  touch-action: pan-y;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(2px);
}

.overlay-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 32px;
  text-align: center;
  min-width: 280px;
}

.overlay-card h2 {
  color: var(--accent);
  margin-bottom: 8px;
  font-size: 28px;
}

.overlay-card p {
  color: var(--dim);
  margin-bottom: 16px;
  font-size: 14px;
}

#overlay-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

#overlay-buttons button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
  min-width: 200px;
  transition: background 0.15s;
}
#overlay-buttons button:hover { background: var(--border); }
#overlay-buttons button.primary {
  background: var(--accent);
  color: #062b14;
  font-weight: 600;
  border-color: var(--accent);
}
#overlay-buttons button.primary:hover { filter: brightness(1.1); }

.diff-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin: 8px 0;
}
.diff-row button {
  min-width: 80px !important;
  padding: 8px 14px !important;
  font-size: 13px !important;
}
.diff-row button.active {
  background: var(--cyan) !important;
  color: #052429 !important;
  border-color: var(--cyan) !important;
}

#hud {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  background: var(--panel);
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 0;
}

.hud-label {
  font-size: 11px;
  color: var(--dim);
}

.hud-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-top: 2px;
}

#hud-effect { font-size: 13px; color: var(--orange); }

#touch-pad {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.touch-row { display: flex; gap: 6px; }

.touch-btn {
  width: 56px;
  height: 56px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 24px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.touch-btn:active { background: var(--accent); color: #062b14; }

#leaderboard-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#leaderboard-section h2 {
  font-size: 16px;
  color: var(--gold);
  margin-bottom: 8px;
}

#lb-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}

.lb-tab {
  background: var(--panel-2);
  color: var(--dim);
  border: 1px solid var(--border);
  padding: 6px 4px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.lb-tab.active {
  background: var(--gold);
  color: #2a1d00;
  border-color: var(--gold);
  font-weight: 600;
}

#leaderboard {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  font-size: 13px;
}

#leaderboard li {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

#leaderboard li .rank {
  color: var(--dim);
  text-align: right;
}
#leaderboard li:nth-child(1) .rank { color: var(--gold); font-weight: 700; }
#leaderboard li:nth-child(2) .rank { color: #c0c0c0; font-weight: 700; }
#leaderboard li:nth-child(3) .rank { color: #cd7f32; font-weight: 710; }

#leaderboard li .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#leaderboard li .score {
  color: var(--accent);
  font-weight: 600;
}

#leaderboard li .diff-tag {
  font-size: 10px;
  padding: 1px 4px;
  border-radius: 3px;
  margin-left: 4px;
}
.diff-tag.easy { background: #143a1c; color: #4ade80; }
.diff-tag.normal { background: #3a3014; color: #fbbf24; }
.diff-tag.hard { background: #3a1414; color: #f87171; }

#leaderboard li.me {
  background: rgba(74, 222, 128, 0.1);
  border-radius: 4px;
}

#leaderboard .empty {
  color: var(--dim);
  text-align: center;
  padding: 20px 0;
}

#btn-refresh-lb {
  margin-top: 8px;
  width: 100%;
}

footer {
  padding: 8px 0;
  text-align: center;
  font-size: 12px;
  color: var(--dim);
  border-top: 1px solid var(--border);
}

/* 弹窗 */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(2px);
  z-index: 100;
}

.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  min-width: 320px;
  max-width: 90vw;
}

.modal-card h3 {
  color: var(--accent);
  margin-bottom: 8px;
  font-size: 20px;
}

.modal-card p {
  color: var(--dim);
  font-size: 13px;
  margin-bottom: 12px;
}

#name-input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: 6px;
  font-size: 15px;
  margin-bottom: 16px;
}
#name-input:focus { outline: none; border-color: var(--accent); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#submit-summary {
  margin: 12px 0 16px;
  font-size: 15px;
}
#submit-summary .row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
}
#submit-summary .row .label { color: var(--dim); }
#submit-summary .row .val { color: var(--text); font-weight: 600; }
#submit-summary .row.new-best .val { color: var(--gold); }

/* 移动端 */
@media (max-width: 720px) {
  html, body { overflow: auto; height: auto; }
  #app { padding: 4px 6px; height: auto; min-height: 100vh; overflow: visible; }
  header { padding: 4px 2px; }
  header h1 { font-size: 16px; }
  #header-right { gap: 6px; }
  #player-name-tag { font-size: 12px; padding: 3px 8px; }
  .mini-btn { padding: 4px 10px; font-size: 12px; }
  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    overflow: visible;
    gap: 6px;
    padding: 6px 0;
  }
  #game-section { gap: 6px; }
  #game-wrapper { height: 60vh; min-height: 320px; }
  #hud {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 6px;
  }
  .hud-item { padding: 2px 0; }
  .hud-label { font-size: 10px; }
  .hud-value { font-size: 14px; }
  #hud-effect { font-size: 11px; }
  #touch-pad { display: flex; gap: 6px; margin-top: 2px; }
  .touch-row { gap: 6px; }
  .touch-btn {
    width: 96px;
    height: 96px;
    font-size: 36px;
  }
  #leaderboard-section { max-height: none; height: auto; padding: 10px; }
  #leaderboard-section h2 { font-size: 14px; }
  #lb-tabs { gap: 3px; margin-bottom: 6px; }
  .lb-tab { padding: 5px 2px; font-size: 11px; }
  #leaderboard { overflow: visible; }
  #leaderboard li { font-size: 12px; padding: 5px 2px; }
  footer { display: none; }
}
