/* Minimal shared chrome for widgets in ui.js. Designs restyle via custom properties
   or override rules; this only guarantees the widgets are usable out of the box. */
:root {
  --ui-font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display-font: 'Lora', Georgia, serif;
  --bg: #f4efe3;
  --panel: #fbf8f0;
  --panel-2: #f1ebdc;
  --line: #d9d0bb;
  --text: #2a241c;
  --muted: #7a7062;
  --accent: #d5006c;
  --accent-soft: rgba(213, 0, 108, 0.12);
  --primary: #2b2118;
  --primary-text: #fff;
  --danger: #b3261e;
  --warn-bg: #fbeacb;
  --radius: 6px;
  --shadow: 0 6px 24px rgba(30, 20, 10, 0.18);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--ui-font); font-size: 13px; color: var(--text); background: var(--bg); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-family: var(--display-font); font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row.three > label { flex: 1; }
.icon { flex: none; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; background: rgba(0,0,0,0.05); padding: 1px 4px; border-radius: 3px; }
kbd { font: 10.5px ui-monospace, monospace; border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; margin-left: auto; color: var(--muted); }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); cursor: pointer; line-height: 1.2; white-space: nowrap; }
.btn:hover:not(:disabled) { background: #fff; border-color: #bfb4a0; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.primary:hover:not(:disabled) { background: #3d3025; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.icon-btn { padding: 5px; }
.btn.file-btn input { display: none; }
.btn.link, button.link { border: none; background: none; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: inherit; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.seg-btn { display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; border: none; background: none; cursor: pointer; color: var(--muted); }
.seg-btn.on { background: var(--primary); color: var(--primary-text); }
.toggle { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--muted); cursor: pointer; font-size: 12px; }
.toggle.on { color: var(--text); border-color: #a89c84; background: #fff; }
.chip { display: inline-block; padding: 1px 6px; border-radius: 999px; background: var(--panel-2); color: var(--muted); font-size: 10.5px; text-transform: capitalize; }
.chip.gm { background: #f3d9d5; color: #7a1410; }
.lock-badge, .gm-badge { display: inline-flex; align-items: center; gap: 3px; margin-left: 8px; padding: 1px 6px; border-radius: 999px; font-size: 10.5px; font-family: var(--ui-font); font-weight: 600; }
.lock-badge { background: #f3dfb3; color: #6b4a12; }
.gm-badge { background: #f3d9d5; color: #7a1410; }
.warning { display: flex; gap: 6px; align-items: flex-start; background: var(--warn-bg); color: #5a3a10; padding: 6px 8px; border-radius: var(--radius); margin: 6px 0; font-size: 12px; }

/* inputs */
input[type="text"], input[type="search"], input[type="number"], select, input:not([type]) { padding: 4px 6px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; min-width: 0; }
input[type="number"] { width: 68px; }
input[type="range"] { flex: 1; min-width: 60px; accent-color: var(--primary); padding: 0; }
input[type="color"] { width: 36px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; }
.switch { position: relative; display: inline-block; width: 32px; height: 18px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; border-radius: 999px; background: #cfc6b3; transition: background .15s; }
.switch .track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(14px); }

/* world list */
.world-list { display: grid; grid-template-columns: 320px 1fr; gap: 24px; padding: 24px; max-width: 1200px; margin: 0 auto; }
.world-create { display: flex; flex-direction: column; gap: 10px; padding: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; align-self: start; }
.world-create label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.world-create label input, .world-create label .row { width: 100%; }
.world-create .row input { flex: 1; }
.world-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; align-content: start; }
.world-card { padding: 14px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.world-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.world-card-head h3 { font-size: 18px; }
.world-card p { margin: 6px 0 10px; font-size: 12px; }

/* breadcrumb */
.breadcrumb { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.crumb { display: inline-flex; align-items: center; gap: 6px; border: none; background: none; padding: 3px 6px; border-radius: 4px; cursor: pointer; color: var(--muted); }
.crumb:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.crumb.current { color: var(--text); font-weight: 600; cursor: default; }
.crumb-scale { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.7; }
.crumb-sep { color: var(--muted); display: inline-flex; }

/* variables */
.vars { display: flex; flex-direction: column; gap: 4px; }
.var-group { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.var-group.irrelevant { opacity: 0.6; }
.var-group summary { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; cursor: pointer; font-weight: 600; list-style: none; }
.var-group summary::-webkit-details-marker { display: none; }
.var-group summary::before { content: '▸'; margin-right: 6px; color: var(--muted); font-size: 11px; }
.var-group[open] summary::before { content: '▾'; }
.var-count { color: var(--muted); font-weight: 400; font-size: 11px; }
.var-row { padding: 6px 10px 8px; border-top: 1px solid var(--line); }
.var-row.inline { display: flex; align-items: center; justify-content: space-between; }
.var-label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.var-row.inline .var-label { margin: 0; }
.var-label output { margin-left: auto; color: var(--text); font-variant-numeric: tabular-nums; }
.var-control { display: flex; gap: 6px; align-items: center; }
.var-control select, .var-control input[type="text"] { width: 100%; }
.var-control.range input[type="number"] { width: 64px; }
.impact { font-size: 10px; padding: 0 5px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.impact.hot { background: var(--accent-soft); color: var(--accent); }
.impact.none { opacity: 0.6; }
.weights, .cultures { flex-direction: column; align-items: stretch; gap: 3px; }
.weight, .culture { display: grid; grid-template-columns: 74px 1fr 30px; gap: 6px; align-items: center; font-size: 11.5px; }
.culture { grid-template-columns: 1fr 1fr; }
.culture span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.story-list { flex-direction: column; align-items: stretch; gap: 4px; }
.story-row { display: grid; grid-template-columns: 1fr 52px 52px 70px 76px 24px; gap: 3px; }
.story-row input, .story-row select { padding: 2px 4px; font-size: 11.5px; width: 100%; }

/* element panel */
.element-panel { display: flex; flex-direction: column; gap: 8px; }
.el-head { position: relative; padding-right: 28px; }
.el-head .close { position: absolute; right: 0; top: 0; }
.el-type { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11.5px; text-transform: capitalize; }
.el-head h2 { font-size: 19px; margin-top: 2px; display: flex; align-items: center; flex-wrap: wrap; }
.el-actions, .el-nav { display: flex; flex-wrap: wrap; gap: 5px; }
.el-nav .btn { width: 100%; justify-content: center; }
table.props { border-collapse: collapse; width: 100%; font-size: 12px; }
table.props th { text-align: left; color: var(--muted); font-weight: 500; padding: 3px 8px 3px 0; vertical-align: top; width: 42%; }
table.props td { padding: 3px 0; word-break: break-word; }
table.props tr { border-top: 1px solid var(--line); }
table.props tr:first-child { border-top: none; }
.el-deps { display: flex; flex-direction: column; gap: 4px; font-size: 12px; padding-top: 6px; border-top: 1px solid var(--line); }
.dep-label { display: block; color: var(--muted); font-size: 11px; }
.map-info h2 { font-size: 18px; margin-bottom: 6px; }
.map-info .row { margin-top: 8px; }
.hint { margin-top: 10px; }

/* element list */
.list-head { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.list-head .search { display: flex; align-items: center; gap: 4px; flex: 1; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 0 6px; color: var(--muted); }
.list-head .search input { border: none; padding: 4px 2px; width: 100%; outline: none; background: none; }
.type-filter { max-width: 46%; }
.element-list { list-style: none; margin: 0; padding: 0; overflow: auto; }
.element-list .group { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 8px 6px 3px; }
.element-list .item { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 4px; cursor: pointer; }
.element-list .item:hover, .element-list .item.hovered { background: var(--panel-2); }
.element-list .item.selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.element-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.element-list .lock-ic { color: #8a5a1e; }

/* context menu and popovers */
.ctx-menu, .popover { position: fixed; z-index: 1000; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); min-width: 220px; max-height: 70vh; overflow: auto; padding: 4px 0; font-size: 12.5px; }
.ctx-group { padding: 4px 0; border-top: 1px solid var(--line); }
.ctx-group:first-child { border-top: none; }
.ctx-title { display: flex; align-items: center; gap: 6px; padding: 3px 12px; font-size: 11px; color: var(--muted); font-weight: 600; }
.ctx-badge { margin-left: auto; font-weight: 400; text-transform: capitalize; }
.ctx-item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: none; background: none; padding: 6px 14px; cursor: pointer; color: var(--text); }
.ctx-item:hover:not(:disabled) { background: var(--panel-2); }
.ctx-item:disabled { opacity: 0.45; cursor: default; }
.ctx-item.primary { font-weight: 600; }
.ctx-item.danger { color: var(--danger); }
.popover { padding: 12px 14px; }
.export-menu h3 { font-size: 15px; margin-bottom: 8px; }
.export-row { display: flex; gap: 10px; }
.export-row label { display: flex; flex-direction: column; gap: 2px; font-size: 11.5px; color: var(--muted); }
.export-plan { margin: 8px 0 4px; font-size: 12px; }
.export-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

/* progress and toasts */
.progress-wrap { position: fixed; left: 0; right: 0; top: 0; z-index: 900; pointer-events: none; }
.progress { position: relative; height: 22px; background: rgba(240, 232, 214, 0.96); border-bottom: 1px solid var(--line); overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); opacity: 0.55; transition: width .12s; }
.progress-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 600; }
.toasts { position: fixed; right: 14px; bottom: 14px; z-index: 950; display: flex; flex-direction: column; gap: 6px; max-width: 360px; }
.toast { display: flex; gap: 8px; align-items: flex-start; background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 6px; box-shadow: var(--shadow); cursor: pointer; font-size: 12.5px; animation: toast-in .18s ease-out; }
.toast.warn { border-left-color: #c47a1a; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.floor-select { display: inline-flex; align-items: center; gap: 6px; }
