:root {
  --bg: #111111; --bg2: #161616; --fg: #ececec; --muted: #8a8a8a; --line: #2a2a2a; --accent: #ffffff;
  --canvas: #111111; --track: #333; --thumb: #f2f2f2; --tag-bg: #2a2a2a;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #fafafa; --bg2: #ffffff; --fg: #161616; --muted: #777; --line: #e3e3e3; --accent: #111;
  --canvas: #ffffff; --track: #d8d8d8; --thumb: #222; --tag-bg: #eaeaea;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.45 -apple-system, "Inter", "Helvetica Neue", Arial, sans-serif; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.top { max-width: 1600px; margin: 0 auto; padding: 32px 40px 24px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.brand { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.topnav { display: flex; align-items: center; gap: 28px; }
.topnav a { color: var(--muted); }
.topnav a:hover { color: var(--fg); }
.count { color: var(--muted); font-size: 12px; margin-left: 4px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 50%; color: var(--fg); opacity: .85; }
.icon-btn:hover { opacity: 1; background: var(--line); }
.icon-btn.on { color: #ff5a5a; }

.view { max-width: 1600px; margin: 0 auto; padding: 0 40px 60px; }
.title-row { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "title actions" "title arrows"; align-items: center; padding: 28px 0 22px; border-bottom: 1px solid var(--line); gap: 8px 40px; }
h1 { grid-area: title; font-size: clamp(30px, 4.2vw, 56px); font-weight: 500; letter-spacing: -0.02em; margin: 0; line-height: 1.1; }
.actions { grid-area: actions; display: flex; align-items: center; gap: 4px; justify-self: start; }
.nav-arrows { grid-area: arrows; display: flex; gap: 8px; justify-self: end; }
@media (min-width: 1100px) {
  .title-row { grid-template-columns: 1fr auto 320px; grid-template-areas: "title actions arrows"; }
}

.body { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 48px; padding-top: 24px; }
@media (max-width: 900px) { .body { grid-template-columns: 1fr; } .top, .view { padding-left: 20px; padding-right: 20px; } }
.stage { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.stage-tools { width: min(100%, 720px); display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { padding: 5px 12px; font-size: 12px; color: var(--muted); }
.seg button.on { background: var(--fg); color: var(--bg); }
.preview { width: min(100%, 720px); aspect-ratio: 1; background-color: var(--canvas); background-repeat: repeat; background-size: 100%; border: 1px solid var(--line); image-rendering: auto; }
.preview.busy { opacity: .6; }
.notes { width: min(100%, 720px); font-size: 13px; margin: 0; }

.panel { display: flex; flex-direction: column; gap: 18px; padding-top: 4px; }
.controls { display: flex; flex-direction: column; gap: 18px; }
.controls + .controls { border-top: 1px solid var(--line); padding-top: 18px; }
.ctl label { display: block; font-size: 14px; margin-bottom: 8px; }
.ctl .row { display: flex; align-items: center; gap: 14px; }
.ctl input[type=range] { flex: 1; accent-color: var(--thumb); height: 2px; }
.ctl .val { min-width: 54px; text-align: right; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ctl select, .ctl input[type=text], .ctl input[type=number] { width: 100%; background: var(--bg2); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; font-size: 13px; }
.ctl input[type=color] { width: 44px; height: 28px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg2); padding: 0 2px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; }
.switch input { appearance: none; width: 34px; height: 18px; border-radius: 9px; background: var(--track); position: relative; margin: 0; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--thumb); transition: left .15s; }
.switch input:checked { background: var(--fg); }
.switch input:checked::after { left: 18px; background: var(--bg); }
.panel-actions { display: flex; justify-content: flex-end; }
.link { color: var(--muted); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--fg); }

.card { border-top: 1px solid var(--line); padding-top: 20px; }
.card-head { display: flex; align-items: center; gap: 10px; font-size: 18px; }
.tag { font-size: 11px; letter-spacing: .08em; padding: 3px 8px; border-radius: 3px; background: var(--tag-bg); color: var(--fg); }
.card p { font-size: 13px; margin: 6px 0 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.btn { border: 1px solid var(--line); border-radius: 6px; padding: 7px 14px; font-size: 13px; }
.btn:hover { background: var(--line); }
.card select { background: var(--bg2); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; font-size: 13px; }
.stats { font-size: 12px; line-height: 1.7; }
.stats .ok { color: #4caf50; }
.stats .bad { color: #e05050; }

.lib-head { display: flex; align-items: center; justify-content: space-between; padding: 28px 0 18px; gap: 20px; flex-wrap: wrap; }
.lib-filters { display: flex; align-items: center; gap: 18px; }
.lib-filters input[type=search] { background: var(--bg2); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; min-width: 240px; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
#library h2 { font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 34px 0 14px; font-weight: 500; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 18px; }
.lcard { display: block; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--bg2); transition: border-color .15s; }
.lcard:hover { border-color: var(--muted); }
.lcard .thumb { aspect-ratio: 1; background: var(--canvas) center/cover no-repeat; }
.lcard .lb { padding: 10px 12px; }
.lcard b { display: block; font-size: 13px; font-weight: 500; }
.lcard small { color: var(--muted); font-size: 11px; }
.lcard .fav { float: right; color: #ff5a5a; font-size: 12px; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 9px 16px; border-radius: 6px; font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,.25); z-index: 10; }
