:root {
  --bg: #e9e7e0;
  --surface: #f7f6f1;
  --paper: #fdfcf7;
  --ink: #18181a;
  --ink-paper: #18181a;
  --muted: #6d6b64;
  --line: #d3d0c5;
  --field: #ffffff;
  --accent: #18181a;
  --accent-ink: #fdfcf7;
  --ok: #1d7f47;
  --warn: #b26a00;
  --danger: #cf1f2b;
  --shadow: 0 1px 0 rgba(0, 0, 0, .04), 0 12px 32px -12px rgba(30, 25, 10, .25);
  --radius: 14px;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212;
    --surface: #1c1c1d;
    --muted: #9b9a94;
    --ink: #ecebe6;
    --line: #333335;
    --field: #141415;
    --accent: #ecebe6;
    --accent-ink: #121212;
    --ok: #3fbf74;
    --warn: #e0a03a;
    --danger: #ff5a5f;
    --shadow: 0 12px 32px -12px rgba(0, 0, 0, .6);
  }
}

:root[data-theme="dark"] {
  --bg: #121212;
  --surface: #1c1c1d;
  --muted: #9b9a94;
  --ink: #ecebe6;
  --line: #333335;
  --field: #141415;
  --accent: #ecebe6;
  --accent-ink: #121212;
  --ok: #3fbf74;
  --warn: #e0a03a;
  --danger: #ff5a5f;
  --shadow: 0 12px 32px -12px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding: clamp(28px, 6vw, 72px) 16px 64px;
}

/* --- Header ------------------------------------------------------------------- */

.eyebrow {
  margin: 0 0 10px;
  font: 500 12px/1 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-size: clamp(40px, 8vw, 76px);
  line-height: .95;
  letter-spacing: -.035em;
  font-weight: 800;
}

.lede {
  max-width: 34em;
  margin: 16px 0 0;
  font-size: 18px;
  color: var(--muted);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 22px 0 0;
  padding: 6px 12px 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font: 500 13px/1.2 var(--mono);
  color: var(--muted);
  background: var(--surface);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status[data-state="ok"] .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.status[data-state="paused"] .dot { background: var(--danger); }
.status[data-state="paused"] { color: var(--danger); }
.status[data-state="waiting"] .dot { background: var(--warn); }
.status[data-state="waiting"] { color: var(--warn); }

/* --- Layout ---------------------------------------------------------------- */

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: clamp(24px, 4vw, 48px);
  align-items: start;
  margin-top: clamp(28px, 5vw, 48px);
}

@media (max-width: 820px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(18px, 3vw, 28px);
  box-shadow: var(--shadow);
}

/* --- Form --------------------------------------------------------------------- */

.field {
  position: relative;
  display: block;
  margin-bottom: 18px;
}

.label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 14px;
}

.muted { color: var(--muted); font-weight: 400; }

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  transition: border-color .15s, box-shadow .15s;
}

select {
  width: 100%;
  padding: 12px 40px 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23888' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") right 14px center / 12px 8px no-repeat,
    var(--field);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  appearance: none;
  cursor: pointer;
}

select:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 15%, transparent); }

.sound-field { margin: 18px 0 0; }
.hint-small { display: block; margin-top: 6px; font-size: 13px; }

textarea {
  resize: vertical;
  min-height: 150px;
  padding-bottom: 30px;
  font-family: var(--mono);
  font-size: 15px;
}

input:focus,
textarea:focus,
.drop:focus-visible,
button:focus-visible {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 15%, transparent);
}

.counter {
  position: absolute;
  right: 12px;
  bottom: 10px;
  font: 12px/1 var(--mono);
  color: var(--muted);
  pointer-events: none;
}

.counter[data-over] { color: var(--danger); font-weight: 700; }

.field-warn {
  margin: -8px 0 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--danger);
}

.drop {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}

.drop svg { flex: none; }
.drop strong { color: var(--ink); }
.drop:hover,
.drop[data-active] {
  border-color: var(--ink);
  color: var(--ink);
  background: color-mix(in srgb, var(--ink) 4%, transparent);
}

kbd {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  font: 12px var(--mono);
  background: var(--field);
}

.attached {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--ok) 10%, transparent);
  font-size: 14px;
}

.attached[hidden] { display: none; }

