:root {
  --wood: #e6c37a;
  --ink: #2a2118;
  --bg: #f7f2e8;
  --panel: #fffdf8;
  --accent: #7a5c2e;
  --danger: #a33a2a;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}
main { max-width: 64rem; margin: 0 auto; padding: 1.4rem 1rem 3rem; }
h1 { font-size: 1.5rem; margin: 0.4rem 0 0.2rem; }
.sub { color: #6b5c46; margin-top: 0; }
h2 { font-size: 1.15rem; border-left: 4px solid var(--wood); padding-left: .5rem; }
h3 { font-size: 1rem; margin-bottom: .3rem; }

#dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .6rem; min-height: 9rem; padding: 1rem;
  background: var(--panel); border: 2px dashed #c9b48a; border-radius: var(--radius);
  cursor: pointer; text-align: center;
}
#dropzone.dragover { border-color: var(--accent); background: #fdf6e6; }
#dropzone:focus-visible { outline: 3px solid var(--accent); }
#file-input { position: absolute; width: 1px; height: 1px; opacity: 0; }
#preview { max-width: 100%; max-height: 16rem; border-radius: 6px; }

button, .btn {
  display: inline-block; min-height: 44px; padding: .55rem 1.1rem;
  font-size: 1rem; font-family: inherit; border-radius: var(--radius);
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  cursor: pointer; text-decoration: none; text-align: center;
}
button:disabled { background: #b9a988; border-color: #b9a988; cursor: not-allowed; }
.btn small { display: block; font-size: .72rem; opacity: .85; }
#convert-btn { margin-top: .8rem; width: 100%; font-size: 1.1rem; }
#status { min-height: 1.4em; color: #6b5c46; }

#error-box {
  background: #fbeae6; border: 1px solid var(--danger); border-radius: var(--radius);
  padding: .7rem 1rem; margin-top: .6rem;
}
#error-main { color: var(--danger); margin: 0 0 .3rem; font-weight: 600; }
#error-detail, #warnings-raw {
  white-space: pre-wrap; word-break: break-all; font-size: .8rem; color: #555;
}

#warnings-box {
  background: #fff7dc; border: 1px solid #d8b74a; border-radius: var(--radius);
  padding: .6rem 1rem; margin-bottom: 1rem;
}
#warnings-list { margin: .2rem 0 .4rem; padding-left: 1.4rem; }

.view-toggle { display: none; gap: .5rem; margin-bottom: .6rem; }
.view-toggle button { background: var(--panel); color: var(--ink); border-color: #c9b48a; }
.view-toggle button.active { background: var(--wood); border-color: var(--accent); font-weight: 700; }

#compare { display: flex; gap: 1rem; flex-wrap: wrap; }
.pane { margin: 0; flex: 1 1 24rem; min-width: 0; }
.pane img, #svg-holder svg { width: 100%; height: auto; border-radius: 6px; background: #fff; box-shadow: 0 2px 10px rgba(60,40,10,.15); }
figcaption { font-size: .82rem; color: #6b5c46; text-align: center; margin-top: .3rem; }

#downloads { display: flex; gap: .6rem; flex-wrap: wrap; margin: 1.1rem 0; }

#editor-details {
  background: var(--panel); border: 1px solid #c9b48a; border-radius: var(--radius);
  padding: .6rem 1rem;
}
#editor-details summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.hint { font-size: .86rem; color: #6b5c46; }
#json-editor {
  width: 100%; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .82rem;
  border: 1px solid #c9b48a; border-radius: 6px; padding: .5rem; background: #fffef9;
}
.editor-actions { display: flex; gap: .6rem; margin-top: .5rem; flex-wrap: wrap; }
.file-btn { position: relative; overflow: hidden; background: var(--panel); color: var(--ink); border-color: #c9b48a; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

footer { margin-top: 2rem; font-size: .84rem; color: #6b5c46; border-top: 1px solid #e3d5b8; padding-top: .8rem; }

@media (max-width: 44rem) {
  .view-toggle { display: flex; }
  #compare .pane { flex-basis: 100%; }
  .pane[hidden] { display: none; }
}
@media (min-width: 44.01rem) {
  /* desktop: always show BOTH panes side by side regardless of the mobile tab
     state — a resize/rotation must not strand one pane hidden (review m2) */
  #pane-original[hidden], #pane-diagram[hidden] { display: block; }
}
.file-btn:focus-within, #dropzone:focus-within { outline: 3px solid var(--accent); }
details > summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
