:root {
  color-scheme: dark light;
  --bg: #0b1020;
  --bg-2: #121a33;
  --card: #151e3a;
  --line: #2a3762;
  --text: #eef2ff;
  --muted: #b4bddc;
  --accent: #6d8dff;
  --accent-2: #a78bfa;
  --accent-ink: #0b1020;
  --ok: #34d399;
  --danger: #fca5a5;
  --radius: 18px;
  --shadow: 0 10px 30px rgb(0 0 0 / 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP',
    'Noto Sans SC', 'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Microsoft YaHei', Meiryo, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7ff;
    --bg-2: #e9edfb;
    --card: #ffffff;
    --line: #d5dcf2;
    --text: #0f172a;
    --muted: #46506b;
    --accent: #3651d8;
    --accent-2: #6d28d9;
    --accent-ink: #ffffff;
    --ok: #047857;
    --danger: #b91c1c;
    --shadow: 0 10px 30px rgb(30 41 82 / 0.12);
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font: 16px/1.6 var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgb(109 141 255 / 0.18), transparent 60%),
    radial-gradient(900px 500px at 110% 0%, rgb(167 139 250 / 0.16), transparent 60%),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--accent);
  text-underline-offset: 3px;
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0 0 0.5em;
}

svg {
  width: 1.4em;
  height: 1.4em;
  flex: none;
}

svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.logo path {
  stroke-width: 4;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
}

.skip:focus {
  top: calc(12px + var(--safe-top));
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: calc(64px + var(--safe-top));
  padding: var(--safe-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  min-height: 44px;
}

.brand .logo {
  width: 34px;
  height: 34px;
}

.topbar-actions {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.lang-menu {
  position: relative;
}

.lang-menu summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 32px 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  list-style: none;
  white-space: nowrap;
}

.lang-menu summary::-webkit-details-marker {
  display: none;
}

.lang-menu summary::after {
  content: '';
  position: absolute;
  right: 14px;
  top: 50%;
  width: 7px;
  height: 7px;
  border: solid var(--muted);
  border-width: 0 2px 2px 0;
  translate: 0 -70%;
  rotate: 45deg;
}

.lang-menu[open] summary::after {
  translate: 0 -30%;
  rotate: 225deg;
}

.lang-menu summary svg {
  width: 1.1em;
  height: 1.1em;
  color: var(--muted);
}

.lang-menu ul {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 180px;
  margin: 0;
  padding: 6px;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.lang-menu a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}

.lang-menu a:hover,
.lang-menu a:focus-visible {
  background: var(--bg-2);
}

.lang-menu a[aria-current='true'] {
  font-weight: 700;
}

.lang-menu a[aria-current='true']::after {
  content: '✓';
  margin-left: auto;
  padding-left: 12px;
  color: var(--accent);
}

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.2s ease, border-color 0.2s ease;
}

.btn:hover {
  border-color: var(--accent);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.btn.primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
}

@media (prefers-color-scheme: dark) {
  .btn.primary {
    background: linear-gradient(135deg, #8aa4ff, #c4b5fd);
  }
}

.btn.ghost {
  background: transparent;
}

.btn.small {
  min-height: 36px;
  padding: 6px 14px;
  font-size: 0.9rem;
}

.btn.big {
  min-height: 56px;
  padding: 14px 30px;
  font-size: 1.1rem;
  box-shadow: 0 12px 30px rgb(109 141 255 / 0.35);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid rgb(255 255 255 / 0.25);
  background: rgb(10 14 30 / 0.55);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.icon-btn[aria-pressed='true'] {
  background: #fde047;
  color: #111;
}

[hidden] {
  display: none !important;
}

/* ------------------------------------------------------------------ scanner */
main {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-left)) 24px max(16px, env(safe-area-inset-right));
}

.intro {
  margin: 4px 0 14px;
}