.link {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.hp {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.print {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin-top: 22px;
  padding: 15px 20px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font: 700 17px/1 var(--sans);
  letter-spacing: -.01em;
  cursor: pointer;
  transition: transform .1s, opacity .15s;
}

.print:hover { opacity: .9; }
.print:active { transform: translateY(1px); }
.print:disabled { opacity: .45; cursor: not-allowed; }

.msg {
  min-height: 1.5em;
  margin: 14px 0 0;
  font-size: 15px;
  font-weight: 500;
}

.msg[data-type="ok"] { color: var(--ok); }
.msg[data-type="error"] { color: var(--danger); }

.rules {
  margin: 22px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
}

.rules h2 {
  margin: 0 0 10px;
  font: 500 12px/1 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.rules ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
}

.rules li::marker { color: var(--line); }

/* --- Receipt preview ---------------------------------------------------------- */

.preview { position: sticky; top: 24px; }

.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  max-width: 460px;
  margin: 0 auto 14px;
}

.preview-label,
.preview-length {
  margin: 0;
  font: 500 12px/1 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.preview-length { letter-spacing: .02em; text-transform: none; }

.preview-note {
  max-width: 460px;
  margin: 18px auto 0;
  font-size: 13px;
  color: var(--muted);
}

/*
 * True-to-scale receipt: 80 mm paper, 72 mm (512 dots) printable,
 * font B = 56 characters per line, line spacing 20 dots.
 * All sizes are tied to the paper width via container units.
 */
.stage {
  --printer: #2b2b2e;
  --printer-hi: #3a3a3e;
  position: relative;
  max-width: 460px;
  margin: 0 auto;
  padding: 0 18px;
}

.printer {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 46px;
  margin: 0 -18px;
  padding: 0 18px 8px;
  border-radius: 14px 14px 10px 10px;
  background: linear-gradient(180deg, var(--printer-hi), var(--printer) 70%);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .08) inset, 0 10px 24px -10px rgba(0, 0, 0, .55);
}

/* paper slot */
.printer::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 6px;
  height: 5px;
  border-radius: 3px;
  background: #0d0d0e;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .07);
}

.printer-led {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 8px #4ade80;
}

