:root {
  color-scheme: dark;
  --bg: #101820;
  --panel: #f7f8f4;
  --panel-strong: #ffffff;
  --ink: #182027;
  --muted: #66717d;
  --line: #d8ded6;
  --accent: #1f9d8a;
  --accent-dark: #0d6f61;
  --warn: #d8842f;
  --danger: #c94a4a;
  --camera-ui: rgba(12, 18, 24, 0.72);
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.24);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.54;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 460px);
  background: #101820;
}

.camera-pane {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  background: #05080b;
}

.camera-feed,
.snapshot-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.snapshot-canvas {
  display: none;
}

.scan-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  background:
    linear-gradient(rgba(5, 8, 11, 0.34), rgba(5, 8, 11, 0.34)),
    radial-gradient(circle at center, transparent 0 32%, rgba(5, 8, 11, 0.18) 55%, rgba(5, 8, 11, 0.64) 100%);
}

.scan-frame {
  position: relative;
  width: min(74vw, 620px);
  aspect-ratio: 2.65 / 1;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.02);
  box-shadow: inset 0 0 0 9999px rgba(255, 255, 255, 0.015);
}

.corner {
  position: absolute;
  width: 34px;
  height: 34px;
  border-color: #f5f7ee;
}

.corner-tl {
  left: -1px;
  top: -1px;
  border-left: 3px solid;
  border-top: 3px solid;
}

.corner-tr {
  right: -1px;
  top: -1px;
  border-right: 3px solid;
  border-top: 3px solid;
}

.corner-bl {
  left: -1px;
  bottom: -1px;
  border-left: 3px solid;
  border-bottom: 3px solid;
}

.corner-br {
  right: -1px;
  bottom: -1px;
  border-right: 3px solid;
  border-bottom: 3px solid;
}

.scan-line {
  position: absolute;
  left: 5%;
  right: 5%;
  top: 50%;
  height: 2px;
  background: #45e0cc;
  box-shadow: 0 0 18px rgba(69, 224, 204, 0.85);
  animation: scan 2.2s ease-in-out infinite;
}

@keyframes scan {
  0%,
  100% {
    transform: translateY(-42px);
    opacity: 0.4;
  }

  50% {
    transform: translateY(42px);
    opacity: 1;
  }
}

.top-bar,
.camera-actions,
.upload-fallback {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  z-index: 2;
}

.top-bar {
  top: max(16px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand,
.state-badge,
.camera-actions,
.upload-fallback {
  color: #fff;
  background: var(--camera-ui);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(14px);
}

.brand {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 750;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: #f0c248;
  color: #101820;
  font-size: 0.78rem;
}

.state-badge {
  min-width: 118px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 8px;
  color: #dce5e0;
  font-size: 0.88rem;
  text-align: center;
}

.state-badge.is-active {
  color: #d7fff8;
  border-color: rgba(69, 224, 204, 0.5);
}

.state-badge.is-error {
  color: #ffe7e7;
  border-color: rgba(201, 74, 74, 0.7);
}

.camera-actions {
  bottom: max(72px, calc(env(safe-area-inset-bottom) + 72px));
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border-radius: 10px;
}

.icon-button,
.square-button,
.text-button,
.print-button,
.upload-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border-radius: 8px;
}

.icon-button {
  color: #eef8f5;
  background: rgba(255, 255, 255, 0.08);
  padding: 8px 10px;
  font-weight: 700;
}

.icon-button.primary {
  color: #08201b;
  background: #45e0cc;
}

.icon-button.is-on {
  color: #101820;
  background: #f0c248;
}

.upload-fallback {
  bottom: max(16px, env(safe-area-inset-bottom));
  padding: 10px 12px;
  font-weight: 700;
}

.upload-fallback input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.control-pane {
  min-height: 100vh;
  overflow-y: auto;
  padding: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: 1.85rem;
  line-height: 1.08;
  letter-spacing: 0;
}

.notice {
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 12px 14px;
  margin-bottom: 18px;
  border: 1px solid #cfdbd4;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: #eef5f1;
  color: #30423d;
  font-size: 0.95rem;
  line-height: 1.35;
}

.notice.is-error {
  border-left-color: var(--danger);
  background: #fff0f0;
  color: #6e2626;
}

.notice.is-warn {
  border-left-color: var(--warn);
  background: #fff6eb;
  color: #604018;
}

.field-group {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.field-group label,
.select-label span,
.section-title {
  color: #39464f;
  font-size: 0.84rem;
  font-weight: 800;
}

.code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 8px;
}

input,
textarea,
select {
  width: 100%;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 157, 138, 0.16);
}

#selectedCode {
  height: 52px;
  padding: 0 14px;
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

#selectedCode::placeholder {
  color: #7c8589;
  opacity: 0.72;
}

.square-button {
  width: 48px;
  color: var(--ink);
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.toolbar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.toggle {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #39464f;
  font-size: 0.92rem;
  font-weight: 700;
}

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

.select-label {
  display: grid;
  gap: 5px;
}

select {
  height: 40px;
  padding: 0 8px;
  font-weight: 700;
}

.results-block,
.raw-block,
.print-block {
  margin-top: 16px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.text-button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--accent-dark);
  background: transparent;
  font-size: 0.86rem;
  font-weight: 800;
}

.candidate-list {
  display: grid;
  gap: 8px;
}

.empty-state,
.candidate-button {
  min-height: 46px;
  border-radius: 8px;
}

.empty-state {
  display: flex;
  align-items: center;
  padding: 12px;
  color: var(--muted);
  border: 1px dashed #cbd4cf;
  background: #fbfcfa;
}

.candidate-button {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 11px 12px;
  color: var(--ink);
  border: 1px solid var(--line);
  background: var(--panel-strong);
  text-align: left;
}

.candidate-button.is-selected {
  border-color: var(--accent);
  background: #eaf7f4;
}

.candidate-text {
  overflow-wrap: anywhere;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0;
}

.candidate-score {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.raw-block {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.raw-block summary {
  cursor: pointer;
  color: #39464f;
  font-size: 0.9rem;
  font-weight: 800;
}

textarea {
  min-height: 114px;
  margin-top: 10px;
  padding: 10px;
  resize: vertical;
  line-height: 1.4;
}

.print-block {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.print-button {
  width: 100%;
  min-height: 52px;
  color: #071916;
  background: var(--accent);
  font-weight: 850;
}

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

.print-status {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

@media (max-width: 860px) {
  .app-shell {
    min-height: 100svh;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(52svh, 1fr) auto;
  }

  .camera-pane {
    min-height: 52svh;
  }

  .control-pane {
    min-height: auto;
    max-height: none;
    padding: 18px 16px 22px;
    border-radius: 16px 16px 0 0;
    margin-top: -14px;
    z-index: 4;
  }

  .scan-frame {
    width: min(86vw, 620px);
  }

  .camera-actions {
    bottom: 72px;
  }

  .toolbar-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .brand span:last-child,
  .icon-button span,
  .upload-fallback span {
    display: none;
  }

  .brand {
    min-width: 46px;
    justify-content: center;
  }

  .camera-actions {
    grid-template-columns: repeat(3, 1fr);
  }

  .icon-button {
    min-width: 0;
  }

  h1 {
    font-size: 1.45rem;
  }
}
