@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/ibm-plex-mono-cyrillic-400-normal.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/ibm-plex-mono-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/ibm-plex-mono-cyrillic-600-normal.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/ibm-plex-mono-latin-600-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #0B0A08;
  --panel: #14110C;
  --amber: #FFB000;
  --amber-dim: #8A5F00;
  --amber-glow: rgba(255, 176, 0, .35);
  --denied: #FF4A1C;
  --granted: #FFD36B;

  --gutter-top: env(safe-area-inset-top, 0px);
  --gutter-right: calc(16px + env(safe-area-inset-right, 0px));
  --gutter-bottom: env(safe-area-inset-bottom, 0px);
  --gutter-left: calc(16px + env(safe-area-inset-left, 0px));
  --bevel: 12px;
  --column: 480px;
  --tracking: .08em;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, Consolas, monospace;
}

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

html, body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
}

body {
  color: var(--amber);
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

:focus-visible {
  outline: 2px dashed var(--granted);
  outline-offset: 3px;
}

h1, h2 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: var(--tracking);
  margin: 0 0 16px;
}

p { margin: 0 0 12px; }

/* ---------- Shell ---------- */

.view {
  min-height: 100vh;
  min-height: 100dvh;
}

.shell {
  background: var(--bg);
  color: var(--amber);
  text-shadow: 0 0 6px var(--amber-glow);
}

.view.shell {
  display: flex;
  flex-direction: column;
  padding: var(--gutter-top) var(--gutter-right) var(--gutter-bottom) var(--gutter-left);
}

.view.shell > * {
  width: 100%;
  max-width: var(--column);
  margin-inline: auto;
}

.view.shell::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  background: repeating-linear-gradient(to bottom, rgba(255, 176, 0, .06) 0 1px, transparent 1px 3px);
}

.dim, .decor { color: var(--amber-dim); }
.decor { font-size: 14px; letter-spacing: var(--tracking); }
.denied { color: var(--denied); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  border-bottom: 1px solid var(--amber-dim);
  text-transform: uppercase;
  letter-spacing: var(--tracking);
  font-weight: 600;
}

.subbar {
  padding: 8px 0;
  border-bottom: 1px solid var(--amber-dim);
  font-size: 14px;
  letter-spacing: var(--tracking);
}

.back {
  min-height: 48px;
  padding: 0 12px 0 0;
  background: none;
  border: 0;
  text-transform: uppercase;
  letter-spacing: var(--tracking);
  font-weight: 600;
  text-shadow: inherit;
}

.btn-main {
  display: block;
  width: 100%;
  min-height: 72px;
  padding: 0 16px;
  background: var(--panel);
  border: 2px solid var(--amber);
  font-size: 18px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking);
  text-shadow: 0 0 6px var(--amber-glow);
  clip-path: polygon(var(--bevel) 0, 100% 0, 100% calc(100% - var(--bevel)), calc(100% - var(--bevel)) 100%, 0 100%, 0 var(--bevel));
}

