:root {
  --base: #153243;
  --base-2: #1C3D52;
  --panel: #284B63;
  --cell: #3A5E76;
  --accent-2: #B4B8AB;
  --accent: #EEF0EB;
  --accent-dim: #B4B8AB;
  --glow: #F4F9E9;
  --ink: #F4F9E9;
  --muted: #B4B8AB;
  --line: #35576F;
  --radius: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--base);
  background-image: radial-gradient(ellipse 80% 60% at 70% -10%, rgba(180, 184, 171, 0.06), transparent);
  color: var(--ink);
  font-family: 'Space Grotesk', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--line);
}

.mark {
  width: 30px; height: 30px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 3px;
}
.mark span { border-radius: 2px; background: var(--accent-2); }
.mark span:nth-child(2) { background: var(--cell); }
.mark span:nth-child(4) { background: var(--cell); }
.mark span:nth-child(5) { background: var(--glow); }
.mark span:nth-child(6) { background: var(--cell); }
.mark span:nth-child(8) { background: var(--cell); }

header h1 { font-size: 17px; font-weight: 700; letter-spacing: 0.02em; }
header .tag {
  margin-left: auto;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(320px, 480px) minmax(320px, 420px);
  justify-content: center;
  gap: 32px;
  padding: 40px 28px 56px;
  width: 100%;
}

/* ---------- Input panel ---------- */
.panel { display: flex; flex-direction: column; gap: 22px; }

.field label,
.opt-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

textarea {
  width: 100%;
  min-height: 130px;
  resize: vertical;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font-family: 'Space Mono', monospace;
  font-size: 14px;
  line-height: 1.6;
  padding: 14px 16px;
  transition: border-color 0.15s;
}
textarea::placeholder { color: #7E93A4; }
textarea:focus { outline: none; border-color: var(--accent); }
textarea:focus-visible { box-shadow: 0 0 0 3px rgba(238, 240, 235, 0.16); }

.meta-row {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  color: var(--muted);
}
.meta-row .error { color: #E07856; }

/* Error correction segmented control */
.seg {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
}
.seg button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: 'Space Grotesk', sans-serif;
  padding: 10px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: background 0.15s, color 0.15s;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button .lvl { font-size: 15px; font-weight: 700; }
.seg button .pct { font-family: 'Space Mono', monospace; font-size: 10px; }
.seg button:hover { color: var(--ink); }
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.seg button[aria-pressed="true"] {
  background: rgba(238, 240, 235, 0.12);
  color: var(--accent);
}

.hint { font-size: 12px; color: var(--muted); margin-top: 8px; line-height: 1.5; }

.opt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.color-row { display: flex; align-items: center; gap: 10px; }
input[type="color"] {
  width: 40px; height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 4px;
  cursor: pointer;
}
input[type="color"]:focus-visible { outline: 2px solid var(--accent); }
.color-row code {
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  color: var(--muted);
}

select {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  padding: 11px 12px;
  cursor: pointer;
}
select:focus-visible { outline: 2px solid var(--accent); }

/* ---------- Preview panel ---------- */
.preview-panel { display: flex; flex-direction: column; gap: 20px; align-items: center; }

.viewfinder {
  position: relative;
  padding: 26px;
  width: 100%;
  max-width: 380px;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Corner brackets */
.viewfinder::before, .viewfinder::after,
.viewfinder .c3, .viewfinder .c4 {
  content: '';
  position: absolute;
  width: 26px; height: 26px;
  border: 2px solid var(--accent);
}
.viewfinder::before { top: 0; left: 0; border-right: none; border-bottom: none; border-top-left-radius: 6px; }
.viewfinder::after { top: 0; right: 0; border-left: none; border-bottom: none; border-top-right-radius: 6px; }
.viewfinder .c3 { bottom: 0; left: 0; border-right: none; border-top: none; border-bottom-left-radius: 6px; }
.viewfinder .c4 { bottom: 0; right: 0; border-left: none; border-top: none; border-bottom-right-radius: 6px; }

.qr-frame {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--panel);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#qrCanvas {
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  display: none;
}
.qr-frame.has-code #qrCanvas { display: block; }
.qr-frame.has-code .empty { display: none; }

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 0 24px;
  line-height: 1.6;
}
.empty .mono { font-family: 'Space Mono', monospace; font-size: 12px; color: #7E93A4; }

/* Scan line */
.scanline {
  position: absolute;
  left: 6%; right: 6%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--glow), transparent);
  opacity: 0;
  pointer-events: none;
}
.qr-frame.has-code .scanline { opacity: 0.85; animation: scan 3.2s ease-in-out infinite; }
@keyframes scan {
  0%   { top: 8%;  opacity: 0; }
  12%  { opacity: 0.85; }
  50%  { top: 90%; opacity: 0.85; }
  88%  { opacity: 0.85; }
  100% { top: 8%;  opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .scanline { display: none; }
}

.qr-meta {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.05em;
  min-height: 16px;
}

.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px;
  font-weight: 500;
  padding: 11px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.btn:hover { border-color: var(--accent-dim); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--base);
  font-weight: 700;
}
.btn.primary:hover { background: #FFFFFF; }

footer {
  text-align: center;
  padding: 16px;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: #7E93A4;
  border-top: 1px solid var(--line);
}

@media (max-width: 800px) {
  main { grid-template-columns: 1fr; gap: 28px; padding: 28px 20px 40px; }
  .preview-panel { order: -1; }
  .viewfinder { max-width: 300px; }
}
