:root {
  --bg: #0a0c10;
  --surface: #12151b;
  --line: #232833;
  --text: #e9ecf1;
  --muted: #8b93a1;
  --accent: #4f8cff;
  --danger: #ff5d6c;

  --radius: 16px;
  --radius-sm: 10px;
  --font-display: 'Space Grotesk', ui-sans-serif, system-ui, sans-serif;
  --font-body: 'Inter', ui-sans-serif, system-ui, sans-serif;
  color-scheme: dark;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
  background-image:
    linear-gradient(to right, color-mix(in srgb, var(--line) 45%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--line) 45%, transparent) 1px, transparent 1px);
  background-size: 56px 56px;
  background-position: center top;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 70% 55% at 50% 40%, transparent 0%, var(--bg) 75%);
  z-index: 0;
}

body > * { position: relative; z-index: 1; }

a { color: inherit; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

.mono { font-family: var(--font-display); font-feature-settings: 'tnum' 1; letter-spacing: 0.04em; }
.muted { color: var(--muted); }
.text-accent { color: var(--accent); }
.text-danger { color: var(--danger); }

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

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px clamp(16px, 4vw, 40px);
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-actions form { margin: 0; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--accent);
  position: relative;
}
.brand-mark::after {
  content: '';
  position: absolute;
  left: 50%; top: 5px;
  width: 8px; height: 8px;
  border-right: 2.5px solid var(--bg);
  border-bottom: 2.5px solid var(--bg);
  transform: translateX(-50%) rotate(45deg);
}

.brand-tag {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.status-pill .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent);
}

/* ---------- Layout público ---------- */

.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 48px;
}

.panel {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: rise 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.panel-narrow { max-width: 380px; text-align: left; align-items: stretch; }

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(32px, 7vw, 44px);
  line-height: 1.05;
  letter-spacing: -0.035em;
  text-wrap: balance;
}
.title-sm { font-size: clamp(26px, 5vw, 32px); }

.subtitle {
  margin: 12px 0 0;
  color: var(--muted);
  text-wrap: pretty;
}

/* ---------- Campo de código ---------- */

.code-form {
  width: 100%;
  margin-top: 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.code-field input {
  width: 100%;
  height: 84px;
  padding: 0 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 44px;
  letter-spacing: 0.28em;
  text-indent: 0.28em;
  text-align: center;
  text-transform: uppercase;
  font-feature-settings: 'tnum' 1;
  caret-color: var(--accent);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.code-field input::placeholder { color: color-mix(in srgb, var(--muted) 35%, transparent); }
.code-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}

.has-error .code-field input {
  border-color: var(--danger);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 16%, transparent);
  animation: shake 0.42s;
}

.field-help {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

/* ---------- Teclado ---------- */

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 8px;
}

.key {
  height: 60px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}
.key:hover { border-color: color-mix(in srgb, var(--muted) 50%, var(--line)); }
.key:active { transform: scale(0.96); }
.key:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.key-muted { color: var(--muted); }
.key-go {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-size: 17px;
  font-weight: 600;
}
.key-go:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); border-color: transparent; }

/* ---------- Estado encontrado ---------- */

.found-badge {
  width: 64px; height: 64px;
  display: grid;
  place-items: center;
  margin-bottom: 24px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  color: var(--accent);
}
.found-badge svg { animation: drop 1.2s ease-in-out infinite; }
.subtitle strong { color: var(--text); font-weight: 600; }

.progress {
  width: 100%;
  height: 4px;
  margin-top: 32px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: left;
  animation: fill var(--delay, 2s) linear both;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 28px;
}

/* ---------- Botões ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 46px;
  padding: 0 20px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; font-weight: 500; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--bg); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface); border-color: color-mix(in srgb, var(--muted) 40%, var(--line)); }
.btn-ghost.is-copied { color: var(--accent); border-color: var(--accent); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

/* ---------- Formulários ---------- */

.stack { display: flex; flex-direction: column; gap: 16px; margin-top: 24px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 500; color: var(--text); }
.field-label .muted { font-weight: 400; }

.input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.input.mono { text-transform: uppercase; }
.input.mono::placeholder { text-transform: none; letter-spacing: 0; font-family: var(--font-body); }

/* ---------- Admin ---------- */

.admin {
  flex: 1;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 8px clamp(16px, 4vw, 40px) 64px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.admin-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 0 4px;
}

.stats {
  display: flex;
  gap: 28px;
  margin: 0;
}
.stats div { display: flex; flex-direction: column-reverse; }
.stats dt { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.stats dd { margin: 0; font-family: var(--font-display); font-size: 28px; font-weight: 600; letter-spacing: -0.02em; }

.card {
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  backdrop-filter: blur(6px);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.card-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.new-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 16px;
  align-items: end;
}
@media (min-width: 860px) {
  .new-form { grid-template-columns: 2.2fr 1.3fr 1fr auto; }
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 12px;
  min-width: min(100%, 280px);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
}
.search:focus-within { border-color: var(--accent); }
.search input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.links { list-style: none; margin: 0; padding: 0; }

.link-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
}
.link-row:first-child { border-top: 0; }
.link-row.is-off .link-info,
.link-row.is-off .code-chip { opacity: 0.5; }
.link-row.is-new .code-chip { animation: pulse 1.6s ease-out 2; }

@media (min-width: 860px) {
  .link-row { grid-template-columns: 150px 1fr auto; align-items: center; gap: 20px; }
}

.link-code { display: flex; align-items: center; gap: 10px; }
@media (min-width: 860px) { .link-code { flex-direction: column; align-items: flex-start; gap: 6px; } }

.code-chip {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--accent);
  font-size: 18px;
  font-weight: 600;
}

.state { font-size: 12px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.state::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.state-on { color: var(--accent); }
.state-off { color: var(--muted); }

.link-info { min-width: 0; }
.link-title { margin: 0; font-weight: 600; }
.link-url {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link-url:hover { color: var(--text); text-decoration: underline; }
.link-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.link-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.link-actions form { margin: 0; }

.empty { padding: 40px 0 24px; text-align: center; }
.empty-title { margin: 0 0 4px; font-family: var(--font-display); font-size: 18px; font-weight: 600; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  z-index: 50;
  transform: translateX(-50%);
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 16px 40px -12px color-mix(in srgb, var(--bg) 80%, transparent);
  animation: toast-in 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  transition: opacity 0.3s, transform 0.3s;
}
.toast-success { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.toast-error { border-color: color-mix(in srgb, var(--danger) 60%, var(--line)); color: var(--danger); }
.toast.is-hiding { opacity: 0; transform: translate(-50%, -8px); }

/* ---------- Modal ---------- */

.modal {
  width: min(92vw, 520px);
  padding: 24px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.modal::backdrop { background: color-mix(in srgb, var(--bg) 75%, transparent); backdrop-filter: blur(4px); }
.modal .stack { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

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

.footer {
  padding: 20px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Animações ---------- */

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes drop { 0%, 100% { transform: translateY(-2px); } 50% { transform: translateY(3px); } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); }
  100% { box-shadow: 0 0 0 12px transparent; }
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -12px); } to { opacity: 1; transform: translateX(-50%); } }

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