:root {
  --ink: #d9d3c6;
  --ink-dim: #8f8a7f;
  --slate: #22262a;
  --slate-2: #2c3136;
  --floor: #3a3f44;
  --line: #3f454b;
  --paper: #f3f1ec;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--floor); color: var(--ink);
  font-family: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", "Noto Serif", Georgia, serif;
  font-size: 13px; line-height: 1.55; }
.app { display: flex; height: 100%; }
.stage { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; padding: 24px; position: relative; }
.sheet { width: min(100%, calc(100vh - 48px)); aspect-ratio: 1; background: var(--paper);
  box-shadow: 0 1px 0 rgba(255,255,255,.06) inset, 0 18px 40px rgba(0,0,0,.35), 0 2px 6px rgba(0,0,0,.25); position: relative; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
#msg { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; padding: 32px; text-align: left;
  color: #3a3833; background: var(--paper); white-space: pre-wrap; font-size: 14px; }
.panel { width: 292px; flex: none; background: var(--slate); border-left: 1px solid var(--line); padding: 22px 22px 28px; overflow-y: auto; }
h1 { font-size: 22px; font-weight: 500; margin: 0 0 2px; letter-spacing: .04em; }
.sub { color: var(--ink-dim); margin: 0 0 20px; font-size: 12px; }
h2 { font-size: 12.5px; font-weight: 500; color: var(--ink-dim); margin: 22px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.seg { display: flex; border: 1px solid var(--line); }
.seg button { flex: 1; background: none; border: 0; color: var(--ink); padding: 7px 0; font: inherit; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--swatch, #777); color: var(--swatch-ink, #fff); }
.seg button:focus-visible, select:focus-visible, .btn:focus-visible, input:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
.palette { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.chip { height: 38px; border: 1px solid rgba(0,0,0,.35); cursor: pointer; padding: 0; position: relative; }
.chip[aria-pressed="true"] { outline: 2px solid var(--ink); outline-offset: 2px; }
.chip:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.pigname { color: var(--ink-dim); margin: 0 0 6px; font-variant-numeric: tabular-nums; }
#pal { display: block; width: 100%; height: auto; border: 1px solid rgba(0,0,0,.45); border-radius: 6px; cursor: crosshair; touch-action: none;
  box-shadow: inset 0 3px 8px rgba(0,0,0,.22); margin-bottom: 6px; }
.brush-preset { margin: 12px 0 8px; }
.preset-label { margin: 0 0 6px; }
.preset-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 8px; margin-bottom: 8px; }
.preset-button { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 84px; min-width: 0; padding: 8px 3px; gap: 4px; border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 11px; color: var(--ink); background: var(--slate-2); cursor: pointer; touch-action: manipulation; }
.preset-button svg { width: 36px; height: 36px; pointer-events: none; }
.preset-button[aria-pressed="true"] { border-color: var(--ink); background: #454b50; box-shadow: inset 0 0 0 1px var(--ink); }
.preset-check { position: absolute; top: 3px; right: 5px; visibility: hidden; font-size: 12px; }
.preset-button[aria-pressed="true"] .preset-check { visibility: visible; }
.preset-button:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.preset-button:active { background: #53595e; }
@media (hover: hover) { .preset-button:hover { border-color: var(--ink-dim); } }
.brushload { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.brushswatch { width: 44px; height: 30px; flex: none; border: 1px solid rgba(0,0,0,.45); background: var(--swatch); border-radius: 0 0 40% 40%; }
.row { display: grid; grid-template-columns: 1fr 44px; align-items: center; gap: 8px; margin: 3px 0; }
.row label { display: block; }
.row output { text-align: right; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.row input[type=range] { grid-column: 1 / -1; width: 100%; margin: 0 0 4px; accent-color: var(--ink); height: 18px; }
.btns { display: flex; gap: 8px; margin-top: 14px; }
.btn { flex: 1; background: var(--slate-2); color: var(--ink); border: 1px solid var(--line); padding: 7px 0; font: inherit; cursor: pointer; }
.btn:hover { background: #363c42; }
.stat { margin-top: 18px; color: var(--ink-dim); font-size: 12px; font-variant-numeric: tabular-nums; }
@media (max-width: 760px) {
  .app { flex-direction: column; height: auto; min-height: 100%; }
  .stage { padding: 12px; }
  .sheet { width: 100%; }
  .panel { width: 100%; border-left: 0; border-top: 1px solid var(--line); }
}
@media (prefers-reduced-motion: no-preference) { .seg button, .btn { transition: background .12s; } }
