:root {
  --bg: #1A1A1A;
  --card: #2A2A2A;
  --line: #3a3a3a;
  --yellow: #F5C400;
  --orange: #FF7A00;
  --ink: #111111;
  --text: #FFFFFF;
  --muted: #E6E6E6;
  --red: #ff5a4f;
  --green: #3ddc84;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding-bottom: calc(78px + var(--safe-b));
}
a { color: var(--yellow); }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 6px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: var(--yellow); color: var(--ink);
  border-bottom: 3px solid var(--ink);
}
.topbar h1 {
  margin: 0; font-size: 20px; font-weight: 900; letter-spacing: .04em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.back { background: none; border: 0; color: var(--ink); padding: 2px; display: flex; cursor: pointer; }

main { max-width: 640px; margin: 0 auto; padding: 16px; }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* home */
.hero { position: relative; margin: -16px -16px 0; height: 170px; overflow: hidden; border-bottom: 3px solid var(--orange); }
.hero-bg { width: 100%; height: 100%; object-fit: cover; object-position: center 60%; display: block; }
.hero-logo {
  position: absolute; left: 50%; bottom: -2px; transform: translateX(-50%);
  width: 118px; height: 118px; border-radius: 22px; border: 3px solid var(--ink);
  background: #fff; object-fit: contain; box-shadow: 0 6px 18px rgba(0,0,0,.5);
}
.headline {
  margin: 18px 0 6px; text-align: center; font-size: 26px; font-weight: 900;
  letter-spacing: .06em; text-transform: uppercase; color: var(--yellow);
}
.lead { text-align: center; margin: 0 4px 18px; color: var(--text); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 18px 10px 16px; border-radius: 18px; text-decoration: none;
  background: var(--card); border: 2px solid var(--orange); color: var(--text);
  font-weight: 800; font-size: 17px; text-align: center;
}
.tile:active { transform: scale(.98); }
.tile img { width: 84px; height: 84px; }
.fineprint { font-size: 14px; color: var(--muted); text-align: center; margin-top: 18px; }

/* forms */
form { display: flex; flex-direction: column; gap: 14px; }
label, .field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: 16px; color: var(--text); }
.label { font-weight: 700; }
small { font-weight: 500; font-size: 14px; color: var(--muted); }
input, select, textarea {
  font: inherit; font-weight: 500; color: var(--text);
  background: var(--card); border: 2px solid #555; border-radius: 12px;
  padding: 12px 12px; width: 100%; min-height: 50px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--yellow); }
