:root {
  --ink: #1c1915;
  --cream: #f6f1e8;
  --paper: #e4ddd2;
  --sheet: #fffcf7;
  --brass: #8a6232;
  --brass-soft: #c4a574;
  --line: rgba(28, 25, 21, 0.1);
  --good: #1d6b34;
  --warn: #8a5a00;
  --bad: #9c2f2f;
  --muted: #6f675e;
  color: var(--ink);
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.4;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
}

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.top {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 12px 18px;
  background: var(--ink);
  color: var(--cream);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.brand strong {
  display: block;
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.brand em {
  display: block;
  margin-top: 1px;
  font-style: normal;
  font-size: 12px;
  color: var(--brass-soft);
}

.mark {
  width: 36px;
  height: 36px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 6px;
  border: 1px solid rgba(242, 228, 207, 0.4);
}

.mark i {
  display: block;
  background: #f2e4cf;
}

.layouts {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  max-width: 100%;
  padding: 3px;
  border: 1px solid rgba(242, 228, 207, 0.2);
  border-radius: 18px;
}

.layouts button {
  border: 0;
  background: transparent;
  color: var(--cream);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 14px;
  white-space: nowrap;
}

.layouts button[aria-pressed="true"] {
  background: #f2e4cf;
  color: var(--ink);
}

.top-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.field, .check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #ddd4c6;
}

select, .stage-tools input[type="range"] {
  accent-color: var(--brass);
}

select {
  background: #2a251f;
  color: var(--cream);
  border: 1px solid rgba(242, 228, 207, 0.25);
  border-radius: 8px;
  padding: 6px 8px;
}

.primary, .ghost, .quiet, .text {
  border-radius: 999px;
  padding: 8px 14px;
}

.primary {
  background: #f2e4cf;
  color: var(--ink);
  border: 0;
  font-weight: 650;
}

.ghost {
  background: transparent;
  color: #f2e4cf;
  border: 1px solid rgba(242, 228, 207, 0.35);
}

.quiet, .text {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.text {
  border: 0;
  padding: 0;
  color: var(--brass);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.primary:disabled, .ghost:disabled { opacity: 0.45; cursor: default; }

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 308px;
}

.library, .inspector-wrap {
  min-height: 0;
  overflow: auto;
  background: #f7f3ec;
}

.library { border-right: 1px solid var(--line); }
.inspector-wrap { border-left: 1px solid var(--line); }

.drop {
  margin: 14px;
  padding: 16px;
  border: 1px dashed rgba(138, 98, 50, 0.55);
  border-radius: 14px;
  background: rgba(255, 252, 247, 0.7);
  text-align: center;
}

.drop p { margin: 0 0 10px; }

.drop-actions { display: flex; justify-content: center; gap: 8px; }

.lib-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 0 16px 8px;
  color: var(--muted);
  font-size: 13px;
}

.lib-list { display: flex; flex-direction: column; gap: 6px; padding: 0 10px 12px; }

.thumb-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
  align-items: stretch;
}

.thumb {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 8px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
}

.thumb img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 6px;
  background: #e7e0d4;
}

.thumb-name, .file-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumb-meta { display: block; color: var(--muted); font-size: 12px; }

