/* Turnkey Machining Solutions website: the one stylesheet.
   Rebrand: change the tokens in :root, then site.json and the page text (see README). */

:root {
  /* Brand: logo red (TURN), steel grey (KEY), charcoal (ruler ticks). */
  --bg: #121314;
  --panel: #17191b;
  --panel-2: #1e2124;
  --line: #2a2d31;
  --line-strong: #464b51;
  --text: #ecedee;
  --muted: #a9aeb3;
  --accent: #c0202f;
  --accent-hover: #d42a3a;
  --accent-ink: #fff;
  --accent-text: #f0505c; /* lighter red for small text on dark: logo red is too dim there */
  --ink-dark: #141414;
  --radius: 8px;
  --wrap: 1200px;
  --gutter: 16px;
  --header-h: 76px;
  --header-h-small: 60px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: dark;
}
@media (min-width: 860px) { :root { --gutter: 32px; } }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h-small) + 16px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1.0625rem/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img, svg, video { display: block; max-width: 100%; height: auto; }
a { color: inherit; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, h3 { line-height: 1.08; margin: 0 0 .5em; letter-spacing: -.01em; }
h1, h2 { font-weight: 900; text-transform: uppercase; }
h1 { font-size: clamp(2.4rem, 6vw, 4.5rem); }
h2 { font-size: clamp(1.8rem, 3.6vw, 2.75rem); }
h3 { font-size: 1.25rem; font-weight: 800; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.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; }
.skip-link { position: absolute; left: 16px; top: -100px; z-index: 100; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: var(--radius); font-weight: 700; }
.skip-link:focus { top: 12px; }

/* ---------- Layout ---------- */
.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 var(--gutter); }
.section { padding: clamp(64px, 10vw, 120px) 0; }
.section-alt { background: var(--panel); border-block: 1px solid var(--line); }
.section-head { max-width: 46rem; margin-bottom: 48px; }
.eyebrow { font: 700 .8rem/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--accent-text); margin-bottom: 1rem; }
.lead { font-size: 1.2rem; color: var(--muted); max-width: 40rem; }
.split { display: grid; gap: 40px; align-items: center; }
@media (min-width: 900px) {
  .split { grid-template-columns: 1fr 1fr; gap: 64px; }
  .split-reverse > :first-child { order: 2; }
}
.split-top { align-items: start; }
.grid { display: grid; gap: 20px; }
@media (min-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) {
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .5em;
  padding: .85em 1.3em; border-radius: var(--radius); border: 1px solid transparent;
  font-weight: 800; font-size: .95rem; letter-spacing: .04em; text-transform: uppercase; text-decoration: none;
  transition: background-color .2s, border-color .2s, box-shadow .2s;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 8px 24px rgba(192, 32, 47, .35); }
