:root {
  --bg: #f3efe7;
  --paper: #fffdf8;
  --ink: #211d18;
  --muted: #777068;
  --line: #ded6ca;
  --accent: #cf5a3d;
  --accent-dark: #9f3825;
  --soft: #fff3df;
  --blue: #275a70;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; border: 0; }
h1, h2, h3, p { margin: 0; }

.topbar {
  height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 24px; letter-spacing: .06em; }
.topbar p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.eyebrow { color: var(--accent); font-size: 10px; font-weight: 900; letter-spacing: .16em; }
.top-actions, .canvas-actions { display: flex; gap: 8px; align-items: center; }

.primary, .ghost, .danger {
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 800;
}
.primary { background: var(--accent); color: white; }
.primary:hover { background: var(--accent-dark); }
.ghost { background: #fffaf1; border: 1px solid var(--line); color: var(--ink); }
.danger { background: #f9e3dd; color: #9d3927; border: 1px solid #e5b2a6; }
.wide { width: 100%; margin-top: 8px; }

.app-shell {
  height: calc(100vh - 126px);
  min-height: 650px;
  display: grid;
  grid-template-columns: 300px minmax(520px, 1fr) 335px;
}
.sidebar, .inspector {
  overflow: auto;
  background: var(--paper);
  padding: 18px;
}
.sidebar { border-right: 1px solid var(--line); }
.inspector { border-left: 1px solid var(--line); }

.dropzone {
  border: 1.5px dashed #cabdae;
  border-radius: 16px;
  padding: 22px 16px;
  text-align: center;
  background: #fbf6ec;
}
.dropzone.dragover { border-color: var(--accent); background: #fff0e9; }
.drop-icon { font-size: 38px; color: var(--accent); line-height: 1; }
.dropzone h2 { font-size: 16px; margin-top: 8px; }
.dropzone p { color: var(--muted); font-size: 12px; line-height: 1.55; margin: 8px 0 10px; }

.panel {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
}
.panel h2, .panel-heading h2 { font-size: 14px; }
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.panel-heading span, .hint { color: var(--muted); font-size: 11px; line-height: 1.6; }

.tool-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tool-grid button {
  padding: 10px 4px;
  border: 1px solid var(--line);
  background: #f5efe4;
  border-radius: 10px;
  font-weight: 900;
}
.tool-grid button.active { color: var(--accent-dark); background: #fde2da; border-color: #df927f; }
.tool-grid span { font-size: 10px; font-weight: 600; }

label { display: block; margin: 12px 0; font-size: 11px; font-weight: 800; }
input, textarea, select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fffefa;
  color: var(--ink);
}
textarea { resize: vertical; }

.item-list, .record-list, .page-list { display: flex; flex-direction: column; gap: 7px; }
.page-list { margin-top: 10px; }
.item, .page-item {
  border: 1px solid var(--line);
  background: #fffaf1;
  border-radius: 10px;
  padding: 9px 10px;
  text-align: left;
}
.item.active, .page-item.active { border-color: var(--accent); background: #fff0e9; }
.item strong, .page-item strong { display: block; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item small, .page-item small { color: var(--muted); font-size: 10px; }
.record {
  padding: 9px;
  border-radius: 10px;
  background: #f6f1e8;
  border: 1px solid var(--line);
  font-size: 11px;
}
.record time { color: var(--muted); display: block; margin-top: 3px; }
.sample-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}
.sample-json {
  max-height: 240px;
  margin-top: 10px;
  font-size: 10px;
}
.sample-details {
  margin-top: 10px;
  color: var(--muted);
  font-size: 11px;
}
.sample-details summary {
  cursor: pointer;
  font-weight: 900;
  color: var(--ink);
}

.workspace { min-width: 0; display: flex; flex-direction: column; }
.canvas-toolbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.canvas-toolbar strong { display: block; font-size: 13px; }
.canvas-toolbar span { display: block; color: var(--muted); font-size: 11px; }
.canvas-actions button { padding: 7px 10px; font-size: 12px; }

.stage {
  position: relative;
  flex: 1;
  overflow: hidden;
  background:
    linear-gradient(45deg, #d7d1c7 25%, transparent 25%),
    linear-gradient(-45deg, #d7d1c7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d7d1c7 75%),
    linear-gradient(-45deg, transparent 75%, #d7d1c7 75%);
  background-size: 32px 32px;
  background-position: 0 0, 0 16px, 16px -16px, -16px 0;
}
canvas {
  position: absolute;
  transform-origin: 0 0;
  background: white;
  box-shadow: 0 16px 45px #0003;
  touch-action: none;
}
.stage-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  color: #716960;
  pointer-events: none;
}
.stage-hint h2 { font-size: 20px; }
.stage-hint p { margin-top: 8px; font-size: 12px; }

.tabs {
  display: flex;
  margin: -18px -18px 18px;
  border-bottom: 1px solid var(--line);
}
.tab {
  flex: 1;
  padding: 14px 4px;
  background: transparent;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.empty {
  padding: 22px 10px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}
.field-row, .coords {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.checkbox { display: flex; align-items: center; gap: 8px; }
.checkbox input { width: auto; margin: 0; }
.image-controls {
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff7e8;
}
.image-control-title {
  font-size: 12px;
  font-weight: 900;
  margin-bottom: 4px;
}
.image-asset-name {
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
pre {
  white-space: pre-wrap;
  max-height: 62vh;
  overflow: auto;
  padding: 12px;
  border-radius: 10px;
  background: #28231e;
  color: #fff2df;
  font-size: 10px;
  line-height: 1.55;
}
.qa-card {
  padding: 14px;
  border-radius: 12px;
  background: #fff7e8;
  border: 1px solid var(--line);
}
.qa-card h2 { font-size: 15px; margin-bottom: 10px; }
.qa-card ul { margin: 0; padding-left: 18px; font-size: 12px; line-height: 1.7; }
.pass { color: #247043; }
.warn { color: #a76110; }

footer {
  height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  background: var(--paper);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
}

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 260px minmax(420px, 1fr); }
  .inspector { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
}

@media (max-width: 760px) {
  .topbar { height: auto; align-items: flex-start; flex-direction: column; }
  .app-shell { display: block; height: auto; min-height: 0; }
  .workspace { height: 70vh; }
  footer { height: auto; padding: 10px 14px; gap: 8px; flex-direction: column; align-items: flex-start; }
}
