:root {
  --bg: #f5f4f1;
  --panel: #ffffff;
  --line: #e7e4de;
  --line-strong: #d6d2ca;
  --text: #1f1d1a;
  --muted: #6e6a63;
  --faint: #9a958c;
  --accent: #d2552c;
  --accent-soft: #fbeae3;
  --accent-ink: #a8401f;
  --ok: #2f8a56;
  --shadow: 0 1px 2px rgba(31, 29, 26, .06), 0 4px 16px rgba(31, 29, 26, .06);
  --radius: 12px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased; font-feature-settings: "cv11", "ss01";
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- top bar */
.top {
  height: 58px; display: flex; align-items: center; gap: 16px; padding: 0 18px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
.brand .mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.brand small { color: var(--faint); font-weight: 500; }
.cast { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: 1; padding: 4px 0; }
.cast::-webkit-scrollbar { display: none; }
.cast button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 12px 5px 5px;
  display: flex; align-items: center; gap: 8px; white-space: nowrap; transition: border-color .15s, background .15s;
}
.cast button img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; background: var(--bg); }
.cast button:hover { border-color: var(--line-strong); }
.cast button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.actions { display: flex; gap: 6px; align-items: center; }

.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 7px 12px;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: #faf9f7; border-color: var(--line-strong); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.icon { padding: 7px; width: 34px; justify-content: center; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--bg); }

