:root {
  --primary: #0a3a2a;
  --primary-2: #16704f;
  --primary-3: #1f8a64;
  --primary-soft: #e6f1eb;
  --primary-softer: #f1f7f3;
  --accent: #c8102e;
  --accent-soft: #fce8ec;

  --bg: #f7f6f1;
  --surface: #ffffff;
  --surface-2: #fbfaf6;
  --surface-elevated: #ffffff;

  --border: #ebe8e0;
  --border-strong: #d9d6cd;
  --border-input: #e2dfd5;

  --text: #1a1f1c;
  --text-muted: #5a6660;
  --text-subtle: #8a948f;

  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --warning: #d97706;
  --success: #059669;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-2xl: 24px;
  --r-full: 999px;

  --shadow-xs: 0 1px 2px rgba(15, 31, 23, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 31, 23, 0.06), 0 1px 2px rgba(15, 31, 23, 0.04);
  --shadow-md: 0 4px 6px rgba(15, 31, 23, 0.05), 0 10px 24px rgba(15, 31, 23, 0.06);
  --shadow-lg: 0 12px 24px rgba(15, 31, 23, 0.08), 0 24px 48px rgba(15, 31, 23, 0.1);
  --shadow-glow: 0 0 0 1px rgba(10, 58, 42, 0.06), 0 8px 24px rgba(10, 58, 42, 0.12);

  --font-display: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: "Inter", "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition: 220ms cubic-bezier(0.4, 0, 0.2, 1);
  --spring: 380ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

*:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
  position: relative;
  overflow-x: hidden;
}

/* ========== Decorative background ========== */
.bg-decoration {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.bg-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.55;
  will-change: transform;
}

.bg-blob-1 {
  width: 420px;
  height: 420px;
  top: -120px;
  right: -120px;
  background: radial-gradient(circle, #b9dcc9 0%, transparent 70%);
}

.bg-blob-2 {
  width: 380px;
  height: 380px;
  bottom: 10%;
  left: -180px;
  background: radial-gradient(circle, #ead7c1 0%, transparent 70%);
}

/* ========== App container ========== */
.app {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.form-stack,
.result-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-stack { min-width: 0; }

/* ========== Hero ========== */
.hero {
  padding: calc(env(safe-area-inset-top, 0px) + 20px) 20px 8px;
  position: relative;
}

.hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 28px;
}

.badge-flag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  box-shadow: var(--shadow-xs);
}

.badge-flag-text {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.flag-stripe {
  display: inline-block;
  width: 14px;
  height: 9px;
  border-radius: 2px;
}

.flag-stripe.red {
  background: var(--accent);
  margin-right: -8px;
}

.flag-stripe.white {
  background: #fff;
  border: 1px solid var(--border);
}

@media (max-width: 380px) {
  .badge-flag-text { display: none; }
  .badge-flag { padding: 5px 6px; }
}

/* Hero brand */
.hero-brand {
  text-align: center;
  margin-bottom: 28px;
}

.hero-logo {
  width: 88px;
  height: 88px;
  margin: 0 auto 18px;
  background: var(--surface);
  border-radius: 24px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.6) inset,
    0 12px 28px rgba(10, 58, 42, 0.18),
    0 4px 10px rgba(10, 58, 42, 0.08);
  border: 1px solid var(--border);
  position: relative;
  animation: heroLogoIn 600ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.hero-logo::before {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 28px;
  background: radial-gradient(circle at 30% 20%, rgba(31, 138, 100, 0.25), transparent 60%);
  z-index: -1;
}

.hero-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

@keyframes heroLogoIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.hero-title {
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.1;
  margin: 0 0 6px;
  color: var(--text);
}

.hero-subtitle {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: -0.01em;
}

/* ========== Main content ========== */
.main {
  flex: 1;
  padding: 20px 20px calc(env(safe-area-inset-bottom, 0px) + 20px);
  display: flex;
  flex-direction: column;
}

.generator-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: panelIn 280ms ease;
}

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

/* ========== QR Showcase ========== */
.qr-showcase {
  background: linear-gradient(160deg, #ffffff 0%, #f1f7f3 100%);
  border: 1px solid var(--border);
  border-radius: var(--r-2xl);
  padding: 32px 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.qr-showcase::before {
  content: "";
  position: absolute;
  top: -40%;
  left: -40%;
  width: 180%;
  height: 180%;
  background:
    radial-gradient(circle at 20% 30%, rgba(31, 138, 100, 0.06) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(200, 16, 46, 0.04) 0%, transparent 40%);
  pointer-events: none;
}

.qr-frame {
  position: relative;
  background: #ffffff;
  padding: 18px;
  border-radius: var(--r-xl);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.8) inset,
    0 12px 32px rgba(10, 58, 42, 0.14),
    0 4px 12px rgba(10, 58, 42, 0.06);
  z-index: 1;
}

#qrCanvas {
  display: block;
  width: min(64vw, 260px);
  height: min(64vw, 260px);
  border-radius: 4px;
  transition: opacity var(--transition);
}

/* Decorative corners around QR frame */
.qr-corner {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2.5px solid var(--primary);
  z-index: 2;
}
.qr-corner.tl { top: 6px; left: 6px; border-right: none; border-bottom: none; border-radius: 4px 0 0 0; }
.qr-corner.tr { top: 6px; right: 6px; border-left: none; border-bottom: none; border-radius: 0 4px 0 0; }
.qr-corner.bl { bottom: 6px; left: 6px; border-right: none; border-top: none; border-radius: 0 0 0 4px; }
.qr-corner.br { bottom: 6px; right: 6px; border-left: none; border-top: none; border-radius: 0 0 4px 0; }

.qr-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  z-index: 1;
}

