/* ==========================================================================
   Torpio CSS — one file, no build step.
   Usage: <link rel="stylesheet" href="/torpio.css">
   Docs:  /design/
   ========================================================================== */

/* 1. Tokens ---------------------------------------------------------------- */
:root {
  /* Brand */
  --t-blue-900: #0b1a4a;
  --t-blue-700: #142f8f;
  --t-blue-600: #1d3fbf; /* primary */
  --t-io:       #3b6cf6; /* the "io" in the logo */
  --t-blue-100: #e6ecfb;
  --t-blue-50:  #f3f6fd;

  /* Neutrals */
  --t-gray-900: #111827;
  --t-gray-700: #374151;
  --t-gray-500: #6b7280;
  --t-gray-300: #d1d5db;
  --t-gray-100: #f3f4f6;
  --t-white:    #ffffff;

  /* Status */
  --t-green: #15803d;
  --t-amber: #b45309;
  --t-red:   #b91c1c;

  /* Semantic */
  --t-primary: var(--t-blue-600);
  --t-primary-hover: var(--t-blue-700);
  --t-text: var(--t-gray-900);
  --t-text-muted: var(--t-gray-500);
  --t-bg: var(--t-white);
  --t-surface: var(--t-blue-50);
  --t-border: var(--t-gray-300);

  /* Type */
  --t-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --t-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Spacing (4px scale) */
  --t-1: 0.25rem;
  --t-2: 0.5rem;
  --t-3: 0.75rem;
  --t-4: 1rem;
  --t-6: 1.5rem;
  --t-8: 2rem;
  --t-12: 3rem;
  --t-16: 4rem;

  /* Shape */
  --t-radius: 8px;
  --t-radius-lg: 16px;
  --t-shadow: 0 1px 2px rgb(11 26 74 / .06), 0 4px 12px rgb(11 26 74 / .06);
  --t-max: 72rem;
}

/* 2. Base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--t-font);
  font-size: 1.125rem;
  line-height: 1.6;
  color: var(--t-text);
  background: var(--t-bg);
  -webkit-font-smoothing: antialiased;
  /* Keep the footer at the bottom on short pages */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
body > main { flex: 1; width: 100%; }

h1, h2, h3, h4 {
  margin: 0 0 var(--t-4);
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--t-blue-900);
}
h1 { font-size: clamp(2.25rem, 5vw, 3.5rem); }
h2 { font-size: 2rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1rem; }

p, ul, ol { margin: 0 0 var(--t-4); }

a { color: var(--t-primary); text-underline-offset: 3px; }
a:hover { color: var(--t-primary-hover); }

img, svg { max-width: 100%; display: block; }

code, pre { font-family: var(--t-mono); font-size: 0.875em; }
code { background: var(--t-gray-100); padding: 0.1em 0.35em; border-radius: 4px; }
pre {
  background: var(--t-blue-900);
  color: var(--t-blue-100);
  padding: var(--t-4);
  border-radius: var(--t-radius);
  overflow-x: auto;
  margin: 0 0 var(--t-4);
}
pre code { background: none; padding: 0; color: inherit; }

hr { border: 0; border-top: 1px solid var(--t-border); margin: var(--t-8) 0; }

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

/* 3. Layout ---------------------------------------------------------------- */
.container { max-width: var(--t-max); margin: 0 auto; padding: 0 var(--t-6); }
.section { padding: var(--t-16) 0; }
.section-alt { background: var(--t-surface); }

