:root {
  color-scheme: dark;
  --bg: #101319;
  --panel: #171b22;
  --panel-2: #1d222b;
  --line: #2c3440;
  --text: #e8edf4;
  --muted: #929eae;
  --accent: #ef9f43;
  --accent-2: #ffc46f;
  --success: #80c995;
  --warning: #ffc46f;
  --danger: #e26969;
  --header: #14181f;
  --hover-bg: #242b35;
  --hover-line: #4b586a;
  --input-bg: #11151b;
  --selected-bg: #332719;
  --shadow: 0 18px 45px rgb(0 0 0 / 24%);
  font-family: Inter, "Noto Sans JP", "Yu Gothic UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: var(--bg); color: var(--text); font-size: 13px; }
button, input, select, textarea { font: inherit; }
button, .button { cursor: pointer; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: var(--header);
}
.app-brand { min-width: 0; display: flex; align-items: center; gap: 9px; }
.app-brand-icon { width: 28px; height: 28px; flex: 0 0 auto; border-radius: 7px; }
.app-header h1 { margin: 0; font-size: 16px; font-weight: 750; letter-spacing: .025em; }
.header-actions { display: flex; gap: 7px; }
.save-state { align-self: center; margin-right: 3px; color: var(--success); font-size: 10px; }
.save-state.unsaved { color: var(--warning); }
.workspace {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 280px;
  height: calc(100% - 56px);
}
.control-panel, .property-panel {
  min-height: 0;
  overflow-y: auto;
  background: var(--panel);
}
.control-panel { border-right: 1px solid var(--line); }
.property-panel { border-left: 1px solid var(--line); }
.panel-section { padding: 13px; border-bottom: 1px solid var(--line); }
.panel-section h2 {
  margin: 0 0 11px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .15em;
  text-transform: uppercase;
}
.section-heading { display: flex; align-items: center; justify-content: space-between; }
.section-heading span { color: var(--muted); font-size: 11px; }

.button, .mode-button, .icon-button {
  display: inline-grid;
  place-items: center;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text);
  text-decoration: none;
}
.button:hover, .mode-button:hover, .icon-button:hover { border-color: var(--hover-line); background: var(--hover-bg); }
.button:disabled, .icon-button:disabled { cursor: not-allowed; opacity: .45; }
.button.primary { border-color: #d88931; background: var(--accent); color: #24170a; font-weight: 800; }
.button.primary:hover { background: var(--accent-2); }
.button.subtle { background: transparent; }
.button.danger { border-color: var(--danger); background: transparent; color: #ffadad; }
.button.compact { min-height: 30px; padding: 0 10px; font-size: 12px; }
.wide { width: 100%; margin-bottom: 7px; }
.material-list { display: grid; gap: 6px; margin-top: 12px; }
.material-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}
.material-row img { width: 32px; height: 32px; border: 1px solid var(--hover-line); image-rendering: pixelated; object-fit: cover; }
.material-row span { display: grid; min-width: 0; gap: 2px; }
.material-row strong, .material-row small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.material-row strong { font-size: 11px; }
.material-row small { color: var(--muted); font-size: 9px; }
.material-row label { margin: 0; }
.material-reset { margin-top: 8px; }
.range-label { display: flex; align-items: center; justify-content: space-between; margin: 10px 1px 5px; }
.range-label output { color: var(--accent-2); font: 11px ui-monospace, monospace; }
input[type="range"] { height: 24px; padding: 0; accent-color: var(--accent); }
.shortcut-list { display: grid; gap: 7px; margin: 0; }
.shortcut-list div { display: grid; grid-template-columns: 105px minmax(0, 1fr); gap: 7px; align-items: baseline; }
.shortcut-list dt { color: var(--accent); font-size: 10px; font-weight: 700; }
.shortcut-list dd { margin: 0; color: var(--muted); font-size: 10px; }
.operation-guide { display: block; }
.operation-guide summary {
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  list-style-position: inside;
}
.operation-guide[open] summary { margin-bottom: 11px; }
.note { margin: 8px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }

input, select, textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--input-bg);
  color: var(--text);
}
input, select { height: 34px; padding: 0 8px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
textarea { padding: 8px; resize: vertical; line-height: 1.5; }
label { display: grid; gap: 5px; margin-bottom: 9px; color: #c5cdd8; font-size: 11px; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
fieldset:disabled { opacity: .45; }
.number-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }

.item-list { display: grid; gap: 5px; max-height: 230px; margin-top: 9px; overflow-y: auto; }
.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 5px;
  min-height: 36px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--input-bg);
  color: var(--text);
  text-align: left;
}
.item-row:hover { border-color: var(--hover-line); }
.item-row.active { border-color: var(--accent); background: var(--selected-bg); color: var(--accent-2); }
.item-row strong, .item-row small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-row small { color: var(--muted); }
.route-mark { color: var(--accent-2); font-size: 10px; }
.route-mark.escape { color: #ffadad; }

.map-stage { display: grid; grid-template-rows: 42px minmax(0, 1fr) 28px; min-width: 0; min-height: 0; }
.stage-toolbar, .status-bar { display: flex; align-items: center; justify-content: space-between; padding: 0 11px; background: var(--panel); }
.stage-toolbar { border-bottom: 1px solid var(--line); }
.stage-toolbar #mode-label { color: var(--accent); font-weight: 700; }
.stage-toolbar #selection-label { flex: 1; margin-left: 18px; color: var(--muted); }
.icon-button { width: 32px; min-width: 32px; min-height: 32px; padding: 0; font-size: 17px; }
.status-bar { border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.status-bar #status.error { color: var(--danger); }
.status-bar #status.warning { color: var(--warning); }
.map-scroller {
  position: relative;
  min-height: 0;
  overflow: auto;
  background-color: #0b0e12;
  background-image: linear-gradient(45deg, #11161d 25%, transparent 25%), linear-gradient(-45deg, #11161d 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #11161d 75%), linear-gradient(-45deg, transparent 75%, #11161d 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}
#map-canvas { display: block; margin: 24px; background: #202a35; box-shadow: 0 8px 30px #000a; cursor: crosshair; }
.empty-hint {
  position: sticky;
  left: 50%;
  bottom: 20px;
  width: max-content;
  max-width: calc(100% - 30px);
  transform: translateX(-50%);
  padding: 8px 12px;
  border: 1px solid var(--hover-line);
  border-radius: 18px;
  background: rgb(17 22 29 / 90%);
  color: var(--muted);
  pointer-events: none;
}
.empty-hint.hidden { display: none; }

dialog { width: min(760px, calc(100% - 30px)); padding: 20px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(0 0 0 / 62%); }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; }
.dialog-heading h2 { margin: 0; font-size: 17px; }
.dialog-note { margin: 10px 0 14px; color: var(--muted); line-height: 1.6; }
.dat-dialog { width: min(520px, calc(100% - 30px)); }
.dat-file-picker { display: grid; gap: 9px; }
.dat-file-picker > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
}
.dat-file-picker strong { font-size: 13px; }
.dat-file-picker span { grid-column: 1; color: var(--muted); font-size: 10px; }
.dat-file-picker label { grid-column: 2; grid-row: 1 / span 2; margin: 0; }
.dat-file-picker output { grid-column: 1 / -1; color: var(--accent-2); font: 11px ui-monospace, monospace; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.output-tabs { display: flex; gap: 6px; margin: 12px 0 8px; }
.output-tab { padding: 7px 10px; border: 1px solid var(--line); border-radius: 5px; background: var(--panel-2); color: var(--muted); }
.output-tab.active { border-color: var(--accent); color: var(--text); }
#output-text { height: min(60vh, 520px); resize: none; font: 12px/1.55 ui-monospace, monospace; }
.validation-dialog { width: min(520px, calc(100% - 30px)); }
.validation-content { display: grid; gap: 12px; margin-top: 14px; }
.validation-group { padding: 11px 13px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); }
.validation-group strong { display: block; margin-bottom: 6px; }
.validation-group.errors strong { color: var(--danger); }
.validation-group.warnings strong { color: var(--accent-2); }
.validation-group ul { margin: 0; padding-left: 19px; color: #c5cdd8; line-height: 1.6; }
.autosave-dialog { width: min(440px, calc(100% - 30px)); }
.autosave-dialog h2 { margin-bottom: 0; }
.restore-description { margin: 10px 0 14px; }
.autosave-dialog .dialog-actions { margin-top: 14px; }
.install-dialog { width: min(440px, calc(100% - 30px)); }
.autosave-date {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--accent-2);
  font-size: 11px;
}

@media (max-width: 980px) {
  .workspace { grid-template-columns: 220px minmax(0, 1fr); }
  .property-panel { position: absolute; z-index: 5; right: 0; top: 56px; bottom: 0; width: 280px; box-shadow: -8px 0 24px #0008; }
}
