:root {
  color-scheme: light;
  --ink: #1d2320;
  --muted: #68716c;
  --line: #dfe3e0;
  --panel: #fff;
  --ground: #eceeec;
  --accent: #1f5f45;
  --accent-soft: #e3efe9;
  --warn: #9a5b00;
  --warn-soft: #fdf3e0;
  --bad: #b3261e;
  --bad-soft: #fbe9e7;
}

* { box-sizing: border-box; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  background: var(--ground);
  color: var(--ink);
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

h1 { margin: 0; font-size: 15px; font-weight: 650; white-space: nowrap; }
h2 { margin: 0 0 8px; font-size: 12px; font-weight: 650; }
p { margin: 0; }
.muted { color: var(--muted); font-weight: 400; }
.push { margin-left: auto; }

button, input, select { font: inherit; color: inherit; }
button {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { border-color: #aeb6b1; }
button:disabled { opacity: .45; cursor: default; }
button.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { border-color: #174a35; background: #174a35; }
button.danger { color: var(--bad); }
button.link { padding: 2px 4px; border: 0; background: none; color: var(--accent); }
button.link:hover { text-decoration: underline; }
button.wide { width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

input[type=number], input[type=search], select {
  width: 100%;
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.topbar {
  display: flex;
  flex: none;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.topbar h1, .lang-switch, .actions { flex: none; }
#summary { min-width: 0; }
.print-hint { min-width: 0; margin-left: auto; color: var(--muted); font-size: 12px; line-height: 1.25; text-align: right; text-wrap: balance; }
.print-hint strong { color: var(--ink); font-weight: 600; }
.actions { display: flex; gap: 6px; }
.lang-switch { display: inline-flex; }
.lang-switch button { padding: 5px 7px; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.lang-switch button:first-child { border-radius: 5px 0 0 5px; }
.lang-switch button:last-child { margin-left: -1px; border-radius: 0 5px 5px 0; }
.lang-switch button:focus-visible { position: relative; z-index: 1; }
.lang-switch button[aria-pressed=true] { position: relative; border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.app {
  display: grid;
  flex: 1;
  grid-template-columns: 264px minmax(0, 1fr) 286px;
  min-height: 0;
}

.panel { display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.library { border-right: 1px solid var(--line); }
.inspector { overflow-y: auto; border-left: 1px solid var(--line); }
.inspector section { padding: 11px 12px; border-bottom: 1px solid var(--line); }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; }

.lib-grid {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: min-content;
  gap: 6px;
  overflow-y: auto;
  padding: 8px;
}
.lib-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 5px;
  text-align: center;
}
.lib-card[aria-pressed=true] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.lib-card img { display: block; width: 100%; height: 56px; object-fit: contain; }
.lib-card span { overflow: hidden; font-size: 10.5px; text-overflow: ellipsis; white-space: nowrap; }

.lib-foot { display: grid; gap: 8px; padding: 9px 10px; border-top: 1px solid var(--line); }
.row { display: flex; align-items: flex-end; gap: 8px; }
.row .field { flex: 1; }

.field { display: grid; gap: 2px; color: var(--muted); font-size: 11.5px; }
.field input, .field select { color: var(--ink); font-size: 13px; }
.check { display: flex; align-items: center; gap: 6px; margin-top: 7px; }
.inline { display: inline-flex; align-items: center; gap: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 8px; margin-bottom: 7px; }
.grid2.align-end { align-items: end; margin: 7px 0 0; }
.btn-row { display: flex; gap: 5px; margin-top: 8px; }
.btn-row button { flex: 1; padding-inline: 4px; }
.bulk { margin-top: 10px; padding-top: 9px; border-top: 1px dashed var(--line); }
.dpi-line { margin-top: 6px; font-size: 12px; }
.dpi-line.low { color: var(--warn); font-weight: 600; }
.keys { padding: 10px 12px; font-size: 11px; }

.placed-list { display: grid; gap: 1px; max-height: 240px; overflow-y: auto; }
.placed-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 2px 4px;
  border: 0;
  border-radius: 3px;
  background: none;
  font-size: 11.5px;
  text-align: left;
}
.placed-row:hover { background: var(--ground); }
.placed-row.selected { background: var(--accent-soft); }
.placed-row img { width: 22px; height: 22px; object-fit: contain; }
.placed-row .nm { overflow: hidden; text-overflow: ellipsis; }
.placed-row .dpi { color: var(--muted); font-variant-numeric: tabular-nums; }
.placed-row .dpi.low { color: var(--warn); font-weight: 650; }
.placed-row .dpi.bad { color: var(--bad); font-weight: 650; }

#workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.view-bar {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 10px;
  padding: 5px 14px;
  border-bottom: 1px solid var(--line);
  background: #f6f7f6;
  font-size: 12px;
}
.view-bar input { width: 110px; accent-color: var(--accent); }

#notices { flex: none; }
.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 12px;
}
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice button { flex: none; padding: 1px 8px; font-size: 12px; }

#sheets {
  --u: 20px;
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: center;
  gap: 26px;
  min-height: 0;
  overflow: auto;
  padding: 24px 20px 40px;
}

.sheet {
  position: relative;
  flex: none;
  width: calc(var(--paper-w) * var(--u));
  height: calc(var(--paper-h) * var(--u));
  overflow: hidden;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  touch-action: none;
}
.sheet-wrap { position: relative; flex: none; }
.sheet-label { position: absolute; top: -18px; left: 0; color: var(--muted); font-size: 11px; }

.sheet.show-grid {
  background-image:
    linear-gradient(to right, rgba(31, 95, 69, .08) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(31, 95, 69, .08) 1px, transparent 1px);
  background-size: calc(var(--grid) * var(--u)) calc(var(--grid) * var(--u));
}

.printable {
  position: absolute;
  top: calc(var(--margin) * var(--u));
  right: calc(var(--margin) * var(--u));
  bottom: calc(var(--margin) * var(--u));
  left: calc(var(--margin) * var(--u));
  border: 1px dashed rgba(31, 95, 69, .4);
  pointer-events: none;
}

.item {
  position: absolute;
  top: calc(var(--y) * var(--u));
  left: calc(var(--x) * var(--u));
  width: calc(var(--fw) * var(--u));
  height: calc(var(--fh) * var(--u));
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.item.dragging { z-index: 4; cursor: grabbing; opacity: .88; }
.item img {
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  width: calc(var(--w) * var(--u));
  max-width: none;
  height: calc(var(--h) * var(--u));
  transform: translate(-50%, -50%) rotate(var(--r));
  pointer-events: none;
}
.item.selected::after,
.item.flagged::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
.item.selected::after { outline: 2px solid var(--accent); }
.item.flagged::after { outline: 2px solid var(--bad); background: repeating-linear-gradient(45deg, rgba(179, 38, 30, .28) 0 4px, transparent 4px 9px); }
.item.selected.flagged::after { outline-style: dashed; }
.badge {
  position: absolute;
  top: 1px;
  left: 1px;
  z-index: 3;
  padding: 0 3px;
  border-radius: 2px;
  background: var(--warn);
  color: #fff;
  font-size: 9.5px;
  line-height: 14px;
  pointer-events: none;
}
.badge.bad { background: var(--bad); }

.guides {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.guides .cut { fill: none; stroke: #444; stroke-width: .018; }
.guides .ruler-line { fill: none; stroke: #000; stroke-width: .012; }
.guides text { fill: #000; font-family: Helvetica, Arial, sans-serif; }

@media screen {
  .guides .cut, .guides .ruler-line { vector-effect: non-scaling-stroke; stroke-width: 1px; }
}

@media print {
  html, body { display: block; width: auto; height: auto; overflow: visible; background: #fff; }
  .topbar, .panel, .view-bar, #notices, .sheet-label, .printable, .badge { display: none !important; }
  .app, #workspace { display: block; width: auto; height: auto; min-height: 0; overflow: visible; }
  #sheets {
    --u: 1cm !important;
    display: block;
    width: auto;
    height: auto;
    padding: 0;
    overflow: visible;
  }
  .sheet-wrap { display: block; break-after: page; break-inside: avoid; }
  .sheet-wrap.print-last { break-after: auto; }
  .sheet-wrap.is-empty { display: none; }
  .sheet { background: #fff !important; box-shadow: none; break-inside: avoid; }
  .item { opacity: 1 !important; }
  .item::after { display: none !important; }
}