.btn-main:active { background: var(--amber); color: var(--bg); text-shadow: none; }
.btn-main:focus-visible { outline: none; background: #2A2010; }

.btn-link {
  display: block;
  width: 100%;
  min-height: 48px;
  background: none;
  border: 0;
  color: var(--amber-dim);
  font-size: 15px;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-shadow: none;
}

.btn-small {
  flex: 1;
  min-height: 52px;
  background: var(--panel);
  border: 2px solid var(--amber-dim);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: var(--tracking);
}

.btn-small.primary { border-color: var(--amber); }
.btn-small:active { background: var(--amber); color: var(--bg); }
.btn-small:disabled { opacity: .5; }

/* ---------- Boot ---------- */

.boot-log {
  margin: 24px 0 0;
  font-family: inherit;
  font-size: 15px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

body.flicker .view.shell { animation: flicker 600ms linear 1; }

@keyframes flicker {
  0% { opacity: .2; }
  10% { opacity: 1; }
  20% { opacity: .35; }
  30% { opacity: 1; }
  55% { opacity: .7; }
  60%, 100% { opacity: 1; }
}

/* ---------- Gate ---------- */

.gate {
  margin: auto 0;
  padding: 32px 0;
}

.gate-mark {
  font-size: 32px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--denied);
  text-shadow: none;
}

/* ---------- Home ---------- */

.counter {
  padding: 24px 0 20px;
  border-bottom: 1px solid var(--amber-dim);
}

.counter-value {
  font-size: 44px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: var(--tracking);
}

.counter-label {
  margin: 4px 0 14px;
  letter-spacing: var(--tracking);
}

.progress {
  height: 14px;
  border: 1px solid var(--amber-dim);
  padding: 2px;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: repeating-linear-gradient(to right, var(--amber) 0 6px, transparent 6px 8px);
  transition: width .4s ease-out;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 28px 0;
  margin-top: auto;
}

.serial {
  margin-top: auto;
  padding-bottom: 8px;
}

.statusbar {
  border-top: 1px solid var(--amber-dim);
  padding-bottom: 4px;
}

.status {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 0;
  background: none;
  border: 0;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: var(--tracking);
  text-shadow: inherit;
  overflow-wrap: anywhere;
}

.status:disabled { cursor: default; color: var(--amber); }
.status[data-state="syncing"] { color: var(--amber-dim); animation: pulse 1.4s ease-in-out infinite; }
.status[data-state="update"] { color: var(--granted); text-decoration: underline; text-underline-offset: 3px; }
.status[data-state="notcached"] { color: var(--denied); }

@keyframes pulse {
  50% { opacity: .45; }
}

.privacy-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0;
  background: none;
  border: 0;
  color: var(--amber-dim);
  font-size: 14px;
  text-shadow: none;
}

