:root {
  --paper: #f6f1e5;
  --paper-2: #fdf9ef;
  --card: #fffdf6;
  --ink: #23262f;
  --ink-soft: #57605f;
  --line: #ded6bf;
  --line-soft: #e9e2cf;
  --accent: #c8433b;
  --accent-2: #2b5d9b;
  --brass: #9a7b3c;
  --ok: #1e7a4f;
  --warn: #b07a1f;
  --err: #c0392b;
  --radius: 12px;
  --shadow: 0 10px 30px -18px rgba(58, 49, 20, 0.55);
  --font-display: "Noto Serif SC", "Songti SC", "STSong", SimSun, serif;
  --font-body: "Noto Serif SC", "Songti SC", "STSong", SimSun, serif;
  --font-mono: "IBM Plex Mono", "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--paper);
  background-image:
    linear-gradient(rgba(154, 123, 60, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(154, 123, 60, 0.055) 1px, transparent 1px);
  background-size: 26px 26px;
  color: var(--ink);
  font-family: var(--font-body);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

::selection { background: rgba(200, 67, 59, 0.22); }

/* ---------- header ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 26px;
  border-bottom: 1.5px solid var(--line);
  background: linear-gradient(180deg, var(--paper-2), var(--paper-2));
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 14px; }
.logo { width: 39px; height: 39px; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.18)); }
.brand h1 {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: 0.06em;
  font-family: var(--font-display);
}
.brand .sub {
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
  margin-top: 2px;
}

.header-actions { display: flex; align-items: center; gap: 10px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  white-space: nowrap;
}
.chip.status.ready { color: var(--ok); border-color: rgba(30, 122, 79, 0.35); background: #f1f8f2; }
.chip.status.warn { color: var(--warn); border-color: rgba(176, 122, 31, 0.4); background: #fdf6e8; }

/* ---------- layout ---------- */
#layout {
  flex: 1;
  display: grid;
  grid-template-columns: 370px minmax(0, 1fr);
  gap: 18px;
  padding: 18px 26px 26px;
  max-width: 1720px;
  width: 100%;
  margin: 0 auto;
}

#sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow);
  animation: rise 0.5s ease both;
}
.card:nth-child(2) { animation-delay: 0.06s; }
.card:nth-child(3) { animation-delay: 0.12s; }
.card:nth-child(4) { animation-delay: 0.18s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.card h2 {
  font-size: 15px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-family: var(--font-display);
}
.card h2 .no {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--ink);
  color: var(--paper-2);
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-mono);
}

