/* ---------------------------------------------------------------
   Tokens
--------------------------------------------------------------- */
:root {
  --bg: #F7F8FA;
  --surface: #FFFFFF;
  --border: #E6E8EC;
  --text: #14161A;
  --text-soft: #6B7280;
  --text-faint: #9CA3AF;
  --accent: #4F46E5;
  --accent-dark: #4038C4;
  --accent-tint: #EEF0FF;
  --success: #0F9D6E;
  --success-tint: #E7F8F1;
  --error: #D92D20;
  --error-tint: #FEF2F1;

  --font-display: 'Space Grotesk', 'Segoe UI', sans-serif;
  --font-body: 'Inter', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow-card: 0 1px 2px rgba(20, 22, 26, 0.04), 0 12px 32px -16px rgba(20, 22, 26, 0.12);
}

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

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }

/* ---------------------------------------------------------------
   Layout shell
--------------------------------------------------------------- */
.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 56px;
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.01em;
}

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

/* ---------------------------------------------------------------
   Hero
--------------------------------------------------------------- */
.hero {
  margin-bottom: 32px;
}

.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(32px, 5vw, 44px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.08;
  margin: 0 0 10px;
}

.hero p {
  font-size: 16px;
  color: var(--text-soft);
  margin: 0;
  max-width: 46ch;
}

/* ---------------------------------------------------------------
   Card
--------------------------------------------------------------- */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 28px;
  overflow: hidden;
}

.progress-rail {
  position: absolute;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: var(--accent);
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.progress-rail.active { width: 78%; }
.progress-rail.done { width: 100%; transition: width 0.25s ease; }

/* ---------------------------------------------------------------
   Form
--------------------------------------------------------------- */
.form-panel {
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.form-panel.is-leaving {
  opacity: 0;
  transform: translateY(-6px);
  position: absolute;
  pointer-events: none;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 6px;
}

.input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 16px;
  padding: 13px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 4px var(--accent-tint);
}

.alias-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.alias-prefix {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-faint);
  white-space: nowrap;
}

.row-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 18px;
}

.toggle-alias {
  background: none;
  border: none;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 0;
}

.toggle-alias:hover { color: var(--accent); }

.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 15px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 22px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }

.btn-primary:focus-visible,
.input:focus-visible,
.toggle-alias:focus-visible,
.btn-ghost:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.error-text {
  color: var(--error);
  font-size: 13px;
  margin-top: 10px;
  display: none;
}

.error-text.show { display: block; }

/* ---------------------------------------------------------------
   Result panel (the "compression" reveal)
--------------------------------------------------------------- */
.result-panel {
  display: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.32s ease, transform 0.32s ease;
}

.result-panel.showing {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.result-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 10px;
}

.result-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--accent-tint);
  border: 1.5px solid #DDD9FF;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.result-url {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 500;
  color: var(--accent-dark);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
}

.result-url .typed-tail {
  border-right: 2px solid var(--accent);
}

.result-url .typed-tail.done {
  border-right: none;
}

.copy-btn {
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid #DDD9FF;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.copy-btn:hover { background: #F4F3FF; }
.copy-btn.copied { background: var(--success-tint); border-color: #B8E9D5; color: var(--success); }

.result-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
}

.result-source {
  font-size: 13px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60%;
}

.btn-ghost {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 0;
}

/* ---------------------------------------------------------------
   Recent links (client-side history)
--------------------------------------------------------------- */
.recent {
  margin-top: 40px;
}

.recent-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 12px;
}

.recent-empty {
  font-size: 14px;
  color: var(--text-faint);
}

.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recent-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.recent-code {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-dark);
  flex-shrink: 0;
}

.recent-url {
  font-size: 13px;
  color: var(--text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.recent-clicks {
  font-size: 12px;
  color: var(--text-faint);
  flex-shrink: 0;
}

/* ---------------------------------------------------------------
   404 / redirect.php not-found page
--------------------------------------------------------------- */
.notfound {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.notfound-card {
  text-align: center;
  max-width: 420px;
}

.notfound-code {
  font-family: var(--font-mono);
  color: var(--text-faint);
  font-size: 14px;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.notfound-card h1 {
  font-family: var(--font-display);
  font-size: 26px;
  margin: 0 0 10px;
}

.notfound-card p {
  color: var(--text-soft);
  font-size: 15px;
  margin: 0 0 20px;
}

.notfound-card .btn { display: inline-block; text-decoration: none; }

/* ---------------------------------------------------------------
   Footer
--------------------------------------------------------------- */
.footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 48px;
}

@media (max-width: 480px) {
  .page { padding: 24px 16px 48px; }
  .card { padding: 20px; }
  .result-chip { flex-wrap: wrap; }
  .result-url { white-space: normal; word-break: break-all; }
}
