:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --ink: #181c24;
  --muted: #5a6270;
  --line: #dfe3ea;
  --accent: #1f5fbf;
  --accent-ink: #ffffff;
  --good: #1a7f43;
  --bad: #c81e32;
  --warn-bg: #fff4cc;
  --check-a: #eceef2;
  --check-b: #fafbfc;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171c; --panel: #1d2128; --ink: #e8eaee; --muted: #9aa3b2; --line: #323843;
    --accent: #5b8def; --warn-bg: #3a3218; --check-a: #2a2f37; --check-b: #333943;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85em; word-break: break-all; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.top nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.top nav a { text-decoration: none; font-weight: 500; }
.top nav a.on { color: var(--ink); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }

/* Picker */
.picker { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 1.25rem;
  max-width: 1100px; margin: 1.25rem auto; padding: 0 16px; }
.picker .help { grid-column: 1 / -1; }
.help ul { padding-left: 1.2rem; }
.help li { margin-bottom: .6rem; }
@media (max-width: 800px) { .picker { grid-template-columns: 1fr; } }

.field { margin-bottom: 1rem; }
.field label, .label { display: block; font-weight: 600; margin-bottom: .35rem; }
.opt { font-weight: 400; color: var(--muted); font-size: .9em; }
.row { display: flex; gap: .5rem; }
.row > input { flex: 1; min-width: 0; }
.conn-row select.cat { flex: 0 0 40%; }
.conn-row select:not(.cat) { flex: 1; min-width: 0; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; }
textarea { min-height: 4.5rem; resize: vertical; }
select:disabled { opacity: .6; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button, .button { font: inherit; font-weight: 500; cursor: pointer; border-radius: 8px; padding: .5rem .9rem;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); text-decoration: none; display: inline-block; }
button:hover, .button:hover { border-color: var(--accent); }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.danger { color: var(--bad); }
.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.button.disabled { pointer-events: none; opacity: .45; }
.small { padding: .25rem .6rem; font-size: .9em; }

.msg { margin: .35rem 0 0; font-size: .9em; color: var(--muted); min-height: 1em; }
.msg.good { color: var(--good); }
.msg.bad { color: var(--bad); }

.checker { aspect-ratio: 1; width: 100%; max-width: 600px; margin: 0 auto; border-radius: 8px; overflow: hidden;
  background: repeating-conic-gradient(var(--check-a) 0 25%, var(--check-b) 0 50%) 0 0 / 24px 24px; }
.checker img { width: 100%; height: 100%; display: block; }
.result { margin-top: 1rem; display: grid; gap: .6rem; }
.out-row { display: grid; grid-template-columns: 7.5rem 1fr auto; gap: .6rem; align-items: center; }
.out-row .k { color: var(--muted); font-size: .9em; }
.out-row code { background: var(--bg); padding: .35rem .5rem; border-radius: 6px; }
@media (max-width: 520px) { .out-row { grid-template-columns: 1fr auto; } .out-row .k { grid-column: 1 / -1; } }
.result .button { justify-self: start; }