/* ---------- dropzone ---------- */
#dropzone {
  position: relative;
  border: 1.6px dashed #bdb49b;
  border-radius: 10px;
  min-height: 128px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  background: #fbf7ec;
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}
#dropzone:hover, #dropzone.drag {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(200, 67, 59, 0.1);
}
#dropzone.has-img { border-style: solid; border-color: var(--line); }
#dropzone #thumb { display: none; max-width: 100%; max-height: 200px; object-fit: contain; }
#dropzone.has-img #thumb { display: block; }
#dropzone.has-img .pick { display: none; }
#dropzone .pick { color: #94896a; font-size: 13px; padding: 18px; text-align: center; line-height: 1.7; }
#dropzone.has-img #removeImg { display: flex; }
#removeImg {
  display: none;
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.img-info { position: absolute; left: 10px; bottom: 8px; font-size: 11px; color: #7d7357; background: rgba(255,255,255,.7); padding: 2px 8px; border-radius: 6px; }

.field-label {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  margin: 11px 0 6px;
  letter-spacing: 0.03em;
}

textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 13px;
  font-family: var(--font-body);
  background: var(--paper-2);
  color: var(--ink);
  resize: vertical;
}
textarea:focus, input:focus, select:focus {
  outline: 2px solid rgba(43, 93, 155, 0.35);
  border-color: var(--accent-2);
}

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 13.5px;
  cursor: pointer;
  color: var(--ink);
  transition: transform 0.12s, box-shadow 0.15s, background 0.15s, border-color 0.15s;
  font-family: var(--font-body);
}
.btn:hover { border-color: #b9ae8e; transform: translateY(-1px); box-shadow: 0 5px 14px -8px rgba(58, 49, 20, 0.5); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.55; cursor: wait; transform: none; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.btn.primary:hover { background: #b33831; }
.btn.wide { width: 100%; }
.btn.ghost { background: transparent; }
.row2 { display: flex; gap: 9px; margin-top: 10px; }
.row2 .btn { flex: 1; }

/* ---------- steps ---------- */
.steps {
  list-style: none;
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.steps li {
  font-size: 12.5px;
  color: var(--ink-soft);
  padding: 6px 10px;
  border-left: 3px solid var(--line);
  background: #faf6ea;
  border-radius: 0 8px 8px 0;
  font-family: var(--font-mono);
}
.steps li.step-active { color: var(--accent-2); border-left-color: var(--accent-2); background: #eef3fa; }
.steps li.step-error { color: var(--err); border-left-color: var(--err); background: #fdf0ee; }
.steps li.step-done { color: var(--ok); border-left-color: var(--ok); background: #eef7f1; }
.steps li.step-default { color: var(--ink-soft); }

.error {
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--err);
  background: #fdf0ee;
  border: 1px solid rgba(192, 57, 43, 0.3);
  border-radius: 8px;
  padding: 9px 11px;
  white-space: pre-wrap;
}
.hidden { display: none !important; }

/* ---------- demos ---------- */
.demos { display: flex; flex-wrap: wrap; gap: 7px; }
.demo-chip {
  border: 1px dashed #bdb49b;
  border-radius: 999px;
  background: transparent;
  padding: 5px 11px;
  font-size: 12px;
  color: var(--accent-2);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-body);
}
.demo-chip:hover { border-color: var(--accent-2); background: #eef3fa; transform: translateY(-1px); }

/* ---------- verify ---------- */
.verify {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbf7ec;
  padding: 12px;
}
.verify-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.score-badge {
  font-size: 26px;
  font-weight: 800;
  color: var(--score-color, var(--ok));
  font-family: var(--font-mono);
  min-width: 58px;
}
.score-badge small { font-size: 12px; font-weight: 500; opacity: 0.7; }
.verify-title { font-weight: 700; margin-bottom: 2px; }
.verify-summary { font-size: 12.5px; color: var(--ink-soft); }
.issues { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.issue {
  border-left: 3px solid var(--warn);
  background: var(--card);
  border-radius: 0 8px 8px 0;
  padding: 8px 11px;
  font-size: 12.5px;
}
.issue.error { border-left-color: var(--err); }
.issue.warning { border-left-color: var(--warn); }
.issue.info { border-left-color: var(--accent-2); }
.issue-head { display: flex; gap: 8px; align-items: center; margin-bottom: 3px; font-size: 11px; }
.issue-head b { text-transform: uppercase; letter-spacing: 0.08em; color: var(--warn); }
.issue.error .issue-head b { color: var(--err); }
.issue.info .issue-head b { color: var(--accent-2); }
.issue-scope {
  background: #e8e0cb;
  border-radius: 5px;
  padding: 1px 8px;
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 11px;
}
.issue-msg { line-height: 1.55; }
.issue-sugg { margin-top: 4px; color: var(--ink-soft); font-size: 12px; }
.noissue { font-size: 13px; color: var(--ok); }
.recs { margin-top: 10px; font-size: 12.5px; }
.recs summary { cursor: pointer; color: var(--accent-2); }
.recs ul { margin: 6px 0 0 18px; color: var(--ink-soft); line-height: 1.7; }
.verify .btn.primary { margin-top: 10px; width: 100%; }

/* ---------- stage ---------- */
#stage {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: rise 0.5s ease 0.1s both;
}

#canvasWrap { position: relative; flex: 1; min-height: 0; }
#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}
#board:active { cursor: grabbing; }
#boardHud {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 11px;
  color: #8f856a;
  background: rgba(255, 253, 246, 0.85);
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-soft);
  pointer-events: none;
}

#player {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: var(--paper-2);
}
.circ {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper-2);
  border: none;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s;
  flex: none;
}
.circ:hover { transform: scale(1.06); }
.circ.small { width: 30px; height: 30px; background: transparent; color: var(--ink-soft); border: 1px solid var(--line); font-size: 13px; }
.circ.playing { background: var(--accent); }
.bar { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.bar-meta { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink-soft); font-family: var(--font-mono); }
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  height: 20px;
}
.speed select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  padding: 6px 8px;
  font-size: 12.5px;
  color: var(--ink);
  font-family: var(--font-mono);
}

