:root {
  color-scheme: light;
  --navy: #123b67;
  --navy-dark: #0b2949;
  --blue: #1c69b7;
  --blue-soft: #eaf3fc;
  --ink: #17273a;
  --muted: #62748a;
  --line: #dce5ee;
  --surface: #f4f7fa;
  --card: #ffffff;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --success: #178250;
  --shadow: 0 16px 45px rgba(22, 48, 76, 0.09);
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(65, 140, 212, 0.12), transparent 30rem),
    var(--surface);
}

button,
input {
  font: inherit;
}

button,
label[for] {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
label[for]:focus-visible {
  outline: 3px solid rgba(28, 105, 183, 0.3);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 12px max(20px, env(safe-area-inset-left)) 12px max(20px, env(safe-area-inset-right));
  color: white;
  background: rgba(12, 43, 75, 0.96);
  backdrop-filter: blur(14px);
  box-shadow: 0 8px 24px rgba(8, 29, 51, 0.18);
}

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

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 12px;
  color: #d9ecff;
  background: rgba(255, 255, 255, 0.08);
  font-weight: 800;
  letter-spacing: 0.08em;
}

.brand h1 {
  margin: 0;
  font-size: clamp(16px, 2vw, 20px);
}

.brand p {
  margin: 3px 0 0;
  color: #bbd0e5;
  font-size: 12px;
}

.language-button {
  min-width: 48px;
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  color: white;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  font-weight: 800;
}

.page-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 28px auto 60px;
}

.hero-card,
.card {
  border: 1px solid rgba(203, 216, 229, 0.9);
  border-radius: 22px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.hero-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  padding: clamp(24px, 4vw, 42px);
  overflow: hidden;
  background:
    linear-gradient(130deg, rgba(255, 255, 255, 0.98), rgba(242, 248, 254, 0.97)),
    var(--card);
}

.hero-card h2 {
  max-width: 700px;
  margin: 10px 0 8px;
  color: var(--navy-dark);
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.12;
  letter-spacing: -0.035em;
}

.hero-card p {
  max-width: 650px;
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.eyebrow,
.step-label {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.hero-actions {
  display: flex;
  min-width: 260px;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 750;
  text-align: center;
  text-decoration: none;
  transition: transform 150ms ease, box-shadow 150ms ease, opacity 150ms ease;
}

.button:not(:disabled):active,
.icon-button:not(:disabled):active {
  transform: translateY(1px);
}

.button-primary {
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--navy));
  box-shadow: 0 8px 18px rgba(28, 105, 183, 0.24);
}

.button-secondary {
  border-color: #b8cce0;
  color: var(--navy);
  background: #f8fbfe;
}

.button-danger {
  width: 100%;
  margin-top: 18px;
  color: white;
  background: linear-gradient(135deg, #c7352b, var(--danger));
}

.button-ghost {
  border-color: var(--line);
  color: var(--ink);
  background: white;
}

button:disabled,
.button:has(+ input:disabled) {
  cursor: not-allowed;
  opacity: 0.45;
  box-shadow: none;
}

.file-status {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  min-height: 42px;
  padding: 10px 14px;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.65);
  font-size: 14px;
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #98a7b7;
}

.file-status.loaded .status-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(23, 130, 80, 0.12);
}

.content-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.card {
  padding: clamp(20px, 3vw, 30px);
}

.settings-card,
.log-card {
  grid-column: 1 / -1;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.section-heading h2,
.dialog-heading h2,
.scanner-header h2 {
  margin: 4px 0 0;
  color: var(--navy-dark);
  font-size: 22px;
}

.section-help {
  margin: 10px 0 18px;
  color: var(--muted);
  line-height: 1.55;
}

.field {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 7px;
  color: #344860;
  font-size: 13px;
  font-weight: 700;
}

.field input {
  width: 100%;
  min-height: 46px;
  padding: 0 13px;
  border: 1px solid #c8d5e2;
  border-radius: 10px;
  color: var(--ink);
  background: #fbfdff;
}

.input-with-action {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.input-with-action input {
  min-width: 0;
  flex: 1;
}

.input-action-button {
  display: inline-flex;
  min-width: 112px;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  gap: 7px;
  border: 1px solid #b8cce0;
  border-radius: 10px;
  color: var(--navy);
  background: var(--blue-soft);
  cursor: pointer;
  font-weight: 750;
}

.field-help {
  color: var(--muted);
  font-weight: 400;
  line-height: 1.5;
}

.field-row {
  display: flex;
  gap: 14px;
  margin-top: 18px;
}

.check-row {
  display: flex;
  align-items: center;
  margin-top: 18px;
  padding: 14px;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  background: #f9fbfd;
}

.check-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--blue);
}

