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

:root {
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #faf9f5;
  --ink: #1a1917;
  --ink-2: #56544e;
  --muted: #9b988f;
  --border: #e4e1d8;
  --border-strong: #d2cec2;
  --accent: #e54b2c;
  --accent-hover: #d03d1e;
  --accent-soft: #fce8e2;
  --success: #2d8659;
  --error: #c43838;
  --shadow-sm: 0 1px 2px rgba(26, 25, 23, 0.04), 0 1px 3px rgba(26, 25, 23, 0.06);
  --shadow-md: 0 4px 12px rgba(26, 25, 23, 0.06), 0 2px 4px rgba(26, 25, 23, 0.04);
  --shadow-lg: 0 12px 32px rgba(26, 25, 23, 0.08), 0 4px 8px rgba(26, 25, 23, 0.04);
  --r: 14px;
  --r-sm: 10px;
  --r-xs: 6px;
  --font-display: "Sora", system-ui, -apple-system, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 3rem 1.25rem 5rem;
  line-height: 1.5;
}

.app {
  width: 100%;
  max-width: 500px;
}

/* ── Header ── */

.app-header {
  margin-bottom: 2rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--ink);
}

.brand-mark {
  color: var(--accent);
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 0.3rem;
  letter-spacing: 0.01em;
}

/* ── Mode Switch ── */

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 4px;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.mode-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.65rem 1rem;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-btn:hover {
  color: var(--ink);
  background: var(--surface-2);
}

.mode-btn.active {
  background: var(--ink);
  color: #fff;
}

/* ── Panels ── */

.panel {
  display: none;
}

.panel.active {
  display: block;
  animation: panelIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Drop Zone ── */

.drop-zone {
  position: relative;
  border: 2px dashed var(--border-strong);
  border-radius: var(--r);
  padding: 2.75rem 1.5rem;
  text-align: center;
  cursor: pointer;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: all 0.25s ease;
  overflow: hidden;
}

.drop-zone:hover,
.drop-zone:focus-visible {
  border-color: var(--ink-2);
  outline: none;
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.01);
}

.drop-zone.scanning {
  border-color: var(--accent);
  border-style: solid;
}

.drop-inner {
  position: relative;
  z-index: 1;
}

.drop-icon {
  color: var(--muted);
  margin-bottom: 0.85rem;
  transition: color 0.2s;
}

.drop-zone:hover .drop-icon {
  color: var(--ink-2);
}

.drop-zone.drag-over .drop-icon {
  color: var(--accent);
}

.drop-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.25rem;
}

.drop-sub {
  font-size: 0.78rem;
  color: var(--muted);
}

.drop-scan {
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent) 30%, var(--accent) 70%, transparent);
  box-shadow: 0 0 12px var(--accent);
  top: 0;
  opacity: 0;
  pointer-events: none;
}

.drop-zone.scanning .drop-scan {
  opacity: 1;
  animation: scanSweep 1.2s ease-in-out infinite;
}

@keyframes scanSweep {
  0%, 100% { top: 0; }
  50% { top: calc(100% - 3px); }
}

/* ── Buttons ── */

.btn-solid {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-solid:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 14px rgba(229, 75, 44, 0.3);
}

.btn-solid:active {
  transform: scale(0.98);
}

.btn-outline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.7rem 1.5rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.btn-outline:hover {
  border-color: var(--ink-2);
  background: var(--surface-2);
}

.btn-ghost {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.2rem;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-ghost:hover {
  color: var(--ink-2);
  background: var(--surface-2);
}

.btn-full {
  width: 100%;
}

.btn-sm {
  padding: 0.45rem 0.9rem;
  font-size: 0.78rem;
}

/* ── Camera ── */

.camera-panel {
  margin-top: 1rem;
  border-radius: var(--r);
  overflow: hidden;
  background: var(--ink);
  box-shadow: var(--shadow-md);
  animation: panelIn 0.3s ease;
}

.camera-frame {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
}

.camera-frame video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-reticle {
  position: absolute;
  inset: 15%;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--r-sm);
  pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.3);
}

.camera-reticle::before,
.camera-reticle::after {
  content: "";
  position: absolute;
  background: var(--accent);
}

.camera-reticle::before {
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  transform: translateY(-50%);
  animation: reticleScan 2s ease-in-out infinite;
}

.camera-reticle::after {
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  opacity: 0.3;
}

@keyframes reticleScan {
  0%, 100% { transform: translateY(-50%) translateX(-40%); opacity: 0; }
  50% { transform: translateY(-50%) translateX(40%); opacity: 1; }
}

.camera-status {
  position: absolute;
  bottom: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.85);
  background: rgba(0, 0, 0, 0.5);
  padding: 0.3rem 0.75rem;
  border-radius: 100px;
  white-space: nowrap;
}

.camera-panel .btn-ghost {
  color: rgba(255, 255, 255, 0.6);
  background: transparent;
}

.camera-panel .btn-ghost:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

/* ── Result Card ── */

.result-card {
  margin-top: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  border-radius: var(--r);
  padding: 1.25rem;
  box-shadow: var(--shadow-md);
  animation: panelIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.result-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.result-tag {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.result-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.result-text {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  padding: 0.85rem;
  background: var(--surface-2);
  border-radius: var(--r-xs);
  border: 1px solid var(--border);
  max-height: 220px;
  overflow-y: auto;
}

.result-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

/* ── Type Switch ── */

.type-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 3px;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.type-btn {
  padding: 0.55rem;
  border: none;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.type-btn:hover {
  color: var(--ink);
}

.type-btn.active {
  background: var(--ink);
  color: #fff;
}

/* ── Form ── */

.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.form-input {
  width: 100%;
  padding: 0.75rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  transition: all 0.2s;
  outline: none;
  box-shadow: var(--shadow-sm);
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-input::placeholder {
  color: var(--muted);
}

textarea.form-input {
  resize: vertical;
  line-height: 1.5;
}

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%239b988f' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  padding-right: 2.5rem;
}

.form-select option {
  background: var(--surface);
  color: var(--ink);
}

/* ── Output ── */

.output-card {
  margin-top: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 1.25rem;
  box-shadow: var(--shadow-md);
  animation: panelIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.output-frame {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.75rem;
  background: #fff;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
  min-height: 160px;
}

.output-frame canvas {
  max-width: 100%;
  height: auto;
}

/* ── Utilities ── */

.hidden {
  display: none !important;
}

/* ── Toast ── */

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  padding: 0.6rem 1.1rem;
  background: var(--ink);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: 100px;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 100;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Responsive ── */

@media (max-width: 520px) {
  body {
    padding: 2rem 1rem 4rem;
  }

  .drop-zone {
    padding: 2rem 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