.grid { display: grid; gap: var(--t-6); grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
.stack > * + * { margin-top: var(--t-4); }
.row { display: flex; flex-wrap: wrap; gap: var(--t-3); align-items: center; }

.muted { color: var(--t-text-muted); }
.lead { font-size: 1.375rem; color: var(--t-gray-700); max-width: 40rem; }
.center { text-align: center; }

/* 4. Header & footer ------------------------------------------------------- */
.header { border-bottom: 1px solid var(--t-border); background: var(--t-bg); }
.header .container {
  display: flex; align-items: center; justify-content: space-between;
  height: 4rem;
}
.logo img, .logo svg { height: 40px; width: auto; }

/* Logo animation: the "io" switches on. Use the inline logo SVG with class .logo-animated. */
.logo-animated .io-bar  { transform-box: fill-box; transform-origin: bottom; animation: t-io-bar .3s .2s ease-out both; }
.logo-animated .io-dot  { transform-box: fill-box; transform-origin: center; animation: t-io-dot .3s .5s ease-out both; }
.logo-animated .io-ring { stroke-dasharray: 51; transform-box: fill-box; transform-origin: center; transform: rotate(-90deg); animation: t-io-ring .5s .8s ease-in-out both; }
@keyframes t-io-bar  { from { transform: scaleY(0); } }
@keyframes t-io-dot  { 0% { transform: scale(0); } 70% { transform: scale(1.4); } }
@keyframes t-io-ring { from { stroke-dashoffset: 51; opacity: 0; } 10% { opacity: 1; } to { stroke-dashoffset: 0; } }
.nav { display: flex; gap: var(--t-6); }
.nav a { color: var(--t-gray-700); text-decoration: none; font-weight: 500; }
.nav a:hover, .nav a[aria-current="page"] { color: var(--t-primary); }

.footer { border-top: 1px solid var(--t-border); padding: var(--t-8) 0; color: var(--t-text-muted); font-size: 1rem; }

/* 5. Buttons --------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--t-2);
  padding: 0.625rem 1.25rem;
  font: inherit; font-weight: 600; line-height: 1.2;
  border: 2px solid var(--t-primary);
  border-radius: var(--t-radius);
  background: var(--t-primary); color: var(--t-white);
  text-decoration: none; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--t-primary-hover); border-color: var(--t-primary-hover); color: var(--t-white); }
.btn-secondary { background: transparent; color: var(--t-primary); }
.btn-secondary:hover { background: var(--t-blue-50); color: var(--t-primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--t-primary); }
.btn-ghost:hover { background: var(--t-blue-50); border-color: transparent; color: var(--t-primary-hover); }
.btn-danger { background: var(--t-red); border-color: var(--t-red); }
.btn-danger:hover { background: #991b1b; border-color: #991b1b; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.875rem; }
.btn-lg { padding: 0.875rem 1.75rem; font-size: 1.125rem; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }

/* 6. Cards ----------------------------------------------------------------- */
.card {
  background: var(--t-bg);
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius-lg);
  padding: var(--t-6);
}
.card > :last-child { margin-bottom: 0; }
.card-raised { border-color: transparent; box-shadow: var(--t-shadow); }

/* 7. Tables ---------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--t-border); border-radius: var(--t-radius); margin: 0 0 var(--t-4); }
.table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.table th, .table td { padding: var(--t-3) var(--t-4); text-align: left; border-bottom: 1px solid var(--t-border); }
.table th { background: var(--t-surface); color: var(--t-blue-900); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table-striped tbody tr:nth-child(even) { background: var(--t-gray-100); }
.table-hover tbody tr:hover { background: var(--t-blue-50); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* 8. Forms ----------------------------------------------------------------- */
.field { margin: 0 0 var(--t-4); }
.label { display: block; font-weight: 600; margin-bottom: var(--t-1); }
.hint { display: block; font-size: 0.875rem; color: var(--t-text-muted); margin-top: var(--t-1); }

.input, .select, .textarea {
  display: block; width: 100%;
  padding: 0.625rem 0.75rem;
  font: inherit; color: var(--t-text);
  background: var(--t-bg);
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius);
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--t-primary); box-shadow: 0 0 0 3px var(--t-blue-100); }
.textarea { min-height: 7rem; resize: vertical; }
.is-invalid { border-color: var(--t-red); }
.is-invalid + .hint { color: var(--t-red); }

