/* irreg Asset Studio: dark, big touch targets, the canvas takes the room. */
:root {
  --bg: #14171f;
  --panel: #1c2029;
  --well: #252a35;
  --line: #333a48;
  --text: #e6e8ee;
  --dim: #8b93a5;
  --accent: #7aa2ff;
  --good: #69db7c;
  --warn: #ffd43b;
  --bad: #ff6b6b;
  --tap: 46px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button { font: inherit; color: inherit; }
input, select { font: inherit; }

.btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--well);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn.icon { padding: 0; font-size: 20px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0b1020; font-weight: 600; }
.btn.big { min-height: 56px; padding: 0 22px; font-size: 17px; }
.btn.on { background: #2f3b57; border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn[disabled] { opacity: 0.4; }
.field {
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--well);
  color: var(--text);
  -webkit-user-select: text;
  user-select: text;
}
.dim { color: var(--dim); font-size: 13px; }
.grow { flex: 1; }

#top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
#modelsBtn { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; }
#modelName { overflow: hidden; text-overflow: ellipsis; }
#modes { display: flex; background: var(--well); border-radius: 12px; padding: 3px; gap: 2px; }
#modes button {
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
}
#modes button.on { background: var(--accent); color: #0b1020; font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--dim); display: inline-block; }
.dot.on { background: var(--good); }
.dot.busy { background: var(--warn); }
.dot.bad { background: var(--bad); }

main {
  display: grid;
  grid-template-columns: auto 1fr 280px;
  min-height: 0;
}
#tools {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}
#tools .btn { width: 56px; height: 56px; padding: 0; flex-direction: column; gap: 0; font-size: 22px; }
#tools .btn small { font-size: 10px; color: var(--dim); }
#tools .btn.on small { color: var(--text); }
#tools hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 2px 0; }

#view { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#gl, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
#overlay { pointer-events: none; }
#hint {
  position: absolute; left: 12px; bottom: 10px; right: 12px;
  color: var(--dim); font-size: 13px; pointer-events: none; text-shadow: 0 1px 2px #000;
}
#empty {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; background: var(--bg);
}
#empty[hidden] { display: none; }

#panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#panel h3 { margin: 4px 0 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--dim); }
#panel label, dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--dim); }
#panel label.row, dialog label.row { flex-direction: row; align-items: center; gap: 8px; }
label.check { flex-direction: row !important; align-items: center; gap: 10px !important; color: var(--text) !important; font-size: 14px !important; }
label.check input { width: 22px; height: 22px; }
.rowbtns { display: flex; flex-wrap: wrap; gap: 6px; }
.rowbtns .btn { flex: 1; }
.movepad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.movepad .btn { font-size: 20px; }
.size3 { display: flex; flex-direction: column; gap: 6px; }
.size3 > label { display: grid !important; grid-template-columns: 74px 1fr; align-items: center; gap: 8px !important; }
.size3 > label { min-width: 0; }
.size3 input { width: 100%; min-width: 0; }

/* Steppers: big − / + around a number, easy with a finger. */
.stepper { display: grid; grid-template-columns: var(--tap) 1fr var(--tap); gap: 4px; align-items: center; }
.stepper input { text-align: center; min-height: 40px; }
.stepper .btn { min-width: 0; }

.slider { display: grid; grid-template-columns: 26px 1fr 54px; align-items: center; gap: 8px; }
.slider b { font-size: 14px; text-align: center; }
.slider input[type=range] { width: 100%; height: 36px; }
.slider .num { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }

.bones { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.bones li {
  display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 10px;
  background: var(--well); border-radius: 10px; border: 1px solid transparent; cursor: pointer;
}
.bones li.on { border-color: var(--accent); background: #2a3550; }
.bones .sw { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.bones .depth { color: var(--dim); }
.bones .keyed { margin-left: auto; color: var(--warn); font-size: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  min-height: 40px; padding: 4px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--well); cursor: pointer; display: flex; flex-direction: column; align-items: center;
}
.chips button small { color: var(--dim); font-size: 11px; }
.chips button.on { border-color: var(--accent); background: #2a3550; }

#bottom { background: var(--panel); border-top: 1px solid var(--line); }
#palette { display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto; align-items: center; }
#palette .sw {
  flex: none; width: 40px; height: 40px; border-radius: 10px; border: 2px solid transparent; cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}
#palette .sw.on { border-color: #fff; transform: scale(1.06); }
#palette .add { flex: none; }
#palette input[type=color] { width: 0; height: 0; opacity: 0; position: absolute; }
body:not([data-mode=build]) #palette { display: none; }

#timeline { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
#timeline[hidden] { display: none; }
#track { position: relative; flex: 1; height: 44px; background: var(--well); border-radius: 10px; touch-action: none; cursor: pointer; }
#marks .m {
  position: absolute; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px;
  transform: rotate(45deg); background: var(--dim); border-radius: 2px; pointer-events: none;
}
#marks .m.sel { background: var(--warn); }
#head { position: absolute; top: 4px; bottom: 4px; width: 3px; margin-left: -1px; background: var(--accent); border-radius: 2px; pointer-events: none; }
#timeText { width: 56px; text-align: right; font-variant-numeric: tabular-nums; color: var(--dim); }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px;
  width: min(560px, 94vw); max-height: 88vh; padding: 16px; display: none; flex-direction: column; gap: 12px;
}
dialog[open] { display: flex; }
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.dlg-head h2 { margin: 0; font-size: 19px; }
.dlg-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; }
#modelList { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
#modelList li {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; min-height: 56px;
  background: var(--well); border-radius: 12px; cursor: pointer;
}
#modelList li:active { background: #2f3b57; }
#modelList .thumb { width: 44px; height: 44px; border-radius: 8px; background: #0e1016; flex: none; }
#modelList .what { flex: 1; min-width: 0; }
#modelList .what b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#modelList .state { font-size: 12px; color: var(--dim); }
#modelList .state.dirty { color: var(--warn); }
#modelList .state.clash { color: var(--bad); }
.pixel-row { display: flex; gap: 12px; align-items: flex-start; }
.pixel-row > div { flex: 1; display: flex; flex-direction: column; gap: 8px; }
#pixelPreview { width: 128px; height: 128px; image-rendering: pixelated; background: #0e1016; border-radius: 10px; }
.clash { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px; background: var(--well); border-radius: 10px; }
.clash b { flex: 1; }

#toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: #000c; padding: 10px 16px; border-radius: 12px; z-index: 10; max-width: 90vw;
}

/* ---- Colour picker (the same as irreg's Draw) ---- */
.cpop {
  position: fixed; left: 12px; bottom: 76px; z-index: 20; width: min(360px, calc(100vw - 24px)); max-height: calc(100vh - 160px);
  overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); display: flex; flex-direction: column; gap: 8px;
}
.cpop[hidden] { display: none; }
.cpop h4 { margin: 4px 0 0; font-size: 13px; color: var(--dim); font-weight: 600; }
.cpop .lhead2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cpop .crow { display: flex; gap: 8px; align-items: center; }
.cpop .cur { flex: none; width: 40px; height: 40px; border-radius: 10px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15); }
.cpop input[type=color] { flex: none; width: 52px; height: 40px; border: 1px solid var(--line); border-radius: 10px; background: none; padding: 2px; cursor: pointer; }
.cpop .mono { flex: 1; min-width: 0; font-family: ui-monospace, Menlo, Consolas, monospace; }
.cpop .hsl { display: grid; gap: 8px; }
.cpop .hsl label { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--dim); }
.cpop .hsl input[type=range] { flex: 1; -webkit-appearance: none; appearance: none; height: 16px; border-radius: 8px; border: 1px solid var(--line); margin: 0; }
.cpop .hsl input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; border-radius: 50%; background: #fff; border: 2px solid #0008; box-shadow: 0 1px 3px #0006; }
.cpop .hsl input[type=range]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 2px solid #0008; }
.cpop .harm { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cpop .harm div { display: flex; flex-direction: column; gap: 3px; }
.cpop .harm span { display: flex; gap: 3px; }
.cpop .harm button { flex: 1; height: 28px; border-radius: 6px; border: 1px solid var(--line); padding: 0; cursor: pointer; }
.cpop .harm small { font-size: 11px; color: var(--dim); text-align: center; white-space: nowrap; }
.cpop .sws { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; }
.cpop .sws button { aspect-ratio: 1; border-radius: 50%; border: 1px solid var(--line); padding: 0; cursor: pointer; }
.cpop .sws button.on { outline: 2px solid var(--text); outline-offset: 2px; }
.cpop .sws.rm button { opacity: 0.6; }
.cpop .mini { min-height: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--well); cursor: pointer; font-size: 12px; }
#palette .curcol { display: inline-block; width: 18px; height: 18px; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2); }
.keylist { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; overflow-y: auto; }
.keylist h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--dim); }
.keyrow { display: flex; gap: 10px; align-items: baseline; padding: 3px 0; font-size: 14px; }
.keyrow kbd { flex: none; min-width: 64px; padding: 2px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--well); font: 12px ui-monospace, Menlo, Consolas, monospace; text-align: center; }
#keysDlg { width: min(760px, 94vw); }