.intro h1 {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  margin-bottom: 4px;
  background: linear-gradient(120deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin: 0;
  color: var(--muted);
}

.viewer {
  position: relative;
  overflow: hidden;
  height: min(68dvh, 640px);
  min-height: 340px;
  border-radius: 26px;
  background:
    radial-gradient(circle at 50% 40%, #1d2a55, #0a0f22 70%);
  box-shadow: var(--shadow);
  isolation: isolate;
  color: #fff;
}

.viewer:focus {
  outline: none;
}

.viewer video,
.viewer canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.viewer video {
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.live .viewer video {
  opacity: 1;
}

.frame {
  position: absolute;
  inset: 50% auto auto 50%;
  width: min(64%, 300px);
  aspect-ratio: 1;
  translate: -50% -50%;
  pointer-events: none;
}

.frame i {
  position: absolute;
  width: 22%;
  height: 22%;
  border: 0 solid rgb(255 255 255 / 0.9);
  border-radius: 6px;
}

.frame i:nth-child(1) {
  left: 0;
  top: 0;
  border-width: 4px 0 0 4px;
  border-top-left-radius: 18px;
}

.frame i:nth-child(2) {
  right: 0;
  top: 0;
  border-width: 4px 4px 0 0;
  border-top-right-radius: 18px;
}

.frame i:nth-child(3) {
  right: 0;
  bottom: 0;
  border-width: 0 4px 4px 0;
  border-bottom-right-radius: 18px;
}

.frame i:nth-child(4) {
  left: 0;
  bottom: 0;
  border-width: 0 0 4px 4px;
  border-bottom-left-radius: 18px;
}

.frame b {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 50%;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, #8aa4ff, transparent);
  box-shadow: 0 0 12px #8aa4ff;
  opacity: 0;
}

.live .frame b {
  opacity: 1;
  animation: sweep 2.2s ease-in-out infinite;
}

@keyframes sweep {
  0%,
  100% {
    top: 8%;
  }
  50% {
    top: 92%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .live .frame b {
    animation: none;
  }
  * {
    transition: none !important;
  }
}

.idle {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: rgb(5 8 20 / 0.35);
}

.live .idle {
  display: none;
}

.hint {
  margin: 0;
  color: #dbe3ff;
  text-shadow: 0 1px 2px rgb(0 0 0 / 0.6);
}

.status {
  position: absolute;
  top: 14px;
  left: 50%;
  translate: -50% 0;
  max-width: calc(100% - 28px);
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgb(5 8 20 / 0.7);
  color: #fff;
  font-size: 0.9rem;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.status[data-mode='live']::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: #34d399;
  vertical-align: 1px;
}

.status[data-mode='error'] {
  background: rgb(127 29 29 / 0.92);
}

.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 14px calc(14px + var(--safe-bottom));
  background: linear-gradient(transparent, rgb(0 0 0 / 0.45));
}

.zoom {
  display: flex;
  align-items: center;
  flex: 0 1 160px;
}

.zoom input {
  width: 100%;
  min-height: 44px;
  accent-color: #8aa4ff;
}

.dropzone {
  position: absolute;
  inset: 12px;
  display: none;
  place-items: center;
  border: 3px dashed rgb(255 255 255 / 0.8);
  border-radius: 20px;
  background: rgb(0 0 0 / 0.5);
  font-size: 1.2rem;
  font-weight: 700;
}

.viewer.drag .dropzone {
  display: grid;
}

.viewer:fullscreen {
  height: 100dvh;
  border-radius: 0;
}

.options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  margin: 14px 2px 0;
}

.options .btn {
  margin-left: auto;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
}

.switch input {
  appearance: none;
  position: relative;
  width: 46px;
  height: 28px;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.switch input::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.4);
  transition: translate 0.2s ease;
}

.switch input:checked {
  background: var(--accent);
}

.switch input:checked::after {
  translate: 18px 0;
}

/* ------------------------------------------------------------------ cards */
.card {
  content-visibility: auto; /* below the fold: laid out when scrolled near */
  contain-intrinsic-size: auto 480px;
  margin-top: 22px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--card) 92%, transparent);
}

