/* ============ Design Tokens ============ */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .05);
  --radius: 16px;
  --radius-sm: 10px;
}

[data-theme="dark"] {
  --bg: #0b0f19;
  --surface: #151a26;
  --surface-2: #1b2130;
  --border: #2a3244;
  --text: #e5e7eb;
  --text-muted: #9aa4b8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-soft: #1e2438;
  --danger: #f87171;
  --danger-soft: #2a1a1e;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 12px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic",
    "Apple SD Gothic Neo", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
}

.app {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 18px 40px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============ Header ============ */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand__logo {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
}

.brand__name {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.5px;
}

.brand__tag {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease, transform .1s ease;
}
.theme-toggle:hover { background: var(--surface-2); }
.theme-toggle:active { transform: scale(.95); }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* ============ Cards ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card__title {
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ============ Input Area ============ */
.input-card { margin-bottom: 16px; }

.input-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.url-input {
  flex: 1 1 260px;
  min-width: 0;
  padding: 14px 16px;
  font-size: 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  transition: border-color .18s ease, box-shadow .18s ease;
}
.url-input::placeholder { color: var(--text-muted); }
.url-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.url-input.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.hint {
  margin: 10px 2px 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.error-msg {
  margin: 8px 2px 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--danger);
}

/* ============ Buttons ============ */
.btn {
  padding: 13px 18px;
  font-size: 14.5px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background .18s ease, border-color .18s ease, color .18s ease, transform .1s ease, opacity .18s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:not(:disabled):hover { background: var(--primary-hover); }

.btn--secondary {
  background: var(--primary-soft);
  color: var(--primary);
}
.btn--secondary:not(:disabled):hover { background: var(--border); }

.btn--ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn--ghost:not(:disabled):hover { background: var(--surface-2); }

.btn--link {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 4px 6px;
  font-size: 13px;
}
.btn--link:hover { color: var(--danger); }

/* ============ Workspace layout ============ */
.workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 720px) {
  .workspace { grid-template-columns: 1fr; }
}

/* ============ Preview ============ */
.preview-card {
  display: flex;
  flex-direction: column;
}

.qr-preview {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 260px;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px dashed var(--border);
}
.qr-preview img,
.qr-preview svg.qr-svg {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

.qr-placeholder {
  text-align: center;
  color: var(--text-muted);
}
.qr-placeholder p {
  margin: 12px 0 0;
  font-size: 13.5px;
  max-width: 220px;
}

.qr-target {
  margin: 12px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
  word-break: break-all;
  text-align: center;
}

/* ============ Controls ============ */
.control-card { display: flex; flex-direction: column; }

.control-group { margin-bottom: 18px; }

.control-label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.range-value {
  color: var(--text-muted);
  font-weight: 500;
}

.segmented {
  display: flex;
  gap: 6px;
  background: var(--surface-2);
  padding: 5px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.seg {
  flex: 1;
  padding: 9px 6px;
  font-size: 13.5px;
  font-weight: 600;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .18s ease, color .18s ease;
}
.seg:hover { color: var(--text); }
.seg.is-active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}

.control-group--colors {
  display: flex;
  gap: 14px;
}
.color-field { flex: 1; }

.color-input {
  width: 100%;
  height: 42px;
  padding: 4px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
}

.range {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

.download-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
}
.download-actions .btn:last-child { grid-column: 1 / -1; }

.toast {
  margin: 12px 0 0;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary);
}
.toast.is-error { background: var(--danger-soft); color: var(--danger); }

/* ============ History ============ */
.history-card { margin-top: 16px; }
.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.history-head .card__title { margin-bottom: 0; }

.history-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color .18s ease, background .18s ease;
}
.history-item:hover { border-color: var(--primary); }
.history-item__thumb {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: #fff;
  flex-shrink: 0;
}
.history-item__url {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-item__time {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ============ Footer ============ */
.footer {
  margin-top: auto;
  padding-top: 28px;
  text-align: center;
}
.footer__links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
}
.footer__links a { color: var(--text-muted); text-decoration: none; }
.footer__links a:hover { color: var(--primary); }
.footer__links .dot { color: var(--border); }
.footer__note {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}
