:root {
  --bg: #1d1913;
  --panel: #29231a;
  --panel2: #342c21;
  --line: #4a3f2f;
  --text: #eadfc4;
  --muted: #a8997a;
  --accent: #d0a95a;
  --accent-ink: #2a1f0e;
  --danger: #b5523b;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: default; border-color: var(--line); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { border-color: #6a3326; color: #f0b9a8; }
button.danger:hover { background: var(--danger); color: #fff; }
input[type=text], input[type=number], input[type=search], select, textarea {
  background: #1f1a13;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
kbd {
  font: 11px ui-monospace, Consolas, monospace;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 4px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { font-family: "IM Fell English SC", Georgia, serif; font-size: 21px; color: var(--accent); white-space: nowrap; }
.brand span { color: var(--text); }
.map-name {
  flex: 0 1 280px;
  font-family: "IM Fell English", Georgia, serif;
  font-size: 16px !important;
  background: transparent !important;
  border-color: transparent !important;
}
.map-name:hover, .map-name:focus { border-color: var(--line) !important; }
.actions { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; align-items: center; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

.layout { flex: 1; display: grid; grid-template-columns: 290px 1fr 290px; min-height: 0; }
.panel { background: var(--panel); overflow-y: auto; padding: 4px 12px 12px; }
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.panel section { padding: 8px 0; border-bottom: 1px solid #3a3226; }
.panel section:last-child { border-bottom: 0; }
.panel section.grow { flex: 1; display: flex; flex-direction: column; min-height: 200px; }
h2 {
  font: 600 11px/1 system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 6px 0 8px;
}
h3.group { font: 12px "IM Fell English", Georgia, serif; color: var(--accent); margin: 10px 0 4px; }
h2.sub { margin-top: 12px; }
h2 kbd { text-transform: none; letter-spacing: 0; font-weight: 400; }
.hint { text-transform: none; letter-spacing: 0; color: var(--text); font-weight: 400; margin-left: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.help p { margin: 4px 0 8px; }

.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.tools button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font-size: 11px; }
.tools svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
.tools button.active, .seg button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tools kbd { background: transparent; border: 0; padding: 0; opacity: 0.6; font-size: 10px; }

.seg { display: flex; gap: 4px; }
.seg button { flex: 1; padding: 5px 2px; font-size: 12px; }
.check { display: flex; align-items: center; gap: 8px; margin: 4px 0; cursor: pointer; }

.swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.swatch {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px 2px; background: transparent; border-color: transparent; font-size: 11px; line-height: 1.15;
}
.swatch canvas { width: 56px; height: 48px; display: block; }
.swatch.active { background: var(--panel2); border-color: var(--accent); }

.icons { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.icon-btn { padding: 3px; aspect-ratio: 1; background: #e9dfc4; border-color: #8a7a5a; display: grid; place-items: center; }
.icon-btn svg { width: 100%; height: 100%; }
.icon-btn.active { outline: 2px solid var(--accent); outline-offset: 1px; background: #fff6dd; }

.stage { position: relative; overflow: hidden; background: #c9bb95; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.viewctl {
  position: absolute; top: 10px; right: 10px;
  display: flex; gap: 4px; align-items: center;
  background: rgba(41, 35, 26, 0.88); padding: 5px; border-radius: 8px; border: 1px solid var(--line);
}
.viewctl button { padding: 3px 9px; min-width: 30px; }
.viewctl .toggle[aria-pressed=true] { background: #4b3f2c; border-color: var(--accent); }
.status {
  position: absolute; left: 10px; bottom: 10px; max-width: calc(100% - 20px);
  background: rgba(41, 35, 26, 0.88); padding: 5px 10px; border-radius: 6px; border: 1px solid var(--line);
  pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status:empty { display: none; }

.panel label:not(.check) { display: block; margin: 8px 0; color: var(--muted); font-size: 12px; }
.panel label:not(.check) > input, .panel label:not(.check) > select, .panel label:not(.check) > textarea { margin-top: 3px; color: var(--text); font-size: 13px; }
.insp-head { display: flex; align-items: center; gap: 8px; }
.topbar .switch { color: var(--muted); text-decoration: none; font-size: 13px; border: 1px solid var(--line); border-radius: 6px; padding: 3px 9px; white-space: nowrap; }
.topbar .switch:hover { color: var(--accent); border-color: var(--accent); }
.viewctl .note { color: var(--muted); font-size: 12px; padding: 0 6px; }
.level-list { list-style: none; margin: 0 0 8px; padding: 0; }
.level-list li { padding: 5px 8px; border-radius: 6px; cursor: pointer; }
.level-list li:hover { background: #3a3226; }
.level-list li.active { background: var(--accent); color: var(--accent-ink); }
.insp-head .renumber { margin-left: auto; padding: 2px 8px; font-size: 12px; }
.coord { font: 22px "IM Fell English", Georgia, serif; color: var(--accent); }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); }
#inspClear { width: 100%; margin-top: 4px; }

#locList { list-style: none; margin: 8px 0 0; padding: 0; overflow-y: auto; flex: 1; }
#locList li {
  display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center;
  padding: 4px 6px; border-radius: 6px; cursor: pointer;
}
#locList li:hover { background: var(--panel2); }
#locList li.active { background: #43382a; }
#locList .ico { width: 26px; height: 26px; background: #e9dfc4; border-radius: 4px; padding: 2px; }
#locList .ico svg { width: 100%; height: 100%; display: block; }
#locList .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#locList .nm small { display: block; color: var(--muted); font-size: 11px; }
#locList .cc { font: 13px "IM Fell English", Georgia, serif; color: var(--muted); }

dialog {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; width: min(400px, 92vw);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog h3 { margin: 0 0 10px; font: 22px "IM Fell English", Georgia, serif; color: var(--accent); }
dialog label:not(.check) { display: block; margin: 8px 0; color: var(--muted); font-size: 12px; flex: 1; }
dialog label > input, dialog label > select { margin-top: 3px; color: var(--text); }
dialog .row { display: flex; gap: 10px; align-items: flex-end; }
dialog .dice { margin-bottom: 8px; padding: 5px 9px; }
dialog menu { display: flex; gap: 6px; justify-content: flex-end; padding: 0; margin: 14px 0 0; flex-wrap: wrap; }

@media (max-width: 1000px) {
  body { overflow: auto; }
  .layout { grid-template-columns: 1fr; grid-template-rows: 65vh auto auto; }
  .stage { order: -1; }
  .panel.left, .panel.right { border: 0; border-top: 1px solid var(--line); overflow: visible; }
}

/* server sync */
.cloud-status {
  font-size: 11px; padding: 3px 9px; border-radius: 10px; background: var(--panel2);
  border: 1px solid var(--line); white-space: nowrap;
}
.cloud-status::before { content: '●'; margin-right: 5px; color: var(--muted); }
.cloud-status[data-state=synced]::before { color: #8fbf6a; }
.cloud-status[data-state=saving]::before { color: var(--accent); }
.cloud-status[data-state=offline]::before, .cloud-status[data-state=auth]::before, .cloud-status[data-state=error]::before { color: #e0785f; }
dialog.wide { width: min(520px, 94vw); }
dialog h2.sub { margin-top: 18px; }
.cloud-list { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
.cloud-list li { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center; padding: 6px 0; border-bottom: 1px solid #3a3226; }
.cloud-list .nm small { display: block; color: var(--muted); font-size: 11px; }
.error { color: #f0a08a; min-height: 1em; margin: 8px 0 0; }
dialog .row button { margin-bottom: 0; }

.viewctl select { width: auto; padding: 3px 6px; }