/* Admin */
.admin { max-width: 1100px; margin: 1.25rem auto; padding: 0 16px; }
.admin > * + *, .admin form > .panel + .panel { margin-top: 1.25rem; }
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; background: var(--warn-bg); }
.flash.good { background: color-mix(in srgb, var(--good) 15%, transparent); }
.flash.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); }
.toolbar { display: flex; gap: .6rem; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar input[type=search] { max-width: 280px; font: inherit; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .85em; color: var(--muted); font-weight: 600; }
td.thumb img { width: 36px; height: 48px; object-fit: contain; display: block; }
td.thumb .none { width: 36px; height: 48px; border: 1px dashed var(--line); border-radius: 4px; }
.tag { display: inline-block; font-size: .8em; padding: .1rem .45rem; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.swatch { display: inline-block; width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(0,0,0,.25); vertical-align: middle; }
.bands { display: inline-flex; gap: 3px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.25rem; }
@media (max-width: 700px) { .grid2 { grid-template-columns: 1fr; } }
.hint { color: var(--muted); font-size: .88em; margin: .3rem 0 0; }
.ticks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .3rem .9rem; }
.ticks label { display: flex; gap: .45rem; align-items: center; font-weight: 400; margin: 0; }
.imgbox { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.imgbox .checker { width: 145px; aspect-ratio: 290 / 390; margin: 0; }
.imgbox .checker img { object-fit: contain; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
.login { max-width: 360px; margin: 4rem auto; padding: 0 16px; }
.band-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.band-row select { width: auto; min-width: 7rem; }

/* Import images */
.import-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1.25rem; margin-top: 1.25rem; }
.admin > .import-grid { margin-top: 1.25rem; }
.import-card { margin: 0 !important; display: grid; gap: .7rem; align-content: start; }
.import-card header { display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.import-card .pair { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.import-card figure { margin: 0; }
.import-card figcaption { font-size: .8em; color: var(--muted); text-align: center; margin-top: .25rem; }
.import-card .checker { aspect-ratio: 870 / 1170; max-width: none; }
.import-card .checker img { object-fit: contain; transition: opacity .2s; }
.import-card .controls { display: flex; gap: .4rem; flex-wrap: wrap; }
.import-card .controls .save { margin-left: auto; }
.import-card .controls select.bg { width: auto; padding: .25rem .4rem; font-size: .9em; }
.import-card .msg { margin: 0; }

.admin-foot { margin-top: 2rem; color: var(--muted); font-size: .85em; text-align: center; }

/* Image editor */
.admin:has(.editor) { max-width: 1440px; }
.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 380px); gap: 1.25rem; align-items: start; }
.admin > .editor { margin-top: 0; }
.ed-stage { position: sticky; top: 1rem; }
@media (max-width: 700px) { .editor { grid-template-columns: 1fr; } .ed-stage { position: static; } }
.ed-canvas-wrap { position: relative; display: flex; justify-content: center; }
#ed { width: 100%; max-width: calc((100vh - 230px) * 870 / 1170); min-width: 220px; height: auto; aspect-ratio: 870 / 1170; border-radius: 8px; touch-action: none; outline: none; box-shadow: 0 0 0 1px var(--line); }
#ed:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.ed-empty { position: absolute; inset: 40% 10% auto; text-align: center; background: var(--panel); padding: 1rem; border-radius: 8px; border: 1px solid var(--line); }
.ed-side .field { margin-bottom: .9rem; }
.ed-side input[type=range] { flex: 1; min-width: 0; }
.ed-side .num { max-width: 5.5rem; }
.ed-side .props { border-top: 1px solid var(--line); padding-top: .8rem; margin-top: .4rem; }
.ed-side .props > .label { margin-bottom: .6rem; }
.editor .btns { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .45rem; }
label.inline { display: flex; align-items: center; gap: .35rem; font-weight: 400; margin: 0; flex: 1; }
label.inline input { min-width: 0; }
.small-label { font-size: .9em; white-space: nowrap; flex: 0 0 auto; }
.layers { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; max-height: 15rem; overflow: auto; }
.layers:empty::after { content: 'No layers yet'; display: block; padding: .6rem; color: var(--muted); font-size: .9em; }
.layers li { display: flex; align-items: center; gap: .25rem; padding: .25rem .35rem; border-bottom: 1px solid var(--line); }
.layers li:last-child { border-bottom: 0; }
.layers li.on { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.layers li.off .nm { opacity: .5; }
.layers .nm { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: .3rem .25rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layers .ic { border: 0; background: none; padding: .2rem .35rem; font-size: .85em; color: var(--muted); }
.layers .ic:hover { color: var(--ink); }
.swatches { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.sw { width: 1.6rem; height: 1.6rem; padding: 0; border-radius: 50%; border: 1px solid rgba(0,0,0,.3); }
.ed-preview { width: 145px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.ed-preview canvas { width: 100%; height: auto; display: block; }
kbd { font: .85em ui-monospace, monospace; border: 1px solid var(--line); border-radius: 4px; padding: 0 .3em; }
