/* ==========================================================================
   FRAGMENTS — onsite challenge
   Stile mobile-first: un'unica colonna fino a 720px, poi respiro sul desktop.
   ========================================================================== */

:root {
  --bg: #06090f;
  --bg-glow-1: rgba(34, 211, 238, 0.14);
  --bg-glow-2: rgba(74, 222, 128, 0.08);
  --surface: #0d141e;
  --surface-2: #111a26;
  --border: #1d2937;
  --border-strong: #27384b;
  --text: #e7eef6;
  --text-dim: #9fb0c3;
  --text-faint: #6d8099;
  --accent: #22d3ee;
  --accent-ink: #04121a;
  --accent-2: #4ade80;
  --danger: #fb7185;
  --warn: #fbbf24;
  --radius: 14px;
  --radius-sm: 10px;
  --shell: 680px;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", "JetBrains Mono",
    "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --shadow: 0 18px 40px -24px rgba(0, 0, 0, 0.9);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image:
    radial-gradient(1100px 520px at 50% -200px, var(--bg-glow-1), transparent 70%),
    radial-gradient(760px 420px at 110% 10%, var(--bg-glow-2), transparent 70%);
  background-repeat: no-repeat;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.015em;
}

p {
  margin: 0;
}

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

code,
.mono {
  font-family: var(--font-mono);
}

.shell {
  width: 100%;
  max-width: var(--shell);
  margin: 0 auto;
  padding: 0 16px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 10px 14px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 0 0 var(--radius-sm) 0;
  font-weight: 600;
  z-index: 50;
}

.skip-link:focus {
  left: 0;
}

/* ---------- header / footer ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: rgba(6, 9, 15, 0.82);
  backdrop-filter: blur(10px);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
}

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

.brand__mark {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.55);
  animation: pulse 2.8s var(--ease) infinite;
}

.site-header__tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}

main.shell {
  flex: 1 0 auto;
  padding-top: 28px;
  padding-bottom: 56px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 18px 0 28px;
  font-size: 12px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

/* ---------- hero ---------- */

.hero {
  padding: 18px 2px 6px;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--accent);
}

.eyebrow--ok {
  color: var(--accent-2);
}

.hero__title {
  margin-top: 10px;
  font-size: clamp(2rem, 11vw, 3.1rem);
  line-height: 1.02;
  letter-spacing: -0.03em;
  background: linear-gradient(180deg, #ffffff 0%, #9fc6d6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero__title--ok {
  background: linear-gradient(180deg, #ffffff 0%, #86efac 100%);
  -webkit-background-clip: text;
  background-clip: text;
}

.hero__lead {
  margin-top: 14px;
  color: var(--text-dim);
  font-size: 1rem;
  max-width: 46ch;
}

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

.panel {
  position: relative;
  background: linear-gradient(180deg, var(--surface) 0%, rgba(13, 20, 30, 0.72) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
}

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

.panel--accent::before {
  content: "";
  position: absolute;
  inset: -1px -1px auto -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  border-radius: var(--radius) var(--radius) 0 0;
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel__title {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text);
  font-weight: 600;
}

.panel__title--small {
  font-size: 0.85rem;
  letter-spacing: 0.14em;
  color: var(--text-dim);
}

.panel__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.panel__actions--tight {
  margin-top: 8px;
}

.panel__actions--wrap {
  flex-wrap: wrap;
}

.chip {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}

/* ---------- hex stream ---------- */

.hex-stream {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  padding: 14px 12px;
  border-radius: var(--radius-sm);
  background: #070c13;
  border: 1px solid var(--border);
  overflow-wrap: anywhere;
}

.hex-stream__byte {
  color: var(--accent);
  background: rgba(34, 211, 238, 0.07);
  border: 1px solid rgba(34, 211, 238, 0.16);
  border-radius: 6px;
  padding: 3px 6px;
  transition: transform 160ms var(--ease), background 160ms var(--ease);
}

.hex-stream__byte:hover {
  transform: translateY(-1px);
  background: rgba(34, 211, 238, 0.14);
}

/* ---------- forms ---------- */

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

.form--inline {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field__label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.field__input {
  width: 100%;
  padding: 13px 14px;
  font-size: 16px; /* evita lo zoom automatico su iOS */
  font-family: inherit;
  color: var(--text);
  background: #070c13;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease);
  -webkit-appearance: none;
  appearance: none;
}

.field__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.16);
}

.field__input--mono {
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

.field__input--area {
  resize: vertical;
  min-height: 84px;
  line-height: 1.5;
}

.field__input--operator {
  width: 72px;
  text-align: center;
  font-size: 22px;
  padding: 10px 0;
  letter-spacing: 0;
}

.field__input--invalid {
  border-color: var(--danger);
}

.field--operator {
  align-items: flex-start;
}

.field--check {
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.field__error {
  font-size: 13px;
  color: var(--danger);
}

.checkbox {
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.checkbox__label {
  font-size: 14px;
  color: var(--text-dim);
  flex: 1 1 240px;
}

select.field__input {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-faint) 50%),
    linear-gradient(135deg, var(--text-faint) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 38px;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid--two {
  grid-template-columns: 1fr 1fr;
}

/* ---------- buttons ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 20px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-decoration: none;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 120ms var(--ease), background 150ms var(--ease),
    border-color 150ms var(--ease), opacity 150ms var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.button:active {
  transform: translateY(1px) scale(0.995);
}

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

.button--primary {
  background: linear-gradient(180deg, #2ee0f2 0%, #19b9d6 100%);
  color: var(--accent-ink);
}

.button--primary:hover {
  background: linear-gradient(180deg, #43e8f8 0%, #1fc6e4 100%);
}

.button--ghost {
  background: rgba(255, 255, 255, 0.03);
  border-color: var(--border-strong);
  color: var(--text-dim);
}

.button--ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.button--block {
  width: 100%;
}

.button--small {
  padding: 9px 14px;
  font-size: 11px;
}

.button[disabled],
.button.is-busy {
  opacity: 0.65;
  pointer-events: none;
}

/* ---------- alerts, note, prose ---------- */

.alert {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  margin-bottom: 14px;
  animation: shake-in 420ms var(--ease);
}

.alert--error {
  color: var(--danger);
  border-color: rgba(251, 113, 133, 0.35);
  background: rgba(251, 113, 133, 0.08);
}

.alert--warn {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.08);
}

.alert--ok {
  color: var(--accent-2);
  border-color: rgba(74, 222, 128, 0.35);
  background: rgba(74, 222, 128, 0.08);
}

.note {
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--text-faint);
  line-height: 1.5;
}

.note code {
  color: var(--accent);
  background: rgba(34, 211, 238, 0.08);
  border: 1px solid rgba(34, 211, 238, 0.16);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 12px;
}

.prose {
  color: var(--text-dim);
  font-size: 15px;
}

.list {
  margin: 0;
  padding-left: 20px;
  color: var(--text-dim);
  font-size: 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pre {
  margin: 0;
  padding: 14px 12px;
  background: #070c13;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-dim);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.mono--block {
  padding: 12px;
  background: #070c13;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.mono--small {
  font-size: 11.5px;
}

.is-hidden {
  display: none !important;
}

/* ---------- byte lab ---------- */

.lab {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 10px;
}

.lab__head {
  padding: 6px 2px 0;
}

.lab__title {
  font-size: 1.05rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
}

.lab__subtitle {
  margin-top: 6px;
  font-size: 13.5px;
  color: var(--text-faint);
}

/* ---------- admin ---------- */

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

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
}

.stat__value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}

.stat__value--warn {
  color: var(--warn);
}

.stat__label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-faint);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 520px;
}

