:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --ink: #26231f;
  --muted: #77706a;
  --line: #e4dfd6;
  --accent: #e2574c;
  --accent-ink: #ffffff;
  --accent-soft: #fde9e6;
  --focus: #2f6fdf;
  --radius: 10px;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "PingFang SC", "Noto Sans JP", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); font-size: 14px; line-height: 1.5; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }

header.top {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; text-decoration: none; }
.brand-mark { display: grid; grid-template-columns: repeat(3, 7px); gap: 2px; }
.brand-mark i { width: 7px; height: 7px; border-radius: 50%; display: block; }
.top .spacer { flex: 1; }
.lang-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.lang-switch button { white-space: nowrap; border: 0; background: none; padding: 3px 10px; cursor: pointer; font-size: 12px; color: var(--muted); }
.lang-switch button[aria-pressed="true"] { background: var(--ink); color: #fff; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #cfc8bc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(0.95); }
.btn.ghost { border-color: transparent; background: none; }
.btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { padding: 3px 8px; font-size: 12px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- 図案ページ ---------- */
.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; padding: 16px 20px; align-items: start; }
.side { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 70px; max-height: calc(100vh - 86px); overflow: auto; padding-bottom: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card h2 { font-size: 13px; margin: 0 0 10px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }

.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 18px 12px; text-align: center;
  cursor: pointer; color: var(--muted); background: #fbfaf7; display: block;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop img { max-width: 100%; max-height: 160px; border-radius: 6px; display: block; margin: 0 auto 8px; }
.drop input { display: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 11px; cursor: pointer; font-size: 13px; }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.custom-size { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.custom-size input { width: 64px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; }
.radio { display: flex; gap: 8px; align-items: flex-start; padding: 3px 0; cursor: pointer; }
.radio input { margin-top: 3px; }
select.full { width: 100%; padding: 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.slider { display: grid; grid-template-columns: 76px 1fr 36px; align-items: center; gap: 6px; font-size: 13px; }
.slider output { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; padding: 3px 0; cursor: pointer; }
.check input { margin-top: 3px; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 600; }
details[open] summary { margin-bottom: 8px; }

.work { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.toolbar .group { display: inline-flex; gap: 0; }
.toolbar .group .btn { border-radius: 0; margin-left: -1px; }
.toolbar .group .btn:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.toolbar .group .btn:last-child { border-radius: 0 8px 8px 0; }
.toolbar .meta { color: var(--muted); font-size: 13px; }
.toolbar .spacer { flex: 1; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.hint.paint { color: #8a3b14; background: #fff2dd; padding: 6px 10px; border-radius: 6px; }

.stage {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: auto; max-height: calc(100vh - 200px); min-height: 360px; position: relative;
}
.stage canvas { display: block; margin: 0 auto; image-rendering: pixelated; }
.stage canvas.paint { cursor: crosshair; }
.stage img.orig { display: block; max-width: 100%; margin: 0 auto; }
.empty { display: grid; place-items: center; min-height: 360px; color: var(--muted); text-align: center; padding: 20px; }
.empty .dots { display: grid; grid-template-columns: repeat(8, 14px); gap: 4px; margin: 0 auto 14px; width: max-content; opacity: .7; }
.empty .dots i { width: 14px; height: 14px; border-radius: 50%; display: block; }
.busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,.6); font-weight: 600; }

.legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }
.legend button {
  display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center; text-align: left;
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 5px 8px; cursor: pointer;
}
.legend button[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.legend .sw { width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; font-size: 11px; font-weight: 700; border: 1px solid rgba(0,0,0,.08); }
.legend .nm { font-size: 12px; line-height: 1.3; overflow: hidden; }
.legend .nm b { display: block; font-size: 13px; }
.legend .nm span { color: var(--muted); }
.legend .ct { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }
.legend-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.legend-head h2 { margin: 0; }

/* ---------- 管理画面 ---------- */
.admin-wrap { max-width: 1080px; margin: 0 auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.login { max-width: 360px; margin: 60px auto; }
.login input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin: 6px 0 12px; }
.err { color: #b3261e; font-size: 13px; min-height: 1.2em; margin: 4px 0; }
.ok { color: #1f7a3a; font-size: 13px; }
table.colors { width: 100%; border-collapse: collapse; }
table.colors th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
table.colors td { padding: 4px 6px; border-bottom: 1px solid #f0ece5; vertical-align: middle; }
table.colors tr.off td:not(:first-child) { opacity: .45; }
table.colors input[type=text] { width: 100%; padding: 4px 6px; border: 1px solid transparent; border-radius: 6px; background: transparent; }
table.colors input[type=text]:hover { border-color: var(--line); }
table.colors input[type=text]:focus { border-color: var(--focus); background: #fff; outline: none; }
table.colors input.sym { width: 54px; text-align: center; font-weight: 700; }
.colorcell { display: flex; align-items: center; gap: 6px; }
.colorcell input[type=color] { width: 34px; height: 28px; border: 1px solid var(--line); border-radius: 6px; padding: 0; background: none; cursor: pointer; }
.colorcell input[type=text] { width: 86px !important; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.table-scroll { max-height: 60vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.row-actions .spacer { flex: 1; }
.search { padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px; width: 180px; }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.card-head .spacer { flex: 1; }
.card p.desc { margin: 0 0 10px; color: var(--muted); font-size: 13px; }

.recog { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 14px; margin-top: 12px; }
.photo-box { position: relative; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fbfaf7; align-self: start; }
.photo-box canvas { display: block; width: 100%; height: auto; cursor: crosshair; }
.marker { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1.5px #000; pointer-events: none; display: grid; place-items: center; font-size: 10px; font-weight: 700; color: #fff; text-shadow: 0 0 2px #000; }
.marker.sel { box-shadow: 0 0 0 3px var(--accent); }
.recog-list { display: flex; flex-direction: column; gap: 4px; max-height: 70vh; overflow: auto; }
.recog-item { display: grid; grid-template-columns: 20px 18px 30px 1fr 1fr; gap: 6px; align-items: center; padding: 4px 6px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.recog-item.sel { border-color: var(--accent); background: var(--accent-soft); }
.recog-item .no { font-size: 11px; color: var(--muted); text-align: center; }
.recog-item .sw { width: 30px; height: 24px; border-radius: 5px; border: 1px solid rgba(0,0,0,.1); }
.recog-item input[type=text] { width: 100%; padding: 3px 5px; border: 1px solid var(--line); border-radius: 5px; font-size: 13px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 8px; font-size: 13px; z-index: 50; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 12px 16px; }
  .side { position: static; max-height: none; }
  .recog { grid-template-columns: 1fr; }
  header.top { padding: 10px 16px; gap: 8px; }
  .brand { font-size: 14px; }
  .stage { max-height: 70vh; }
}

@media print {
  header.top, .side, .toolbar, .hint, .no-print { display: none !important; }
  .layout { display: block; padding: 0; }
  .stage { max-height: none; overflow: visible; border: 0; }
  .stage canvas { max-width: 100%; height: auto !important; width: auto !important; }
  body, :root { background: #fff; }
}

/* 狭い画面のヘッダー */
.brand > span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.brand { min-width: 0; flex-shrink: 1; }
header.top > *:not(.brand) { flex-shrink: 0; }
@media (max-width: 560px) {
  header.top { gap: 6px; padding: 8px 12px; }
  .brand > span:last-child { display: none; }
  header.top .btn.ghost { padding: 6px 6px; }
}

.style-pick { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.style-pick .label { font-size: 13px; font-weight: 600; color: var(--muted); }
.style-pick .hint { margin: 0; }
#loadMsg { margin: 8px 0 0; }

.versions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.version { display: flex; flex-direction: column; gap: 4px; padding: 4px; border: 2px solid var(--line); border-radius: 10px; background: var(--panel); cursor: pointer; text-align: center; }
.version[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.version .v-img { position: relative; display: block; aspect-ratio: 4 / 3; border-radius: 6px; overflow: hidden; background: #eee; }
.version .v-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.version.loading .v-img img, .version.idle .v-img img { filter: blur(3px) grayscale(.4); opacity: .6; }
.version .v-state { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink); }
.version .v-state.err { color: #b3261e; background: rgba(255,255,255,.7); }
.version .v-label { font-size: 12px; font-weight: 600; }
.spin { width: 16px; height: 16px; border: 2px solid rgba(0,0,0,.15); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; display: block; }
@keyframes spin { to { transform: rotate(360deg); } }
#regen { align-self: flex-start; }
