/*
 * LENK.CF — Design System v2
 * Aesthetic: "The Exchange" — Dark Editorial Brutalism
 * Palette: warm charcoal background, cream text, electric amber accent
 * Fonts: Bricolage Grotesque (display) + Fira Code (mono)
 */

/* ─── Design Tokens ────────────────────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg:           oklch(13% 0.022 72);
  --surface:      oklch(17% 0.020 72);
  --surface-hi:   oklch(21% 0.018 72);

  /* Text */
  --ink:          oklch(92% 0.014 72);
  --ink-muted:    oklch(56% 0.012 72);

  /* Accent: electric amber */
  --accent:       oklch(77% 0.19 68);
  --accent-deep:  oklch(70% 0.21 65);
  --accent-dim:   oklch(77% 0.19 68 / 10%);

  /* States */
  --danger:       oklch(64% 0.22 28);
  --success:      oklch(72% 0.18 155);

  /* Borders */
  --line:         oklch(26% 0.018 72);
  --line-light:   oklch(33% 0.014 72);
  --accent-line:  3px solid var(--accent);

  /* Typography */
  --font-display: 'Bricolage Grotesque', 'Space Grotesk', system-ui, sans-serif;
  --font-mono:    'Fira Code', 'JetBrains Mono', 'Courier New', monospace;

  /* Spacing (4-point) */
  --s1:  4px;   --s2:  8px;   --s3: 12px;   --s4: 16px;
  --s5: 24px;   --s6: 32px;   --s7: 48px;   --s8: 64px;

  /* Easing */
  --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.45, 0, 0.55, 1);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

/* ─── Base ─────────────────────────────────────────────────────────────── */
body {
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: clamp(13px, 1.8vw, 15px);
  line-height: 1.65;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--s6) var(--s4);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Intro Overlay ────────────────────────────────────────────────────── */
.intro-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s var(--ease-in-out), visibility 0.5s;
}

.intro-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.intro-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s4);
  padding: var(--s6);
}

/* Long URL: starts off-screen right, slides in */
.intro-long-url {
  font-family: var(--font-mono);
  font-size: clamp(0.6rem, 2.2vw, 0.8rem);
  color: var(--ink-muted);
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  max-width: 0;
  opacity: 0;
  transition:
    max-width 0.55s var(--ease-out),
    opacity 0.3s var(--ease-out);
}

.intro-long-url.is-visible {
  max-width: 440px;
  opacity: 1;
}

.intro-long-url.is-compressing {
  max-width: 0;
  opacity: 0;
  transition:
    max-width 0.45s var(--ease-in-out),
    opacity 0.25s 0.1s var(--ease-in-out);
}

/* Arrow connector */
.intro-arrow {
  color: var(--accent);
  opacity: 0;
  transform: scaleX(0.3);
  transition:
    opacity 0.25s var(--ease-out),
    transform 0.4s var(--ease-out);
}

.intro-arrow.is-visible {
  opacity: 1;
  transform: scaleX(1);
}

/* Short URL: scales up from slightly smaller */
.intro-short-url {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--accent);
  opacity: 0;
  transform: scale(0.88) translateY(6px);
  transition:
    opacity 0.4s var(--ease-out),
    transform 0.4s var(--ease-out);
}

.intro-short-url.is-visible {
  opacity: 1;
  transform: scale(1) translateY(0);
}

.intro-dot {
  color: var(--ink);
  opacity: 0.5;
}

.intro-short-url strong {
  font-weight: 800;
  color: var(--ink);
}

/* Label beneath short URL */
.intro-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
  opacity: 0;
  transition: opacity 0.3s var(--ease-out) 0.15s;
}

.intro-label.is-visible {
  opacity: 1;
}

/* Progress bar at bottom */
.intro-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--line);
  overflow: hidden;
}

.intro-progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 1.7s var(--ease-in-out);
}

.intro-progress-fill.is-running {
  width: 100%;
}

/* ─── Main Container ───────────────────────────────────────────────────── */
.container {
  position: relative;
  width: min(100%, 600px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: var(--accent-line);
  opacity: 0;
  transform: translateY(14px);
}

.container.is-visible {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.55s var(--ease-out), transform 0.55s var(--ease-out);
}

/* ─── Header ───────────────────────────────────────────────────────────── */
.site-header {
  padding: var(--s6) var(--s6) var(--s5);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
}

.wordmark {
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.05em;
  line-height: 1;
  color: var(--ink);
}

.wordmark .dot {
  color: var(--accent);
}

.wordmark .tld {
  font-weight: 300;
  color: oklch(75% 0.012 72);
}

.header-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--s2);
  flex-shrink: 0;
  padding-top: 4px;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 3px var(--s2);
}