#toggles {
  display: flex;
  gap: 8px;
  padding: 9px 16px;
  border-top: 1px solid var(--line-soft);
  background: var(--paper-2);
  flex-wrap: wrap;
}
.tog {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  letter-spacing: 0.05em;
  font-family: var(--font-body);
}
.tog.on { background: #eef3fa; color: var(--accent-2); border-color: rgba(43, 93, 155, 0.35); }

#infobar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: var(--card);
}
.info-left { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; }
.legend { color: var(--ink-soft); font-family: var(--font-mono); font-size: 11.5px; }
#checksRow { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: 55%; }
.chip-check {
  font-size: 11.5px;
  background: #f3eedd;
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  padding: 2px 9px;
  color: var(--ink-soft);
}
.chip-check.dim { opacity: 0.6; }

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(35, 30, 17, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  width: min(430px, 100%);
  padding: 22px;
  position: relative;
  box-shadow: 0 30px 60px -20px rgba(30, 25, 10, 0.5);
  animation: pop 0.22s ease;
}
.modal-box.wide { width: min(760px, 100%); }
@keyframes pop {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: none; }
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: none;
  background: transparent;
  font-size: 15px;
  color: var(--ink-soft);
  cursor: pointer;
}
.modal-box h3 { font-size: 17px; margin-bottom: 8px; font-family: var(--font-display); }
.modal-desc { font-size: 12.5px; color: var(--ink-soft); line-height: 1.7; margin-bottom: 14px; }
.modal-desc code {
  background: #f2ecda;
  border-radius: 5px;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 11.5px;
}
#keyInput {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 14px;
}
.key-msg { margin-top: 10px; font-size: 12.5px; color: var(--ink-soft); min-height: 18px; }
#jsonText {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: #fdfbf3;
  line-height: 1.5;
}

/* ---------- scrollbar ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cfc6ab; border-radius: 6px; border: 2px solid var(--paper); }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1080px) {
  #layout { grid-template-columns: 1fr; }
  #sidebar { overflow: visible; }
  #checksRow { justify-content: flex-start; max-width: none; }
  #infobar { flex-direction: column; }
}

@media (max-width: 760px) {
  #layout { padding: 12px 10px 18px; gap: 10px; }
  #topbar { padding: 10px 14px; gap: 8px; }
  .brand h1 { font-size: 17px; }
  .brand .sub { font-size: 11px; }
  .card { padding: 12px 12px; border-radius: 10px; }
  #canvasWrap { order: -1; min-height: 58vh; height: 58vh; }
  #stage { max-height: none; }
  #player { padding: 8px 10px; gap: 7px; flex-wrap: wrap; }
  .bar { flex: 1 1 100%; order: 3; }
  .circ { width: 34px; height: 34px; }
  #rangeInfo { font-size: 10px; }
  #toggles { padding: 7px 10px; gap: 6px; }
  .tog { padding: 3px 10px; font-size: 11px; }
  #boardHud { display: none; }
  #infobar { padding: 8px 10px; gap: 6px; }
  .chip-check { font-size: 10.5px; padding: 2px 7px; }
  .modal-box { padding: 16px; width: min(94vw, 430px); }
  .modal-box.wide { width: min(96vw, 760px); }
  .verify { padding: 10px; }
  .issue { padding: 7px 9px; }
  #keyInput { font-size: 14px; }
  #jsonText { font-size: 11.5px; }
}

@media (max-width: 420px) {
  #topbar { flex-wrap: wrap; }
  .header-actions { width: 100%; justify-content: space-between; }
  .btn { padding: 8px 12px; font-size: 12.5px; }
  .row2 { flex-wrap: wrap; }
  .row2 .btn { flex: 1 1 40%; }
  .demo-chip { font-size: 11px; padding: 4px 9px; }
}
