:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #101417;
  color: #f5f7f8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #101417;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

button,
select,
input {
  font: inherit;
}

.app {
  display: grid;
  gap: 14px;
  min-height: 100vh;
  padding: max(12px, env(safe-area-inset-top)) 12px max(18px, env(safe-area-inset-bottom));
}

.scanner {
  position: relative;
  min-height: 44vh;
  overflow: hidden;
  border: 1px solid #30383d;
  border-radius: 8px;
  background: #080a0b;
}

video {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 44vh;
  object-fit: cover;
}

.search-overlay {
  position: absolute;
  top: 12px;
  left: 50%;
  display: none;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 7px 10px;
  border: 1px solid rgb(125 226 165 / 65%);
  border-radius: 999px;
  background: rgb(16 20 23 / 84%);
  color: #7de2a5;
  font-size: 13px;
  font-weight: 750;
  text-align: center;
  white-space: nowrap;
}

.search-overlay.is-active {
  display: block;
}

.scan-region-overlay {
  position: absolute;
  display: none;
  border: 1px solid #e6ff58;
  border-radius: 0;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 54%), 0 0 10px rgb(230 255 88 / 48%);
  pointer-events: none;
}

.scan-region-overlay.is-active {
  display: block;
}

.status-bar {
  position: absolute;
  right: 10px;
  bottom: 10px;
  left: 10px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 8px;
  background: rgb(16 20 23 / 82%);
  color: #d9e2e6;
  font-size: 14px;
}

.controls,
.latest,
.history {
  border: 1px solid #30383d;
  border-radius: 8px;
  background: #171d20;
}

.controls {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.field {
  display: grid;
  gap: 6px;
  color: #aeb8bd;
  font-size: 13px;
}

select,
button {
  min-height: 44px;
  border: 1px solid #3d484e;
  border-radius: 8px;
  background: #222a2f;
  color: #f5f7f8;
}

select {
  width: 100%;
  padding: 0 12px;
}

input[type="number"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid #3d484e;
  border-radius: 8px;
  padding: 0 12px;
  background: #222a2f;
  color: #f5f7f8;
}

input[type="range"] {
  width: 100%;
  accent-color: #7de2a5;
}

button {
  padding: 0 14px;
  font-weight: 650;
}

button:disabled {
  color: #7f8a90;
  background: #1b2023;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.tuning-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: #d9e2e6;
  font-size: 14px;
}

.toggle-field input {
  width: 20px;
  height: 20px;
  accent-color: #7de2a5;
}

.latest {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 10px;
  padding: 12px;
}

.label {
  display: block;
  color: #aeb8bd;
  font-size: 12px;
  text-transform: uppercase;
}

#latest-code,
#total-count {
  display: block;
  min-width: 0;
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 22px;
}

.history {
  min-height: 160px;
  overflow: hidden;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid #30383d;
}

h1 {
  margin: 0;
  font-size: 16px;
}

#clear-button {
  min-height: 36px;
}

#scan-list {
  display: grid;
  gap: 1px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.scan-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  background: #1b2226;
}

.scan-code {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.scan-meta {
  margin-top: 4px;
  color: #aeb8bd;
  font-size: 12px;
}

.scan-count {
  align-self: center;
  min-width: 46px;
  padding: 5px 9px;
  border-radius: 999px;
  background: #7de2a5;
  color: #102018;
  text-align: center;
  font-weight: 800;
}

@media (min-width: 760px) {
  .app {
    grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
    align-content: start;
    max-width: 1180px;
    margin: 0 auto;
  }

  .scanner {
    grid-row: span 3;
    min-height: calc(100vh - 32px);
  }

  video {
    min-height: calc(100vh - 32px);
  }
}