.privacy-link span {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.info-icon { width: 18px; height: 18px; flex: none; }

/* ---------- Privacy ---------- */

.privacy {
  padding: 20px 0 calc(24px + var(--gutter-bottom));
  font-size: 15px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.privacy ul {
  margin: 0;
  padding-left: 1.2em;
}

.privacy li { margin-bottom: 14px; }
.privacy strong { font-weight: 600; color: var(--granted); }

/* ---------- Scanner ---------- */

.view.scanner { height: 100vh; height: 100dvh; }

.scan-area {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 12px 0 0;
  background: #000;
  overflow: hidden;
}

.scan-area {
  display: flex;
  align-items: center;
}

/* The decoder samples the element size, so the video must keep its own aspect ratio. */
.reader { width: 100%; border: 0 !important; }

.reader video {
  width: 100% !important;
  height: auto !important;
  display: block;
}

.reader img, .reader canvas, .reader div { display: none !important; }

.scan-frame {
  position: absolute;
  inset: 14% 10%;
  pointer-events: none;
}

.scan-frame i {
  position: absolute;
  width: 40px;
  height: 40px;
  border: 0 solid var(--amber);
  filter: drop-shadow(0 0 4px var(--amber-glow));
}

.scan-frame i:nth-child(1) { top: 0; left: 0; border-top-width: 4px; border-left-width: 4px; }
.scan-frame i:nth-child(2) { top: 0; right: 0; border-top-width: 4px; border-right-width: 4px; }
.scan-frame i:nth-child(3) { bottom: 0; right: 0; border-bottom-width: 4px; border-right-width: 4px; }
.scan-frame i:nth-child(4) { bottom: 0; left: 0; border-bottom-width: 4px; border-left-width: 4px; }

.scan-hint {
  margin: 0;
  padding: 14px 0;
  text-align: center;
  letter-spacing: var(--tracking);
  font-weight: 600;
}

.scan-error {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
}

.scan-error .denied { font-size: 20px; font-weight: 600; letter-spacing: var(--tracking); }
.scan-error .btn-main { margin-top: 12px; }

/* ---------- Feedback (scanner + manual) ---------- */

.feedback {
  letter-spacing: var(--tracking);
  overflow-wrap: anywhere;
}

.scan-area .feedback {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  text-align: center;
  background: var(--bg);
}

.feedback-title { font-size: 24px; font-weight: 600; }
.feedback-detail { font-size: 16px; }
.feedback[data-state="decrypting"] .feedback-title { color: var(--amber-dim); animation: pulse 1s ease-in-out infinite; }
.feedback[data-state="granted"] { color: var(--granted); }
.feedback[data-state="denied"] { color: var(--denied); }

/* Indeterminate: shown only while the state is "decrypting", so it cannot finish before decryption does. */
.feedback-bar {
  display: none;
  position: relative;
  width: 100%;
  max-width: 240px;
  height: 14px;
  padding: 2px;
  border: 1px solid var(--amber-dim);
  overflow: hidden;
}

.feedback[data-state="decrypting"] .feedback-bar { display: block; }

.feedback-bar span {
  display: block;
  width: 35%;
  height: 100%;
  background: repeating-linear-gradient(to right, var(--amber) 0 6px, transparent 6px 8px);
  animation: feedback-sweep 1.1s linear infinite;
}

@keyframes feedback-sweep {
  from { transform: translateX(-100%); }
  to { transform: translateX(290%); }
}

.feedback.inline { margin: 4px 0 12px; }
.feedback.inline .feedback-bar { margin-top: 8px; }
.feedback.inline .feedback-title { font-size: 18px; }

/* ---------- Files ---------- */

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

.file-row {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 14px 0;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--amber-dim);
  text-align: left;
  text-shadow: inherit;
}

.file-row:active { background: var(--panel); }

.file-title {
  display: block;
  font-size: 17px;
  overflow-wrap: anywhere;
}

.file-time {
  display: block;
  margin-top: 4px;
  font-size: 14px;
  color: var(--amber-dim);
}

.empty {
  padding: 40px 0;
  letter-spacing: var(--tracking);
}

.empty p:first-child { font-weight: 600; font-size: 18px; }

/* ---------- Manual dialog ---------- */

.dialog {
  width: min(calc(100% - 32px), 420px);
  max-width: none;
  margin: auto;
  padding: 20px;
  border: 2px solid var(--amber);
}

.dialog::backdrop { background: rgba(0, 0, 0, .8); }

.dialog input {
  display: block;
  width: 100%;
  height: 56px;
  margin: 0 0 8px;
  padding: 0 12px;
  background: var(--panel);
  border: 2px solid var(--amber-dim);
  border-radius: 0;
  color: var(--amber);
  font-family: var(--mono);
  font-size: 20px;
  caret-color: var(--amber);
}

.dialog input:focus { outline: none; border-color: var(--amber); }
.dialog-actions { display: flex; gap: 12px; margin-top: 8px; }

/* ---------- Document views ---------- */

.doc-view { background: var(--doc-bg, #F4F1EA); }

.doc-topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: var(--gutter-top) var(--gutter-right) 0 var(--gutter-left);
  border-bottom: 2px solid var(--amber);
}

.image-view {
  position: fixed;
  inset: 0;
  background: #000;
}

.image-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

.image-stage img {
  flex: none;
  transform-origin: center center;
  will-change: transform;
  -webkit-user-drag: none;
  user-select: none;
}

.back.floating {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: calc(12px + env(safe-area-inset-left, 0px));
  z-index: 2;
  padding: 0 14px;
  background: rgba(11, 10, 8, .6);
  border: 1px solid var(--amber-dim);
  color: var(--amber);
}

/* ---------- Low screens (small phones, landscape) ---------- */

@media (max-height: 600px) {
  .subbar.decor, .serial { display: none; }
  .counter { padding: 14px 0 12px; }
  .counter-value { font-size: 34px; }
  .counter-label { margin: 2px 0 10px; }
  .actions { padding: 16px 0; }
  .btn-main { min-height: 60px; }
  .scan-area { margin-top: 8px; }
  .scan-hint { padding: 8px 0; }
}

@media (orientation: landscape) and (max-height: 500px) {
  #view-home {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "top top" "counter actions" "status privacy";
    column-gap: 32px;
  }

  #view-home > * { max-width: none; }
  #view-home .topbar { grid-area: top; }
  #view-home .counter { grid-area: counter; align-self: center; border-bottom: 0; }
  #view-home .actions { grid-area: actions; align-self: center; margin: 0; padding: 12px 0; }
  #view-home .statusbar { grid-area: status; }
  #view-home .privacy-link { grid-area: privacy; justify-content: flex-end; border-top: 1px solid var(--amber-dim); }
}

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }

  .feedback-bar span { width: 100%; opacity: .6; }
}