.btn-ghost { border-color: var(--line-strong); color: var(--text); }
.btn-ghost:hover { border-color: var(--text); }
.btn-dark { background: var(--ink-dark); color: #fff; }
.btn-dark:hover { background: #000; box-shadow: 0 8px 24px rgba(0, 0, 0, .3); }
.quote-band a:focus-visible { outline-color: var(--accent-ink); }
.btn-lg { font-size: 1.05rem; padding: 1.05em 1.6em; }
.btn .arrow { transition: transform .2s var(--ease); }
.btn:hover .arrow { transform: translateX(3px); }
.btn-row { display: flex; flex-wrap: wrap; gap: 12px; }

/* ---------- Header ---------- */
.site-header {
  position: fixed; inset: 0 0 auto; z-index: 50;
  border-bottom: 1px solid transparent;
  transition: background-color .3s, border-color .3s;
  view-transition-name: site-header;
}
.header-inner { display: flex; align-items: center; gap: 24px; height: var(--header-h); transition: height .3s var(--ease); }
.site-header.is-scrolled { background: var(--bg); border-bottom-color: var(--line); }
.site-header.is-scrolled .header-inner { height: var(--header-h-small); }
.logo { margin-right: auto; display: block; flex-shrink: 0; text-decoration: none; }
.logo img { height: 58px; width: auto; transition: height .3s var(--ease); }
.site-header.is-scrolled .logo img { height: 44px; }
.site-footer .logo img { height: 64px; margin-bottom: 16px; }
/* Larger header logo only where it fits beside the full nav (304px logo + 611px nav + gaps). */
@media (min-width: 1024px) {
  :root { --header-h: 104px; --header-h-small: 76px; }
  .site-header .logo img { height: 87px; }
  .site-header.is-scrolled .logo img { height: 66px; }
}
.site-nav { display: flex; align-items: center; gap: 28px; }
.site-nav a:not(.btn) { position: relative; padding: 6px 0; color: var(--muted); font-weight: 600; font-size: .95rem; text-decoration: none; transition: color .2s; }
.site-nav a:not(.btn):hover, .site-nav a[aria-current="page"] { color: var(--text); }
.site-nav a[aria-current="page"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 2px; background: var(--accent); }
.nav-cta { padding: .6em 1em; font-size: .85rem; }
.menu-toggle { display: none; }
/* Without JavaScript the header simply sits at the top of the page. */
html:not(.js) .site-header { position: relative; background: var(--bg); border-bottom-color: var(--line); }
html:not(.js) .hero, html:not(.js) .page-hero { padding-top: 48px; }

/* ---------- Mobile menu and action bar ---------- */
.action-bar { display: none; }
@media (max-width: 859px) {
  .js-ready .menu-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; background: none; color: var(--text);
    border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
  }
  .bars, .bars::before, .bars::after { display: block; width: 18px; height: 2px; background: currentColor; transition: transform .25s var(--ease), background-color .2s; }
  .bars { position: relative; }
  .bars::before, .bars::after { content: ""; position: absolute; left: 0; }
  .bars::before { top: -6px; }
  .bars::after { top: 6px; }
  .menu-open .bars { background: transparent; }
  .menu-open .bars::before { transform: translateY(6px) rotate(45deg); }
  .menu-open .bars::after { transform: translateY(-6px) rotate(-45deg); }
  .menu-open .site-header { background: var(--bg); border-bottom-color: var(--line); }
  .menu-open .site-header .header-inner { height: var(--header-h-small); }
  .logo img { height: 52px; }
  .menu-open .logo img { height: 44px; }
  .hero-photo { opacity: .45; }
  .menu-open body { overflow: hidden; }
  .js-ready .site-nav {
    position: fixed; inset: var(--header-h-small) 0 0; flex-direction: column; align-items: stretch; gap: 0;
    padding: 24px var(--gutter); background: var(--bg);
    opacity: 0; visibility: hidden; transform: translateY(-8px);
    transition: opacity .25s, transform .25s var(--ease), visibility 0s .25s;
  }
  .menu-open .site-nav { opacity: 1; visibility: visible; transform: none; transition: opacity .25s, transform .25s var(--ease); }
  .js-ready .site-nav a:not(.btn) { padding: 14px 0; border-bottom: 1px solid var(--line); color: var(--text); font-size: 1.4rem; font-weight: 800; }
  .js-ready .site-nav a[aria-current="page"] { color: var(--accent-text); }
  .js-ready .site-nav a[aria-current="page"]::after { display: none; }
  .js-ready .site-nav .nav-cta { margin-top: 24px; justify-content: center; padding: 1em; font-size: 1rem; }
  html:not(.js-ready) .site-header { background: var(--bg); border-bottom-color: var(--line); }
  html:not(.js-ready) .header-inner { height: auto; flex-wrap: wrap; padding-block: 12px; }
  html:not(.js-ready) .site-nav { flex-wrap: wrap; gap: 8px 18px; }

  .action-bar {
    position: fixed; inset: auto 0 0; z-index: 40;
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
    padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(15, 20, 25, .97); border-top: 1px solid var(--line);
  }
  .action-bar a {
    padding: 12px; border: 1px solid var(--line-strong); border-radius: var(--radius);
    font-weight: 800; letter-spacing: .04em; text-align: center; text-transform: uppercase; text-decoration: none;
  }
  .action-bar .action-quote { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
  .menu-open .action-bar { display: none; }
  body { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
}

/* ---------- Heroes ---------- */
.hero, .page-hero { position: relative; isolation: isolate; overflow: hidden; }
.hero { display: flex; align-items: center; min-height: min(92vh, 820px); padding: calc(var(--header-h) + 48px) 0 72px; }
.page-hero { padding: calc(var(--header-h) + 72px) 0 72px; border-bottom: 1px solid var(--line); }
.hero::before, .page-hero::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background:
    linear-gradient(180deg, transparent 75%, var(--bg)),
    linear-gradient(90deg, var(--bg) 30%, rgba(18, 19, 20, .55) 65%, rgba(18, 19, 20, .2)),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .035) 0 2px, transparent 2px 16px),
    radial-gradient(ellipse at 78% 45%, #3c3f43, #151617 60%);
}
.page-hero::before { opacity: .7; }
.hero-photo { position: absolute; inset: 0; z-index: -2; width: 100%; height: 100%; object-fit: cover; object-position: 70% center; }
/* With a hero image, keep the fades but drop the solid backdrop so the image shows. */
.hero:has(.hero-photo)::before {
  background:
    linear-gradient(180deg, transparent 75%, var(--bg)),
    linear-gradient(90deg, var(--bg) 30%, rgba(18, 19, 20, .55) 65%, rgba(18, 19, 20, .2));
}
.hero h1 em { font-style: normal; color: var(--accent-text); }
.hero .lead { margin-bottom: 2rem; }
.hero-content > *, .page-hero .wrap > * { animation: rise .8s var(--ease) backwards; }
.hero-content > :nth-child(2), .page-hero .wrap > :nth-child(2) { animation-delay: .08s; }
.hero-content > :nth-child(3), .page-hero .wrap > :nth-child(3) { animation-delay: .16s; }
.hero-content > :nth-child(4), .page-hero .wrap > :nth-child(4) { animation-delay: .24s; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
@media (min-width: 860px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stats-band { margin-top: -40px; position: relative; z-index: 1; }
.stat { background: var(--panel); padding: 28px 24px; }
.stat b { display: block; margin-bottom: 6px; font-size: clamp(1.8rem, 4vw, 2.6rem); font-weight: 900; line-height: 1; }
.stat .label { color: var(--muted); font-size: .9rem; }

/* ---------- Cards ---------- */
.card {
  position: relative; display: block; padding: 28px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none;
  transition: transform .25s var(--ease), box-shadow .25s, border-color .25s;
}
.section-alt .card { background: var(--bg); }
.card:hover { transform: translateY(-4px); box-shadow: 0 16px 40px rgba(0, 0, 0, .35); border-color: #3a3e43; }
.card p { margin: 0; color: var(--muted); }
.card .num { display: block; margin-bottom: 14px; font: 700 .8rem var(--mono); letter-spacing: .1em; color: var(--accent-text); }
.card .more { display: inline-block; margin-top: 16px; color: var(--accent-text); font-weight: 700; font-size: .9rem; }
.card h2 { font-size: 1.6rem; }
.card ul { margin: 1em 0 0; padding-left: 1.2em; color: var(--muted); }

/* ---------- Lists, tags, tables ---------- */
.checklist { display: grid; gap: 10px; margin: 0 0 1.5em; padding: 0; list-style: none; }
.checklist li { position: relative; padding-left: 28px; }
.checklist li::before { content: ""; position: absolute; left: 0; top: .5em; width: 10px; height: 10px; border: 2px solid var(--accent); transform: rotate(45deg); }
.tags { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 1.5em; padding: 0; list-style: none; }
.tags li { padding: 6px 12px; border: 1px solid var(--line-strong); border-radius: 999px; color: var(--muted); font-size: .9rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; min-width: 560px; border-collapse: collapse; font-size: .95rem; }
th, td { padding: 14px 18px; border-bottom: 1px solid var(--line); text-align: left; }
th { background: var(--panel); color: var(--muted); font: 700 .75rem var(--mono); letter-spacing: .12em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }

/* ---------- Image placeholders (swap for <img> when real photos arrive) ---------- */
.ph {
  display: grid; place-items: center; aspect-ratio: var(--ratio, 4 / 3); padding: 16px;
  background: repeating-linear-gradient(45deg, rgba(255, 255, 255, .03) 0 2px, transparent 2px 14px), var(--panel-2);
  border: 1px dashed var(--line-strong); border-radius: var(--radius);
  color: var(--muted); font: 600 .8rem/1.4 var(--mono); letter-spacing: .08em; text-align: center; text-transform: uppercase;
}

/* Stand-in drawings (tools/drawings.py) sit where photos will go. */
.drawing { width: 100%; border: 1px solid var(--line); border-radius: var(--radius); }

/* Shop photos (4:3 in split sections, 3:4 in the gallery). */
.photo { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); }
.gallery .photo { aspect-ratio: 3 / 4; }

/* ---------- Quote band ---------- */
.quote-band { padding: clamp(48px, 8vw, 80px) 0; background: var(--accent); color: var(--accent-ink); }
.quote-band .wrap { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 24px; }
.quote-band h2 { margin: 0; }
.quote-band p { margin: .5em 0 0; font-weight: 600; }

/* ---------- Contact ---------- */
.contact-actions { display: grid; gap: 16px; margin-bottom: 48px; }
@media (min-width: 760px) { .contact-actions { grid-template-columns: 1fr 1fr; } }
.contact-card { padding: 32px; }
.contact-card .big { display: block; margin-top: 6px; font-size: clamp(1.3rem, 3vw, 1.9rem); font-weight: 900; overflow-wrap: anywhere; }
.contact-card.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.contact-card.primary p { color: var(--accent-ink); }
.info-card { padding: 28px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.info-card a { overflow-wrap: anywhere; }

/* ---------- Footer ---------- */
.site-footer { padding: 64px 0 0; border-top: 1px solid var(--line); font-size: .95rem; }
.footer-grid { display: grid; gap: 32px; }
@media (min-width: 760px) { .footer-grid { grid-template-columns: 1.4fr 1fr 1fr 1fr; } }
.footer-title { margin-bottom: 12px; color: var(--muted); font: 700 .75rem var(--mono); letter-spacing: .14em; text-transform: uppercase; }
.site-footer a { overflow-wrap: anywhere; }
.site-footer nav a { display: block; padding: 3px 0; color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--text); }
.footer-base { margin-top: 48px; padding-block: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; }
.footer-base p { margin: 0; }

/* ---------- Motion ---------- */
/* .js (inline script in <head>) only fixes the header layout before first paint. Anything that hides content
   or the phone menu waits for .js-ready, which site.js adds as its last step: if the script is missing or
   breaks, every section stays visible and the nav simply wraps. */
.js-ready [data-reveal] { opacity: 0; }
.js-ready [data-reveal].is-visible { opacity: 1; animation: rise .7s var(--ease) var(--reveal-delay, 0ms) backwards; }
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}
/* Page-change milling (site.js). .mill-in holds a plain steel cover until the script paints the real blank;
   if the script never runs the cover fades out by itself. */
.mill { position: fixed; inset: 0; z-index: 1000; pointer-events: none; }
.mill canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.mill-in body::after {
  content: ""; position: fixed; inset: 0; z-index: 1000; pointer-events: none;
  background: linear-gradient(to bottom right, #66696d, #9a9da1 45%, #55585c);
  animation: mill-failsafe .3s 1.5s forwards;
}
@keyframes mill-failsafe { to { opacity: 0; visibility: hidden; } }
/* Section headings (site.js wraps each main h2): the text is cut into view behind a spinning end mill. */
.mill-cut { position: relative; display: inline-block; }
.mill-text { display: inline-block; clip-path: inset(-.25em 100% -.25em 0); }
.mill-bit {
  position: absolute; top: 50%; left: 0; width: 1.3em; height: 1.3em; margin: -.65em 0 0 -.65em;
  opacity: 0; pointer-events: none;
}
.mill-bit > span {
  position: absolute; inset: 0; z-index: 1; border-radius: 50%;
  background:
    radial-gradient(circle, #121314 0 13%, #33363a 14% 30%, transparent 31%),
    radial-gradient(circle, transparent 0 30%, #1e2023 31% 58%, transparent 59%),
    repeating-conic-gradient(var(--accent) 0 20deg, #1e2023 20deg 60deg);
  box-shadow: inset 0 0 0 .05em #464b51, 0 .15em .4em rgba(0, 0, 0, .5);
  animation: mill-spin .25s linear infinite;
}
/* A thin bright line at the cut, plus a spray of chips trailing the bit. */
.mill-bit::before {
  content: ""; position: absolute; left: 50%; top: -.3em; bottom: -.3em; width: 2px; margin-left: -1px;
  background: linear-gradient(transparent, #d9dee3 30% 70%, transparent);
}
.mill-bit::after {
  content: ""; position: absolute; left: 0; top: 50%; width: 3px; height: 3px; border-radius: 50%;
  box-shadow: -.3em -.5em 0 var(--accent), -.6em .2em 0 #d9dee3, -.2em .55em 0 var(--accent),
    -.9em -.25em 0 #d9dee3, -1.1em .45em 0 var(--accent), -.5em -.8em 0 #d9dee3;
  animation: mill-chips .18s steps(2) infinite;
}
.is-milled .mill-text { animation: mill-sweep .9s cubic-bezier(.45, 0, .55, 1) forwards; }
.is-milled .mill-bit { animation: mill-travel .9s cubic-bezier(.45, 0, .55, 1) forwards; }
@keyframes mill-sweep { to { clip-path: inset(-.25em 0 -.25em 0); } }
@keyframes mill-travel {
  0% { left: 0; opacity: 0; }
  10% { opacity: 1; }
  85% { opacity: 1; }
  100% { left: 100%; opacity: 0; }
}
@keyframes mill-spin { to { transform: rotate(360deg); } }
@keyframes mill-chips { 50% { transform: rotate(40deg) scale(.8); opacity: .6; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .js-ready [data-reveal] { opacity: 1; }
  .card:hover, .btn:hover .arrow { transform: none; }
}
