/* ─── Custom Properties ─────────────────────────────────────────────────── */
:root {
  --bg:            #f7f7fb;
  --surface:       #ffffff;
  --surface-alt:   #f3f3f8;
  --accent:        #6c63ff;
  --accent-hover:  #5952e0;
  --accent-glow:   rgba(108, 99, 255, 0.15);
  --success:       #22c55e;
  --error:         #ef4444;
  --text-primary:  #16161e;
  --text-muted:    #6b7080;
  --border:        #e8e8f2;
  --shadow-sm:     0 1px 4px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.06);
  --radius-sm:     8px;
  --radius-md:     12px;
  --radius-lg:     20px;
}

/* ─── Reset + Base ──────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 56px 16px 80px;
}

/* ─── Utility ───────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Generator Layout ──────────────────────────────────────────────────── */
#app {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ─── Header ────────────────────────────────────────────────────────────── */
header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.logo-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #16161e;
  border-radius: 50px;
  padding: 14px 32px;
}

.logo {
  height: 36px;
  display: block;
}

header h1 {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  line-height: 1.15;
}

header p {
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1.5;
  max-width: 400px;
}

/* ─── Form Section ──────────────────────────────────────────────────────── */
.form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-sm);
}

form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

input[type="url"] {
  flex: 1;
  width: 100%;
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: 14px 18px;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  min-width: 0;
}

input[type="url"]::placeholder {
  color: var(--text-muted);
}

input[type="url"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--surface);
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 14px 28px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

button:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--accent-glow);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  padding: 10px 20px;
  font-size: 0.9rem;
  width: 100%;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-alt);
  border-color: var(--accent);
  color: var(--text-primary);
  box-shadow: none;
  transform: none;
}

.error {
  color: var(--error);
  font-size: 0.875rem;
  margin-top: 12px;
}

/* ─── Result Section ────────────────────────────────────────────────────── */
#result-section {
  animation: fadeSlideUp 0.35s ease both;
}

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

.result-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

@media (min-width: 600px) {
  .result-grid {
    grid-template-columns: auto 1fr;
    align-items: start;
  }
}

/* ─── QR Panel ──────────────────────────────────────────────────────────── */
.qr-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

#qr-container {
  background: #fff;
  padding: 14px;
  border-radius: var(--radius-md);
  line-height: 0;
  box-shadow: 0 1px 8px rgba(0,0,0,0.08);
  border: 1px solid var(--border);
}

/* ─── Link Panel ────────────────────────────────────────────────────────── */
.link-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: var(--shadow-sm);
}

.link-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.copy-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  overflow: hidden;
}

.copy-row a {
  flex: 1;
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.95rem;
  min-width: 0;
}

.copy-row a:hover {
  text-decoration: underline;
}

#copy-btn {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  padding: 7px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  box-shadow: none;
}

#copy-btn:hover:not(:disabled) {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
  transform: none;
  box-shadow: none;
}

#copy-btn.copied {
  border-color: var(--success);
  color: var(--success);
}

.feedback {
  color: var(--success);
  font-size: 0.8rem;
}

.original-url {
  color: var(--text-muted);
  font-size: 0.875rem;
  word-break: break-all;
  line-height: 1.5;
}

/* ─── Stats ─────────────────────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.stat-value {
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}

/* ─── Redirect Screen ───────────────────────────────────────────────────── */
#redirect-screen {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.redirect-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  color: var(--text-muted);
  font-size: 1rem;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Not Found ─────────────────────────────────────────────────────────── */
.not-found {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.not-found h2 {
  color: var(--text-primary);
  font-size: 1.5rem;
  font-weight: 700;
}

.not-found p {
  color: var(--text-muted);
}

.not-found a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  margin-top: 4px;
}

.not-found a:hover {
  text-decoration: underline;
}

/* ─── Stats View Link (inside result panel) ────────────────────────────── */
.stats-view-link {
  color: var(--accent);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  align-self: flex-start;
}

.stats-view-link:hover {
  text-decoration: underline;
}

/* ─── Stats Screen ──────────────────────────────────────────────────────── */
#stats-screen {
  width: 100%;
  max-width: 720px;
}

.stats-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  min-height: 50vh;
  color: var(--text-muted);
  font-size: 1rem;
  width: 100%;
}

.stats-page {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: color 0.15s;
  align-self: flex-start;
}

.back-link:hover {
  color: var(--accent);
}