.check { display: flex; align-items: center; gap: var(--t-2); margin-bottom: var(--t-2); cursor: pointer; }
.check input { width: 1.125rem; height: 1.125rem; accent-color: var(--t-primary); }

/* 9. Feedback -------------------------------------------------------------- */
.alert {
  padding: var(--t-4);
  border-left: 4px solid var(--t-primary);
  border-radius: var(--t-radius);
  background: var(--t-blue-50);
  margin: 0 0 var(--t-4);
}
.alert-success { border-color: var(--t-green); background: #f0fdf4; }
.alert-warning { border-color: var(--t-amber); background: #fffbeb; }
.alert-danger  { border-color: var(--t-red);   background: #fef2f2; }

.badge {
  display: inline-block;
  padding: 0.125rem 0.625rem;
  font-size: 0.75rem; font-weight: 600;
  border-radius: 999px;
  background: var(--t-blue-100); color: var(--t-blue-700);
}
.badge-success { background: #dcfce7; color: var(--t-green); }
.badge-warning { background: #fef3c7; color: var(--t-amber); }
.badge-danger  { background: #fee2e2; color: var(--t-red); }

/* 10. Hero ----------------------------------------------------------------- */
.hero { padding: var(--t-16) 0; background: linear-gradient(180deg, var(--t-blue-50), var(--t-bg)); }
.hero .lead { margin-bottom: var(--t-8); }

/* 11. Responsive ----------------------------------------------------------- */
@media (max-width: 40rem) {
  .nav { gap: var(--t-4); }
  .section, .hero { padding: var(--t-12) 0; }
}

/* 12. Terminal ------------------------------------------------------------- */
.terminal {
  background: var(--t-blue-900);
  color: var(--t-blue-100);
  border-radius: var(--t-radius-lg);
  box-shadow: var(--t-shadow);
  overflow: hidden;
  font-family: var(--t-mono);
  font-size: 1rem;
  line-height: 1.7;
  position: relative;
}
.terminal:focus-within { outline: 3px solid var(--t-io); outline-offset: 3px; }
.terminal a { color: var(--t-io); }
.terminal-input { position: absolute; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; font-size: 16px; pointer-events: none; }
.terminal-bar { display: flex; gap: 6px; padding: var(--t-3) var(--t-4); background: rgb(255 255 255 / .06); }
.terminal-bar span { width: 10px; height: 10px; border-radius: 50%; background: rgb(255 255 255 / .2); }
.terminal-body { margin: 0; padding: var(--t-4); height: 22rem; overflow-y: auto; white-space: pre-wrap; background: none; color: inherit; border-radius: 0; }
.terminal .prompt { color: var(--t-io); }
.terminal .comment { color: #8b9bc9; }
.terminal .ok { color: #4ade80; }
.cursor { display: inline-block; width: 0.55em; height: 1.1em; vertical-align: text-bottom; background: var(--t-io); animation: t-blink 1s steps(1) infinite; }
@keyframes t-blink { 50% { opacity: 0; } }

/* 13. Status --------------------------------------------------------------- */
/* A small pill with a pulsing dot. Add .status-busy for an amber, still dot. */
.status {
  display: inline-flex; align-items: center; gap: var(--t-2);
  padding: var(--t-1) var(--t-3);
  border: 1px solid var(--t-border); border-radius: 999px;
  background: var(--t-bg);
  font-size: 0.875rem; color: var(--t-gray-700);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--t-green); animation: t-pulse 2s infinite; }
.status-busy .status-dot { background: var(--t-amber); animation: none; }
@keyframes t-pulse {
  0%   { box-shadow: 0 0 0 0 rgb(21 128 61 / .5); }
  70%  { box-shadow: 0 0 0 8px rgb(21 128 61 / 0); }
  100% { box-shadow: 0 0 0 0 rgb(21 128 61 / 0); }
}

@media (prefers-reduced-motion: reduce) {
  .logo-animated *, .cursor, .status-dot { animation: none !important; }
}
