:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-soft: #fafafa;
  --text: #171717;
  --muted: #6f6f6f;
  --line: #dedede;
  --accent: #e56600;
  --accent-dark: #b94f00;
  --success: #2f7d4f;
  --danger: #b73535;
  --warning: #b87900;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 18px 90px;
}

h1 {
  margin: 0 0 24px;
  font-size: 24px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0 0 16px;
  font-size: 21px;
  font-weight: 500;
}

h3 {
  margin: 18px 0 8px;
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

p {
  color: var(--muted);
  line-height: 1.45;
}

.setup-panel,
#view-results,
#view-map,
#view-settings,
#step-result,
#step-manual {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

label {
  display: block;
  margin: 14px 0 6px;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

input,
select {
  width: 100%;
  padding: 12px 13px;
  font-size: 16px;
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  background: var(--surface);
}

button {
  min-height: 44px;
  padding: 11px 15px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

button:hover:not(:disabled) {
  border-color: #c8c8c8;
}

#btn-continue-setup,
#btn-capture,
#btn-accept-result,
#btn-save-manual,
#btn-login,
#btn-signup {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}

#btn-continue-setup:hover:not(:disabled),
#btn-capture:hover:not(:disabled),
#btn-accept-result:hover:not(:disabled),
#btn-save-manual:hover:not(:disabled),
#btn-login:hover:not(:disabled),
#btn-signup:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.controls {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.controls button {
  flex: 1;
}

#viewport {
  position: relative;
  width: 100%;
  max-width: 430px;
  aspect-ratio: 9 / 16;
  margin: 0 auto;
  background: #111;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid #222;
}

video,
#overlay,
#rdt-overlay-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

video {
  object-fit: cover;
  z-index: 1;
}

#overlay {
  z-index: 2;
  pointer-events: none;
}

#rdt-overlay-img {
  object-fit: fill;
  z-index: 3;
  pointer-events: none;
}

#capture-canvas {
  width: 100%;
  margin-top: 12px;
  background: #111;
  border-radius: 12px;
  border: 1px solid var(--line);
}

#status {
  margin: 14px 2px 0;
  font-size: 13px;
  color: var(--muted);
}

.checkbox-row {
  display: block;
  padding: 9px 0;
  font-size: 16px;
  color: var(--text);
}

.checkbox-row input {
  width: auto;
  margin-right: 8px;
}

.result-card {
  display: flex;
  gap: 12px;
  padding: 12px;
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
}

.result-thumb {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 10px;
  background: #e9e9e9;
  flex-shrink: 0;
}

.result-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.result-title {
  font-size: 16px;
  font-weight: 500;
}

.result-text {
  font-size: 15px;
  font-weight: 500;
}

.result-sub {
  font-size: 13px;
  color: var(--muted);
}

.result-badge.positive,
.result-text.positive {
  color: var(--danger);
}

.result-badge.negative,
.result-text.negative {
  color: var(--success);
}

.result-badge.invalid,
.result-text.invalid {
  color: var(--warning);
}

#result-detail-panel {
  position: fixed;
  inset: 24px;
  bottom: 84px;
  z-index: 2000;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  color: var(--text);
}

.result-detail-img {
  width: 100%;
  max-height: 45vh;
  object-fit: contain;
  background: #f0f0f0;
  border-radius: 12px;
  margin-bottom: 16px;
}

#btn-close-detail {
  width: 100%;
  margin-top: 16px;
}

#auth-panel {
  display: grid;
  gap: 10px;
}

#auth-status {
  margin-top: 0;
}

#tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 64px;
  display: flex;
  align-items: stretch;
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  z-index: 1000;
}

#tabbar button {
  position: relative;

  flex: 1;

  display: flex;
  align-items: center;
  justify-content: center;

  padding-top: 10px;

  border: none;
  border-radius: 0;

  background: transparent;

  color: var(--muted);

  font-size: 13px;
  font-weight: 500;

  transition:
    color 0.2s ease,
    background 0.2s ease;
}

#tabbar button::before {
  content: '';

  position: absolute;

  top: 10px;
  left: 50%;

  transform: translateX(-50%);

  width: 6px;
  height: 6px;

  border-radius: 50%;

  background: transparent;

  transition: background 0.2s ease;
}

#tabbar button:hover {
  color: var(--text);
}

#tabbar button.active,
#tabbar button[aria-current="page"] {
  color: var(--accent);
}

#tabbar button.active::before,
#tabbar button[aria-current="page"]::before {
  background: var(--accent);
}

@media (max-width: 520px) {
  main {
    padding: 18px 14px 86px;
  }

  h1 {
    font-size: 22px;
  }

  .controls {
    flex-direction: column;
  }
}

.setup-actions {
  display: flex;
  justify-content: center;
  margin-top: 26px;
}

.setup-actions button {
  min-width: 240px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;

  gap: 16px;

  margin: 18px 0 8px;

  font-size: 16px;
  color: var(--text);
}

.switch-row input {
  display: none;
}

.switch {
  position: relative;

  width: 48px;
  height: 28px;

  border-radius: 999px;

  background: #d8d8d8;

  flex-shrink: 0;

  transition: background 0.2s ease;
}

.switch::after {
  content: '';

  position: absolute;

  top: 3px;
  left: 3px;

  width: 22px;
  height: 22px;

  border-radius: 50%;

  background: white;

  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);

  transition: transform 0.2s ease;
}

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

.switch-row input:checked + .switch::after {
  transform: translateX(20px);
}

.map-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

#map {
  width: 100%;
  height: 420px;
  border-radius: 14px;
  border: 1px solid var(--line);
  overflow: hidden;
  background: #e8e8e8;
}

#map-status {
  margin-top: 10px;
  font-size: 13px;
}

select,
input,
button {
  accent-color: var(--accent);
}

select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: center;

  gap: 12px;

  margin: 4px 0 28px;
}

.app-logo {
  width: 42px;
  height: 42px;

  object-fit: contain;
}

.app-header h1 {
  margin: 0;

  font-size: 32px;
  font-weight: 600;

  letter-spacing: -0.03em;
}