:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1b1d21;
  --muted: #5b6270;
  --line: #e2e5ea;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --bar: #93c5fd;
  --bar-lead: #2563eb;
  --danger: #b91c1c;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  padding: 24px clamp(12px, 3vw, 40px) 48px;
}

.top { max-width: 900px; margin: 0 auto 20px; }
.top h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: -0.01em; }
.top p { margin: 0; color: var(--muted); max-width: 640px; }

.layout {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  gap: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.board-panel {
  flex: 0 0 auto;
  width: min(360px, 100%);
}

.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06), 0 0 0 1px var(--line);
}

.board-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#board { touch-action: none; cursor: crosshair; }
#overlay { pointer-events: none; }

.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
}

.label-field {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.label-field input {
  width: 56px;
  height: 40px;
  text-align: center;
  font: 600 20px var(--mono);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
}

.label-field input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.btn {
  height: 40px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font: 500 15px var(--font);
  cursor: pointer;
}
.btn:hover { border-color: #c9ced6; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.primary[disabled] { opacity: 0.6; cursor: wait; }
.btn.link {
  border: none;
  background: none;
  color: var(--danger);
  padding: 0 6px;
  height: auto;
  font-size: 13px;
}

.status {
  margin-top: 10px;
  min-height: 20px;
  font-size: 13px;
  color: var(--muted);
}
.status.ok { color: #047857; }
.status.warn { color: var(--danger); }

.compute {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06), 0 0 0 1px var(--line);
  font-size: 12px;
  color: var(--muted);
}
.compute-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 500;
  color: var(--ink);
  font-size: 13px;
}
.compute-cpu { font: 600 13px var(--mono); }
.meter {
  height: 6px;
  margin: 8px 0 10px;
  background: #eef0f3;
  border-radius: 999px;
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
}
.meter-fill.hot { background: #f59e0b; }
.compute-grid {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
}
.compute-grid div { display: flex; flex-direction: column; gap: 1px; }
.compute-grid dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.compute-grid dd { margin: 0; font: 500 12px var(--mono); color: var(--ink); }

.probs-panel {
  flex: 1 1 320px;
  min-width: 280px;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06), 0 0 0 1px var(--line);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.add-form { display: flex; gap: 8px; }
.add-form input {
  flex: 1;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: 15px var(--mono);
  color: var(--ink);
  background: var(--panel);
}
.add-form input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.rows { display: flex; flex-direction: column; gap: 6px; }

.row {
  display: grid;
  grid-template-columns: 34px 1fr 52px 34px 24px;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
}
.row:hover { background: #f7f8fa; }
.row.selected { background: var(--accent-soft); }

.row .char {
  font: 600 20px var(--mono);
  text-align: center;
}

.row .track {
  height: 18px;
  background: #eef0f3;
  border-radius: 999px;
  overflow: hidden;
}
.row .bar {
  height: 100%;
  width: 0%;
  background: var(--bar);
  border-radius: 999px;
  transition: background-color 200ms;
}
.row.lead .bar { background: var(--bar-lead); }

.row .pct { font: 500 13px var(--mono); text-align: right; color: var(--ink); }
.row .count { font-size: 12px; color: var(--muted); text-align: right; }
.row .remove {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.row .remove:hover { color: var(--danger); }

.verdict {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  padding: 2px 6px;
}
.verdict.ok { color: #047857; }
.verdict.unknown { color: #b45309; }
.verdict[hidden] { display: none; }

.unknown-row { cursor: default; margin-top: 4px; border-top: 1px dashed var(--line); padding-top: 8px; }
.unknown-row:hover { background: none; }
.unknown-row .char { color: var(--muted); }
.unknown-row .bar { background: #d6d9de; }
.unknown-row.lead .bar { background: #f59e0b; }
.unknown-row .count { font-size: 11px; }
.unknown-row[hidden] { display: none; }

.gallery-panel {
  max-width: 900px;
  margin: 24px auto 0;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06), 0 0 0 1px var(--line);
  padding: 16px;
}
.gallery-head h2 { margin: 0 0 4px; font-size: 16px; }
.gallery-head h2 span { color: var(--muted); font-weight: 400; }
.gallery-head p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 10px;
}
.sample {
  position: relative;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  overflow: hidden;
}
.sample canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  image-rendering: auto;
}
.sample-label {
  position: absolute;
  left: 4px;
  bottom: 4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  font: 600 13px var(--mono);
  cursor: pointer;
}
.sample-label:hover { background: #1d4ed8; }
.sample-remove {
  position: absolute;
  right: 2px;
  top: 2px;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: none;
  background: rgba(255,255,255,0.85);
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.sample-remove:hover { color: var(--danger); background: #fff; }

.empty { color: var(--muted); font-size: 14px; padding: 8px 4px; }
.empty[hidden] { display: none; }

.panel-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.panel-footer .spacer { flex: 1; }
.check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.model-info { font-size: 12px; }

.explain {
  max-width: 900px;
  margin: 28px auto 0;
  color: var(--muted);
  font-size: 14px;
}
.explain summary { cursor: pointer; color: var(--ink); font-weight: 500; }
.explain ol { padding-left: 20px; }
.explain li { margin: 6px 0; }
.explain strong { color: var(--ink); }

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .board-panel { width: 100%; }
}