.live-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  animation: pulse-dot 2s var(--ease-in-out) infinite alternate;
}

@keyframes pulse-dot {
  from { opacity: 1; }
  to   { opacity: 0.15; }
}

.hostname-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--ink-muted);
  letter-spacing: 0.05em;
}

/* ─── Form Section ─────────────────────────────────────────────────────── */
.form-section {
  padding: var(--s6);
}

.field {
  margin-bottom: var(--s5);
}

.field-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: var(--s2);
}

.optional {
  font-weight: 400;
  opacity: 0.55;
  text-transform: lowercase;
  letter-spacing: 0;
}

.field-input {
  display: block;
  width: 100%;
  padding: var(--s3) var(--s4);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line-light);
  outline: none;
  transition: border-color 0.18s var(--ease-out), background 0.18s var(--ease-out);
  -webkit-appearance: none;
  appearance: none;
  font-feature-settings: "liga" 0;
}

.field-input::placeholder {
  color: oklch(40% 0.01 72);
}

.field-input:focus {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.field-input:focus-visible {
  outline: none;
}

.field-hint {
  display: block;
  margin-top: var(--s1);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: oklch(42% 0.01 72);
  letter-spacing: 0.02em;
}

/* Alias composition row */
.alias-row {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line-light);
  transition: border-color 0.18s var(--ease-out);
}

.alias-row:focus-within {
  border-color: var(--accent);
}

.alias-prefix {
  display: flex;
  align-items: center;
  padding: var(--s3);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  background: var(--surface-hi);
  color: var(--ink-muted);
  border-right: 1px solid var(--line-light);
  white-space: nowrap;
  flex-shrink: 0;
  user-select: none;
}

.alias-input {
  border: none;
  flex: 1;
  min-width: 0;
  background: var(--bg);
}

.alias-input:focus {
  border: none;
  background: var(--accent-dim);
}

/* ─── Submit Button ────────────────────────────────────────────────────── */
.action-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--s4) var(--s5);
  background: var(--accent);
  color: var(--bg);
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: none;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: background 0.2s var(--ease-out);
}

/* Sliding fill on hover */
.action-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--accent-deep);
  transform: translateX(-101%);
  transition: transform 0.3s var(--ease-out);
}

.action-btn:hover::before {
  transform: translateX(0);
}

.action-btn:active {
  transform: scale(0.993);
}

.action-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: var(--accent);
}

.action-btn:disabled::before {
  display: none;
}

.action-btn__label,
.action-btn__icon {
  position: relative;
  z-index: 1;
}

.action-btn__icon {
  font-size: 1.1rem;
  transition: transform 0.2s var(--ease-out);
}

.action-btn:hover .action-btn__icon {
  transform: translateX(4px);
}

/* Bouncing dots during loading */
.dots-loader {
  display: none;
  gap: 5px;
  align-items: center;
  position: relative;
  z-index: 1;
}

.action-btn.is-loading .dots-loader {
  display: flex;
}

.action-btn.is-loading .action-btn__label,
.action-btn.is-loading .action-btn__icon {
  display: none;
}

.dots-loader span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--bg);
  animation: dot-bounce 1s var(--ease-in-out) infinite;
}

.dots-loader span:nth-child(2) { animation-delay: 0.14s; }
.dots-loader span:nth-child(3) { animation-delay: 0.28s; }

@keyframes dot-bounce {
  0%, 100% { transform: translateY(0);    opacity: 0.35; }
  50%       { transform: translateY(-6px); opacity: 1; }
}

/* ─── Result Section ───────────────────────────────────────────────────── */
.result-section {
  border-top: 1px solid var(--line);
  padding: var(--s5) var(--s6);
  background: var(--accent-dim);
  animation: slide-in 0.4s var(--ease-out) both;
}

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

.result-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: var(--s3);
}

.result-label code {
  color: var(--ink);
  background: oklch(77% 0.19 68 / 18%);
  padding: 0 4px;
  font-weight: 500;
  letter-spacing: 0;
}

.result-row {
  display: flex;
  gap: var(--s2);
}

.result-input {
  flex: 1;
  min-width: 0;
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line-light);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--ink);
  background: var(--bg);
  outline: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s3) var(--s4);
  background: var(--surface-hi);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid var(--line-light);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}