input[type=date] { color-scheme: dark; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #fff 50%), linear-gradient(135deg, #fff 50%, transparent 50%); background-position: calc(100% - 22px) 22px, calc(100% - 16px) 22px; background-size: 6px 6px; background-repeat: no-repeat; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { flex-direction: row; align-items: flex-start; gap: 12px; font-weight: 600; }
.check input { width: 26px; height: 26px; min-height: 0; flex: none; accent-color: var(--yellow); margin-top: 1px; }
.invalid { border-color: var(--red) !important; }
.error { margin: 0; color: #fff; background: #5a1d1a; border: 2px solid var(--red); padding: 10px 12px; border-radius: 12px; font-weight: 600; }

.tip { display: flex; gap: 12px; align-items: flex-start; background: var(--card); border-left: 5px solid var(--orange); padding: 12px 14px; border-radius: 12px; font-size: 15px; }
.tip svg { flex: none; margin-top: 2px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  font: inherit; font-weight: 800; font-size: 17px; text-decoration: none; cursor: pointer;
  border-radius: 14px; padding: 14px 18px; min-height: 52px; border: 2px solid var(--ink);
}
.btn-primary { background: var(--yellow); color: var(--ink); width: 100%; }
.btn-primary:active { background: var(--orange); }
.btn-primary[disabled] { opacity: .6; }
.btn-ghost { background: transparent; color: var(--text); border-color: #777; }
.btn.sm { min-height: 40px; padding: 8px 14px; font-size: 15px; }
.btn-scan { width: 100%; min-height: 96px; background: var(--card); color: var(--yellow); border: 2px dashed var(--yellow); font-size: 19px; }
.scan-preview { display: flex; flex-direction: column; gap: 10px; }
.scan-preview img { width: 100%; max-height: 360px; object-fit: contain; background: #fff; border-radius: 12px; border: 2px solid var(--yellow); }
.row-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* lists */
.list { display: flex; flex-direction: column; gap: 12px; }
.item { display: flex; gap: 12px; align-items: center; background: var(--card); border-radius: 14px; padding: 10px; text-decoration: none; color: var(--text); border: 2px solid transparent; }
.item:active { border-color: var(--orange); }
.item .thumb { width: 64px; height: 64px; border-radius: 10px; background: #fff; object-fit: cover; flex: none; }
.item .thumb.ph { display: flex; align-items: center; justify-content: center; background: #3a3a3a; }
.item .meta { flex: 1; min-width: 0; }
.item .t { font-weight: 800; font-size: 17px; }
.item .s { font-size: 14px; color: var(--muted); }
.chip { font-size: 13px; font-weight: 800; padding: 4px 9px; border-radius: 999px; white-space: nowrap; flex: none; align-self: center; line-height: 1.2; }
.chip.sent { background: #173d27; color: var(--green); }
.chip.failed { background: #4a1714; color: #ffb3ad; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.empty .btn { margin-top: 16px; }

/* detail */
.detail img.full { width: 100%; background: #fff; border-radius: 12px; border: 2px solid var(--yellow); }
.kv { background: var(--card); border-radius: 14px; padding: 4px 14px; margin: 14px 0; }
.kv div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.kv div:last-child { border-bottom: 0; }
.kv b { color: var(--muted); font-weight: 600; }
.kv span { text-align: right; font-weight: 700; word-break: break-word; }
.detail .btn { width: 100%; margin-top: 10px; }

/* sent */
.sent { text-align: center; padding: 30px 6px; display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.sent-check { width: 110px; height: 110px; border-radius: 50%; background: var(--yellow); border: 4px solid var(--ink); margin: 0 auto 6px; display: flex; align-items: center; justify-content: center; }
.sent h2 { margin: 0; font-size: 28px; font-weight: 900; text-transform: uppercase; letter-spacing: .04em; }
.sent p { margin: 0 0 10px; }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: #111; border-top: 3px solid var(--yellow);
  padding-bottom: var(--safe-b);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 4px 8px; color: #fff; text-decoration: none; font-size: 13px; font-weight: 700; text-align: center; line-height: 1.15; }
.tabbar a.on { color: var(--orange); }

/* scanner */
.scanner { position: fixed; inset: 0; z-index: 20; background: #000; display: flex; flex-direction: column; padding-top: var(--safe-t); }
.scanner[hidden] { display: none; }
.scanner-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; color: #fff; font-weight: 800; }
.scanner-head .spacer { width: 70px; }
.scanner-head #scanStep { flex: 1; text-align: center; }
.scanner-stage { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; }
#scanCanvas { max-width: 100%; max-height: 100%; touch-action: none; }
.scan-busy { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.6); font-weight: 800; font-size: 20px; }
.scan-msg { margin: 6px 14px; text-align: center; font-weight: 700; min-height: 1.4em; }
.scan-msg.warn { color: var(--yellow); }
.scanner-foot { display: grid; grid-auto-flow: column; gap: 10px; padding: 10px 12px calc(12px + var(--safe-b)); }
.scanner-foot[hidden] { display: none; }

.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); background: #fff; color: var(--ink); padding: 10px 16px; border-radius: 12px; font-weight: 700; z-index: 30; max-width: 90vw; text-align: center; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
[hidden] { display: none !important; }
