:root {
  --ink: #241c16;
  --paper: #f4efe4;
  --well: #efe6d4;
  --wine: #6b2833;
  --sheet: #fbf8f3;
  --desk: #e4dccb;
  --line: #d2c6b0;
  --ui: "Palatino Linotype", Palatino, Georgia, serif;
  --display: "Cormorant Garamond", "Palatino Linotype", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--desk);
  color: var(--ink);
  font-family: var(--display);
}

.sprite { position: absolute; width: 0; height: 0; }

.app {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.panel {
  min-height: 0;
  overflow: auto;
  padding: 22px 22px 28px;
  background: #efe8da;
  border-right: 1px solid var(--line);
}

.brand strong {
  display: block;
  font-size: 28px;
  font-weight: 600;
  font-style: italic;
  line-height: 0.95;
}

.brand p,
.note,
.photo-note,
.status {
  margin: 8px 0 0;
  font-family: var(--ui);
  font-size: 14px;
  line-height: 1.4;
}

.group { margin-top: 22px; }

.group h2 {
  margin: 0 0 10px;
  font-family: var(--ui);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 10px;
  font-family: var(--ui);
  font-size: 14px;
}

input[type="text"],
input[type="number"],
input[type="file"],
input[type="range"] {
  font: 16px var(--ui);
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid #c9baa4;
  padding: 7px 8px;
  width: 100%;
}

input[type="range"] {
  padding: 0;
  background: transparent;
  border: 0;
}

.counts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

button {
  font: 16px var(--display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--ink);
  color: #f6f1e7;
  border: 1px solid var(--ink);
  padding: 9px 14px;
  cursor: pointer;
}

button:hover { background: #3a2e24; }

button.ghost {
  background: transparent;
  color: var(--ink);
}

button.ghost:hover { background: rgba(36, 28, 22, 0.06); }

button:disabled {
  opacity: 0.45;
  cursor: default;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--wine);
  outline-offset: 2px;
}

.dock {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 10px 16px;
  background: #efe8da;
  border-bottom: 1px solid var(--line);
}

.dock-title {
  font-size: 26px;
  font-weight: 600;
  font-style: italic;
  line-height: 1;
}

.dock #save { margin-left: auto; }

.dock .short { display: none; }

.templates {
  display: grid;
  gap: 8px;
}

.template {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  text-align: left;
  text-transform: none;
  letter-spacing: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--ui);
}

.template b {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 600;
  font-style: italic;
  letter-spacing: 0;
  line-height: 1;
}

.template span {
  font-family: var(--ui);
  font-size: 15px;
  letter-spacing: 0;
  text-transform: none;
}

.template.is-on {
  background: var(--ink);
  color: #f6f1e7;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  margin: 4px 0 8px;
  font-family: var(--ui);
  font-size: 18px;
  line-height: 1.25;
}

.toggle input {
  width: 28px;
  height: 28px;
  margin: 0;
  flex: 0 0 auto;
  accent-color: var(--wine);
}

input.is-off { opacity: 0.45; }

.stage {
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

@media (min-width: 861px) {
  .brand { display: none; }
}

#scaler {
  margin: 18px auto 36px;
  overflow: hidden;
}

#pages { width: 210mm; }

.sheet {
  width: 210mm;
  height: 297mm;
  background: var(--sheet);
  padding: 8mm 8mm 6mm;
  box-shadow: 0 10px 28px rgba(50, 36, 20, 0.14);
}

.sheet + .sheet { margin-top: 18px; }

.row {
  display: flex;
  justify-content: center;
  gap: 4mm;
}

.row + .row { margin-top: 4.5mm; }

.die { position: relative; padding: 3.2mm; }

.mark { position: absolute; background: #1c1c1c; }
.mark.h { height: 0.15mm; width: 2.6mm; }
.mark.v { width: 0.15mm; height: 2.6mm; }
.mark.h.tl { top: 3.2mm; left: 0; }
.mark.v.tl { left: 3.2mm; top: 0; }
.mark.h.tr { top: 3.2mm; right: 0; }
.mark.v.tr { right: 3.2mm; top: 0; }
.mark.h.bl { bottom: 3.2mm; left: 0; }
.mark.v.bl { left: 3.2mm; bottom: 0; }
.mark.h.br { bottom: 3.2mm; right: 0; }
.mark.v.br { right: 3.2mm; bottom: 0; }

.back {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-height: 48px;
  padding: 10px 16px;
  background: var(--wine);
  color: #f6f1e7;
  border: 1px solid var(--wine);
  font-family: var(--display);
  font-size: 18px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  text-align: center;
}

.back:hover { background: #541f28; }

.cutline {
  margin: 5mm 0 0;
  text-align: center;
  font-family: var(--ui);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #5c5348;
}

.empty {
  margin: 48px auto;
  width: min(420px, 80%);
  text-align: center;
  font-family: var(--ui);
  font-size: 18px;
}

@media (max-width: 860px) {
  .app {
    display: flex;
    flex-direction: column;
    height: auto;
  }

  .stage {
    order: -1;
    position: sticky;
    top: 0;
    z-index: 4;
    height: min(46svh, 340px);
    min-height: 240px;
    overflow: auto;
    background: var(--desk);
    border-bottom: 1px solid var(--line);
  }

  #scaler { margin: 8px auto; }

  .panel {
    order: 0;
    border-right: 0;
    padding: 18px 16px calc(180px + env(safe-area-inset-bottom));
  }

  .brand strong { font-size: 34px; }

  .brand p,
  .note,
  .photo-note,
  .status,
  label.field {
    font-size: 18px;
  }

  input[type="text"],
  input[type="number"],
  input[type="file"] {
    font-size: 20px;
    min-height: 52px;
    padding: 12px;
  }

  button { min-height: 52px; font-size: 18px; }

  .dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 6;
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin: 0;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    background: #efe8da;
    border-top: 1px solid var(--line);
    border-bottom: 0;
  }

  .dock-title { display: none; }
  .dock #save { margin-left: 0; }
  .back { grid-column: 1 / -1; min-height: 56px; }

  .dock .long { display: none; }
  .dock .short { display: inline; }
  .dock button {
    font-size: 15px;
    letter-spacing: 0.04em;
    padding: 10px 4px;
  }
}

@media print {
  html, body {
    height: auto;
    overflow: visible;
    background: white;
  }

  .app { display: block; height: auto; }
  .panel, .dock { display: none !important; }
  .stage {
    order: 0;
    position: static;
    height: auto;
    overflow: visible;
    border: 0;
  }
  #scaler {
    width: auto !important;
    height: auto !important;
    margin: 0 !important;
    overflow: visible !important;
  }
  #pages {
    transform: none !important;
    width: auto !important;
  }
  .sheet {
    margin: 0;
    box-shadow: none;
    break-after: page;
    page-break-after: always;
  }
  .sheet:last-child {
    break-after: auto;
    page-break-after: auto;
  }
  .label, .well, .sheet, .rule i {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}

@page { size: A4 portrait; margin: 0; }