.check-row span {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.check-row small {
  color: var(--muted);
  font-weight: 400;
}

.state-pill {
  padding: 7px 10px;
  border-radius: 999px;
  color: var(--muted);
  background: #eef2f6;
  font-size: 12px;
  font-weight: 750;
}

.state-pill.ready {
  color: #0c6b42;
  background: #e7f6ee;
}

.scan-steps {
  position: relative;
}

.scan-step {
  display: flex;
  align-items: center;
  padding: 14px;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdff;
}

.step-number {
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--navy);
  font-weight: 800;
}

.step-content {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 4px;
}

.code-value {
  overflow: hidden;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  padding: 0 12px;
  gap: 6px;
  border: 1px solid #bbcee0;
  border-radius: 10px;
  color: var(--navy);
  background: white;
  cursor: pointer;
  font-weight: 750;
}

.text-button {
  display: block;
  margin: 7px auto 0;
  padding: 7px 10px;
  border: 0;
  color: var(--blue);
  background: transparent;
  cursor: pointer;
  font-weight: 700;
}

.text-button.compact {
  margin: 0;
}

.connector {
  width: 2px;
  height: 14px;
  margin: 0 0 0 29px;
  background: #c9d6e3;
}

.danger-card {
  border-color: #efd1cf;
  background: linear-gradient(180deg, #fff, #fffbfb);
}

.danger-text {
  color: var(--danger);
}

.live-log {
  max-height: 320px;
  margin-top: 18px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fafc;
}

.log-entry {
  display: grid;
  grid-template-columns: 76px 1fr;
  padding: 14px;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.log-entry:last-child {
  border-bottom: 0;
}

.log-entry time {
  padding-top: 2px;
  color: #728399;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
}

.log-entry p {
  margin: 0 0 4px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.log-entry p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

dialog {
  width: min(94vw, 620px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  color: var(--ink);
  background: white;
  box-shadow: 0 30px 90px rgba(7, 25, 43, 0.36);
}

dialog::backdrop {
  background: rgba(5, 20, 35, 0.78);
  backdrop-filter: blur(4px);
}

.scanner-dialog {
  overflow: hidden;
}

.scanner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 16px;
}

.close-button {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: #f0f4f7;
  cursor: pointer;
  font-size: 26px;
}

.camera-stage {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #081523;
}

.camera-stage video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-frame {
  position: absolute;
  inset: 50% auto auto 50%;
  width: min(62%, 310px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
}

.scan-frame i {
  position: absolute;
  width: 34px;
  height: 34px;
  border-color: #71d6ff;
  border-style: solid;
}

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

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

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

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

.scan-line {
  position: absolute;
  top: 8%;
  right: 5%;
  left: 5%;
  height: 2px;
  background: #78ddff;
  box-shadow: 0 0 12px #78ddff;
  animation: scan 2.1s ease-in-out infinite;
}

@keyframes scan {
  0%, 100% { top: 8%; opacity: 0.55; }
  50% { top: 90%; opacity: 1; }
}

.camera-status {
  margin: 16px 22px 0;
  color: var(--muted);
  line-height: 1.5;
  text-align: center;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  padding: 18px 22px 22px;
  gap: 10px;
}

.input-dialog form {
  padding: 24px;
}

.input-dialog .field {
  margin-top: 20px;
}

.input-dialog .dialog-actions {
  padding: 22px 0 0;
}

.toast {
  position: fixed;
  z-index: 100;
  right: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  max-width: min(420px, calc(100vw - 40px));
  padding: 13px 16px;
  border-radius: 12px;
  color: white;
  background: #102f50;
  box-shadow: 0 12px 30px rgba(6, 25, 44, 0.28);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 760px) {
  .topbar {
    min-height: 64px;
  }

  .brand p {
    display: none;
  }

  .page-shell {
    width: min(100% - 22px, 680px);
    margin-top: 14px;
  }

  .hero-card {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .hero-actions {
    min-width: 0;
  }

  .content-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .settings-card,
  .log-card {
    grid-column: auto;
  }

  .field-row {
    flex-direction: column;
  }

  .input-with-action {
    flex-direction: column;
  }

  .input-action-button {
    min-height: 46px;
    width: 100%;
  }

  .scan-step {
    align-items: flex-start;
  }

  .icon-button {
    flex-direction: column;
    min-width: 64px;
    padding: 7px;
    font-size: 12px;
  }

  .log-entry {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .dialog-actions {
    flex-direction: column-reverse;
  }

  .dialog-actions .button {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
