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

:root {
  --bg: #12101c;
  --panel: #1b1828;
  --card: #241f36;
  --line: #37304e;
  --text: #e8e4f4;
  --muted: #9a92b8;
  --accent: #ff5e8a;
  --accent2: #5ec8ff;
  --ok: #5eff9c;
}

html, body { height: 100%; }
body {
  background: var(--bg);
  background-image: radial-gradient(rgba(255,255,255,0.03) 1px, transparent 1.5px);
  background-size: 18px 18px;
  color: var(--text);
  font-family: "M PLUS Rounded 1c", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
}

/* ---------- header ---------- */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 16px; letter-spacing: 0.5px; }
.brand strong { color: var(--accent); font-family: "Mochiy Pop One", "M PLUS Rounded 1c", sans-serif; font-weight: 400; }

#tabs { display: flex; gap: 6px; flex: 1; }
.tab {
  padding: 8px 18px;
  background: none;
  border: 2px solid transparent;
  border-radius: 20px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}
.tab:hover { color: var(--text); background: var(--card); transform: translateY(-1px); }
.tab.active { color: #fff; background: var(--accent); border-color: rgba(255,255,255,0.25); box-shadow: 0 3px 0 rgba(0,0,0,0.35); }

.actions { display: flex; align-items: center; gap: 10px; }
#dirty-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: transparent;
}
#dirty-dot.on { background: #ffb84d; box-shadow: 0 0 8px #ffb84d; }

.btn {
  display: inline-block;
  padding: 8px 16px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, transform 0.12s;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; box-shadow: 0 3px 0 rgba(0,0,0,0.35); }
.btn.primary:hover { filter: brightness(1.12); }
.btn.primary:active { transform: translateY(2px); box-shadow: none; }
.btn.ghost { background: none; }
.btn.danger { color: #ff7d7d; }
.btn.danger:hover { border-color: #ff7d7d; }
.btn.small { padding: 3px 9px; font-size: 12px; border-radius: 6px; }

/* ---------- panels ---------- */
main { padding: 22px; max-width: 1280px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
h2 { font-size: 18px; font-weight: 600; }
.hint { color: var(--muted); margin-bottom: 14px; }
.hint code { background: var(--card); padding: 1px 6px; border-radius: 4px; }
.hint a { color: var(--accent2); }
.section-gap { margin-top: 22px; }
.swatch { flex: 0 0 44px; padding: 2px; height: 36px; cursor: pointer; }
.empty-note { color: var(--muted); padding: 30px; text-align: center; }

/* ---------- forms ---------- */
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 2; }
.row > select { flex: 1; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
}
.form-grid .wide { grid-column: 1 / -1; }

/* ---------- characters ---------- */
#char-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.char-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.char-card .card-head { display: flex; justify-content: space-between; align-items: center; }
.char-card .char-id { color: var(--muted); font-family: Consolas, monospace; font-size: 12px; }
.sprite-row { display: flex; gap: 6px; align-items: center; }
.sprite-row input { flex: 1; }
.sprite-row select { flex: 1.4; }
.sprite-thumb { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); }

/* ---------- scenes ---------- */
.scenes-layout { display: flex; gap: 18px; align-items: flex-start; }
#scene-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  position: sticky;
  top: 70px;
}
#scene-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
#scene-list li {
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#scene-list li:hover { background: var(--card); color: var(--text); }
#scene-list li.active { background: var(--card); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
#scene-list .start-star { color: #ffb84d; font-size: 12px; }

#scene-editor { flex: 1; min-width: 0; }
.scene-meta {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 16px;
}
.scene-meta .wide { grid-column: 1 / -1; }
.scene-toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }

/* step cards */
#step-list { display: flex; flex-direction: column; gap: 10px; }
.step-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  gap: 12px;
}
.step-card .step-body { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.step-card .step-fields { display: flex; gap: 8px; flex-wrap: wrap; }
.step-card .step-fields label { min-width: 120px; flex: 1; }
.step-card .step-fields label.grow { flex: 100%; }
.step-card textarea { min-height: 54px; resize: vertical; }
.step-tag {
  align-self: flex-start;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 3px 11px;
  border-radius: 20px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--accent2);
  white-space: nowrap;
  transform: skew(-6deg);
}
.step-tag.t-dialogue { color: var(--accent); }
.step-tag.t-choice { color: #ffb84d; }
.step-tag.t-goto, .step-tag.t-branch, .step-tag.t-end { color: var(--ok); }
.step-ctrl { display: flex; flex-direction: column; gap: 4px; }
.step-num { color: var(--muted); font-family: Consolas, monospace; font-size: 12px; width: 26px; text-align: right; padding-top: 4px; }

.opt-row {
  display: flex;
  gap: 6px;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
}
.opt-row input, .opt-row select { padding: 5px 8px; font-size: 13px; }
.opt-row .opt-text { flex: 3; }
.opt-row .opt-goto { flex: 1.4; }
.opt-row .opt-flag, .opt-row .opt-val { flex: 1; }

.add-step-bar {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 10px 14px;
}
.add-step-bar select { max-width: 220px; }

/* ---------- assets ---------- */
#asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.asset-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.asset-card .thumb {
  height: 110px;
  background: repeating-conic-gradient(#1d1930 0% 25%, #16131f 0% 50%) 0 / 20px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
}
.asset-card .thumb img { width: 100%; height: 100%; object-fit: contain; }
.asset-card .meta { padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }
.asset-card .fname { font-size: 12px; word-break: break-all; color: var(--text); }
.asset-card .fsize { font-size: 11px; color: var(--muted); }
.asset-card .aactions { display: flex; gap: 6px; }
.upload-label { cursor: pointer; }

/* ---------- json ---------- */
#json-editor {
  width: 100%;
  height: calc(100vh - 220px);
  font-family: Consolas, "Cascadia Code", monospace;
  font-size: 13px;
  line-height: 1.5;
  background: var(--panel);
  resize: vertical;
}

/* ---------- toast ---------- */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 22px;
  border-radius: 30px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  transition: transform 0.25s ease;
  z-index: 200;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.ok { border-color: var(--ok); }
#toast.err { border-color: #ff7d7d; }
