:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --ink: #1d1c1a;
  --muted: #77736b;
  --line: #e3dfd7;
  --accent: #d4502c;
  --accent-ink: #fff;
  --ok: #2a7a4b;
  --warn: #a8641a;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
a { color: var(--accent); }
.muted { color: var(--muted); }

.top {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; gap: 12px; align-items: center; }
.logo { font-size: 26px; color: var(--accent); }
h1 { font-size: 18px; margin: 0; letter-spacing: -0.01em; }
.sub { margin: 0; font-size: 12px; color: var(--muted); }
nav { display: flex; gap: 8px; }

.layout {
  display: grid; grid-template-columns: 290px 1fr 330px; gap: 0;
  height: calc(100vh - 63px);
}
.panel { background: var(--panel); padding: 18px; overflow: auto; }
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }
h2:first-child { margin-top: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-size: 14px; cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: #c9c3b8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); width: 100%; padding: 11px; font-weight: 600; }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { padding: 5px 10px; font-size: 13px; }

.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  border: 2px dashed #cfc9be; border-radius: var(--radius); padding: 18px; min-height: 130px;
  cursor: pointer; color: var(--muted); font-size: 14px; margin-bottom: 14px; background: #faf9f6;
}
.drop.over { border-color: var(--accent); background: #fff4ef; }
.drop b { color: var(--ink); }
.drop-icon { font-size: 22px; margin-bottom: 4px; }
.drop img { max-width: 100%; max-height: 140px; border-radius: 6px; margin-top: 8px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field select, .field input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; font-size: 14px; background: #fff;
}
.field small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }

.msg { margin-top: 12px; padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.msg.error { background: #fdecea; color: #9b2c1c; }
.msg.ok { background: #e9f5ee; color: var(--ok); }

.help { margin-top: 18px; font-size: 13px; color: #3b3935; }
.help summary { cursor: pointer; font-weight: 600; }
.help ol { padding-left: 18px; line-height: 1.5; }
.recent { list-style: none; padding: 0; margin: 8px 0; }
.recent li { padding: 6px 0; border-bottom: 1px solid var(--line); }

.viewer { display: flex; flex-direction: column; min-width: 0; }
.toolbar {
  display: flex; gap: 12px; align-items: center; padding: 10px 14px;
  border-bottom: 1px solid var(--line); background: #fbfaf8; flex-wrap: wrap;
}
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--ink); color: #fff; }
.chk { font-size: 13px; display: flex; gap: 5px; align-items: center; }
.ruler-out { font-weight: 700; font-size: 15px; color: var(--accent); }

.canvas-wrap { position: relative; flex: 1; min-height: 0; background: #2b2a28; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #e8e4dc; text-align: center; padding: 40px;
}
.empty .muted { color: #a19c92; max-width: 420px; font-size: 14px; }
.busy {
  position: absolute; inset: 0; background: rgba(20, 20, 20, .55); color: #fff;
  display: flex; gap: 12px; align-items: center; justify-content: center; font-size: 15px;
}
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.3); border-top-color: #fff; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.mtable { width: 100%; border-collapse: collapse; font-size: 14px; }
.mtable td { padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.mtable td.v { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; }
.tag { font-size: 11px; background: #fff1de; color: var(--warn); padding: 2px 6px; border-radius: 4px; margin-left: 4px; }
.warn { font-size: 13px; background: #fff6e8; color: #7a4a10; border-radius: 8px; padding: 8px 10px; margin-top: 8px; }

#overlay { width: 100%; border-radius: 8px; border: 1px solid var(--line); display: block; }
.row { display: flex; gap: 8px; margin-top: 8px; }
.quality { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; margin: 0; }
.quality dt { color: var(--muted); }
.quality dd { margin: 0; font-variant-numeric: tabular-nums; }
.embed { font-size: 11.5px; background: #f6f4f0; padding: 10px; border-radius: 8px; white-space: pre-wrap; word-break: break-all; }

.camera-btn { margin-bottom: 10px; display: none; }
.phone-dlg { border: 0; border-radius: 14px; padding: 22px; max-width: 380px; width: calc(100% - 32px); }
.phone-dlg::backdrop { background: rgba(0,0,0,.45); }
.phone-dlg h2 { margin-top: 0; }
.phone-dlg .qr { display: block; width: 240px; height: 240px; margin: 0 auto 8px; }
.phone-dlg .url { font-size: 18px; word-break: break-all; }
.phone-dlg p, .phone-dlg li { font-size: 14px; line-height: 1.45; }
.phone-dlg code { background: #f1eee8; padding: 1px 5px; border-radius: 4px; }

/* touch devices: show the camera button, bigger controls */
@media (pointer: coarse) {
  .camera-btn { display: flex; font-size: 17px; padding: 14px; }
  .drop { min-height: 90px; padding: 12px; }
  .seg button, .btn.small { padding: 9px 14px; }
  #phone-btn { display: none; }
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .viewer { height: 75vh; height: 75dvh; }
  .top { flex-wrap: wrap; gap: 8px; padding: 10px 14px; }
  nav { flex-wrap: wrap; }
}