/* ---- Tools (map, balance, dialogue) share one layout ---- */
#toolTabs { display: flex; gap: 2px; background: var(--well); border-radius: 12px; padding: 3px; }
#toolTabs button {
  min-height: 40px; padding: 0 12px; border: 0; border-radius: 9px; background: transparent; cursor: pointer;
  display: flex; align-items: center; gap: 6px; font-size: 18px;
}
#toolTabs button span { font-size: 14px; }
#toolTabs button.on { background: #2f3b57; box-shadow: inset 0 0 0 1px var(--accent); }
body:not([data-tool=models]) .models-only { display: none !important; }
.toolpage { grid-row: 2 / 4; display: grid; grid-template-rows: 1fr auto; min-height: 0; position: relative; }
.toolpage[hidden] { display: none; }
.toolgrid { display: grid; grid-template-columns: auto 1fr 300px; min-height: 0; }
.rail {
  display: flex; flex-direction: column; gap: 6px; padding: 8px; background: var(--panel);
  border-right: 1px solid var(--line); overflow-y: auto;
}
.rail .btn { width: 56px; height: 56px; padding: 0; flex-direction: column; gap: 0; font-size: 22px; }
.rail .btn small { font-size: 10px; color: var(--dim); }
.rail .btn.on small { color: var(--text); }
.rail hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 2px 0; }
.view { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.view > canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.hint { position: absolute; left: 12px; bottom: 10px; right: 12px; color: var(--dim); font-size: 13px; pointer-events: none; text-shadow: 0 1px 2px #000; }
.panel {
  background: var(--panel); border-left: 1px solid var(--line); padding: 12px; overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column; gap: 10px;
}
.panel h3 { margin: 4px 0 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--dim); }
.panel label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--dim); }
.pal { display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto; background: var(--panel); border-top: 1px solid var(--line); }
.chip {
  flex: none; display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--well); cursor: pointer; white-space: nowrap;
}
.chip.on { border-color: var(--accent); background: #2a3550; }
.chip small { color: var(--dim); }
.chip .sq { width: 20px; height: 20px; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15); }
.chip .dot { width: 14px; height: 14px; }
.colorfield { padding: 2px; height: 44px; }
.emptybox {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg); text-align: center; padding: 20px;
}
.emptybox[hidden] { display: none; }

