@font-face {
  font-family: "SpaceBar";
  src: url("./spacebar.woff") format("woff");
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #121113;
  --bg-2: #191117;
  --panel: #1f1520;
  --panel-2: #2a1a27;
  --line: #37172f;
  --line-soft: #2b292d;
  --text: #eeeef0;
  --muted: #b5b2bc;
  --dim: #7c7a85;
  --pink: #de51a8;
  --pink-soft: #ff8dcc;
  --blue: #2e7fc2;
  --blue-soft: #8ed1fc;
  --ok: #00d084;
  --warn: #fcb900;
  --bad: #ff5f7a;
  --grad: linear-gradient(90deg, #e3218f 0%, #357fc2 100%);
  --radius: 10px;
  --display: "SpaceBar", "DM Mono", monospace;
  --body: "DM Mono", ui-monospace, Menlo, monospace;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: inherit; }

html { scroll-padding-top: env(safe-area-inset-top, 0px); -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100%;
}

h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: 0.02em; margin: 0; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

a { color: var(--pink-soft); }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* Layout */
.wrap { max-width: 560px; margin: 0 auto; padding: 16px; }
.wrap.wide { max-width: 960px; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
}
.topbar .logo { height: 22px; width: auto; display: block; }
.topbar .spacer { flex: 1; }
.topbar .tag { font-size: 12px; color: var(--muted); }

/* Panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.panel h2 { margin-bottom: 10px; }

/* Forms */
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
label:first-child { margin-top: 0; }
input, select, textarea, button {
  font: inherit; color: inherit;
}
input[type="text"], input[type="number"], input[type="email"], input[type="password"],
input[type="date"], input[type="tel"], select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 12px 14px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--pink); box-shadow: 0 0 0 3px rgba(222, 81, 168, 0.25); }
textarea { min-height: 90px; resize: vertical; }
input::placeholder { color: var(--dim); }

.code-input {
  font-family: var(--display);
  font-size: 34px;
  letter-spacing: 0.35em;
  text-align: center;
  padding: 14px 8px 14px 18px;
}