/* ---------------------------------------------------------------- layout */
.main { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 18px; padding: 18px; height: calc(100% - 58px); }
.stage { display: flex; flex-direction: column; gap: 12px; min-width: 0; min-height: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar .toggle { margin-right: 4px; }
.toolbar .spacer { flex: 1; }

.seg { display: inline-flex; background: #ecebe7; border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; border-radius: 7px; padding: 5px 12px; color: var(--muted); font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
}
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg button:disabled { opacity: .4; cursor: default; }
.seg svg { width: 15px; height: 15px; }

select.pick {
  appearance: none; border: 1px solid var(--line); background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236e6a63' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  border-radius: 9px; padding: 6px 30px 6px 11px;
}

.canvas {
  position: relative; flex: 1; min-height: 0; background: #d6d2cb; border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--line); overflow: hidden;
}
.canvas canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.zoombar {
  position: absolute; right: 12px; bottom: 12px; display: flex; align-items: center; gap: 2px; padding: 3px;
  background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 11px; backdrop-filter: blur(6px);
}
.zoombar .btn.icon { width: 30px; padding: 6px; }
.zoomval { border: 0; background: none; min-width: 52px; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); padding: 6px 4px; border-radius: 7px; }
.zoomval:hover { background: var(--bg); color: var(--text); }
.badge {
  position: absolute; top: 12px; left: 12px; background: rgba(255,255,255,.92); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 10px 3px 8px; font-size: 12px; color: var(--muted);
  display: flex; align-items: center; gap: 6px; backdrop-filter: blur(6px);
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.badge.busy .dot { background: var(--accent); animation: pulse .8s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .3; } to { opacity: 1; } }
.hint {
  position: absolute; bottom: 14px; left: 14px; font-size: 12px; color: #fff; background: rgba(31,29,26,.55);
  border-radius: 999px; padding: 4px 11px; pointer-events: none; max-width: calc(100% - 210px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------------------------------------------------------------- expression combobox */
.combo { position: relative; }
.combo input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 40px 9px 12px; background: var(--panel);
  font-weight: 500;
}
.combo input::placeholder { color: var(--faint); font-weight: 400; }
.combo input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.combo-btn {
  position: absolute; right: 4px; top: 4px; bottom: 4px; width: 32px; border: 0; background: none; border-radius: 7px;
  color: var(--muted); display: grid; place-items: center;
}
.combo-btn:hover { background: var(--bg); }
.combo-btn svg { width: 16px; height: 16px; transition: transform .15s; }
.combo.open .combo-btn svg { transform: rotate(180deg); }
.combo-list {
  display: none; position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 15; margin: 0; padding: 4px;
  list-style: none; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  max-height: 290px; overflow-y: auto;
}
.combo.open .combo-list { display: block; }
.combo-list li { padding: 7px 10px; border-radius: 7px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.combo-list li small { color: var(--faint); font-size: 11.5px; text-align: right; }
.combo-list li b { font-weight: 500; }
.combo-list li.on b { color: var(--accent-ink); font-weight: 650; }
.combo-list li:hover, .combo-list li.active { background: var(--accent-soft); }
.combo-list li.none { color: var(--faint); cursor: default; background: none; }

.player {
  display: none; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 12px; box-shadow: var(--shadow);
}
.player.show { display: flex; }
.player input[type=range] { flex: 1; }
.player .count { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; min-width: 70px; text-align: right; }

/* ---------------------------------------------------------------- inspector */
.inspector {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 8px; }
.tabs button {
  flex: 1; border: 0; background: none; padding: 13px 4px 11px; color: var(--muted); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.pane { display: none; overflow-y: auto; padding: 4px 18px 22px; flex: 1; }
.pane.on { display: block; }

.sec { padding: 16px 0 6px; border-bottom: 1px solid var(--line); }
.sec:last-child { border-bottom: 0; }
.sec-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sec-h h3 { margin: 0; font-size: 13px; font-weight: 650; letter-spacing: .01em; }
.sec-h .sub { color: var(--faint); font-weight: 500; font-size: 12px; margin-left: 6px; }
.link { border: 0; background: none; color: var(--accent-ink); font-size: 12px; font-weight: 600; padding: 2px 4px; border-radius: 6px; }
.link:hover { background: var(--accent-soft); }
.note { color: var(--muted); font-size: 12px; margin: 4px 0 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 11px; font-size: 13px;
  transition: all .12s;
}
.chip:hover { border-color: var(--line-strong); }
.chip.on { background: var(--text); border-color: var(--text); color: #fff; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); gap: 8px; }
.tile {
  border: 1.5px solid var(--line); background: #faf9f7; border-radius: 10px; padding: 0 0 5px; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: var(--muted);
  transition: border-color .12s, transform .12s;
}
.tile img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #f1efeb; }
.tile.hand img { object-fit: contain; padding: 6px; }
.tile:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.tile.on { border-color: var(--accent); color: var(--accent-ink); font-weight: 600; box-shadow: 0 0 0 3px var(--accent-soft); }

.row { display: grid; grid-template-columns: 96px 1fr 44px; align-items: center; gap: 10px; margin: 7px 0; }
.row label { color: var(--muted); font-size: 13px; }
.row output { font-variant-numeric: tabular-nums; color: var(--faint); font-size: 12px; text-align: right; cursor: pointer; }
.row output:hover { color: var(--accent-ink); }
.row.off { opacity: .4; pointer-events: none; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(var(--accent), var(--accent)) 0 / var(--fill, 50%) 100% no-repeat, #e6e3dd; }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: #e6e3dd; }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #fff; margin-top: -6px;
  border: 1.5px solid var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 1.5px solid var(--accent); }

.limb { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 6px; margin-bottom: 10px; }
.limb-h { display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.limb-h span { color: var(--faint); font-weight: 500; font-size: 12px; }

.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); cursor: pointer; user-select: none; }
.toggle input { display: none; }
.toggle i { width: 30px; height: 18px; border-radius: 999px; background: #dcd8d1; position: relative; transition: background .15s; }
.toggle i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.toggle input:checked + i { background: var(--accent); }
.toggle input:checked + i::after { transform: translateX(12px); }

.lookpad {
  width: 128px; height: 128px; border-radius: 50%; background: radial-gradient(circle, #fff 0 30%, #f3f1ed 31% 100%);
  border: 1px solid var(--line); position: relative; touch-action: none; cursor: crosshair; flex: none;
}
.lookpad::before, .lookpad::after { content: ""; position: absolute; background: var(--line); }
.lookpad::before { left: 50%; top: 8px; bottom: 8px; width: 1px; }
.lookpad::after { top: 50%; left: 8px; right: 8px; height: 1px; }
.lookpad b { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; background: var(--text); border: 4px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.25); z-index: 1; }
.lookwrap { display: flex; gap: 16px; align-items: center; }
.lookwrap .chips { flex-direction: column; align-items: flex-start; }

details.more { margin-top: 6px; }
details.more summary { cursor: pointer; color: var(--accent-ink); font-size: 12px; font-weight: 600; list-style: none; padding: 4px 0; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::before { content: "▸ "; }
details.more[open] summary::before { content: "▾ "; }

.hand-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 12px 0; }
.hand-card .limb-h { margin-bottom: 10px; }
.blend { display: grid; grid-template-columns: 1fr; gap: 6px; margin-top: 12px; background: #faf9f7; border-radius: 10px; padding: 10px; }
.blend .chips .chip { padding: 3px 9px; font-size: 12px; }

.anim-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; }
.anim-grid button { border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 9px 8px; text-align: left; font-size: 13px; }
.anim-grid button:hover { border-color: var(--accent); background: var(--accent-soft); }
.anim-grid button.on { border-color: var(--accent); background: var(--accent); color: #fff; }

.saved { display: flex; flex-direction: column; gap: 6px; }
.saved .item { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 8px 8px 12px; }
.saved .item b { flex: 1; font-weight: 600; }
.saved .item small { color: var(--faint); }
.empty { color: var(--faint); text-align: center; padding: 28px 8px; font-size: 13px; }
.field { display: flex; gap: 8px; }
.field input, .input {
  flex: 1; border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px; background: var(--panel); min-width: 0;
}
.field input:focus, .input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px); opacity: 0; background: var(--text); color: #fff;
  border-radius: 10px; padding: 10px 16px; font-size: 13px; transition: all .2s; z-index: 50; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.menu { position: relative; }
.menu .pop {
  display: none; position: absolute; right: 0; top: 42px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 6px; min-width: 200px; z-index: 30;
}
.menu.open .pop { display: block; }
.pop button { display: block; width: 100%; text-align: left; border: 0; background: none; border-radius: 8px; padding: 8px 10px; }
.pop button:hover { background: var(--bg); }
.pop .who { padding: 8px 10px 6px; color: var(--faint); font-size: 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.18); width: min(420px, 92vw); }
dialog::backdrop { background: rgba(31,29,26,.25); }
dialog h3 { margin: 0 0 4px; }
dialog p { color: var(--muted); margin: 0 0 14px; font-size: 13px; }
dialog .stack { display: flex; flex-direction: column; gap: 10px; }
dialog .btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
dialog pre { white-space: pre-wrap; word-break: break-word; background: #f6f5f2; border-radius: 10px; padding: 12px; overflow: auto; font-size: 12px; max-height: 300px; margin: 0; }

kbd { font: 11px var(--font); background: #fff; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; }

/* ---------------------------------------------------------------- login / setup */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 30px; width: min(380px, 100%); }
.auth-card .brand { margin-bottom: 22px; }
.auth-card h1 { font-size: 20px; margin: 0 0 6px; letter-spacing: -.01em; }
.auth-card p { color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.auth-card label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
.auth-card .input { width: 100%; padding: 10px 12px; }
.auth-card .btn { width: 100%; justify-content: center; margin-top: 22px; padding: 10px; }
.err { color: #b42318; font-size: 13px; margin-top: 12px; min-height: 18px; }
.meter { height: 4px; border-radius: 4px; background: #ece9e3; margin-top: 8px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s, background .2s; }

@media (max-width: 960px) {
  .main { grid-template-columns: 1fr; height: auto; }
  .canvas { aspect-ratio: 16 / 10; flex: none; }
  .hint { display: none; }
  .inspector { max-height: none; }
  .brand small, .actions .label { display: none; }
  .top { flex-wrap: wrap; height: auto; padding: 8px 14px; row-gap: 6px; }
  .actions { margin-left: auto; }
  .cast { order: 3; flex-basis: 100%; }
}
@media (max-width: 560px) {
  .top { gap: 10px; padding: 0 12px; }
  .main { padding: 12px; gap: 12px; }
  .brand span { display: none; }
}

.share-dlg { width: min(520px, 94vw); }
.share-thumb { width: 100%; aspect-ratio: 16 / 9; border-radius: 10px; border: 1px solid var(--line); background: #f1efeb; margin-bottom: 14px; display: block; object-fit: cover; }
.share-label { font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.share-label span { color: var(--faint); font-weight: 500; margin-left: 4px; }
.field input[readonly] { font-size: 12.5px; color: var(--muted); background: #faf9f7; }
.btn.copied { background: var(--ok); border-color: var(--ok); color: #fff; }
a.btn { text-decoration: none; color: inherit; }