/* ---- Balance sandbox ---- */
.balgrid { display: grid; grid-template-columns: 340px 1fr; min-height: 0; grid-row: 1 / 3; }
.balform { border-left: 0; border-right: 1px solid var(--line); }
.balform .btn.big { margin-top: 6px; }
.results { overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.emptynote { margin: auto; text-align: center; max-width: 420px; }
.runcard { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.runcard.latest { border-color: var(--accent); }
.runcard header { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.runcard header b { font-size: 17px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.stat { background: var(--well); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 2px; }
.stat small { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--dim); font-size: 12px; }
.stat.good b { color: var(--good); }
.stat.warn b { color: var(--warn); }
.stat.bad b { color: var(--bad); }

/* ---- Dialogue and quests ---- */
.dlggrid { display: grid; grid-template-columns: 240px 1fr 340px; min-height: 0; grid-row: 1 / 3; }
#dialogueTool[data-view=quests] .dlggrid { grid-template-columns: 240px 1fr; }
#dialogueTool[data-view=quests] .graph, #dialogueTool[data-view=quests] .dlgedit { display: none; }
#dialogueTool:not([data-view=quests]) .questpage { display: none; }
#dialogueTool[data-view=quests] .questpage { grid-column: 2; grid-row: 1; }
.dlgside { border-left: 0; border-right: 1px solid var(--line); }
.listrow {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; width: 100%;
  min-height: 48px; padding: 8px 10px; border-radius: 10px; border: 1px solid transparent; background: var(--well); cursor: pointer;
}
.listrow.on { border-color: var(--accent); background: #2a3550; }
.listrow small { color: var(--dim); }
.graph { position: relative; overflow: hidden; touch-action: none; background:
  radial-gradient(circle, #252a35 1px, transparent 1px) 0 0 / 24px 24px, var(--bg); cursor: grab; }
.plane { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.wires { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.wires path { fill: none; stroke: #5b6578; stroke-width: 2.5; }
.wires path.hot { stroke: var(--accent); stroke-width: 3; }
.node {
  position: absolute; width: 240px; background: var(--panel); border: 2px solid var(--line); border-radius: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35); cursor: pointer; user-select: none;
}
.node.on { border-color: var(--accent); }
.node.start { box-shadow: 0 0 0 3px rgba(105, 219, 124, 0.35), 0 4px 14px rgba(0, 0, 0, 0.35); }
.nhead { display: flex; justify-content: space-between; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--dim); }
.nhead b { color: var(--text); }
.ntext { padding: 8px 10px; font-size: 13px; max-height: 6.4em; overflow: hidden; }
.ndo { padding: 0 10px 6px; font-size: 11px; color: var(--warn); }
.nchoice { position: relative; padding: 6px 22px 6px 10px; border-top: 1px dashed var(--line); font-size: 12px; display: flex; flex-direction: column; }
.nchoice small { color: var(--dim); font-size: 11px; }
.port { position: absolute; right: -7px; top: 50%; width: 12px; height: 12px; margin-top: -6px; border-radius: 50%; background: var(--accent); }
.port.end { background: var(--dim); border-radius: 2px; }
.dlgedit textarea, .questpage textarea { min-height: 90px; padding: 10px 12px; resize: vertical; font: inherit; }
.choice { display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: 12px; background: var(--well); }
.rules { display: flex; flex-direction: column; gap: 6px; }
.rule { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px; border-radius: 10px; background: var(--bg); }
.rule .field { width: auto; flex: 1; min-width: 120px; }
.rule .stepper { flex: 1; min-width: 150px; }
.questpage { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; max-width: 760px; }
.questpage h2 { margin: 0; }
.questpage label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--dim); }
.questpage h3 { margin: 6px 0 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--dim); }
.trydlg .trybody { overflow-y: auto; max-height: 55vh; display: flex; flex-direction: column; gap: 6px; }
.trydlg .say { margin: 0; padding: 8px 12px; border-radius: 12px; background: var(--well); }
.trydlg .say.me { background: #2a3550; align-self: flex-end; }
.tryopts { display: flex; flex-direction: column; gap: 6px; }
.tryopts .btn { justify-content: flex-start; white-space: normal; text-align: left; padding: 8px 12px; }

/* Portrait tablets and phones: the side panel becomes a strip under the view. */
@media (max-width: 900px) and (orientation: portrait), (max-width: 700px) {
  main { grid-template-columns: auto 1fr; grid-template-rows: 1fr auto; }
  #panel { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); max-height: 34vh; }
  #modes button { padding: 0 10px; }
  #linkText { display: none; }
  #toolTabs button span { display: none; }
  .toolgrid { grid-template-columns: auto 1fr; grid-template-rows: 1fr auto; }
  .toolgrid > .panel { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); max-height: 34vh; }
  .balgrid { grid-template-columns: 1fr; grid-template-rows: auto 1fr; overflow-y: auto; }
  .balform { border-right: 0; border-bottom: 1px solid var(--line); max-height: none; overflow: visible; }
  .results { overflow: visible; }
  .dlggrid { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .dlgside { max-height: 22vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .dlgedit { max-height: 38vh; border-left: 0; border-top: 1px solid var(--line); }
  #dialogueTool[data-view=quests] .dlggrid { grid-template-columns: 1fr; }
  #dialogueTool[data-view=quests] .questpage { grid-column: 1; grid-row: 2; }
}