.card h2 {
  font-size: 1.3rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.muted {
  color: var(--muted);
}

.lead {
  color: var(--muted);
  margin-top: 0;
}

.features {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 14px;
  padding: 0;
  margin: 18px 0 0;
  list-style: none;
}

.features li {
  padding: 16px;
  border-radius: 14px;
  background: var(--bg-2);
}

.features h3 {
  font-size: 1.02rem;
}

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

.steps {
  margin: 0;
  padding-left: 1.4em;
}

.steps li + li {
  margin-top: 8px;
}

details {
  border-top: 1px solid var(--line);
}

details:last-of-type {
  border-bottom: 1px solid var(--line);
}

summary {
  padding: 14px 4px;
  font-weight: 600;
  cursor: pointer;
  list-style-position: outside;
}

details p {
  margin: 0 4px 16px;
  color: var(--muted);
}

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

.history-list li + li {
  border-top: 1px solid var(--line);
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  min-height: 48px;
  padding: 10px 4px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.history-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item time {
  flex: none;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ------------------------------------------------------------------ result sheet */
.sheet {
  width: min(640px, 100%);
  max-height: min(86dvh, 760px);
  margin: auto auto 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 24px 24px 0 0;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
}

@media (min-width: 700px) {
  .sheet {
    margin: auto;
    border-radius: 24px;
  }
}

.sheet[open] {
  display: flex;
  flex-direction: column;
  animation: rise 0.22s ease-out;
}

@keyframes rise {
  from {
    translate: 0 30px;
    opacity: 0;
  }
}

.sheet::backdrop {
  background: rgb(3 6 18 / 0.6);
  backdrop-filter: blur(3px);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 4px 22px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 1.2rem;
}

.sheet-head .icon-btn {
  border-color: var(--line);
  background: var(--bg-2);
  color: var(--text);
}

.sheet-body {
  overflow: auto;
  padding: 8px 22px;
}

.sheet-foot {
  display: flex;
  justify-content: flex-end;
  padding: 12px 22px calc(18px + var(--safe-bottom));
}

.result-item + .result-item {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
}

.badge {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.82rem;
  font-weight: 700;
}

@media (prefers-color-scheme: dark) {
  .badge {
    background: #8aa4ff;
  }
}

.badge.subtle {
  background: var(--bg-2);
  color: var(--muted);
}

.payload {
  margin: 0 0 12px;
  padding: 14px;
  max-height: 40dvh;
  overflow: auto;
  border-radius: 12px;
  background: var(--bg-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: all;
}

.host {
  margin: 0 0 12px;
  overflow-wrap: anywhere;
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 0 0 12px;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  z-index: 50;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 14px;
  background: #1e293b;
  color: #fff;
  box-shadow: var(--shadow);
  translate: -50% 40px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, translate 0.2s ease;
  overflow-wrap: anywhere;
}

.toast.show {
  opacity: 1;
  translate: -50% 0;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toast.show.has-action {
  pointer-events: auto;
}

.toast .btn {
  flex: none;
  border-color: rgb(255 255 255 / 0.35);
  background: transparent;
  color: #fff;
}

.warn-text {
  margin: 0 0 12px;
  color: var(--danger);
  font-weight: 600;
}

.badge.warn {
  margin: 0 6px;
  background: #fde68a;
  color: #713f12;
}

/* ------------------------------------------------------------------ footer */
.footer {
  padding: 24px 16px calc(32px + var(--safe-bottom));
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.langs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 6px;
  margin: 8px 0;
  padding: 0;
  list-style: none;
}

.langs a {
  display: inline-block;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
}

.langs a[aria-current='page'] {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.footer a {
  display: inline-block;
  min-height: 44px;
  padding: 10px 6px;
}

.notfound {
  text-align: center;
  padding: 18vh 16px;
}

@media (max-width: 520px) {
  .brand span {
    font-size: 0.98rem;
  }
  .btn#install span {
    display: none;
  }
  .viewer {
    height: 62dvh;
    border-radius: 22px;
  }
  .options .btn {
    margin-left: 0;
  }
}

@media (display-mode: fullscreen), (display-mode: standalone) {
  .viewer {
    height: calc(100dvh - 130px - var(--safe-top));
  }
}