.stats-hero {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stats-code {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.03em;
}

.stats-created {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.stats-url-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stats-url-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stats-divider {
  height: 1px;
  background: var(--border);
}

.stats-link-url {
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
  font-size: 0.95rem;
  word-break: break-all;
}

.stats-link-url:hover {
  text-decoration: underline;
}

.stats-original-url {
  color: var(--text-muted);
  font-weight: 400;
}

.stats-counts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.stat-card--total {
  background: var(--accent);
  border-color: var(--accent);
}

.stat-card--total .stat-label {
  color: rgba(255, 255, 255, 0.7);
}

.stat-card--total .stat-value {
  color: #fff;
}

/* ─── Input Tabs ─────────────────────────────────────────────────────────── */
.input-tabs {
  display: flex;
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: calc(var(--radius-md) - 2px);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  box-shadow: none;
  width: auto;
}

.tab-btn:hover:not(:disabled) {
  background: rgba(108, 99, 255, 0.08);
  color: var(--accent);
  transform: none;
  box-shadow: none;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.tab-btn.active:hover:not(:disabled) {
  background: var(--surface);
  transform: none;
  box-shadow: var(--shadow-sm);
}

/* ─── File Drop Zone ─────────────────────────────────────────────────────── */
.file-drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--surface-alt);
}

.file-drop-zone:hover,
.file-drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-glow);
}

#file-input {
  display: none;
}

.drop-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.drop-content svg {
  color: var(--accent);
  opacity: 0.7;
}

.drop-content p {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.browse-link {
  color: var(--accent);
  font-weight: 600;
}

.file-hint {
  font-size: 0.8rem !important;
  opacity: 0.7;
}

.file-selected-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.file-selected-info svg {
  color: var(--accent);
  flex-shrink: 0;
}

#file-name-display {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
  max-width: 280px;
}

#clear-file-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 4px 8px;
  font-size: 1.2rem;
  line-height: 1;
  flex-shrink: 0;
  box-shadow: none;
  width: auto;
}

#clear-file-btn:hover:not(:disabled) {
  color: var(--error);
  background: transparent;
  transform: none;
  box-shadow: none;
}

/* ─── Code Preview ───────────────────────────────────────────────────────── */
.code-preview {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.preview-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.preview-row {
  display: flex;
  align-items: center;
}

.preview-base {
  font-size: 0.95rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.code-input {
  min-width: 60px;
  max-width: 140px;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--accent);
  border-radius: 0;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace;
  padding: 0 4px 2px;
  outline: none;
  transition: border-color 0.2s;
}

.code-input:focus {
  border-bottom-color: var(--accent-hover);
  box-shadow: none;
  background: transparent;
}

.code-input.invalid {
  border-bottom-color: var(--error);
  color: var(--error);
}

.code-error {
  font-size: 0.8rem;
  color: var(--error);
  margin-top: 2px;
}

#regenerate-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.15rem;
  padding: 4px 8px;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: none;
  line-height: 1;
  width: auto;
}

#regenerate-btn:hover:not(:disabled) {
  color: var(--accent);
  transform: rotate(-30deg);
  background: transparent;
  box-shadow: none;
}

/* ─── How to Use ────────────────────────────────────────────────────────── */
.how-to {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.how-to-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.how-to-steps {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.how-to-step {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.how-to-step:last-child {
  border-bottom: none;
}

.step-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

.step-body h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.step-body p {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.step-body code {
  font-size: 0.82rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace;
  color: var(--accent);
}

/* ─── Perks ─────────────────────────────────────────────────────────────── */
.how-to-perks {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.perks-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.perks-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.perks-list li {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.perk-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  background: var(--accent-glow);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--accent);
  font-weight: 700;
  margin-top: 1px;
}

.perks-list li div strong {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.perks-list li div p {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.55;
}

/* ─── Mobile ────────────────────────────────────────────────────────────── */
@media (max-width: 500px) {
  body { padding: 32px 12px 60px; }

  header h1 { font-size: 1.9rem; }

  .stats-counts {
    grid-template-columns: 1fr 1fr;
  }

  .stat-card--total {
    grid-column: 1 / -1;
  }

  .stats-code { font-size: 1.8rem; }

  #file-name-display { max-width: 200px; }

  .how-to-step { padding: 16px; }

  .how-to-perks { padding: 16px; }
}
