:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #1c232d;
  --border: #2a3547;
  --accent: #4a9eff;
  --red: #ff5544;
  --gold: #ffaa44;
  --text: #dce3ec;
  --dim: #8b98a9;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13px;
}

#toolbar {
  height: 46px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-wrap: nowrap;
  overflow-x: auto;
}

.tb-group { display: flex; align-items: center; gap: 6px; }
.tb-right { margin-left: auto; }

.tb-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 11px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.tb-btn:hover:not(:disabled) { border-color: var(--accent); }
.tb-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.tb-btn.primary { background: #1d4ed8; border-color: #1d4ed8; }
.tb-btn.primary:hover:not(:disabled) { background: #2563eb; }

.tb-sel {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
}

.tb-label { color: var(--dim); font-size: 12px; white-space: nowrap; }
.tb-val { color: var(--accent); min-width: 22px; text-align: center; font-weight: 600; }
input[type="range"] { width: 110px; accent-color: var(--accent); }

#main {
  display: flex;
  height: calc(100% - 46px);
}

#left {
  width: 300px;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border-right: 1px solid var(--border);
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--dim);
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}

.stat-chip {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1px 7px;
  font-size: 11px;
  color: var(--text);
}
.stat-chip.bad { color: var(--red); border-color: var(--red); }
.stat-chip.good { color: #57c785; border-color: #57c785; }

#scriptArea {
  flex: 1;
  background: #0b0f14;
  border: none;
  outline: none;
  color: #b7c4d4;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  padding: 10px;
  resize: none;
  tab-size: 2;
}

.hint {
  padding: 7px 10px;
  font-size: 11px;
  color: var(--dim);
  border-top: 1px solid var(--border);
  line-height: 1.5;
}

#center {
  flex: 1;
  position: relative;
  min-width: 0;
}

#preview {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#particleCount {
  position: absolute;
  top: 8px;
  left: 10px;
  background: rgba(13, 17, 23, 0.75);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px 9px;
  font-size: 11px;
  color: var(--dim);
}

#flash {
  display: none;
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg2);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 6px 16px;
  font-size: 12px;
  z-index: 5;
  max-width: 80%;
}
#flash.err { border-color: var(--red); color: var(--red); }
#flash.ok { border-color: #57c785; color: #57c785; }

#right {
  width: 260px;
  min-width: 210px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

.panel {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.panel .panel-head { background: transparent; }

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 12px;
  font-size: 12.5px;
  color: var(--dim);
  border-bottom: 1px solid rgba(42, 53, 71, 0.5);
}
.stat-row:last-child { border-bottom: none; }
.stat-row b { color: var(--text); font-variant-numeric: tabular-nums; }
.stat-row b.hit { color: #57c785; }
.stat-row b.miss { color: var(--red); }

#statusCard { padding: 6px; min-height: 70px; }
.status-empty {
  text-align: center;
  color: var(--dim);
  font-size: 12px;
  padding: 14px 6px;
  line-height: 1.8;
}
.status-empty span { font-size: 11px; }
.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  margin-bottom: 5px;
  background: rgba(13, 17, 23, 0.5);
  border-left: 3px solid #fff;
  border-radius: 6px;
  font-size: 12.5px;
}
.status-icon { font-size: 14px; }
.status-name { font-weight: 600; }
.status-stack {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 6px;
  font-size: 11px;
  color: var(--gold);
}
.status-time { margin-left: auto; color: var(--dim); font-variant-numeric: tabular-nums; }

.tips ul {
  list-style: none;
  padding: 8px 12px;
  font-size: 11.5px;
  color: var(--dim);
  line-height: 1.9;
}
.tips li::before { content: "· "; color: var(--accent); }

#modalOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 50;
  align-items: center;
  justify-content: center;
}

#modal {
  width: 480px;
  max-width: 92vw;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
#modal h3 { font-size: 14px; margin-bottom: 10px; }
#modal textarea {
  width: 100%;
  height: 220px;
  background: #0b0f14;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  padding: 8px;
  resize: vertical;
  outline: none;
}
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

@media (max-width: 900px) {
  html, body { height: auto; overflow: auto; }
  #toolbar { flex-wrap: wrap; height: auto; padding: 8px 10px; row-gap: 8px; }
  #main { flex-direction: column; height: auto; }
  #left { width: 100%; min-width: 0; height: 170px; }
  #center { height: 52vh; min-height: 260px; flex: none; }
  #right { width: 100%; min-width: 0; border-left: none; border-top: 1px solid var(--border); }
  .tb-btn { min-height: 34px; min-width: 44px; }
  .tb-sel { min-height: 32px; }
  input[type="range"] { flex: 1; min-width: 60px; max-width: 140px; }
  #baseDamage { width: auto; }
  .hint { display: none; }
}
