/* Emberwood editor. Colours come from the same Endesga 32 palette as the starter art. */
:root {
  --bg: #13101d; --panel: #1c1829; --panel2: #231f33; --line: #2f2a45; --line2: #3a3456;
  --text: #dfe5f0; --muted: #8b9bb4; --dim: #5f6787;
  --accent: #feae34; --accent2: #2ce8f5; --danger: #e43b44; --good: #63c74d; --ember: #f77622;
  --r: 6px; --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --mono: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 13px/1.4 var(--font); display: grid; grid-template-rows: 44px 1fr 24px; overflow: hidden; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--bg); border: 1px solid var(--line2); border-radius: 4px; padding: 5px 7px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent2); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; line-height: 1.4; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 650; }
h2 { font-size: 17px; display: flex; align-items: center; gap: 8px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 8px; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.icon { flex: none; display: block; }
.hidden-file { display: none; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 30px; min-width: 30px; padding: 0 7px; border: 1px solid transparent; border-radius: var(--r); background: transparent; color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--panel2); border-color: var(--line2); }
.btn:disabled { opacity: .35; cursor: default; }
.btn.active { background: #3a2a18; border-color: var(--accent); color: var(--accent); }
.btn.labeled { padding: 0 10px; border-color: var(--line2); background: var(--panel2); }
.btn.small { height: 24px; min-width: 24px; padding: 0 4px; }
.btn.small .icon { width: 14px; height: 14px; }
.btn.wide { width: 100%; margin-top: 4px; }
.btn.danger:hover:not(:disabled) { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn.play { background: var(--ember); border-color: var(--ember); color: #181425; font-weight: 650; }
.btn.play:hover { background: var(--accent) !important; border-color: var(--accent) !important; }
.btn.dirty { border-color: var(--accent); color: var(--accent); }
label.btn { position: relative; }

/* toolbar */
.toolbar { display: flex; align-items: center; gap: 4px; padding: 0 8px; background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0; overflow: hidden; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .02em; margin-right: 8px; color: var(--accent); }
.brand-mark { width: 16px; height: 16px; image-rendering: pixelated; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8' shape-rendering='crispEdges'%3E%3Cpath fill='%23f77622' d='M3 0h1v1h1v1h1v3h1v2H1V5h1V3h1z'/%3E%3Cpath fill='%23fee761' d='M3 4h2v3H3z'/%3E%3C/svg%3E") center/contain no-repeat; }
.brand-mark.big { width: 56px; height: 56px; }
.project-name { background: none; border: 1px solid transparent; border-radius: var(--r); padding: 4px 8px; cursor: pointer; font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-name:hover { border-color: var(--line2); background: var(--panel2); }
.caret { color: var(--muted); margin-left: 4px; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; flex: none; }
.group { display: flex; gap: 2px; }
.zoom-label { min-width: 42px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.menu { position: fixed; z-index: 50; background: var(--panel2); border: 1px solid var(--line2); border-radius: var(--r); padding: 4px; box-shadow: 0 8px 30px #0008; min-width: 190px; }
.menu-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; background: none; border: 0; border-radius: 4px; cursor: pointer; text-align: left; }
.menu-item:hover { background: var(--line2); }

/* workspace */
.workspace { --left-w: 220px; --right-w: 300px; display: grid; grid-template-columns: var(--left-w) 1fr var(--right-w); min-height: 0; }
.sidebar { position: relative; background: var(--panel); min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.resize-handle { position: absolute; top: 0; bottom: 0; width: 6px; cursor: col-resize; z-index: 5; }
.resize-handle[data-side=left] { right: -3px; }
.resize-handle[data-side=right] { left: -3px; }
.resize-handle:hover, .resize-handle.dragging { background: var(--accent2); opacity: .5; }
.sidebar.left { border-right: 1px solid var(--line); }
.tree { overflow-y: auto; flex: 1; }
.sidebar.right { border-left: 1px solid var(--line); }
.workspace:has(#right[hidden]) { grid-template-columns: var(--left-w) 1fr; }
.stage { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.map-host { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.map-canvas { display: block; outline: none; touch-action: none; }
.doc-host { flex: 1; min-height: 0; overflow: auto; }
.pick-banner { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #0f3a40; color: var(--accent2); border-bottom: 1px solid var(--accent2); }
.pick-banner span { flex: 1; }

/* project tree */
.tree { padding: 6px 0 16px; }
.tree-section { margin-bottom: 6px; }
.tree-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px 4px 12px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 650; }
.tree-head span { flex: 1; }
.tree-row { display: flex; align-items: center; gap: 6px; padding: 3px 6px 3px 14px; cursor: pointer; min-height: 28px; border-left: 2px solid transparent; }
.tree-row:hover { background: var(--panel2); }
.tree-row.active { background: #2a2338; border-left-color: var(--accent); }
.tree-row.settings { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 8px; color: var(--muted); }
.tree-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-actions { display: none; gap: 1px; }
.tree-row:hover .tree-actions, .tree-row.active .tree-actions { display: flex; }
.tree-empty { margin: 2px 14px 6px; color: var(--dim); font-size: 12px; }
.star { color: var(--accent); width: 14px; display: flex; }
.star-gap { width: 14px; flex: none; }
.thumb { width: 16px; height: 16px; image-rendering: pixelated; flex: none; }

/* right side: layers and options */
.layers { border-bottom: 1px solid var(--line); flex: none; max-height: 40%; overflow-y: auto; }
.panel-head { display: flex; align-items: center; gap: 6px; padding: 8px 8px 6px 12px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 650; }
.panel-head span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-list { padding-bottom: 6px; }
.layer-row { display: flex; align-items: center; gap: 6px; padding: 2px 6px 2px 8px; min-height: 28px; cursor: pointer; border-left: 2px solid transparent; }
.layer-row:hover { background: var(--panel2); }
.layer-row.active { background: #2a2338; border-left-color: var(--accent); }
.layer-row.hidden .layer-name { color: var(--dim); text-decoration: line-through; }
.layer-row.special .layer-icon { width: 24px; display: flex; justify-content: center; color: var(--muted); }
.layer-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-actions { display: none; }
.layer-row:hover .layer-actions { display: flex; }
.badge { font-size: 10px; padding: 0 5px; border-radius: 8px; background: #0f3a40; color: var(--accent2); }
.count { color: var(--muted); font-size: 11px; padding-right: 6px; }
.options { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.options > .entity-list, .options > .inspector, .options > .hint, .options > .choices, .options > .entity-types { flex: none; }
.options:has(.inspector), .options:has(.entity-types) { overflow-y: auto; }
.palette-scroll { flex: 1; min-height: 80px; overflow: auto; padding: 4px 8px 8px; }
.palette-canvas, .sheet-canvas { display: block; image-rendering: pixelated; cursor: pointer; }
.tile-info-host { flex: none; border-top: 1px solid var(--line); }
.tile-info { display: flex; gap: 10px; padding: 10px 12px; align-items: flex-start; }
.tile-preview { width: 48px; height: 48px; image-rendering: pixelated; background: var(--bg); border: 1px solid var(--line2); border-radius: 4px; flex: none; }
.tile-fields { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.tile-title { font-weight: 600; }
.tile-info-host > p { padding: 10px 12px; margin: 0; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 12px 10px; }
.hint.warn { color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 3px 0; }
.choices { display: flex; flex-direction: column; gap: 6px; padding: 4px 12px; }
.choice { display: flex; gap: 10px; align-items: center; text-align: left; padding: 8px 10px; border: 1px solid var(--line2); border-radius: var(--r); background: var(--panel2); cursor: pointer; }
.choice span:last-child { display: flex; flex-direction: column; }
.choice small { color: var(--muted); }
.choice.active { border-color: var(--accent); background: #3a2a18; }
.swatch { width: 22px; height: 22px; border-radius: 4px; flex: none; border: 1px solid #0006; }
.swatch.blocked { background: rgba(228,59,68,.8); } .swatch.open { background: rgba(99,199,77,.75); } .swatch.auto { background: repeating-linear-gradient(45deg, #3a3456 0 4px, #231f33 4px 8px); }
.entity-types { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 0 12px 6px; }
.etype { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border: 1px solid var(--line2); border-radius: var(--r); background: var(--panel2); cursor: pointer; text-align: left; }
.etype:hover { border-color: var(--muted); }
.etype.active { border-color: var(--accent); background: #3a2a18; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.inspector { margin: 4px 12px 10px; padding: 10px; border: 1px solid var(--line2); border-radius: var(--r); background: var(--panel2); display: flex; flex-direction: column; gap: 8px; }
.inspector-head { display: flex; align-items: center; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field-label { color: var(--muted); font-size: 12px; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.form-hint { color: var(--dim); font-size: 11.5px; }
.entity-list { padding: 0 0 12px; }
.list-title { padding: 6px 12px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 650; }
.entity-row { display: flex; align-items: center; gap: 8px; padding: 4px 12px; cursor: pointer; }
.entity-row:hover { background: var(--panel2); }
.entity-row.active { background: #2a2338; }
.entity-row small { color: var(--dim); font-family: var(--mono); font-size: 11px; }

/* documents (tileset, sprite, settings) */
.doc { padding: 16px 20px 40px; max-width: 1200px; }
.doc-head { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.doc-head p { margin: 4px 0 0; }
.doc-head .hint { margin-left: 0; }
.doc > .hint { margin: 0 0 12px; }
.doc-body { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; align-items: start; }
.doc-main { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 8px; overflow: auto; max-height: calc(100vh - 210px); }
.doc-main .palette-scroll { padding: 0; }
.doc-side { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 8px; }
.big-preview { width: 96px; height: 96px; image-rendering: pixelated; background: var(--bg); border: 1px solid var(--line2); border-radius: 4px; }
.anim-preview { image-rendering: pixelated; border-radius: 4px; border: 1px solid var(--line2); align-self: flex-start; }
.row { display: flex; gap: 4px; }
.anims { display: flex; flex-direction: column; gap: 4px; }
.anim-row { display: grid; grid-template-columns: 1fr 1.4fr 52px 24px; gap: 4px; align-items: center; padding: 2px; border-radius: 4px; }
.anim-row.active { background: #3a2a18; }
.anim-row.head { color: var(--muted); font-size: 11px; }
.anim-row input { padding: 3px 5px; font-family: var(--mono); font-size: 12px; }
.anim-list { display: flex; flex-wrap: wrap; gap: 4px; }
.anim-chip { padding: 3px 8px; border: 1px solid var(--line2); border-radius: 12px; background: var(--panel2); cursor: pointer; }
.anim-chip.active { border-color: var(--accent); color: var(--accent); }
.hint-box { margin-top: 8px; color: var(--muted); font-size: 12px; }
.hint-box summary { cursor: pointer; color: var(--text); }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-top: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 4px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.keys dt { font-family: var(--mono); font-size: 12px; color: var(--accent); white-space: nowrap; }
.keys dd { margin: 0; color: var(--muted); }

/* welcome */
.welcome { overflow-y: auto; display: flex; justify-content: center; padding: 48px 20px; }
.welcome-inner { width: 100%; max-width: 760px; }
.welcome-title { display: flex; align-items: center; gap: 18px; margin-bottom: 28px; }
.welcome-title h1 { font-size: 32px; color: var(--accent); }
.welcome-title p { margin: 4px 0 0; color: var(--muted); font-size: 15px; }
.welcome-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.welcome-card { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 16px; background: var(--panel); border: 1px solid var(--line2); border-radius: 10px; cursor: pointer; text-align: left; }
.welcome-card:hover:not(:disabled) { border-color: var(--accent); }
.welcome-card.primary { border-color: var(--ember); }
.welcome-card .icon { color: var(--accent); }
.welcome-card b { font-size: 15px; }
.welcome-card small { color: var(--muted); }
.welcome-card:disabled { opacity: .4; cursor: default; }
.welcome-lists { display: grid; gap: 4px; margin-top: 20px; }
.recent-row { display: flex; align-items: center; gap: 6px; }
.recent-open { flex: 1; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid transparent; border-radius: var(--r); background: none; cursor: pointer; text-align: left; }
.recent-open:hover { background: var(--panel); border-color: var(--line2); }
.recent-open span { display: flex; flex-direction: column; }
.recent-open small { color: var(--muted); }
.notice { padding: 10px 14px; border-radius: var(--r); background: var(--panel); border: 1px solid var(--line2); color: var(--muted); }
.notice.warn { border-color: var(--accent); color: var(--accent); }

/* status bar */
.status { display: flex; align-items: center; gap: 16px; padding: 0 12px; background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; }
.st-pos { font-family: var(--mono); font-size: 11.5px; min-width: 150px; }
.st-store.dirty { color: var(--accent); }

/* dialogs */
.modal-back { position: fixed; inset: 0; background: #0009; display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--line2); border-radius: 10px; padding: 18px 20px; box-shadow: 0 20px 60px #000a; max-height: 90vh; overflow-y: auto; }
.modal.wide { max-width: 620px; }
.modal h2 { margin-bottom: 12px; }
.modal-text { white-space: pre-line; color: var(--muted); margin: 0 0 12px; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-buttons button { padding: 7px 16px; border-radius: var(--r); border: 1px solid var(--line2); background: var(--panel2); cursor: pointer; }
.modal-buttons .primary { background: var(--ember); border-color: var(--ember); color: #181425; font-weight: 650; }
.modal-buttons .primary.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.form { display: flex; flex-direction: column; gap: 10px; }
.form-row { display: flex; flex-direction: column; gap: 4px; }
.form-row.check { flex-direction: row; align-items: center; gap: 8px; }
.form-label { color: var(--muted); font-size: 12px; }
.form-error { color: #ff7a83; margin: 0; min-height: 1em; }
.toasts { position: fixed; bottom: 36px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; z-index: 200; pointer-events: none; }
.toast { padding: 8px 14px; border-radius: var(--r); background: var(--panel2); border: 1px solid var(--line2); box-shadow: 0 6px 20px #0008; transition: opacity .3s, transform .3s; max-width: 70vw; }
.toast.good { border-color: var(--good); }
.toast.warn { border-color: var(--accent); color: var(--accent); }
.toast.out { opacity: 0; transform: translateY(6px); }

/* play overlay */
.play-overlay { position: fixed; inset: 0; z-index: 80; background: #0c0a12f2; display: flex; flex-direction: column; }
.play-bar { display: flex; align-items: center; gap: 14px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.play-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 16px; }
.play-canvas { image-rendering: pixelated; image-rendering: crisp-edges; box-shadow: 0 0 0 2px var(--line2); outline: none; background: #000; }
.play-error { color: #ff7a83; text-align: center; margin: 0 0 16px; min-height: 1em; }

@media (max-width: 900px) { .doc-body { grid-template-columns: 1fr; } }

/* server mode */
.server-banner { background: #3a2a18; color: var(--accent); border-bottom-color: var(--accent); }
.card.setup { max-width: 440px; margin: 0 0 20px; padding: 6px 20px 20px; }
.card.setup h3 { font-size: 15px; text-transform: none; letter-spacing: 0; color: var(--text); }
.card.setup p, .card.setup li { color: var(--muted); }
.card.setup ol { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.primary-btn { background: var(--ember) !important; border-color: var(--ember) !important; color: #181425 !important; font-weight: 650; height: 34px; }
.account-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; margin-bottom: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); color: var(--muted); }
.account-bar b { color: var(--text); }
.account-bar .badge { margin-left: 6px; }
.small { font-size: 12px; }
.team { display: flex; flex-direction: column; gap: 4px; min-width: 320px; }
.team-row { padding: 4px 6px; border-radius: var(--r); background: var(--panel2); }
.team-row .tree-label { display: flex; align-items: center; gap: 6px; }
.team > .btn.labeled { margin-top: 8px; align-self: flex-start; }
