:root {
  --ink: #120e0c;
  --soot: #1b1613;
  --char: #262019;
  --char-2: #302822;
  --edge: #3b322b;
  --edge-soft: #2f2722;
  --rind: #ee6a2a;
  --rind-deep: #c8481a;
  --candle: #ffc24b;
  --cream: #f3e3c9;
  --paper: #f6f1e6;
  --dim: #a08f82;
  --text: #efe6da;
  --danger: #ff6357;
  --good: #7bc47f;
  --r: 12px;
  --pad: 16px;
  --libw: 300px;
  --inspw: 280px;
  --shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 8px 24px -12px rgba(0, 0, 0, .7);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--ink);
  color: var(--text);
  font-family: Montserrat, ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

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

button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--candle);
  outline-offset: 2px;
}

#app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 18px;
  background: linear-gradient(180deg, #221b17, var(--ink));
  border-bottom: 1px solid var(--edge-soft);
  box-shadow: 0 1px 0 rgba(255, 190, 90, .05);
}

.brand {
  font-family: 'Rum Raisin', Georgia, serif;
  font-size: 30px;
  line-height: 1;
  letter-spacing: .01em;
  color: var(--cream);
  text-decoration: none;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .35);
}

.brand em {
  font-style: normal;
  color: var(--rind);
}

.modes {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: #0f0c0a;
  border: 1px solid var(--edge-soft);
  border-radius: 999px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .6);
}

.modes button {
  border: 0;
  background: none;
  color: var(--dim);
  padding: 7px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: .02em;
  transition: color .18s, background .18s, box-shadow .18s;
}

.modes button:hover { color: var(--text); }

.modes button[aria-selected='true'] {
  background: linear-gradient(180deg, #f9803e, var(--rind-deep));
  color: #2a1208;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .25) inset, 0 3px 10px -3px rgba(238, 106, 42, .8);
}

.topactions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.btn {
  background: linear-gradient(180deg, var(--char-2), var(--char));
  border: 1px solid var(--edge);
  border-radius: var(--r);
  padding: 9px 15px;
  font-weight: 600;
  font-size: 13px;
  box-shadow: var(--shadow);
  transition: border-color .18s, background .18s, transform .1s, box-shadow .18s;
}

.btn:hover:not(:disabled) { border-color: #5a4c41; }
.btn:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
.btn:disabled { opacity: .35; cursor: default; }
.btn.ghost { background: none; box-shadow: none; }

.btn.primary {
  background: linear-gradient(180deg, #fb8543, var(--rind-deep));
  border-color: #d2531f;
  color: #2a1208;
  font-weight: 700;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .3) inset, 0 6px 16px -6px rgba(238, 106, 42, .9);
}

.btn.primary:hover { filter: brightness(1.06); }
.btn.wide { width: 100%; }

main {
  display: grid;
  grid-template-columns: var(--libw) 6px minmax(0, 1fr) 6px var(--inspw);
  min-height: 0;
}

.resizer {
  cursor: col-resize;
  background: var(--ink);
  position: relative;
  touch-action: none;
}

.resizer::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 2px;
  width: 2px;
  height: 36px;
  margin-top: -18px;
  border-radius: 2px;
  background: var(--edge);
  transition: background .15s;
}

.resizer:hover::after, .resizer.active::after { background: var(--candle); }

.rail {
  background: var(--soot);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--edge) transparent;
}

.rail.inspect { padding: var(--pad); gap: 18px; }

.tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px 10px 0;
  gap: 4px;
  background: linear-gradient(180deg, var(--soot) 78%, rgba(27, 22, 19, 0));
}

.tabs button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: none;
  color: var(--dim);
  padding: 9px 2px 8px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  transition: color .15s, background .15s, border-color .15s;
}

.tabs button svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  stroke: none;
}

.tabs button svg .hole { fill: var(--soot); }
.tabs button:hover { color: var(--cream); background: var(--char); }

.tabs button[aria-selected='true'] {
  color: var(--candle);
  background: var(--char);
  border-color: var(--edge);
  box-shadow: 0 2px 0 var(--candle) inset, 0 -2px 0 rgba(255, 194, 75, .35) inset;
}

.tabs button[aria-selected='true'] svg .hole { fill: var(--char); }

.libgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 9px;
  padding: 12px;
}

.chip {
  position: relative;
  aspect-ratio: 1 / 1.16;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--char-2), var(--char));
  border: 1px solid var(--edge-soft);
  border-radius: var(--r);
  padding: 9px 9px 0;
  color: var(--cream);
  box-shadow: var(--shadow);
  transition: border-color .15s, transform .12s, box-shadow .15s;
}

.chip:hover {
  border-color: var(--candle);
  transform: translateY(-2px);
}

.chip[aria-pressed='true'] {
  border-color: var(--rind);
  background: linear-gradient(180deg, #4a2a1c, #37201a);
  color: #ffd3a8;
}

.chip svg {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: block;
}

.chip .lbl {
  height: 24px;
  line-height: 24px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .03em;
  color: var(--dim);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.chip[aria-pressed='true'] .lbl { color: var(--rind); }

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 18px;
  min-height: 0;
  background: radial-gradient(120% 90% at 50% 0%, #241c17 0%, var(--ink) 60%);
  transition: background .5s;
}

.stage::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(60% 50% at 50% 100%, rgba(0, 0, 0, .45), transparent 70%);
}

.stage.lit {
  background: radial-gradient(90% 60% at 50% 55%, #2d1c0d 0%, #090706 70%);
}

.sheetwrap {
  position: relative;
  height: 100%;
  aspect-ratio: 850 / 1100;
  max-width: 100%;
  border-radius: 4px;
  transition: box-shadow .6s;
}

.stage.lit .sheetwrap {
  box-shadow: 0 0 110px 26px rgba(255, 150, 40, .17);
}

#sheet {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s;
}

#overlay.on { opacity: 1; }

.hint {
  position: relative;
  margin: 0;
  font-size: 12px;
  color: var(--dim);
  text-align: center;
  min-height: 18px;
}

.panel h2 {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 10px;
}

.panel + .panel {
  border-top: 1px solid var(--edge-soft);
  padding-top: 17px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.row label {
  width: 46px;
  font-size: 12px;
  font-weight: 500;
  color: var(--dim);
  flex-shrink: 0;
}

input[type='range'] {
  flex: 1;
  accent-color: var(--rind);
  min-width: 0;
}

select, input[type='text'] {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: #15110e;
  border: 1px solid var(--edge);
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 13px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .5);
}

.minis {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mini {
  flex: 1;
  min-width: 60px;
  background: linear-gradient(180deg, var(--char-2), var(--char));
  border: 1px solid var(--edge);
  border-radius: 9px;
  padding: 8px 4px;
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.mini:hover { border-color: #5a4c41; }
.mini.danger:hover { border-color: var(--danger); color: var(--danger); }

.empty {
  font-size: 12.5px;
  color: var(--dim);
  margin: 0;
}

.credit {
  margin: 14px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: #6f6259;
}

.credit a { color: #9a8a7e; }

.verdict {
  border-radius: var(--r);
  padding: 12px 13px;
  font-size: 12.5px;
  line-height: 1.45;
  border: 1px solid var(--edge);
  background: var(--char);
}

.verdict.good { border-color: #3d6b42; background: #16241a; }
.verdict.warn { border-color: #8a4f1c; background: #2c1b10; }
.verdict strong { display: block; margin-bottom: 3px; font-size: 13px; }

.meter { display: flex; gap: 4px; margin-top: 8px; }
.meter i { height: 5px; flex: 1; border-radius: 3px; background: var(--edge); }
.meter i.on { background: linear-gradient(90deg, var(--candle), var(--rind)); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  background: var(--candle);
  color: #241505;
  font-weight: 700;
  font-size: 13px;
  padding: 11px 22px;
  border-radius: 999px;
  box-shadow: 0 10px 30px -8px rgba(255, 194, 75, .6);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 60;
}

.toast.on { opacity: 1; transform: translate(-50%, 0); }

.sel-outline {
  fill: none;
  stroke: var(--candle);
  stroke-width: 2;
  stroke-dasharray: 6 5;
  vector-effect: non-scaling-stroke;
}

.handle {
  fill: var(--candle);
  stroke: #2a1208;
  stroke-width: 2.5;
  cursor: grab;
}

.item { cursor: move; }
.mode-lit .item, .mode-stencil .item { cursor: default; }

.welcome {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 5, 4, .72);
  backdrop-filter: blur(3px);
  animation: fadeIn .3s ease;
}

.welcome.open { display: flex; }

.welcome-card {
  width: 100%;
  max-width: 600px;
  max-height: 92vh;
  overflow: auto;
  border-radius: 16px;
  background: var(--paper);
  color: #2c261f;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .8);
  animation: slideIn .35s ease;
}

.welcome-head {
  position: relative;
  padding: 22px 60px 20px 24px;
  background: linear-gradient(135deg, #ff8c42 0%, #ee6a2a 100%);
  color: #fff;
}

.welcome-head h1 {
  margin: 0;
  font-family: 'Rum Raisin', Georgia, serif;
  font-weight: 400;
  font-size: 30px;
  line-height: 1.1;
  text-shadow: 0 2px 4px rgba(0, 0, 0, .25);
}

.welcome-head h1 span { font-size: 32px; margin-right: 6px; }

.welcome-x {
  position: absolute;
  right: 16px;
  top: 18px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: rgba(255, 255, 255, .18);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .3s, background .2s;
}

.welcome-x:hover { background: rgba(255, 255, 255, .32); transform: rotate(90deg); }
.welcome-x svg { width: 18px; height: 18px; stroke: #fff; stroke-width: 2.5; stroke-linecap: round; fill: none; }

.welcome-body { padding: 24px; }
.welcome-body .lead { margin: 0 0 18px; font-size: 15.5px; line-height: 1.55; }
.welcome-body .lead strong { color: #1e1812; }

.features {
  list-style: none;
  margin: 0;
  padding: 18px;
  background: #fff;
  border: 1px solid #ebe3d4;
  border-radius: 12px;
  display: grid;
  gap: 14px;
}

.features li { display: flex; gap: 14px; align-items: flex-start; font-size: 13.5px; line-height: 1.45; }

.features i {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #ffeadd;
  display: flex;
  align-items: center;
  justify-content: center;
  font-style: normal;
  font-size: 17px;
}

.features strong { color: var(--rind-deep); }

.tagline {
  margin: 18px 0 0;
  text-align: center;
  font-style: italic;
  color: var(--rind-deep);
  font-weight: 600;
}

.welcome-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: #efe8da;
  border-top: 1px solid #e3d9c6;
}

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #5c5246; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--rind); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { opacity: 0; transform: translateY(-24px); } to { opacity: 1; transform: none; } }

#printroot { display: none; }

@media (max-width: 980px) {
  main {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .resizer { display: none; }

  .stage {
    order: 1;
    flex: 0 0 auto;
    height: 46vh;
    min-height: 300px;
    padding: 10px;
    position: sticky;
    top: 0;
    z-index: 3;
    border-bottom: 1px solid var(--edge-soft);
  }

  .sheetwrap {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    width: auto;
    max-width: 100%;
  }

  .rail.library {
    order: 2;
    flex: 0 0 auto;
    overflow: visible;
    border-top: 1px solid var(--edge-soft);
  }

  .tabs {
    position: static;
    padding-top: 8px;
    background: var(--soot);
  }
  .tabs button { padding: 7px 2px 6px; font-size: 10px; }

  .rail.inspect {
    order: 3;
    flex: 0 0 auto;
    overflow: visible;
    border-top: 1px solid var(--edge-soft);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-start;
    padding: 12px;
  }

  .rail.inspect .panel { flex: 1 1 46%; }
  .panel + .panel { border-top: 0; padding-top: 0; }
  .libgrid { grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  .brand { font-size: 26px; }
  .topactions { width: 100%; margin-left: 0; }
  .topactions .btn { flex: 1; padding: 9px 6px; font-size: 12px; }
  .welcome-foot { flex-direction: column; align-items: stretch; }
  .welcome-foot .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

@media print {
  body { overflow: visible; background: #fff; }
  #app, .toast, .welcome { display: none !important; }
  #printroot { display: block; }
  .print-page { page-break-after: always; break-after: page; position: relative; }
  .print-page:last-child { page-break-after: auto; }
}

@page {
  size: letter portrait;
  margin: 0.4in;
}