/* --- Variables (light default) --- */
:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #5c5c5c;
  --border: #d8dce3;
  --accent: #0066cc;
  --accent-hover: #0052a3;
  --input-bg: #ffffff;
  --shadow: rgba(0, 0, 0, 0.06);
  --shadow-md: rgba(0, 0, 0, 0.1);
  --checker: #e0e0e0;
  --radius: 10px;
  --radius-sm: 8px;
  --space: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
}

[data-theme="dark"] {
  --bg: #161618;
  --surface: #222226;
  --text: #e8e8ed;
  --text-muted: #9a9aa2;
  --border: #3a3a3e;
  --accent: #3b8ef6;
  --accent-hover: #5ba0f7;
  --input-bg: #2c2c30;
  --shadow: rgba(0, 0, 0, 0.25);
  --shadow-md: rgba(0, 0, 0, 0.4);
  --checker: #2c2c30;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

/* --- Page wrapper --- */
.page {
  max-width: 1280px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Header --- */
.header {
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--space-lg) var(--space-xl);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-lg);
}

.brand {
  min-width: 0;
}

.header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.tagline {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 400;
}

.theme-toggle {
  flex-shrink: 0;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.875rem;
  cursor: pointer;
  color: var(--text);
  font-size: 1rem;
}

.theme-toggle:hover {
  background: var(--border);
}

.theme-toggle .dark-icon { display: none; }
[data-theme="dark"] .theme-toggle .light-icon { display: none; }
[data-theme="dark"] .theme-toggle .dark-icon { display: inline; }

/* --- Main layout --- */
.main {
  flex: 1;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 0;
  min-height: 0;
}

.controls {
  overflow-y: auto;
  padding: var(--space-xl);
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.controls-title {
  margin: 0 0 var(--space-lg);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* --- Accordion --- */
.accordion-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: var(--space);
  overflow: hidden;
}

.accordion-section:last-of-type {
  margin-bottom: 0;
}

.accordion-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  background: var(--input-bg);
  border: none;
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease;
}

.accordion-head:hover {
  background: var(--border);
}

.accordion-icon {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  opacity: 0.7;
}

.accordion-section[data-collapsed="true"] .accordion-icon {
  transform: rotate(-135deg);
}

.accordion-panel {
  padding: 1rem 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.accordion-section[data-collapsed="true"] .accordion-panel {
  display: none;
}

/* --- Form fields --- */
.field {
  margin-bottom: 1rem;
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
}

.field input[type="text"],
.field input[type="email"],
.field input[type="tel"],
.field textarea,
.field select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9375rem;
}

.field input[type="color"] {
  width: 100%;
  height: 38px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--input-bg);
}

.field input[type="range"] {
  width: calc(100% - 3.5rem);
  vertical-align: middle;
  margin-right: 0.5rem;
}

.field.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.range-value {
  display: inline-block;
  min-width: 2.5rem;
  font-variant-numeric: tabular-nums;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.checkbox-field input {
  width: auto;
  margin: 0;
}

.checkbox-field label {
  margin: 0;
  font-weight: 400;
}

.meta {
  margin-top: 0.375rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.hint {
  display: block;
  margin-top: 0.25rem;
}

/* --- Presets --- */
.presets { margin-top: 1rem; }
.presets-label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
}

.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.preset-btn {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.preset-btn:hover {
  background: var(--border);
}

.preset-fields {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.preset-fields label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.8125rem;
}

.preset-fields input,
.preset-fields select {
  width: 100%;
  margin-bottom: 0.75rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
}

.hidden { display: none !important; }

/* --- Buttons --- */
.btn-primary {
  display: block;
  width: 100%;
  padding: 0.625rem 1rem;
  margin-bottom: 0.5rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-primary:last-of-type {
  margin-bottom: 0;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-secondary {
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-secondary:hover {
  background: var(--border);
}

#vcardApply, #wifiApply { margin-top: 0.25rem; }

.btn-reset {
  margin-top: 1rem;
  width: 100%;
}

/* --- Preview area (right column) --- */
.preview-area {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
  padding: var(--space-xl);
  overflow-y: auto;
  align-items: center;
  justify-content: center;
  min-height: 400px;
}

.preview-card {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-xl);
  box-shadow: 0 2px 12px var(--shadow);
}

.preview-label,
.output-label {
  margin: 0 0 var(--space);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.preview-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 200px;
  min-height: 200px;
  padding: var(--space-lg);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

/* Checkerboard when transparent */
.preview-wrap.checkerboard {
  background-image:
    linear-gradient(45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker) 75%);
  background-size: 14px 14px;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0;
  background-color: var(--surface);
}

#previewContainer {
  display: flex;
  align-items: center;
  justify-content: center;
}

#previewContainer canvas,
#previewContainer svg {
  max-width: 100%;
  height: auto;
  display: block;
}

.scan-tips {
  margin: var(--space) 0 0;
  padding-top: var(--space);
  border-top: 1px solid var(--border);
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* --- Output card --- */
.output-card {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-xl);
  box-shadow: 0 2px 12px var(--shadow);
}

.output-form .field-inline {
  margin-bottom: 1rem;
}

.empty-message {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.download-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.download-buttons .btn-primary {
  margin-bottom: 0;
}

/* --- File input --- */
.field input[type="file"] {
  font-size: 0.875rem;
  color: var(--text);
}

/* --- Responsive --- */
@media (max-width: 960px) {
  .main {
    grid-template-columns: 1fr;
  }

  .controls {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 50vh;
  }

  .preview-area {
    order: 0;
    min-height: auto;
    justify-content: flex-start;
  }

  .download-buttons {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .preview-card,
  .output-card {
    padding: var(--space);
  }
}

/* --- Focus for accessibility --- */
.accordion-head:focus-visible,
.preset-btn:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.theme-toggle:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
