:root {
  --bg: #efe7d6;
  --bg2: #e6dcc6;
  --card: #fbf7ee;
  --ink: #2f2838;
  --muted: #7a6f80;
  --line: #d9cdb4;
  --accent: #c8484f;
  --accent2: #3f6fb0;
  --stage-top: #bfe0f2;
  --stage-bot: #f3ecd9;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1a24; --bg2: #24202d; --card: #2a2533; --ink: #ece4f2; --muted: #a497ad; --line: #3d3548;
    --accent: #e0636a; --accent2: #6f9de0; --stage-top: #2c3b56; --stage-bot: #3a3346;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.4 system-ui, "Segoe UI", sans-serif; }
button, select, input { font: inherit; color: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 18px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .3px; }
.brand small { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
.logo { color: var(--accent); }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.name-input { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 10px; width: 170px; font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none;
  border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 6px 12px;
  transition: background .12s, transform .05s;
}
.btn:hover { background: var(--bg2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn.icon { padding: 5px 9px; }
.btn.active { background: var(--accent2); border-color: var(--accent2); color: #fff; }

.layout {
  display: grid; grid-template-columns: 330px minmax(0, 1fr) 300px; gap: 16px;
  padding: 16px; max-width: 1500px; margin: 0 auto; align-items: start;
}
@media (max-width: 1150px) { .layout { grid-template-columns: 320px minmax(0, 1fr); } #rightPanel { grid-column: 1 / -1; } }
@media (max-width: 760px) { .layout { grid-template-columns: 1fr; padding: 10px; } .stage-col { order: -1; } }

.panel { display: flex; flex-direction: column; gap: 14px; }
.stage-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card h2 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); }

.row { display: grid; grid-template-columns: 84px 1fr; align-items: center; gap: 8px; margin: 6px 0; }
.row-label { color: var(--muted); font-size: 13px; }
.cycler { display: grid; grid-template-columns: 28px 1fr 28px; gap: 4px; }
.cycler button { border: 1px solid var(--line); background: var(--bg); border-radius: 6px; cursor: pointer; padding: 0; }
.cycler button:hover { background: var(--bg2); }
select { border: 1px solid var(--line); background: var(--bg); border-radius: 6px; padding: 4px 6px; min-width: 0; width: 100%; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }

.color-row { display: grid; grid-template-columns: 84px 30px 1fr; align-items: center; gap: 8px; margin: 5px 0; }
.color-row input[type=color] { width: 30px; height: 24px; border: 1px solid var(--line); border-radius: 6px; padding: 0; background: none; cursor: pointer; }
.swatches { display: flex; flex-wrap: wrap; gap: 3px; }
.swatch { width: 15px; height: 15px; border-radius: 4px; border: 1px solid rgba(0,0,0,.25); cursor: pointer; padding: 0; }
.swatch:hover { transform: scale(1.15); }

.anim-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.anim-tabs .btn { padding: 4px 11px; }
.stage-wrap {
  display: flex; justify-content: center; align-items: center; border-radius: 8px; overflow: hidden;
  background: linear-gradient(var(--stage-top), var(--stage-bot)); padding: 8px; min-height: 300px;
}
#stage { image-rendering: pixelated; image-rendering: crisp-edges; max-width: 100%; height: auto; }
.stage-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.dir-pad { display: flex; gap: 4px; }
.playback { display: flex; align-items: center; gap: 4px; }
.frame-label { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 52px; text-align: center; }
.view-opts { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; color: var(--muted); font-size: 13px; }
.view-opts select { width: auto; }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; font-size: 13px; }
.strip { display: block; margin-top: 10px; image-rendering: pixelated; max-width: 100%; height: auto; background: repeating-conic-gradient(var(--bg2) 0 25%, var(--card) 0 50%) 0 0 / 16px 16px; border-radius: 6px; cursor: pointer; }

.roster-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.roster-head h2 { margin: 0; }
.roster { display: flex; flex-wrap: wrap; gap: 8px; }
.roster-item { position: relative; width: 108px; text-align: center; border: 1px solid var(--line); border-radius: 8px; padding: 4px; cursor: pointer; background: var(--bg); }
.roster-item:hover { border-color: var(--accent2); }
.roster-item canvas { width: 99px; height: 99px; image-rendering: pixelated; display: block; margin: 0 auto; }
.roster-item span { display: block; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roster-item .del { position: absolute; top: 2px; right: 4px; border: none; background: none; cursor: pointer; color: var(--muted); font-size: 13px; }

.field-label { color: var(--muted); font-size: 12px; margin: 8px 0 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.sheet-info { margin: 10px 0 6px; font-size: 12px; color: var(--muted); }
.export-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.sheet-preview { margin-top: 10px; width: 100%; image-rendering: pixelated; background: repeating-conic-gradient(var(--bg2) 0 25%, var(--card) 0 50%) 0 0 / 12px 12px; border-radius: 6px; }

/* ---- top bar extras ---- */
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 2px; }
a.btn { text-decoration: none; color: inherit; }
.btn.accent2 { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.btn.accent2:hover { filter: brightness(1.08); background: var(--accent2); }
.anim-tabs .btn { font-size: 13px; }

/* ---- workshop modal ---- */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(20, 14, 30, .55); display: flex; align-items: flex-start; justify-content: center; overflow: auto; padding: 24px 12px; }
.modal[hidden] { display: none; }
.modal-box { background: var(--card); border: 1px solid var(--line); border-radius: 12px; width: min(1240px, 100%); padding: 14px 16px 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.modal-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-head .hint { margin: 0; flex: 1; min-width: 200px; }
.ws-grid { display: grid; grid-template-columns: 260px minmax(0, 1fr) 270px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .ws-grid { grid-template-columns: 1fr; } }
.ws-step { display: grid; grid-template-columns: 26px 1fr; gap: 8px; margin-bottom: 12px; }
.ws-step > b { width: 24px; height: 24px; border-radius: 50%; background: var(--accent2); color: #fff; display: grid; place-items: center; font-size: 13px; }
.ws-step input[type=text] { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 6px; padding: 5px 8px; }
.ws-step .field-label:first-child { margin-top: 2px; }
.ws-btns { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 4px; }
.ws-btns select { width: auto; flex: 1; }
.ws-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.ws-canvas-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); padding: 6px; text-align: center; }
#wsCanvas { max-width: 100%; height: auto; image-rendering: pixelated; cursor: crosshair; touch-action: none; }
.ws-palette-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.ws-free { display: inline-flex; align-items: center; gap: 6px; }
.ws-free input { width: 34px; height: 24px; padding: 0; border: 2px solid var(--line); border-radius: 6px; background: none; cursor: pointer; }
.ws-free input.sel { border-color: var(--accent); }
.ws-palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 4px 14px; margin-top: 4px; }
.ws-pal-row { display: flex; align-items: center; gap: 3px; }
.ws-pal-row span { width: 64px; font-size: 12px; color: var(--muted); }
.ws-sw { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(0, 0, 0, .3); padding: 0; cursor: pointer; }
.ws-sw.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
.ws-prev canvas { width: 100%; max-width: 288px; image-rendering: pixelated; border-radius: 8px; background: linear-gradient(var(--stage-top), var(--stage-bot)); display: block; }
.ws-tips { padding-left: 18px; margin: 10px 0 0; }
.ws-tips li { margin: 3px 0; }
.ws-library { display: flex; flex-direction: column; gap: 4px; max-height: 190px; overflow: auto; }
.ws-lib-row { display: grid; grid-template-columns: 1fr auto auto; gap: 4px; align-items: center; border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; }
.ws-lib-row span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.ws-lib-row small { color: var(--muted); margin-left: 6px; }

.site-footer { text-align: center; color: var(--muted); font-size: 12px; padding: 18px 12px 24px; }