.thumb.active { background: #fff; border-color: rgba(138, 98, 50, 0.45); }

.remove {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 0 8px;
}

.privacy {
  margin: 4px 16px 18px;
  color: var(--muted);
  font-size: 12px;
}

.stage {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 8px 16px 14px;
}

.stage-tools {
  display: flex;
  justify-content: center;
  gap: 18px;
  min-height: 36px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.sheet-frame {
  flex: 1;
  min-height: 360px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sheet-wrap {
  position: relative;
  background: var(--sheet);
  box-shadow: 0 18px 50px rgba(60, 40, 20, 0.16);
  user-select: none;
  overflow: hidden;
}

#sheet { width: 100%; height: 100%; display: block; }

.sheet-slots { position: absolute; inset: 0; touch-action: none; }

.slot { position: absolute; overflow: hidden; }

.slot.filled { cursor: grab; }
.slot.panning { cursor: grabbing; }

.slot.selected { box-shadow: inset 0 0 0 2px var(--brass); z-index: 1; }

.slot.drop-target { box-shadow: inset 0 0 0 3px var(--brass-soft); }

.slot:not(.filled)::before,
.slot:not(.filled)::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  background: #c4b8a6;
}

.slot:not(.filled)::before { width: 16px; height: 1px; transform: translate(-50%, -50%); }
.slot:not(.filled)::after { width: 1px; height: 16px; transform: translate(-50%, -50%); }

.handle {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgba(28, 25, 21, 0.72);
  color: white;
  font-size: 11px;
  cursor: grab;
}

.dpi-badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(255, 252, 247, 0.92);
  font-size: 11px;
  pointer-events: none;
}

.size-tag {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 5px;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.03em;
  color: rgba(28, 25, 21, 0.62);
  pointer-events: none;
}

.dpi-badge.good { color: var(--good); }
.dpi-badge.warn { color: var(--warn); }
.dpi-badge.bad { color: var(--bad); }

.thirds {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to right, transparent 33.2%, rgba(255, 255, 255, 0.45) 33.2% 33.5%, transparent 33.5% 66.5%, rgba(255, 255, 255, 0.45) 66.5% 66.8%, transparent 66.8%),
    linear-gradient(to bottom, transparent 33.2%, rgba(255, 255, 255, 0.45) 33.2% 33.5%, transparent 33.5% 66.5%, rgba(255, 255, 255, 0.45) 66.5% 66.8%, transparent 66.8%);
  mix-blend-mode: difference;
}

.empty {
  position: absolute;
  inset: 14% 12%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  color: var(--muted);
}

.empty h2 {
  margin: 0 0 8px;
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-weight: 500;
  color: var(--ink);
}

.empty p { margin: 0; }

.stage-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding-top: 10px;
}

.measure, .warn-line {
  margin: 8px auto 0;
  max-width: 68ch;
  text-align: center;
  font-size: 13px;
}

.measure { color: var(--ink); }
.warn-line { color: var(--warn); margin-top: 4px; }

.inspector { padding: 16px 16px 8px; }

.inspector h2 {
  margin: 0 0 8px;
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: 26px;
  font-weight: 500;
}

.inspector p { margin: 0 0 10px; }

.control { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; font-size: 13px; }

.control input[type="range"] { width: 100%; accent-color: var(--brass); }

.row { display: flex; gap: 8px; align-items: center; }

.rot {
  width: 42px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: white;
}

.readout {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: white;
  font-size: 13px;
}

.readout.good { color: var(--good); }
.readout.warn { color: var(--warn); }
.readout.bad { color: var(--bad); }

.hint { color: var(--muted); font-size: 13px; }

.soft {
  padding: 10px 12px;
  border-radius: 10px;
  background: #f8ebe3;
  color: var(--bad);
  font-size: 13px;
}

.tips { margin: 8px 16px 18px; color: var(--muted); font-size: 13px; }
.tips summary { cursor: pointer; color: var(--ink); }
.tips li { margin: 6px 0; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 21, 0.46);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 5;
}

.modal-card {
  width: min(480px, 100%);
  background: #fffdf9;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.modal-card h2 {
  margin: 0 0 8px;
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-weight: 500;
}

.modal-card ul { margin: 8px 0 16px; padding-left: 18px; max-height: 180px; overflow: auto; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.bar {
  height: 6px;
  border-radius: 99px;
  background: #efe7db;
  overflow: hidden;
}

.bar div {
  height: 100%;
  width: 0;
  background: var(--brass);
}

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--cream);
  padding: 10px 14px;
  border-radius: 999px;
  z-index: 6;
  max-width: min(560px, calc(100% - 24px));
}

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 240px minmax(0, 1fr); }
  .inspector-wrap { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); max-height: none; }
}

@media (max-width: 800px) {
  body { height: auto; overflow: auto; }
  .workspace { grid-template-columns: 1fr; }
  .library, .inspector-wrap { border: 0; border-top: 1px solid var(--line); overflow: visible; }
  .top-actions { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
