:root {
  --bg: #0f131a;
  --panel: #161b24;
  --panel2: #1d2430;
  --line: #2a3343;
  --ink: #e8eef7;
  --ink-dim: #93a1b5;
  --accent: #7bc043;
  --accent-ink: #0f1a0c;
  --warn-bg: #3a2a12;
  --warn-line: #6b4f1e;
  --warn-ink: #f0d69a;
  --radius: 10px;
  --ui: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
body { background: var(--bg); color: var(--ink); font-family: var(--ui); font-size: 14px; line-height: 1.6; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.app { display: grid; grid-template-columns: 400px 1fr; min-height: 100vh; }

.side {
  background: var(--panel); border-right: 1px solid var(--line);
  height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
}
.brand { padding: 20px 20px 0; }
.brand h1 { font-size: 17px; font-weight: 800; letter-spacing: .02em; }
.brand p { font-size: 12px; color: var(--ink-dim); margin-top: 2px; }

.step { padding: 18px 20px 4px; border-top: 1px solid transparent; }
.step + .step { border-top-color: var(--line); margin-top: 14px; }
.step__head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 14px; font-weight: 700; }
.step__num {
  width: 22px; height: 22px; flex: none; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 800; font-size: 12px; display: grid; place-items: center;
}
.step--more summary { cursor: pointer; list-style: none; }
.step--more summary::-webkit-details-marker { display: none; }
.step--more summary::after { content: "▾"; margin-left: auto; color: var(--ink-dim); transition: transform .15s; }
.step--more:not([open]) summary::after { transform: rotate(-90deg); }
.step--more:not([open]) summary { margin-bottom: 0; }
.step--more[open] { padding-bottom: 8px; }

.hint { font-size: 12px; color: var(--ink-dim); margin: 0 0 10px; }
.drop + .hint { margin-top: 8px; }

.drop {
  display: block; border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 22px 14px; text-align: center; cursor: pointer; background: var(--panel2);
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over, .drop:focus-within { border-color: var(--accent); background: #1f2a1c; }
.drop b { display: block; margin-bottom: 3px; }
.drop span { font-size: 12px; color: var(--ink-dim); }

label.f { display: block; margin-bottom: 12px; }
label.f > span:first-child { display: block; font-size: 12px; color: var(--ink-dim); margin-bottom: 4px; }
input[type=text], textarea, select {
  width: 100%; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px;
}
input[type=text]:focus, textarea:focus, select:focus { border-color: var(--accent); outline: none; }
textarea { resize: vertical; min-height: 130px; line-height: 1.7; }

.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.slider { display: flex; align-items: center; gap: 10px; }
input[type=range] { flex: 1; accent-color: var(--accent); }
.val { width: 48px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-dim); font-size: 12px; }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.sw { width: 38px; height: 38px; border-radius: 9px; border: 2px solid transparent; cursor: pointer; position: relative; }
.sw.on { border-color: #fff; box-shadow: 0 0 0 2px #000 inset; }
.sw--custom { display: grid; place-items: center; background: var(--panel2); border: 1px dashed var(--line); font-size: 16px; color: var(--ink-dim); }
.sw--custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }

.bggrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.bgcell {
  border: 2px solid transparent; border-radius: 8px; overflow: hidden; cursor: pointer;
  background: var(--panel2); display: block; position: relative; padding: 0;
}
.bgcell canvas { display: block; width: 100%; height: 52px; }
.bgcell em {
  position: absolute; inset: auto 0 0 0; font-style: normal; font-size: 10px; padding: 3px 4px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .85)); text-align: center; line-height: 1.3;
}
.bgcell.on { border-color: var(--accent); }

.btn {
  display: block; width: 100%; background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 9px; padding: 12px; font-weight: 800; cursor: pointer; transition: filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn--ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); font-weight: 600; padding: 9px; }
.btn--ghost:hover { border-color: var(--accent); filter: none; }
.btn--danger:hover { border-color: #d0605a; color: #f1a39e; }
.btnrow { display: flex; gap: 8px; margin: 8px 0 12px; }
.btnrow .btn { flex: 1; }
#refit { margin-bottom: 14px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chips--center { justify-content: center; margin-bottom: 14px; }
.tab { display: inline-flex; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); }
.tab.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tab__main { background: none; border: 0; padding: 5px 4px 5px 12px; cursor: pointer; font-size: 13px; border-radius: 999px; }
.tab__main:last-child { padding-right: 12px; }
.tab.on .tab__main { font-weight: 700; }
.tab__code { margin-left: 6px; opacity: .6; font-size: 11px; font-weight: 500; }
.tab__x { background: none; border: 0; padding: 0 10px 0 6px; cursor: pointer; opacity: .6; border-radius: 999px; }
.tab__x:hover { opacity: 1; }
.chip-add {
  background: var(--panel2); border: 1px dashed var(--line); border-radius: 999px;
  padding: 5px 12px; cursor: pointer; font-size: 13px; color: var(--ink-dim); width: auto;
}

.warn {
  background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink);
  border-radius: 8px; padding: 9px 11px; font-size: 12px; margin: 0 0 12px;
}
.warn:empty { display: none; }

.savebar {
  position: sticky; bottom: 0; margin-top: auto; padding: 14px 20px 16px;
  background: linear-gradient(to bottom, rgba(22, 27, 36, .85), var(--panel) 30%);
  border-top: 1px solid var(--line); display: grid; gap: 8px;
}

.main {
  padding: 28px; display: flex; justify-content: center; align-items: flex-start;
  background: radial-gradient(circle at 50% 0%, #1a2130, #0b0e14 70%);
}
.preview { position: sticky; top: 28px; width: 100%; max-width: 1100px; display: flex; flex-direction: column; align-items: center; }
#stage {
  display: block; max-width: 100%; max-height: calc(100vh - 170px); width: auto; height: auto;
  border-radius: 12px; cursor: grab; touch-action: none; box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}
#stage.dragging { cursor: grabbing; }
.stagenote { font-size: 12px; color: var(--ink-dim); text-align: center; margin-top: 10px; }
.stagenote + .stagenote { margin-top: 2px; }
kbd { background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; font-size: 11px; font-family: inherit; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10;
  display: flex; align-items: center; gap: 14px; padding: 10px 16px; border-radius: 10px;
  background: #e8eef7; color: #10141c; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); font-size: 13px;
}
.toast button { background: none; border: 0; color: #2f6f1e; font-weight: 700; cursor: pointer; }

@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; }
  .main {
    order: -1; position: sticky; top: 0; z-index: 5; padding: 10px 12px 8px;
    border-bottom: 1px solid var(--line); background: #0b0e14;
  }
  .preview { position: static; }
  .chips--center { margin-bottom: 8px; }
  #stage { max-height: 38vh; border-radius: 8px; }
  .stagenote { display: none; }
  .side { height: auto; overflow: visible; border-right: 0; }
  .savebar { position: sticky; bottom: 0; }
}
