/* =================================================================
   THREADBOX — design tokens
   Concept: a long URL is a length of thread, wound into a small coil
   (the short code). The coil mark is the signature element: it's the
   logo, and it's also the loading state (thread spinning/unwinding).
   ================================================================= */

:root {
  --bg: #F1F7F4;
  --surface: #FFFFFF;
  --surface-sunken: #E7EFEA;
  --text: #16241F;
  --muted: #5C6F68;
  --border: rgba(22, 36, 31, 0.10);
  --accent: #C97A1E;       /* amber thread, darkened for AA contrast on light bg */
  --accent-strong: #A8631A;
  --teal: #1F8A7D;         /* darkened teal for light-mode contrast */
  --error: #C9432B;
  --shadow: 0 1px 2px rgba(22,36,31,0.04), 0 8px 24px rgba(22,36,31,0.06);

  --font-display: 'Fraunces', serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
}

html[data-theme="dark"] {
  --bg: #0F1B18;
  --surface: #16241F;
  --surface-sunken: #0C1613;
  --text: #E7F0EC;
  --muted: #8AA39C;
  --border: rgba(231, 240, 236, 0.10);
  --accent: #E8A33D;
  --accent-strong: #F2B85B;
  --teal: #4FD1C5;
  --error: #E2664D;
  --shadow: 0 1px 2px rgba(0,0,0,0.2), 0 12px 32px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: var(--font-body);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.4s ease, color 0.4s ease;
  position: relative;
  overflow-x: hidden;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Subtle grain texture so flat color fields don't feel sterile */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

html[data-theme="dark"] .grain { opacity: 0.06; }

/* ---------------- Topbar ---------------- */

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px clamp(20px, 5vw, 56px) 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.coil-mark {
  width: 22px;
  height: 22px;
  color: var(--accent);
}

.brand-name {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  font-weight: 500;
}

.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  transition: background 0.3s ease, transform 0.15s ease;
}

.theme-toggle:hover { transform: translateY(-1px); }
.theme-toggle:active { transform: translateY(0); }

.theme-toggle svg { width: 18px; height: 18px; position: absolute; transition: opacity 0.25s ease, transform 0.4s ease; }

.icon-sun { opacity: 0; transform: rotate(-40deg) scale(0.7); }
.icon-moon { opacity: 1; transform: rotate(0) scale(1); }

html[data-theme="dark"] .icon-sun { opacity: 1; transform: rotate(0) scale(1); }
html[data-theme="dark"] .icon-moon { opacity: 0; transform: rotate(40deg) scale(0.7); }

/* ---------------- Stage / Hero ---------------- */

.stage {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(40px, 8vh, 96px) 20px 60px;
}

.hero {
  max-width: 640px;
  text-align: center;
  margin-bottom: 40px;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 20px;
}

.headline {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-variation-settings: 'opsz' 60;
  font-weight: 500;
  font-size: clamp(2.4rem, 6vw, 3.8rem);
  line-height: 1.05;
  letter-spacing: -0.01em;
  margin: 0 0 20px;
  color: var(--text);
}

.subhead {
  font-size: 1.05rem;
  line-height: 1.55;
  color: var(--muted);
  max-width: 460px;
  margin: 0 auto;
}

/* ---------------- Panels ---------------- */

.panel {
  width: 100%;
  max-width: 640px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: clamp(20px, 4vw, 32px);
  transition: background 0.4s ease, border-color 0.4s ease;
}

.input-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

#url-input {
  flex: 1 1 280px;
  min-width: 0;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px 18px;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#url-input::placeholder { color: var(--muted); opacity: 0.7; }

#url-input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--accent);
  color: #1A1006;
  border: none;
  border-radius: 12px;
  padding: 15px 22px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s ease, transform 0.15s ease;
}

.btn-primary:hover { background: var(--accent-strong); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.btn-primary:disabled { opacity: 0.7; cursor: progress; }

.btn-spinner {
  width: 18px;
  height: 18px;
  display: none;
}

.btn-primary.is-loading .btn-label { display: none; }
.btn-primary.is-loading .btn-spinner {
  display: block;
  animation: spin-coil 0.9s linear infinite;
}

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

.field-message {
  margin: 12px 2px 0;
  font-size: 0.85rem;
  color: var(--error);
  min-height: 1.2em;
}

/* ---------------- Result panel ---------------- */

.result-panel {
  margin-top: 20px;
  animation: rise-in 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

.result-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.result-link {
  font-family: var(--font-mono);
  font-size: clamp(1.1rem, 3vw, 1.4rem);
  font-weight: 500;
  color: var(--teal);
  text-decoration: none;
  word-break: break-all;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}
.result-link:hover { border-color: var(--teal); }

.btn-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-sunken);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}
.btn-icon svg { width: 18px; height: 18px; }
.btn-icon:hover { background: var(--accent); color: #1A1006; }
.btn-icon:active { transform: scale(0.94); }
.btn-icon.is-copied { background: var(--teal); color: #08201C; }
.btn-icon:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

.result-origin {
  margin: 14px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  word-break: break-all;
}
.result-origin span { color: var(--text); opacity: 0.8; }

.qr-wrap {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#qr-canvas {
  background: #fff;
  padding: 12px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  line-height: 0;
}

.qr-caption {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.btn-text {
  margin-top: 22px;
  background: none;
  border: none;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px 0;
  transition: color 0.2s ease;
}
.btn-text:hover { color: var(--accent); }
.btn-text:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ---------------- Footer ---------------- */

.foot {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 20px;
  font-size: 0.8rem;
  color: var(--muted);
  font-family: var(--font-mono);
}

/* ---------------- Motion & accessibility ---------------- */

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

:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

@media (max-width: 480px) {
  .input-row { flex-direction: column; }
  .btn-primary { width: 100%; }
}
