@font-face { font-family: "Cherry Swash"; src: url(/fonts/CherrySwash-Bold.ttf); font-weight: 700; }
@font-face { font-family: "Crimson"; src: url(/fonts/CrimsonText-Regular.ttf); }
@font-face { font-family: "Crimson"; src: url(/fonts/CrimsonText-Bold.ttf); font-weight: 700; }
@font-face { font-family: "Crimson"; src: url(/fonts/CrimsonText-Italic.ttf); font-style: italic; }

:root {
  --bg: #1b1612;
  --panel: #251e18;
  --panel-2: #2e251d;
  --line: #43372b;
  --text: #efe4cf;
  --muted: #a8977d;
  --accent: #c8963e;
  --accent-ink: #1b1612;
  --danger: #c4553f;
  --good: #7fae6a;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.4 "Crimson", Georgia, serif; }
h2 { font: 700 19px "Cherry Swash", Georgia, serif; margin: 0 0 8px; letter-spacing: .02em; }
code { font: 12px ui-monospace, Menlo, Consolas, monospace; background: var(--panel-2); padding: 1px 4px; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.muted { color: var(--muted); font-size: 14px; }
[hidden] { display: none !important; }

button, .filebtn, select, input {
  font: inherit; color: var(--text);
}
button, .filebtn {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: var(--radius);
  padding: 7px 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover, .filebtn:hover { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.ghost, .filebtn.ghost { background: transparent; }
button.small, .small { padding: 4px 10px; font-size: 14px; }
button.danger:hover { border-color: var(--danger); color: var(--danger); }
select, input[type=number], input[type=search] {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px;
}
input[type=number] { width: 72px; }
select:focus, input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Header */
.bar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px;
  padding: 10px 20px; background: #140f0c; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { font: 700 24px "Cherry Swash", Georgia, serif; color: var(--accent); letter-spacing: .03em; }
.tabs { display: flex; gap: 4px; }
.tab { background: transparent; border-color: transparent; color: var(--muted); }
.tab.active { color: var(--text); border-color: var(--line); background: var(--panel); }
.pill { background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 700; }
.bar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.summary { color: var(--muted); font-size: 14px; }

main { padding: 16px 20px 60px; max-width: 1500px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

/* Catalogue */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar input[type=search] { flex: 1 1 260px; max-width: 420px; }
.check, .radio { display: flex; align-items: center; gap: 8px; cursor: pointer; margin: 4px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip { padding: 3px 11px; border-radius: 14px; font-size: 14px; background: transparent; color: var(--muted); }
.chip.on { background: var(--panel-2); color: var(--text); border-color: var(--accent); }
.cat-head { font: 700 17px "Cherry Swash", Georgia, serif; color: var(--accent); margin: 22px 0 10px; display: flex; gap: 10px; align-items: baseline; }
.cat-head .muted { font: 14px "Crimson", serif; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }

.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; display: flex; flex-direction: column; gap: 6px; position: relative; }
.tile.picked { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.tile img { width: 100%; aspect-ratio: 180/250; object-fit: cover; border-radius: 6px; cursor: zoom-in; background: #0f0b09; display: block; }
.tile .name { font-weight: 700; line-height: 1.15; }
.tile .sub { color: var(--muted); font-size: 13px; line-height: 1.15; min-height: 15px; }
.badge { position: absolute; top: 12px; left: 12px; background: var(--accent); color: var(--accent-ink); font-weight: 700; border-radius: 12px; padding: 0 9px; font-size: 14px; box-shadow: 0 1px 4px #000a; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { padding: 2px 0; width: 30px; justify-content: center; }
.stepper input { width: 46px; text-align: center; padding: 3px 2px; -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }
.back-select { display: flex; align-items: center; gap: 6px; }
.back-select select { flex: 1; min-width: 0; padding: 3px 4px; font-size: 14px; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid #0007; flex: none; }

/* Custom */
.custom-layout { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 24px; align-items: start; }
.import { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; position: sticky; top: 76px; }
.import textarea, .modal textarea {
  width: 100%; min-height: 180px; resize: vertical; background: #120e0b; color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px; font: 12.5px/1.45 ui-monospace, Menlo, Consolas, monospace;
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.row label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
.msg { font-size: 14px; min-height: 18px; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--good); }
.help { font-size: 14px; color: var(--muted); }
.help summary { cursor: pointer; color: var(--text); }
.help ul { padding-left: 18px; margin: 8px 0 0; }
.help li { margin-bottom: 4px; }

.ccard { display: grid; grid-template-columns: 170px 1fr; gap: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }
.ccard .pv { position: relative; }
.ccard .pv img { width: 170px; aspect-ratio: 180/250; border-radius: 6px; display: block; cursor: zoom-in; background: #0f0b09; }
.ccard .pv .more { position: absolute; bottom: 6px; right: 6px; background: #000c; padding: 0 7px; border-radius: 10px; font-size: 13px; }
.ccard .spin { width: 170px; aspect-ratio: 180/250; border-radius: 6px; background: linear-gradient(110deg, #2a221b 30%, #3a2f25 50%, #2a221b 70%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }
.ccard h3 { margin: 0; font: 700 18px "Cherry Swash", Georgia, serif; }
.ccard .meta { color: var(--muted); font-size: 14px; margin: 2px 0 8px; }
.ccard .controls { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.ccard .controls label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
.ccard .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.warn { color: #e0b15a; font-size: 14px; margin-top: 8px; }
.warn div::before { content: "⚠ "; }
.empty { color: var(--muted); padding: 40px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

/* Print list */
.plist { width: 100%; border-collapse: collapse; }
.plist th { text-align: left; color: var(--muted); font-weight: 400; font-size: 14px; border-bottom: 1px solid var(--line); padding: 6px 8px; }
.plist td { border-bottom: 1px solid var(--line); padding: 6px 8px; vertical-align: middle; }
.plist img { width: 44px; border-radius: 3px; display: block; }
.plist .total td { border-bottom: 0; font-weight: 700; }
.sheet-note { color: var(--muted); margin: 12px 0; }

/* Drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 100vw); background: var(--panel); border-left: 1px solid var(--line); z-index: 40; padding: 18px; overflow-y: auto; box-shadow: -12px 0 30px #0008; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.field { margin-bottom: 20px; }
.label { font-weight: 700; margin-bottom: 8px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 52px; height: 72px; border-radius: 6px; border: 2px solid transparent; padding: 0; overflow: hidden; background: none; }
.swatch img { width: 100%; height: 100%; object-fit: cover; display: block; }
.swatch.on { border-color: var(--accent); box-shadow: 0 0 0 2px #0008; }

/* Modal */
.modal { position: fixed; inset: 0; background: #000b; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; max-width: 980px; width: 100%; max-height: 92vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
.zoom { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.zoom img { width: min(330px, 100%); border-radius: 10px; }
.modal textarea { min-height: 50vh; }

/* Loading + toast */
.loading { position: fixed; inset: 0; background: #000c; z-index: 60; display: flex; align-items: center; justify-content: center; }
.loading-box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 24px; width: min(420px, 90vw); text-align: center; }
.loading-title { font: 700 20px "Cherry Swash", Georgia, serif; margin-bottom: 14px; }
.progress { height: 8px; background: #120e0b; border-radius: 4px; overflow: hidden; margin-bottom: 10px; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--accent); padding: 10px 18px; border-radius: var(--radius); z-index: 70; box-shadow: 0 6px 24px #000a; }
.toast.err { border-color: var(--danger); }

@media (max-width: 860px) {
  .custom-layout { grid-template-columns: 1fr; }
  .import { position: static; }
  .bar { padding: 10px 16px; gap: 10px; position: static; }
  main { padding: 12px 16px 60px; }
  .ccard { grid-template-columns: 110px 1fr; }
  .ccard .pv img, .ccard .spin { width: 110px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