.qr-meta-pill {
  padding: 4px 10px;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: var(--r-full);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.005em;
  padding: 13px 18px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  width: 100%;
}

.btn:active { transform: scale(0.97); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn svg { flex-shrink: 0; }

.btn-primary {
  background: linear-gradient(180deg, var(--primary-2) 0%, var(--primary) 100%);
  color: #fff;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.15) inset,
    0 0 0 1px rgba(10, 58, 42, 0.5),
    0 6px 14px rgba(10, 58, 42, 0.28),
    0 2px 4px rgba(10, 58, 42, 0.18);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

/* ========== Cards ========== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2xl);
  padding: 20px;
  box-shadow: var(--shadow-xs);
  position: relative;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.card-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid #d8e8df;
}

.card-title {
  font-family: var(--font-display);
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text);
  line-height: 1.2;
}

.card-subtitle {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* ========== Form ========== */
.field {
  display: flex;
  flex-direction: column;
}

.field label {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 7px;
  letter-spacing: 0.01em;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

textarea,
input[type="text"],
input[type="number"] {
  width: 100%;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--text);
  background: var(--surface-2);
  border: 1.5px solid var(--border-input);
  border-radius: var(--r-md);
  padding: 12px 14px;
  transition: all var(--transition-fast);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

textarea {
  resize: vertical;
  min-height: 78px;
  line-height: 1.45;
  font-family: var(--font-mono);
  font-size: 14px;
}

textarea::placeholder,
input::placeholder {
  color: var(--text-subtle);
}

textarea:focus,
input[type="text"]:focus,
input[type="number"]:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 4px rgba(10, 58, 42, 0.08);
}

/* Color input */
.color-input {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-2);
  border: 1.5px solid var(--border-input);
  border-radius: var(--r-md);
  padding: 7px 14px 7px 7px;
  height: 52px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.color-input:hover {
  border-color: var(--border-strong);
}

.color-input input[type="color"] {
  width: 38px;
  height: 38px;
  border: none;
  background: none;
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
  flex-shrink: 0;
}

.color-input input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-input input[type="color"]::-webkit-color-swatch {
  border: 1px solid var(--border);
  border-radius: 8px;
}

.color-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.color-info span:first-child {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.color-label {
  font-size: 0.7rem;
  color: var(--text-subtle);
  font-weight: 500;
  letter-spacing: 0.01em;
}

/* Preset row */
.preset-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.preset {
  display: inline-flex;
  background: var(--surface-2);
  border: 1.5px solid var(--border-input);
  border-radius: var(--r-md);
  padding: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
  height: 36px;
  width: 56px;
  position: relative;
  overflow: hidden;
}

.preset:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.preset:active { transform: scale(0.95); }

.preset span {
  flex: 1;
  border-radius: 5px;
  margin: 1px;
  border: 1px solid rgba(0, 0, 0, 0.06);
}

/* ========== Footer ========== */
.footer {
  padding: 24px 20px calc(env(safe-area-inset-bottom, 0px) + 24px);
  text-align: center;
}

.footer-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-strong), transparent);
  margin-bottom: 14px;
}