.table th,
.table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table th {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-faint);
  background: rgba(255, 255, 255, 0.02);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table td form {
  margin: 0;
}

.tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid;
  background: transparent;
  cursor: pointer;
  transition: opacity 150ms var(--ease);
}

.tag:hover {
  opacity: 0.75;
}

.tag--ok {
  color: var(--accent-2);
  border-color: rgba(74, 222, 128, 0.4);
}

.tag--warn {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.4);
}

/* ---------- toast ---------- */

.toast-stack {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  width: calc(100% - 32px);
  max-width: 420px;
  pointer-events: none;
}

.toast {
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.04em;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(13, 20, 30, 0.96);
  border: 1px solid var(--border-strong);
  color: var(--text);
  box-shadow: var(--shadow);
  animation: toast-in 220ms var(--ease);
}

.toast--ok {
  border-color: rgba(74, 222, 128, 0.45);
  color: var(--accent-2);
}

.toast--error {
  border-color: rgba(251, 113, 133, 0.45);
  color: var(--danger);
}

.toast.is-leaving {
  animation: toast-out 200ms var(--ease) forwards;
}

/* ---------- animazioni ---------- */

.reveal {
  animation: reveal 520ms var(--ease) both;
}

main.shell > .reveal:nth-child(1) { animation-delay: 0ms; }
main.shell > .reveal:nth-child(2) { animation-delay: 70ms; }
main.shell > .reveal:nth-child(3) { animation-delay: 140ms; }
main.shell > .reveal:nth-child(4) { animation-delay: 210ms; }
main.shell > .reveal:nth-child(5) { animation-delay: 280ms; }

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

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.5); }
  70% { box-shadow: 0 0 0 7px rgba(34, 211, 238, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0); }
}

@keyframes shake-in {
  0% { opacity: 0; transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  70% { transform: translateX(-3px); }
  100% { opacity: 1; transform: translateX(0); }
}

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

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

/* ---------- desktop ---------- */

@media (min-width: 721px) {
  :root {
    --shell: 760px;
  }

  main.shell {
    padding-top: 40px;
    gap: 22px;
  }

  .panel {
    padding: 22px 22px;
  }

  .hero {
    padding-top: 26px;
  }

  .hero__lead {
    font-size: 1.06rem;
  }

  .lab {
    margin-top: 18px;
  }
}

@media (max-width: 420px) {
  .grid--two {
    grid-template-columns: 1fr;
  }

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

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