:root {
  --paper: #efe8dc;
  --card: #fffaf3;
  --ink: #1c1612;
  --muted: #5e564c;
  --line: #e3d8c8;
  --accent: #c4491d;
  --entry: #0e7a45;
  --print: #184e86;
  --exit: #a33b24;
  --shadow: 0 18px 40px rgba(58, 34, 12, 0.06);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 252, 247, 0.7), rgba(255, 252, 247, 0) 320px),
    var(--paper);
  font-family: Outfit, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

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

a { color: inherit; }

h1, h2, .who-name, .result-name, .stat b {
  font-family: Fraunces, Palatino, "Times New Roman", serif;
  font-weight: 560;
  letter-spacing: -0.03em;
}

h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 52px);
  line-height: 1.02;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px 24px;
  flex-wrap: wrap;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(239, 232, 220, 0.92);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--ink);
  color: #f4ecdf;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Fraunces, Palatino, serif;
  font-size: 18px;
}

.brand strong { display: block; font-size: 15px; letter-spacing: -0.02em; }
.brand small { display: block; color: var(--muted); font-size: 12px; }

nav { display: flex; flex-wrap: wrap; gap: 6px; }

nav a {
  text-decoration: none;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
}

nav a.active { background: var(--ink); color: #f6f1e8; }

img, video { max-width: 100%; }

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 16px calc(64px + env(safe-area-inset-bottom));
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.kicker {
  margin: 0 0 8px;
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.lede, .hint, .footnote, .who-meta {
  color: var(--muted);
}

.lede { max-width: 62ch; margin: 12px 0 0; font-size: 17px; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.layout {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: stretch;
}

.layout > * { flex: 1 1 320px; }

.fields { display: flex; flex-direction: column; gap: 14px; }

label span, .gate span {
  display: block;
  margin-bottom: 8px;
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

input, select {
  width: 100%;
  background: #fff;
  border: 1px solid #ddd2c3;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 18px;
}

input:focus, select:focus, button:focus-visible {
  outline: 2px solid #e39a6a;
  outline-offset: 2px;
  border-color: var(--accent);
}

::placeholder { color: #b3a89b; }

.form-error {
  min-height: 1.3em;
  margin: 12px 0 0;
  color: #9f2d2d;
}

.form-actions, .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.primary, .ghost {
  border-radius: 999px;
  padding: 13px 18px;
  font-weight: 640;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
}

.primary {
  background: var(--ink);
  color: #f6f1e8;
  border: 0;
}

.primary:hover { background: #3a3128; }
.primary:disabled { opacity: 0.45; cursor: wait; }

.ghost {
  background: transparent;
  border: 1px solid #d9cebf;
  color: var(--ink);
}

.ghost:hover { background: rgba(255, 255, 255, 0.7); }

.preview { text-align: center; }

.qr-frame {
  width: 232px;
  height: 232px;
  margin: 0 auto;
  border-radius: 18px;
  border: 1px dashed #d9cebf;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  padding: 8px;
}

.qr-frame img { width: 210px; height: 210px; }

#qr-empty { margin: 0; color: var(--muted); padding: 0 18px; }

.ticket-rule {
  border: 0;
  border-top: 1px dashed #e0d5c6;
  margin: 18px 0;
}

.who-name { margin: 8px 0 4px; font-size: 34px; line-height: 1.05; }
.who-meta { margin: 0; font-size: 16px; }

.code {
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-size: 18px;
  letter-spacing: 0;
  margin: 10px 0 0;
}

.preview .actions { justify-content: center; }
.hint, .footnote { font-size: 14px; overflow-wrap: anywhere; }
.footnote { margin-top: 22px; }

.station-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 18px;
}

.station-card {
  flex: 1 1 220px;
  text-decoration: none;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 4px solid var(--ink);
  border-radius: 18px;
  padding: 16px 16px 14px;
  box-shadow: var(--shadow);
}

.tone-entry { --tone: var(--entry); }
.tone-print { --tone: var(--print); }
.tone-exit { --tone: var(--exit); }
.station-card.tone-entry { border-top-color: var(--entry); }
.station-card.tone-print { border-top-color: var(--print); }
.station-card.tone-exit { border-top-color: var(--exit); }

.station-card .num {
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tone, var(--accent));
}

.station-card strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 22px;
  letter-spacing: -0.03em;
}

.station-card p { margin: 0; color: var(--muted); }

.station-card:hover { transform: translateY(-2px); }

body.landing {
  background:
    radial-gradient(820px 420px at -10% -10%, #f3d2bc 0%, transparent 58%),
    radial-gradient(640px 380px at 110% 110%, #d9e4f2 0%, transparent 52%),
    #f3f0e8;
}

.landing-top {
  display: flex;
  align-items: center;
  max-width: 1080px;
  margin: 0 auto;
  padding: 22px 20px 0;
  background: transparent;
  border: 0;
  position: static;
}

body.landing .brand strong {
  font-family: Fraunces, Palatino, "Times New Roman", serif;
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 560;
  letter-spacing: -0.03em;
}

body.landing main {
  max-width: 1080px;
  padding-top: 18px;
}

.landing-stage {
  display: flex;
  flex-wrap: wrap;
  max-width: 560px;
  margin: 0 auto;
  background: #fffdfb;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 32px;
  overflow: hidden;
  box-shadow: 0 28px 70px rgba(48, 28, 12, 0.08);
}

.landing-stage.has-pass { max-width: none; }

.landing-form {
  flex: 1 1 100%;
  min-width: 0;
  padding: 36px 32px 28px;
}

.landing-form h1 { font-size: clamp(34px, 7vw, 56px); }

.landing-form .lede { margin-bottom: 26px; }

body.landing label span {
  font-family: Outfit, "Segoe UI", sans-serif;
  font-size: 13px;
  font-weight: 640;
  letter-spacing: 0;
  text-transform: none;
  color: #3c342c;
}

body.landing input {
  min-height: 56px;
  border: 1px solid transparent;
  border-radius: 16px;
  background: #f4f1eb;
}

body.landing input:focus {
  background: #fff;
  border-color: #1c1612;
  outline: none;
}

body.landing .form-actions .primary { flex: 1; border-radius: 16px; min-height: 54px; }

.landing-pass {
  flex: 1 1 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 28px;
  background:
    radial-gradient(420px 220px at 50% 0%, rgba(255, 214, 186, 0.16), transparent 70%),
    #161310;
  color: #f7f1e8;
}

.landing-pass .kicker { color: #e7b89a; }
.landing-pass .who-name { color: #f7f1e8; }
.landing-pass .who-meta,
.landing-pass .hint { color: #c9bfb4; }
.landing-pass .code { color: #f7f1e8; }

.landing-pass .qr-frame {
  width: min(232px, 72vw);
  height: auto;
  aspect-ratio: 1;
  background: #fff;
  border: 0;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
}

.landing-pass .qr-frame img { width: 86%; height: auto; }

.landing-pass .who-name,
.landing-pass .code { overflow-wrap: anywhere; }

.landing-pass #qr-empty { color: #6f675e; }

.landing-pass .primary {
  background: #f4ece3;
  color: #171411;
}

.landing-pass .primary:hover { background: #fff; }
.landing-pass .primary:disabled { opacity: 0.4; }

.landing-pass .ghost {
  border-color: #4d463f;
  color: #f7f1e8;
  background: transparent;
}

.landing-pass .ghost:hover { background: rgba(255, 255, 255, 0.06); }

@media (min-width: 900px) {
  .landing-stage.has-pass { flex-wrap: nowrap; }
  .landing-stage.has-pass .landing-form { flex: 1.15 1 0; }
  .landing-stage.has-pass .landing-pass { flex: 0.9 1 0; }
}

@media (max-width: 800px) {
  .landing-top { padding: 16px 16px 0; }
  .landing-form { padding: 28px 20px 22px; }
  .landing-pass { padding: 28px 18px 24px; }
  .landing-stage { border-radius: 24px; }
  body.landing .form-actions { flex-direction: column; }
  body.landing .form-actions .primary,
  body.landing .form-actions .ghost,
  .landing-pass .actions,
  .landing-pass .primary,
  .landing-pass .ghost { width: 100%; }
}

.scanner-wrap { max-width: 680px; margin: 0 auto; }

.scanner-card { border-top: 6px solid var(--tone, var(--ink)); }

.scan-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.clock {
  margin: 0;
  font-family: "IBM Plex Mono", Consolas, monospace;
  color: var(--muted);
}

.gate { display: block; margin: 18px 0 6px; }

.gate select {
  font-size: 20px;
  background: #fff;
  min-height: 56px;
}

.scan-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
  margin-top: 16px;
}

.scan-row input { flex: 1; min-width: 0; }

.scan-input {
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-size: 16px;
  min-height: 56px;
}

#reader {
  margin-top: 12px;
  border-radius: 16px;
  overflow: hidden;
  background: #1c1612;
}

.result {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  min-height: 112px;
}

.result-msg {
  margin: 0;
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.result-name {
  margin: 8px 0 4px;
  font-size: clamp(32px, 6vw, 46px);
  line-height: 1.02;
  overflow-wrap: anywhere;
}

.result-meta, .result-extra { margin: 0; }
.result-meta { font-size: 18px; color: var(--muted); }
.result-extra { margin-top: 8px; }

.tone-entry .result.ok { background: #e7f6ee; border-color: var(--entry); }
.tone-print .result.ok { background: #e7f0fa; border-color: var(--print); }
.tone-exit .result.ok { background: #fdeee8; border-color: var(--exit); }
.result.warn { background: #fff6e8; border-color: #b45309; }
.result.bad { background: #fdeceb; border-color: #b42318; }
.result.idle { background: transparent; border-style: dashed; }

.tone-entry .result.ok .result-msg { color: var(--entry); }
.tone-print .result.ok .result-msg { color: var(--print); }
.tone-exit .result.ok .result-msg { color: var(--exit); }
.result.warn .result-msg { color: #9a3412; }
.result.bad .result-msg { color: #9f2d2d; }

.slip-preview {
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 14px;
  background: #fff;
  border: 1px dashed var(--line);
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-size: 12px;
  line-height: 1.35;
  white-space: pre-wrap;
  text-align: left;
  overflow-x: auto;
}

.recent-title {
  margin: 22px 0 8px;
  font-family: Outfit, "Segoe UI", sans-serif;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 640;
}

.recent { list-style: none; margin: 0; padding: 0; }

.recent li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #eee6dc;
}

.recent li.empty { color: var(--muted); display: block; }
.recent .who { font-weight: 640; }
.recent time, .recent .note { color: var(--muted); font-size: 14px; }

.station-url {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.station-url span {
  font-family: "IBM Plex Mono", Consolas, monospace;
  color: var(--ink);
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.stats article {
  flex: 1 1 140px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px;
}

.stat b, .stats b {
  display: block;
  font-size: 34px;
  line-height: 1;
}

.stats span {
  color: var(--muted);
  font-size: 13px;
}

#search { max-width: 320px; }

.table-wrap { overflow-x: auto; padding: 8px 12px 12px; }

table { width: 100%; border-collapse: collapse; min-width: 760px; }

th {
  text-align: left;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 640;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
}

td {
  padding: 14px 10px;
  border-bottom: 1px solid #eee6dc;
  vertical-align: top;
}

.visitor-name { font-weight: 640; }
.visitor-sub { color: var(--muted); font-size: 14px; }

.mono {
  font-family: "IBM Plex Mono", Consolas, monospace;
  letter-spacing: 0.04em;
  text-decoration: none;
}

.pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 640;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.pill.inside { background: #e5f6ec; color: #0f5c36; }
.pill.out { background: #f3efe6; color: #5e564c; }
.pill.expected { background: #fff4df; color: #92400e; }

.ticket { text-align: center; }
.narrow { max-width: 460px; margin: 0 auto; }
.banner {
  background: #fff6e8;
  border: 1px solid #e7c89a;
  border-radius: 12px;
  padding: 12px 14px;
}

.slip-sheet {
  position: absolute;
  left: -10000px;
  top: 0;
  width: 58mm;
  color: #000;
  background: #fff;
}

.slip-sheet,
.paper-slip {
  text-align: center;
  font-family: "Segoe UI", Arial, sans-serif;
}

.slip-line {
  margin: 0;
  width: 100%;
  line-height: 1.15;
  text-align: center;
}

.slip-line.bold { font-weight: 700; }

.slip-sheet img {
  width: 22mm;
  height: auto;
  display: block;
  margin: 1mm auto 0;
}

.slip-sheet img:not([src]) { display: none; }

.scanner-card.flash { animation: flash 500ms ease; }

@keyframes flash {
  from { box-shadow: 0 0 0 4px rgba(196, 73, 29, 0.28); }
  to { box-shadow: var(--shadow); }
}

@media (max-width: 760px) {
  .top { padding: 14px 14px; }
  nav { width: 100%; }
  nav a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 auto;
    text-align: center;
  }
  main { padding: 18px 12px calc(40px + env(safe-area-inset-bottom)); }
  .page-head { align-items: stretch; }
  #search { max-width: none; width: 100%; }
  .scan-title { flex-wrap: wrap; }
  .scan-row { flex-wrap: wrap; }
  .scan-row .ghost,
  .gate select,
  .scan-input { width: 100%; }
  .result { min-height: 0; }
  .stats article { flex: 1 1 calc(50% - 12px); }
  .stats b { font-size: 28px; }
  .table-wrap { padding: 4px 8px 12px; }
  table { min-width: 0; }
  thead { display: none; }
  tbody tr {
    display: block;
    padding: 8px 0 12px;
    border-bottom: 1px solid var(--line);
  }
  td {
    display: block;
    border: 0;
    padding: 8px 4px 4px;
  }
  td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
  td[colspan] { display: block; }
  td[colspan]::before { content: none; }
  .narrow { width: min(460px, 100%); }
  .ticket { padding: 18px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .station-card:hover { transform: none; }
}

.settings-layout {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: flex-start;
}

.settings-form { flex: 1.2 1 340px; min-width: 0; }
.settings-side { flex: 0.8 1 280px; min-width: 0; }

.settings-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.settings-grid label { flex: 1 1 140px; }

.check-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 0;
}

.check-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
}

.check-list input {
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  accent-color: #1c1612;
}

.paper-stage {
  background: #e7e1d6;
  border-radius: 18px;
  padding: 18px 12px 22px;
}

.paper-slip {
  margin: 0 auto;
  background: #fff;
  color: #111;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
}

.paper-slip img {
  display: block;
  margin: 1mm auto 0;
  height: auto;
}

@media (max-width: 800px) {
  .settings-side { flex-basis: 100%; }
}

@media print {
  @page { size: 58mm auto; margin: 1mm; }
  .slip-sheet { display: none !important; }
  body.printing-slip { background: #fff !important; }
  body.printing-slip header,
  body.printing-slip main { display: none !important; }
  body.printing-slip .slip-sheet {
    display: block !important;
    position: static;
    left: auto;
    width: 100% !important;
    text-align: center !important;
  }
}
