:root {
  color-scheme: light dark;
  --bg: #f7f4ec;
  --panel: #fffaf1;
  --ink: #1d1b17;
  --muted: #6c6458;
  --line: #d9cdb9;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #ad2f2f;
  --ok: #1f7a42;
  --shadow: 0 18px 50px rgba(69, 48, 22, 0.14);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181512;
    --panel: #221e19;
    --ink: #f3eadb;
    --muted: #b8ac9b;
    --line: #443b30;
    --accent: #4fd1c5;
    --accent-strong: #7ddbd3;
    --danger: #ff8b8b;
    --ok: #81d39d;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.26);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(15, 118, 110, 0.12), transparent 34rem),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a {
  color: var(--accent-strong);
}

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

button,
select,
input[type="file"],
input[type="number"] {
  min-height: 42px;
}

button,
select,
input[type="number"],
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 88%, white);
  color: var(--ink);
}

button {
  padding: 0.62rem 0.9rem;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

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

button.primary,
.download-link {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

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

.hero {
  padding: 20px 0 18px;
}

.home-link {
  display: inline-flex;
  margin-bottom: 22px;
  color: var(--muted);
  text-decoration: none;
}

.hero__title {
  display: flex;
  align-items: center;
  gap: 18px;
}

.mark {
  display: grid;
  width: 64px;
  height: 64px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--accent-strong);
  font-weight: 800;
  box-shadow: var(--shadow);
}

h1 {
  margin: 0;
  font-size: clamp(2.2rem, 8vw, 5.4rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.hero p {
  max-width: 760px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.source-note {
  font-size: 0.95rem;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
  border-bottom: 1px solid var(--line);
}

.tab {
  min-width: 108px;
  margin-bottom: -1px;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  background: transparent;
}

.tab.is-active {
  border-color: var(--line);
  border-bottom-color: var(--panel);
  background: var(--panel);
  color: var(--accent-strong);
  font-weight: 700;
}

.panel {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel[hidden] {
  display: none;
}

.panel-grid,
.camera-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(320px, 1.08fr);
  gap: 22px;
  align-items: start;
}

.control-stack {
  display: grid;
  gap: 12px;
}

label {
  color: var(--muted);
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 220px;
  padding: 14px;
  resize: vertical;
}

select,
input[type="number"] {
  padding: 0.45rem 0.65rem;
}

.inline-controls,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.number-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 12px;
}

.number-grid label {
  display: grid;
  gap: 6px;
}

.qr-stage,
.camera-stage {
  position: relative;
  display: grid;
  min-height: 420px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.qr-stage canvas {
  width: min(100%, 540px);
  height: auto;
  image-rendering: pixelated;
}

.qr-stage--file {
  min-height: 480px;
}

.placeholder,
.camera-placeholder {
  padding: 20px;
  color: var(--muted);
  text-align: center;
}

.camera-stage {
  background: #090806;
}

video {
  display: none;
  width: 100%;
  height: 100%;
  min-height: 420px;
  object-fit: cover;
}

.camera-stage.is-running video {
  display: block;
}

.camera-stage.is-running .camera-placeholder {
  display: none;
}

.result-box,
.receive-card {
  display: grid;
  gap: 12px;
}

.result-box textarea {
  min-height: 310px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.status {
  min-height: 1.5rem;
  margin: 0;
  color: var(--muted);
}

.status.is-error {
  color: var(--danger);
}

.status.is-ok {
  color: var(--ok);
}

.frame-meter {
  margin-top: 10px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92rem;
  text-align: center;
}

progress {
  width: 100%;
  height: 16px;
  accent-color: var(--accent);
}

.chunk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(26px, 1fr));
  gap: 4px;
  max-height: 180px;
  overflow: auto;
}

.chunk-grid span {
  padding: 3px 2px;
  border-radius: 5px;
  background: color-mix(in srgb, var(--muted) 14%, transparent);
  color: var(--muted);
  font-size: 0.7rem;
  text-align: center;
}

.chunk-grid .is-received {
  background: color-mix(in srgb, var(--ok) 60%, transparent);
  color: #fff;
}

.download-area {
  display: grid;
  gap: 10px;
}

.download-link {
  display: inline-flex;
  justify-content: center;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  text-decoration: none;
}

.notes {
  margin-top: 18px;
  color: var(--muted);
}

@media (max-width: 820px) {
  .shell {
    width: min(100% - 24px, 680px);
    padding-top: 18px;
  }

  .hero__title,
  .panel-grid,
  .camera-layout {
    grid-template-columns: 1fr;
  }

  .hero__title {
    display: grid;
  }

  .panel {
    padding: 16px;
  }

  .qr-stage,
  .camera-stage,
  video {
    min-height: 330px;
  }

  .number-grid {
    grid-template-columns: 1fr;
  }
}
