@font-face { font-family: "Areal Mono"; src: url(../fonts/areal-mono.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Areal"; src: url(../fonts/areal-medium.woff2) format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Areal"; src: url(../fonts/areal-bold.woff2) format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Areal Mono Bold"; src: url(../fonts/areal-mono-bold.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Herkules"; src: url(../fonts/herkules.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Biedermeier"; src: url(../fonts/biedermeier.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Utusi"; src: url(../fonts/utusi.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Gondrini"; src: url(../fonts/gondrini.woff2) format("woff2"); font-display: swap; }

:root {
  --sage: #9fbcb7;
  --pink: #ff0084;
  --ink: #111;
  --paper: #f8f7f2;
  --mono: "Areal Mono", "Courier New", monospace;
  --line: 1.5px solid var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--sage);
  color: var(--ink);
  font: 12px/1.4 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; letter-spacing: 0; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .chip:focus-within { outline: 2px solid var(--pink); outline-offset: 2px; }

/* ---------- header ---------- */

.top { display: flex; align-items: center; gap: 18px; padding: 8px 16px 8px 18px; border-bottom: var(--line); }
.logo { font: 46px/1 "Biedermeier", Georgia, serif; text-transform: none; letter-spacing: 0; color: var(--ink); text-decoration: none; padding-top: 6px; }
.title { font-size: 11px; line-height: 1.18; letter-spacing: 0.06em; }
.go {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--pink); border: var(--line);
  font: 700 15px/1 "Areal", Arial, sans-serif; text-transform: none; letter-spacing: -0.01em;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform 0.12s, box-shadow 0.12s;
  flex: none; margin-left: auto;
}
.go:active, .go.busy { transform: translateY(4px); box-shadow: 0 0 0 var(--ink); }
.go.busy span { animation: buzz 0.18s steps(2) infinite; }
@keyframes buzz { 50% { opacity: 0.45; } }

/* ---------- layout ---------- */

main { display: grid; grid-template-columns: 360px minmax(0, 1fr); min-height: 0; }
#panel { overflow: auto; border-right: var(--line); padding: 0 16px 48px; scrollbar-width: thin; scrollbar-color: var(--ink) transparent; }
#stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#c3d { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#c3d .gl { width: 100%; height: 100%; display: block; object-fit: contain; touch-action: none; }
#c3d.checker, .sw.checker { background: repeating-conic-gradient(#d9d9d9 0 25%, #fff 0 50%) 0 0 / 16px 16px; }

.hint { position: absolute; left: 16px; right: 130px; bottom: 12px; margin: 0; font-size: 10px; opacity: 0.6; pointer-events: none; }
.btn.view { position: absolute; right: 16px; bottom: 10px; font-size: 11px; background: var(--sage); }
#toast {
  position: absolute; top: 14px; left: 50%; transform: translate(-50%, -6px);
  background: var(--ink); color: var(--pink); padding: 7px 12px; font-size: 11px;
  opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none; z-index: 5; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.recdot { position: absolute; top: 14px; right: 16px; color: var(--pink); background: var(--ink); padding: 4px 8px; font-size: 11px; display: none; }
body.recording .recdot { display: block; animation: buzz 1s steps(2) infinite; }
body.recording #dlPhoto, body.recording #dlFlat, body.recording .fmt { pointer-events: none; opacity: 0.45; }
body.recording #rec { background: var(--pink); }
.dropzone { position: absolute; inset: 12px; border: 2px dashed var(--ink); display: none; place-items: center; font-size: 13px; background: rgba(255, 255, 255, 0.35); pointer-events: none; z-index: 4; }
#stage.drop .dropzone { display: grid; }

/* ---------- panel ---------- */

.sec { padding-top: 16px; }
.sec h2 { font: 700 24px/1 "Areal", Arial, sans-serif; text-transform: none; letter-spacing: -0.02em; margin: 0; }
.rule { overflow: hidden; white-space: nowrap; line-height: 1; margin: 4px 0 10px; user-select: none; }
.rule::before { content: "========================================================================================"; }
.rule.dash::before { content: "----------------------------------------------------------------------------------------"; }
.note { margin: 6px 0 8px; font-size: 10px; line-height: 1.45; opacity: 0.72; }

.row { display: grid; grid-template-columns: 84px minmax(0, 1fr) auto; align-items: center; gap: 8px; margin: 7px 0; }
.row > :nth-child(2):last-child { grid-column: 2 / 4; }
.row .lbl { font-size: 10px; opacity: 0.75; }
.row output { min-width: 50px; text-align: right; font-size: 11px; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { border: var(--line); padding: 4px 8px; font-size: 11px; line-height: 1.25; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; background: transparent; }
.chip:hover { background: rgba(255, 255, 255, 0.35); }
.chip.on { background: var(--ink); color: var(--sage); }
.chip.danger { border-color: var(--ink); background: var(--pink); }
.chip.upload { cursor: pointer; }
.chip.primary { background: var(--pink); }
.colours { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.pick { width: 30px; height: 26px; padding: 0; border: var(--line); background: none; cursor: pointer; }
.pick::-webkit-color-swatch-wrapper { padding: 2px; }
.pick::-webkit-color-swatch { border: 0; }
.fonts .chip { padding: 3px 7px; }
.swatches .chip { padding: 3px; }
.sw { display: block; width: 22px; height: 16px; border: 1px solid var(--ink); }
.swatches .chip.on { background: transparent; outline: 2px solid var(--ink); outline-offset: 1px; }
.presets .chip { min-width: 72px; justify-content: center; }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 20px; background: transparent; margin: 0; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: var(--ink); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--pink); border: var(--line); margin-top: -7px; }
input[type="range"]::-moz-range-track { height: 2px; background: var(--ink); }
input[type="range"]::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: var(--pink); border: var(--line); }

.txt, textarea, select.txt {
  width: 100%; min-width: 0; background: rgba(255, 255, 255, 0.32); border: var(--line); border-radius: 0;
  padding: 5px 8px; font-size: 12px; outline: none; text-transform: none;
}
select.txt { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%); background-position: calc(100% - 13px) 50%, calc(100% - 8px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 24px; }
.txt.short { max-width: 110px; }
textarea { display: block; resize: vertical; min-height: 54px; line-height: 1.38; font-family: var(--mono); }
.txt:focus, textarea:focus { background: var(--paper); }

.card { border-bottom: 1.5px dashed var(--ink); }
.card-h { display: flex; align-items: center; gap: 6px; padding: 7px 0; }
.card-t { flex: 1; display: flex; gap: 8px; align-items: center; text-align: left; min-width: 0; }
.card-t b { font-weight: normal; background: var(--ink); color: var(--sage); padding: 1px 5px; font-size: 10px; flex: none; }
.card.open .card-t b { background: var(--pink); color: var(--ink); }
.card-t .sum { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.8; text-transform: none; font-size: 11px; }
.card-a { display: flex; gap: 1px; flex: none; }
.ib { width: 24px; height: 24px; display: grid; place-items: center; border: 1.5px solid transparent; font-size: 13px; text-transform: none; }
.ib:hover { border-color: var(--ink); }
.card-b { display: none; padding: 0 0 12px; }
.card.open .card-b { display: block; }
.add { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 12px; }

.items { display: grid; gap: 4px; margin: 6px 0; }
.item { display: grid; grid-template-columns: minmax(0, 1fr) 72px 24px; gap: 4px; }
.item .price { text-align: right; }

.lib { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; margin-top: 10px; }
.stk { aspect-ratio: 1; background: var(--paper); border: var(--line); display: grid; place-items: center; padding: 5px; overflow: hidden; }
.stk img { max-width: 100%; max-height: 100%; }
.stk:hover { background: #fff; box-shadow: inset 0 0 0 2px var(--pink); }

.selbox { border: var(--line); background: rgba(255, 255, 255, 0.25); padding: 6px 10px 10px; margin: 4px 0 10px; }
.selhead { display: flex; justify-content: space-between; align-items: center; }
.selhead b { font-weight: normal; background: var(--pink); padding: 1px 5px; font-size: 10px; }

/* ---------- footer ---------- */

.bottom { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-top: var(--line); flex-wrap: wrap; }
.bottom .grp { display: inline-flex; gap: 6px; align-items: center; }
.bottom .fmt .lbl { font-size: 10px; opacity: 0.7; margin-right: 2px; }
.bottom .grow { flex: 1; }
.btn { border: var(--line); padding: 6px 10px; }
.btn:hover { background: var(--ink); color: var(--sage); }

/* ---------- phone ---------- */

.tools, .tabs, .sec.export { display: none; }
#stage { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* the stage takes the screen, the settings open one tab at a time in a
   sheet under it, the tab bar sits at the thumb */
@media (max-width: 860px) {
  body { grid-template-rows: auto minmax(0, 1fr) auto; overscroll-behavior: none; }
  .top { gap: 10px; padding: 6px 12px; padding-top: max(6px, env(safe-area-inset-top)); }
  .logo { font-size: 32px; padding-top: 4px; }
  .title { display: none; }
  .go { width: 48px; height: 48px; font-size: 12px; box-shadow: 0 3px 0 var(--ink); }
  .go:active, .go.busy { transform: translateY(3px); }
  main { display: flex; flex-direction: column; }
  #stage { order: -1; flex: 1 1 auto; }
  #panel { display: none; flex: none; max-height: 42dvh; overflow: auto; overscroll-behavior: contain; border-right: 0; border-top: var(--line); padding: 0 14px 16px; }
  body.sheet #panel { display: block; }
  .sec.export { display: block; }
  #panel .sec.off, #panel .sec > h2, #panel .sec > h2 + .rule { display: none; }
  .sec { padding-top: 12px; }
  .chip { padding: 6px 9px; }
  .row { margin: 9px 0; }
  input[type="range"] { height: 30px; }
  input[type="range"]::-webkit-slider-thumb { width: 22px; height: 22px; margin-top: -10px; }
  .lib { grid-template-columns: repeat(6, minmax(0, 1fr)); }

  .bottom { display: none; }
  .savebox .grp { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
  .savebox .fmt .lbl { width: 100%; }
  .savebox .grow { display: none; }
  .savebox > .btn { margin: 0 6px 6px 0; }
  .savebox .btn { padding: 8px 10px; }

  .tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabs button { padding: 13px 0 12px; font-size: 11px; border-left: var(--line); }
  .tabs button:first-child { border-left: 0; }
  .tabs button.on { background: var(--ink); color: var(--sage); }

  .tools { display: block; position: absolute; left: 12px; bottom: 10px; }
  .tools .chip { background: var(--sage); padding: 7px 10px; }
  .tools .chip.on { background: var(--ink); }
  .btn.view { right: 12px; bottom: 10px; padding: 7px 10px; }
  .hint { top: 12px; bottom: auto; left: 16px; right: 16px; text-align: center; transition: opacity 0.4s; }
  #stage.used .hint, body.sheet .hint, body.sheet .tools { opacity: 0; pointer-events: none; }
}
/* phone on its side: the sheet opens beside the stage */
@media (max-width: 860px) and (orientation: landscape) {
  main { flex-direction: row; }
  #panel { max-height: none; width: 320px; border-top: 0; border-left: var(--line); }
  .top { padding-top: 4px; padding-bottom: 4px; }
  .logo { font-size: 26px; }
  .go { width: 38px; height: 38px; font-size: 10px; }
  .tabs button { padding: 9px 0 8px; }
}
@media (max-width: 420px) {
  .lib { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .row { grid-template-columns: 70px minmax(0, 1fr) auto; }
}