.footer p {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-subtle);
  letter-spacing: 0.01em;
}

/* ========== Toast ========== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 28px);
  transform: translateX(-50%) translateY(20px);
  background: rgba(15, 23, 18, 0.94);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--r-full);
  font-family: var(--font-display);
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.06);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
  z-index: 50;
  max-width: 90%;
  text-align: center;
  letter-spacing: -0.005em;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

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

/* ========== Tablet (≥ 720px): wider single column ========== */
@media (min-width: 720px) {
  .app {
    max-width: 720px;
  }

  .hero {
    padding-top: calc(env(safe-area-inset-top, 0px) + 36px);
    padding-bottom: 16px;
  }

  .hero-logo {
    width: 96px;
    height: 96px;
  }

  .hero-title {
    font-size: 2rem;
  }

  .hero-subtitle {
    font-size: 1rem;
  }

  .main {
    padding: 28px 24px;
  }

  #qrCanvas {
    width: 280px;
    height: 280px;
  }
}

/* ========== Desktop (≥ 1024px): two-column dashboard layout ========== */
@media (min-width: 1024px) {
  body {
    padding: 0;
  }

  .app {
    max-width: 1120px;
    padding: 0 32px;
  }

  .hero {
    padding: 48px 0 16px;
  }

  .hero-top {
    margin-bottom: 36px;
  }

  .hero-brand {
    text-align: left;
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    column-gap: 20px;
    margin-bottom: 32px;
  }

  .hero-logo {
    margin: 0;
    width: 80px;
    height: 80px;
    grid-row: 1 / span 2;
    align-self: center;
  }

  .hero-title {
    grid-column: 2;
    grid-row: 1;
    font-size: 2.4rem;
    margin-bottom: 4px;
    align-self: end;
  }

  .hero-subtitle {
    grid-column: 2;
    grid-row: 2;
    font-size: 1.05rem;
    align-self: start;
  }

  .main {
    padding: 12px 0 48px;
  }

  /* Two-column layout: form on left, result on right */
  .generator-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr);
    gap: 28px;
    align-items: start;
  }

  .form-stack {
    gap: 20px;
  }

  .result-stack {
    position: sticky;
    top: 24px;
    gap: 14px;
  }

  .qr-showcase {
    padding: 36px 24px 28px;
  }

  #qrCanvas {
    width: 320px;
    height: 320px;
  }

  .card {
    padding: 24px;
  }

  .footer {
    padding: 32px 0 40px;
  }
}

/* ========== Wide desktop (≥ 1280px) ========== */
@media (min-width: 1280px) {
  .app {
    max-width: 1200px;
  }

  #qrCanvas {
    width: 360px;
    height: 360px;
  }
}

/* Touch devices: reduce hover effects */
@media (hover: none) {
  .preset:hover {
    transform: none;
    box-shadow: none;
  }
}

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