:root {
      color-scheme: dark;
      --navy: #111827;
      --card: rgba(30, 39, 59, .96);
      --primary: #870303;
      --secondary: #0247B3;
      --secondary-hover: #013786;
      --secondary-bright: #8bb2ff;
      --secondary-soft: rgba(2, 71, 179, .26);
      --green-bg: rgba(22, 101, 52, .28);
      --red: #ff9898;
      --red-bg: rgba(135, 3, 3, .32);
      --amber-bg: rgba(161, 98, 7, .27);
      --text: #f8fbff;
      --muted: #c0cad9;
      --line: rgba(196, 210, 232, .18);
    }
    * { box-sizing: border-box; }
    body {
      margin: 0; min-height: 100dvh; color: var(--text); background: linear-gradient(135deg, #1c1018, var(--navy) 48%, #101c33);
      font-family: system-ui, -apple-system, sans-serif; display: flex; flex-direction: column;
    }
    button, input { font: inherit; cursor: pointer; }
    button:disabled { cursor: wait; opacity: .6; }
    .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
    
    .app { width: min(100%, 500px); margin: 0 auto; padding: 16px; display: flex; flex-direction: column; flex: 1; }
    header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
    .brand { display: flex; align-items: center; gap: 10px; }
    .mark { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 12px; background: linear-gradient(135deg, var(--primary), var(--secondary)); }
    .brand strong { font-size: 14px; display: block; }
    .brand span, .clock span, .schedule, .hint, footer { color: var(--muted); font-size: 11px; }
    .clock { text-align: right; }
    .clock time { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; display: block; }

    .status-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
    .status-pill {
      display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px;
      border-radius: 999px; font-size: 11px; font-weight: 700; border: 1px solid rgba(251,191,36,.3);
      color: #ffedac; background: var(--amber-bg);
    }
    .status-pill[data-state="ready"] { color: #c5d8ff; background: var(--secondary-soft); border-color: rgba(2,71,179,.58); }
    .status-pill[data-state="error"] { color: #ffd3da; background: var(--red-bg); border-color: rgba(255,152,152,.48); }
    .status-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

    .scanner-card { padding: 10px; border: 1px solid var(--line); border-radius: 20px; background: var(--card); }
    .camera { position: relative; height: 340px; overflow: hidden; border-radius: 14px; background: #02070c; }
    #reader { width: 100%; height: 100%; }
    #reader video { width: 100% !important; height: 100% !important; object-fit: cover !important; }
    #reader img, #reader__dashboard { display: none !important; }

    .overlay { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; pointer-events: none; }
    .target { width: 80%; height: 130px; position: relative; border-radius: 12px; box-shadow: 0 0 0 1000px rgba(2,10,18,.6); }
    .corner { position: absolute; width: 28px; height: 28px; border-color: var(--secondary-bright); border-style: solid; }
    .corner.tl { top: 0; left: 0; border-width: 3px 0 0 3px; }
    .corner.tr { top: 0; right: 0; border-width: 3px 3px 0 0; }
    .corner.bl { bottom: 0; left: 0; border-width: 0 0 3px 3px; }
    .corner.br { right: 0; bottom: 0; border-width: 0 3px 3px 0; }

    .camera-message {
      position: absolute; inset: 0; z-index: 8; display: grid; place-items: center;
      padding: 20px; text-align: center; background: rgba(6,20,33,.92); visibility: hidden; opacity: 0; transition: .2s;
    }
    .camera-message.show { visibility: visible; opacity: 1; }
    .loader { width: 30px; height: 30px; margin: 0 auto 10px; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--secondary-bright); border-radius: 50%; animation: spin .8s linear infinite; }
    @keyframes spin { to { transform: rotate(360deg); } }

    .retry, .manual button {
      margin-top: 12px; padding: 8px 14px; border: 0; border-radius: 10px;
      color: #ffffff; background: var(--secondary); font-weight: 700;
    }
    .retry:hover, .manual button:hover { background: var(--secondary-hover); }
    .hint { margin: 10px 4px; text-align: center; }

    .result { margin-top: 12px; padding: 14px; border-radius: 14px; border: 1px solid; animation: in .2s ease; }
    .result[hidden] { display: none; }
    .result.early { color: #caffdd; background: var(--green-bg); border-color: rgba(74,222,128,.3); }
    .result.late, .result.error { color: #ffd3da; background: var(--red-bg); border-color: rgba(255,152,152,.48); }
    .result.warning { color: #ffedac; background: var(--amber-bg); border-color: rgba(251,191,36,.3); }
    @keyframes in { from { opacity: 0; transform: translateY(6px); } }
    .result-top { display: flex; justify-content: space-between; font-weight: 800; font-size: 12px; }
    .result-name { margin-top: 6px; color: #fff; font-size: 15px; font-weight: 700; }
    .result-room { margin-top: 2px; font-size: 11px; opacity: .85; }

    details { margin-top: 10px; }
    summary { text-align: center; font-size: 11px; cursor: pointer; color: var(--muted); }
    .manual { display: flex; gap: 8px; margin-top: 8px; }
    .manual input {
      flex: 1; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px;
      background: rgba(255,255,255,.05); color: #fff; text-transform: uppercase; outline: none;
    }
    .manual input:focus { border-color: var(--secondary); }
    footer { margin-top: auto; padding-top: 14px; text-align: center; font-size: 9px; }
    [hidden] { display: none !important; }
    .account-actions { display: flex; align-items: center; gap: 10px; font-size: 11px; margin-bottom: 14px; }
    .account-actions span { flex: 1; color: var(--muted); }
    .account-actions a { color: var(--secondary-bright); }
    .account-actions button { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; color: var(--text); background: transparent; }
    .manual input { min-width: 0; cursor: text; }
    .manual button { margin-top: 0; }
    .reading-state { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
    #queueStatus { flex: 1; font-size: 12px; color: var(--muted); }
    #queueStatus[data-waiting="true"] { color: #ffedac; }
    .reading-state button, .serial-controls button, .unconfirmed button {
      border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
      color: var(--text); background: rgba(255,255,255,.07); font-size: 12px;
    }
    .result-sync { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12px; }
    .result-sync:empty { display: none; }
    .input-hint { color: var(--muted); font-size: 12px; line-height: 1.5; }
    .serial-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; font-size: 12px; }
    .serial-controls select { padding: 8px; background: var(--navy); color: var(--text); border: 1px solid var(--line); border-radius: 8px; }
    .unconfirmed { margin-top: 12px; padding: 14px; border: 1px solid var(--red); border-radius: 12px; background: var(--red-bg); font-size: 12px; }
    .unconfirmed p { line-height: 1.5; }
    .unconfirmed-codes { overflow-wrap: anywhere; max-height: 100px; overflow-y: auto; }
    #cameraDetail { display: block; margin-top: 8px; font-size: 12px; }
    button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--secondary-bright); outline-offset: 3px; }
    @media (max-width: 390px) {
      .status-row { align-items: flex-start; flex-direction: column; gap: 10px; }
      .brand strong { font-size: 12px; }
      .clock time { font-size: 16px; }
    }

.local-notice{font-size:13px;padding:12px;border-left:3px solid var(--red);background:rgba(2,71,179,.2);line-height:1.6;} #exportAttendance{margin-bottom:16px;padding:10px;border-radius:8px;}

@media screen and (max-width: 560px) {
  .app { width: 100%; padding: max(10px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom)); }
  header { gap: 8px; }
  .brand { min-width: 0; gap: 8px; }
  .brand > div:last-child { min-width: 0; }
  .brand strong { overflow-wrap: anywhere; }
  .clock { flex: 0 0 auto; }
  .account-actions { flex-wrap: wrap; gap: 8px 14px; }
  .account-actions a, .account-actions button { min-height: 40px; display: inline-flex; align-items: center; }
  .local-notice { overflow-wrap: anywhere; }
  #exportAttendance { width: 100%; min-height: 42px; }
  .camera { height: min(42vh, 340px); height: clamp(210px, 42svh, 340px); }
  .reading-state { align-items: stretch; flex-wrap: wrap; }
  #queueStatus { flex: 1 0 100%; margin: 4px 0; }
  .reading-state button, .manual button, .serial-controls button, .unconfirmed button, .retry { min-height: 42px; }
  .manual input { height: 44px; font-size: 16px; }
  .schedule { line-height: 1.5; }
}

@media screen and (max-height: 560px) and (orientation: landscape) {
  .app { padding-top: 8px; padding-bottom: 8px; }
  .camera { height: min(42vh, 230px); height: clamp(160px, 42svh, 230px); }
  .scanner-card { padding: 8px; }
  .hint { margin: 6px 4px; }
}