.printer-led[data-state="paused"] { background: #f87171; box-shadow: 0 0 8px #f87171; }
.printer-led[data-state="waiting"] { background: #fbbf24; box-shadow: 0 0 8px #fbbf24; }
.printer-led[data-state="busy"] { animation: blink .35s steps(2) infinite; }
@keyframes blink { 50% { opacity: .2; } }

.feed {
  position: relative;
  z-index: 1;
  margin-top: -8px;
  container-type: inline-size;
}

.paper {
  --ink: #1c1a19;
  --char: calc(90cqw / 56);
  --line: calc(90cqw * 20 / 512);
  --feed-lines: 2;
  position: relative;
  min-height: 30cqw;
  /* bottom: blank lines before the cut */
  padding: 7cqw 5cqw calc(var(--line) * var(--feed-lines) + 2cqw);
  background:
    linear-gradient(180deg, rgba(0, 0, 0, .10), transparent 4cqw),
    linear-gradient(90deg, rgba(0, 0, 0, .025), transparent 6%, transparent 94%, rgba(0, 0, 0, .025)),
    var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: calc(var(--char) / .6);
  line-height: var(--line);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 24px 40px -22px rgba(30, 25, 10, .55);
  transform-origin: top center;
}

/* cleanly cut edge */
.paper::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: rgba(0, 0, 0, .08);
}

.r-meta,
.r-text {
  margin: 0;
  font: inherit;
  white-space: pre;
  overflow: hidden;
}

.r-meta {
  margin-bottom: calc(var(--line) / 2); /* half a line of space before the message */
  color: color-mix(in srgb, var(--ink) 92%, transparent);
}

.r-img {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

.r-empty {
  margin: 0;
  font: inherit;
  white-space: normal;
  color: #a8a59b;
}

/* On submit: the receipt is cut and falls, a new one feeds out of the printer */
.paper[data-cut] { animation: cut-fall .7s cubic-bezier(.55, 0, .75, .2) forwards; }
.paper[data-feeding] { animation: feed-in .55s cubic-bezier(.2, .7, .3, 1); }

@keyframes cut-fall {
  0% { transform: none; opacity: 1; }
  15% { transform: translateY(2px); }
  100% { transform: translateY(70%) rotate(-5deg); opacity: 0; }
}

@keyframes feed-in {
  from { clip-path: inset(0 0 100% 0); }
  to { clip-path: inset(0 0 0 0); }
}

@media (prefers-reduced-motion: reduce) {
  .paper[data-cut],
  .paper[data-feeding],
  .printer-led[data-state="busy"] { animation: none; }
}

/* --- Admin ----------------------------------------------------------------- */

.admin .wrap { max-width: 760px; }
.admin h1 { font-size: clamp(36px, 7vw, 56px); }
.stack { display: grid; gap: 18px; margin-top: 32px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.spread { justify-content: space-between; }
.card h2 { margin: 0 0 14px; font-size: 13px; font-family: var(--mono); font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }

.kill {
  display: block;
  width: 100%;
  padding: 28px 20px;
  border: 0;
  border-radius: 16px;
  background: var(--danger);
  color: #fff;
  font: 800 clamp(26px, 6vw, 38px)/1 var(--sans);
  letter-spacing: -.02em;
  cursor: pointer;
  box-shadow: 0 10px 30px -10px color-mix(in srgb, var(--danger) 70%, transparent);
  transition: transform .1s, filter .15s;
}

.kill:hover { filter: brightness(1.06); }
.kill:active { transform: scale(.99); }
.kill[data-paused] { background: var(--ok); box-shadow: 0 10px 30px -10px color-mix(in srgb, var(--ok) 70%, transparent); }
.kill small { display: block; margin-top: 8px; font: 500 14px/1.3 var(--sans); letter-spacing: 0; opacity: .9; }

.btn {
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  color: var(--ink);
  font: 600 15px/1 var(--sans);
  cursor: pointer;
}

.btn:hover { border-color: var(--ink); }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--accent-ink); border-color: var(--ink); }
.btn-danger { color: var(--danger); }
.btn-small { padding: 7px 11px; font-size: 13px; }

.volume { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 220px; }
.volume input[type="range"] { flex: 1; accent-color: var(--ink); }
.volume output { min-width: 4.5ch; font: 700 16px var(--mono); text-align: right; }

.actions { margin-top: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.stat b { display: block; font: 700 22px/1.1 var(--mono); }
.stat span { display: block; font-size: 13px; line-height: 1.3; color: var(--muted); }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font: 600 12px/1.5 var(--mono); }
.pill-ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.pill-bad { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.pill-warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }

.queue { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.queue li { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.queue .q-meta { font: 12px var(--mono); color: var(--muted); }
.queue .q-text { margin: 4px 0 0; font: 13px/1.4 var(--mono); white-space: pre-wrap; word-break: break-word; }
.queue img { display: block; max-width: 160px; max-height: 200px; margin-top: 8px; border: 1px solid var(--line); border-radius: 6px; cursor: zoom-in; }
.queue .q-actions { display: flex; flex-direction: column; gap: 6px; }
.empty { color: var(--muted); font-size: 14px; margin: 0; }
.error-text { color: var(--danger); font-size: 13px; }
.pill-muted { background: color-mix(in srgb, var(--muted) 15%, transparent); color: var(--muted); }

.hint {
  margin: 0 0 14px;
  padding: 10px 14px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  color: var(--ink);
  font-size: 14px;
}

.chips { margin-bottom: 14px; gap: 6px; }

.small { margin: 12px 0 0; font-size: 14px; }
.sound-test { margin-top: 12px; flex-wrap: nowrap; }
.sound-actions { margin-bottom: 12px; }
.btn-stop:disabled { opacity: .45; cursor: default; }
.btn-stop.is-active { background: var(--danger); border-color: var(--danger); color: #fff; }
.volume.is-muted { opacity: .45; }
.sound-test select { flex: 1; min-width: 0; padding-top: 9px; padding-bottom: 9px; font-size: 15px; }
.quiet-row { gap: 16px; }
.quiet-row .check { gap: 8px; font-weight: 600; }
.quiet-row .time { gap: 8px; color: var(--muted); }
.quiet-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--ink); }
input[type="time"] {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  color: var(--ink);
  font: 600 15px var(--mono);
}
input[type="time"]:disabled { opacity: .5; }

.log { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.log li { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.log li[data-status="deleted"],
.log li[data-status="blocked"] { opacity: .75; }
.log-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.log .q-meta { font: 12px var(--mono); color: var(--muted); }
.log .q-text { margin: 6px 0 0; font: 13px/1.4 var(--mono); white-space: pre-wrap; word-break: break-word; }
.log .error-text { margin: 6px 0 0; }
.log img { display: block; max-width: 160px; max-height: 200px; margin-top: 8px; border: 1px solid var(--line); border-radius: 6px; cursor: zoom-in; }

.thumb { display: block; padding: 0; border: 0; background: none; cursor: zoom-in; overflow: hidden; border-radius: 6px; }
.thumb img { cursor: inherit; transition: filter .2s; }
.thumb[data-blurred] { position: relative; cursor: pointer; }
.thumb[data-blurred] img { filter: blur(16px) saturate(.6); }
.thumb[data-blurred]::after {
  content: "Anzeigen";
  position: absolute;
  inset: 8px 0 0;
  display: grid;
  place-items: center;
  font: 600 12px var(--sans);
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .6);
}
.mod-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.check-small { gap: 6px; font-size: 13px; color: var(--muted); }
.small-top { margin: 0 0 12px; font-size: 13px; }
.bans { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.bans li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--accent-ink);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
}

[hidden] { display: none !important; }