input.count-input {
  font-family: var(--display);
  font-size: 56px;
  text-align: center;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-bottom: 4px solid transparent;
  border-image: var(--grad) 1;
  border-radius: 0;
  width: 100%;
}
input.count-input:focus { box-shadow: none; }
input.count-input.again { font-size: 34px; border-image: none; border-bottom: 2px solid var(--line-soft); }
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  padding: 14px 18px;
  border-radius: 8px;
  border: 1px solid var(--line-soft);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  min-height: 48px;
}
.btn:hover { border-color: var(--pink); }
.btn:focus-visible { outline: 2px solid var(--pink-soft); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--pink); border-color: var(--pink); color: #fff; font-weight: 700; }
.btn.primary:hover { background: #e968b8; }
.btn.quiet { background: transparent; }
.btn.danger { border-color: var(--bad); color: var(--bad); background: transparent; }
.btn.auto { width: auto; padding: 8px 12px; min-height: 36px; font-size: 13px; }
.btn.mt { margin-top: 14px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.choice {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  cursor: pointer;
  margin-top: 8px;
  color: var(--text);
  font-size: 15px;
}
.choice.disabled { opacity: 0.45; cursor: not-allowed; }
.choice input { width: 20px; height: 20px; margin: 0; accent-color: var(--pink); }
.choice.ok:has(input:checked) { border-color: var(--ok); }
.choice.bad:has(input:checked) { border-color: var(--bad); }

.msg { padding: 12px 14px; border-radius: 8px; margin-top: 12px; font-size: 14px; }
.msg.error { background: rgba(255, 95, 122, 0.12); border: 1px solid rgba(255, 95, 122, 0.5); color: #ffb3c0; }
.msg.good { background: rgba(0, 208, 132, 0.1); border: 1px solid rgba(0, 208, 132, 0.4); color: #9ff0cf; }
.msg.info { background: rgba(46, 127, 194, 0.15); border: 1px solid rgba(46, 127, 194, 0.5); color: var(--blue-soft); }

/* Staff page */
.staff-hero { text-align: center; padding: 26px 0 18px; }
.staff-hero .logo { height: 30px; width: auto; }
.staff-hero p { margin-top: 10px; color: var(--muted); }
.machine-card { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 12px 14px; background: var(--bg); border: 1px solid var(--line-soft); border-radius: 8px; margin-bottom: 8px; }
.machine-card .name { font-family: var(--display); font-size: 20px; }
.machine-card .who { color: var(--muted); font-size: 13px; }
.done-big { font-family: var(--display); font-size: 64px; line-height: 1; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; text-align: center; margin: 14px 0 4px; }
.done-sub { text-align: center; color: var(--muted); }

/* Admin nav */
.nav {
  display: flex; gap: 4px; overflow-x: auto; padding: 8px 12px;
  border-bottom: 1px solid var(--line); background: var(--bg-2);
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
  white-space: nowrap; padding: 8px 12px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-size: 14px;
}
.nav a.active { color: var(--text); background: var(--panel-2); }
.nav a:hover { color: var(--text); }

/* Tables */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
th { color: var(--muted); font-weight: 400; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.inactive td { color: var(--dim); }
tr:last-child td { border-bottom: none; }
td .sub { display: block; color: var(--dim); font-size: 12px; }

/* Rank bars */
.rank { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.rank:last-child { border-bottom: none; }
.rank .name { font-family: var(--display); font-size: 18px; }
.rank .stat { text-align: right; font-variant-numeric: tabular-nums; }
.rank .stat b { font-size: 18px; font-weight: 700; }
.rank .bar { grid-column: 1 / -1; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.rank .bar i { display: block; height: 100%; background: var(--grad); width: var(--w, 0%); border-radius: 3px; }
.rank .meta { grid-column: 1 / -1; color: var(--dim); font-size: 12px; }
.rank.worst .name { color: var(--muted); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.tile .k { color: var(--muted); font-size: 12px; }
.tile .v { font-family: var(--display); font-size: 28px; line-height: 1.2; margin-top: 4px; }
.tile .v.small { font-size: 18px; }
.tile.best { border-color: var(--pink); }
.tile.worst { border-color: var(--line-soft); }

.seg { display: flex; max-width: 100%; overflow-x: auto; border: 1px solid var(--line-soft); border-radius: 8px; margin-bottom: 14px; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { background: transparent; border: none; color: var(--muted); padding: 8px 12px; cursor: pointer; font-size: 13px; white-space: nowrap; flex: 1; }
.seg button.active { background: var(--panel-2); color: var(--text); }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; }
.pill.ok { background: rgba(0,208,132,0.15); color: #9ff0cf; }
.pill.bad { background: rgba(255,95,122,0.15); color: #ffb3c0; }
.pill.open { background: rgba(252,185,0,0.15); color: #ffe08a; }
.pill.closed { background: var(--panel-2); color: var(--dim); }

.list-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line-soft); }
.list-item:last-child { border-bottom: none; }
.list-item .main { flex: 1; min-width: 0; }
.list-item .t { font-size: 12px; color: var(--dim); }
.list-item .n { font-family: var(--display); font-size: 22px; min-width: 64px; text-align: right; }
.list-item .note { margin-top: 4px; color: var(--muted); font-size: 13px; white-space: pre-wrap; }

.day-head { color: var(--muted); font-size: 12px; margin: 16px 0 4px; }
.day-head:first-child { margin-top: 0; }

.diff-pos { color: var(--ok); }
.diff-neg { color: var(--bad); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters select, .filters input { width: auto; flex: 1; min-width: 120px; padding: 8px 10px; }

/* Sticker */
.sticker {
  width: 50mm; height: 68mm; background: #fff; color: #111;
  border-radius: 3mm; padding: 3mm; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  font-family: var(--body);
}
.sticker .qr { width: 38mm; height: 38mm; }
.sticker .qr svg { width: 100%; height: 100%; display: block; }
.sticker .tagno { font-family: var(--display); font-size: 40px; line-height: 1; letter-spacing: 0.08em; color: #111; }
.sticker .mname { font-size: 10px; text-align: center; color: #333; line-height: 1.2; }
.sticker .foot { font-size: 7px; color: #666; text-align: center; line-height: 1.3; }

@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .sticker { margin: 0; border-radius: 0; }
  @page { size: 50mm 68mm; margin: 0; }
}

@media (prefers-reduced-motion: no-preference) {
  .rank .bar i { transition: width 400ms ease; }
}

@media (max-width: 480px) {
  .wrap { padding: 12px; }
  input.count-input { font-size: 48px; }
  th, td { padding: 8px 6px; }
}

td.wk { white-space: nowrap; }