.copy-btn:hover {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.copy-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.copy-btn--success {
  background: var(--success);
  color: var(--bg);
  border-color: var(--success);
}

/* ─── Footer ───────────────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--line);
  padding: var(--s4) var(--s6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  flex-wrap: wrap;
}

.footer-nav {
  display: flex;
  gap: var(--s5);
  align-items: center;
  flex-wrap: wrap;
}

.footer-nav a,
.footer-link-btn {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-muted);
  text-decoration: none;
  letter-spacing: 0.04em;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: color 0.12s;
}

.footer-nav a:hover,
.footer-link-btn:hover {
  color: var(--accent);
}

.footer-nav a:focus-visible,
.footer-link-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.footer-version {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: oklch(32% 0.012 72);
  letter-spacing: 0.06em;
}

/* ─── Domains Panel ────────────────────────────────────────────────────── */
.domains-panel {
  position: fixed;
  inset: auto var(--s5) var(--s5) auto;
  z-index: 500;
  width: min(300px, calc(100vw - var(--s6)));
  background: var(--surface);
  border: 1px solid var(--line-light);
  border-left: var(--accent-line);
  animation: panel-in 0.3s var(--ease-out) both;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.domains-panel__inner {
  padding: var(--s5);
  position: relative;
}

.panel-close {
  position: absolute;
  top: var(--s4);
  right: var(--s4);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--line-light);
  font-size: 0.7rem;
  color: var(--ink-muted);
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}

.panel-close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.panel-title {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0em;
  text-transform: uppercase;
  margin-bottom: var(--s4);
  color: var(--ink);
}

.domain-list {
  list-style: none;
  margin-bottom: var(--s4);
}

.domain-list li {
  border-top: 1px solid var(--line);
}

.domain-list li:last-child {
  border-bottom: 1px solid var(--line);
}

.domain-list li a {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--ink);
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s3) 0;
  transition: color 0.12s, padding-left 0.15s var(--ease-out);
}

.domain-list li a::after {
  content: '→';
  color: var(--ink-muted);
  transition: color 0.12s, transform 0.15s var(--ease-out);
}

.domain-list li a:hover {
  color: var(--accent);
  padding-left: var(--s2);
}

.domain-list li a:hover::after {
  color: var(--accent);
  transform: translateX(4px);
}

.panel-note {
  font-size: 0.65rem;
  color: var(--ink-muted);
  line-height: 1.5;
}

/* ─── Top API Loader ───────────────────────────────────────────────────── */
.loader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 9999;
  overflow: hidden;
  background: oklch(26% 0.018 72 / 60%);
}

.loader__bar {
  display: block;
  height: 100%;
  width: 40%;
  background: var(--accent);
  animation: loading-bar 1.1s var(--ease-in-out) infinite;
}

@keyframes loading-bar {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(260%); }
}

/* ─── Toasts ───────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: var(--s5);
  right: var(--s5);
  z-index: 10000;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--s2);
  pointer-events: none;
}

.toast {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s4);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  border: 1px solid var(--line-light);
  animation: toast-in 0.25s var(--ease-out) both;
  pointer-events: auto;
  max-width: 260px;
}

.toast--error {
  border-left: 3px solid var(--danger);
}

.toast--success {
  border-left: 3px solid var(--accent);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}

.toast.is-exiting {
  animation: toast-out 0.2s var(--ease-in-out) forwards;
}

@keyframes toast-out {
  to { opacity: 0; transform: translateX(12px); }
}

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

/* ─── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  body {
    padding: 0;
    align-items: flex-start;
  }

  .container {
    width: 100%;
    border-left-width: 2px;
    border-right: none;
    border-bottom: none;
  }

  .site-header {
    padding: var(--s5);
  }

  .wordmark {
    font-size: 2rem;
  }

  .form-section {
    padding: var(--s5);
  }

  .result-section {
    padding: var(--s4) var(--s5);
  }

  .site-footer {
    padding: var(--s3) var(--s5);
  }

  #toast-container {
    right: var(--s4);
    left: var(--s4);
  }

  .toast {
    max-width: 100%;
  }

  .domains-panel {
    inset: auto var(--s3) var(--s3) var(--s3);
    width: auto;
  }

  .alias-prefix {
    font-size: 0.72rem;
    padding: var(--s3) var(--s2);
  }
}

/* ─── Reduced Motion ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .intro-overlay {
    display: none;
  }

  .container {
    opacity: 1;
    transform: none;
  }
}
