@layer reset, base, components, pages, responsive;

/* ============================================================
   Agent Nocturne - Nocturne stage design system
   Dark-first. The keyboard is the only light source.
   ============================================================ */

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { scroll-behavior: smooth; }
  body, h1, h2, h3, p, ul, ol, dl, dd, pre { margin: 0; }
  ul, ol { padding: 0; list-style: none; }
  button, input, textarea, select { font: inherit; }
  img, svg { display: block; max-width: 100%; }
}

@layer base {
  :root {
    /* Nocturne dark stage (default) */
    --canvas:   oklch(14% 0.005 90);   /* warm near-black */
    --paper:    oklch(18% 0.005 90);   /* card / panel layer */
    --ink:      oklch(94% 0.005 90);   /* warm white */
    --muted:    oklch(62% 0.008 90);
    --hairline: oklch(25% 0.006 100);
    --signal:   oklch(76% 0.045 155);  /* forest green, lifted for dark */
    --signal-soft: oklch(30% 0.03 155);

    /* Keyboard stage - always dark (backlight needs dark optical env) */
    --stage-bg: oklch(7% 0.003 90);
    --keycap:   oklch(12% 0.004 90);
    --key-edge: oklch(22% 0.006 90);
    --light:    oklch(100% 0 0);

    --font-sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
    --font-mono: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
    --shell: 1280px;
    --page-pad: clamp(20px, 4vw, 64px);
    --radius: 3px;
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
  }

  /* Default: dark room (the nocturne stage). Declared explicitly so the
     room toggle is reversible and the dark values are co-located. */
  html[data-room="dark"] {
    --canvas:   oklch(14% 0.005 90);
    --paper:    oklch(18% 0.005 90);
    --ink:      oklch(94% 0.005 90);
    --muted:    oklch(62% 0.008 90);
    --hairline: oklch(25% 0.006 100);
    --signal:   oklch(76% 0.045 155);
    --signal-soft: oklch(30% 0.03 155);
  }

  /* Room lights on - paper-light editorial mode */
  :root[data-room="light"] {
    --canvas:   oklch(97.4% 0.004 100);
    --paper:    oklch(99% 0.002 100);
    --ink:      oklch(20% 0.008 90);
    --muted:    oklch(48% 0.008 90);
    --hairline: oklch(86% 0.006 100);
    --signal:   oklch(43% 0.035 155);
    --signal-soft: oklch(91% 0.018 155);
  }

  html {
    color: var(--ink);
    background: var(--canvas);
    font-family: var(--font-sans);
    font-synthesis: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 400ms var(--ease), color 400ms var(--ease);
  }

  body {
    min-width: 320px;
    min-height: 100dvh;
    background: var(--canvas);
    font-size: 16px;
    line-height: 1.55;
    overflow-x: hidden;
  }

  a { color: inherit; }
  button { color: inherit; }

  :focus-visible {
    outline: 2px solid var(--signal);
    outline-offset: 4px;
    border-radius: 2px;
  }

  ::selection { color: var(--ink); background: var(--signal-soft); }

  h1, h2, h3 {
    font-weight: 500;
    text-wrap: balance;
    letter-spacing: -0.02em;
  }

  h1 { font-size: clamp(2.9rem, 6vw, 5.5rem); line-height: 0.98; letter-spacing: -0.035em; }
  h2 { font-size: clamp(2.1rem, 4.2vw, 4rem); line-height: 1.02; letter-spacing: -0.028em; }
  h3 { font-size: clamp(1.25rem, 2vw, 1.75rem); line-height: 1.15; letter-spacing: -0.015em; }

  p { text-wrap: pretty; }
  code, pre { font-family: var(--font-mono); }

  html:lang(zh-CN) body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
    line-height: 1.75;
  }
  html:lang(zh-CN) h1, html:lang(zh-CN) h2, html:lang(zh-CN) h3 { letter-spacing: 0; }
  html:lang(zh-CN) h1 { font-size: clamp(2.6rem, 5vw, 4.4rem); }

  .shell { width: min(100%, var(--shell)); margin-inline: auto; padding-inline: var(--page-pad); }
  .section-space { padding-block: clamp(64px, 9vw, 140px); }
  .top-anchor { display: block; position: relative; top: -80px; visibility: hidden; }

  .skip-link {
    position: fixed; top: 12px; left: 12px; z-index: 100;
    padding: 10px 16px; border-radius: var(--radius);
    color: var(--canvas); background: var(--ink);
    transform: translateY(-180%); transition: transform 160ms var(--ease);
    font-size: 14px; text-decoration: none;
  }
  .skip-link:focus { transform: translateY(0); }

  .eyebrow {
    margin-bottom: 22px;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.16em;
    text-transform: uppercase;
  }

  .section-head { max-width: 60ch; margin-bottom: clamp(40px, 6vw, 72px); }
  .section-head h2 { margin-bottom: 20px; }
  .section-lede { max-width: 54ch; color: var(--muted); font-size: clamp(16px, 1.5vw, 19px); line-height: 1.6; }

  .button {
    display: inline-flex; min-height: 46px; align-items: center; justify-content: center;
    padding: 0 22px; border: 1px solid var(--ink); border-radius: var(--radius);
    font-size: 15px; font-weight: 500; line-height: 1; text-decoration: none; white-space: nowrap;
    touch-action: manipulation; cursor: pointer;
    transition: background-color 200ms var(--ease), color 200ms var(--ease), transform 120ms var(--ease);
  }
  .button:active { transform: translateY(1px); }
  .button-primary { color: var(--canvas); background: var(--ink); border-color: var(--ink); }

  .text-link {
    display: inline-flex; min-height: 46px; align-items: center;
    color: var(--ink); font-size: 15px; font-weight: 500; text-decoration: none;
    border-bottom: 1px solid var(--hairline);
    transition: color 160ms var(--ease), border-color 160ms var(--ease);
  }

}

@layer components {
  /* ---------- Header ---------- */
  .site-header {
    position: sticky; top: 0; z-index: 50;
    border-bottom: 1px solid var(--hairline);
    background: var(--canvas);
  }
  .nav-shell {
    display: flex; min-height: 68px; align-items: center; justify-content: space-between; gap: 24px;
  }
  .wordmark {
    display: inline-flex; align-items: center; gap: 10px;
    font-size: 16px; font-weight: 500; letter-spacing: -0.01em; text-decoration: none; white-space: nowrap;
  }
  .wordmark-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--light);
    box-shadow: 0 0 8px 2px oklch(100% 0 0 / 0.7);
    animation: dot-breath 4.8s infinite var(--ease);
  }
  @keyframes dot-breath {
    0%, 100% { opacity: 0.28; box-shadow: 0 0 4px 1px oklch(100% 0 0 / 0.4); }
    44%, 52% { opacity: 1; box-shadow: 0 0 10px 3px oklch(100% 0 0 / 0.8); }
  }
  .primary-nav { display: flex; align-items: center; gap: clamp(18px, 2.4vw, 32px); }
  .primary-nav a, .nav-toggle {
    position: relative; min-height: 40px; display: inline-flex; align-items: center;
    color: var(--muted); font-size: 14px; text-decoration: none; background: none; border: 0; cursor: pointer;
    transition: color 160ms var(--ease);
  }
  .primary-nav a:hover, .nav-toggle:hover { color: var(--ink); }
  .nav-toggle { font-family: var(--font-mono); font-size: 13px; letter-spacing: 0.06em; }
  .menu-button {
    display: none; min-width: 44px; min-height: 40px; padding: 0; border: 0; background: transparent;
    font-size: 14px; text-decoration: underline; text-underline-offset: 5px; cursor: pointer;
  }

  /* ---------- Keyboard stage ---------- */
  .stage {
    position: relative;
    padding: clamp(20px, 3vw, 36px);
    border-radius: 6px;
    background: var(--stage-bg);
    border: 1px solid oklch(20% 0.005 90);
    overflow: hidden;
  }
  .stage-glow {
    position: absolute; inset: 0; pointer-events: none; z-index: 0;
    box-shadow: inset 0 0 120px 40px oklch(100% 0 0 / 0.06);
    animation: stage-glow 4.8s infinite var(--ease);
  }
  @keyframes stage-glow {
    0%, 100% { opacity: 0.08; }
    44%, 52% { opacity: 0.34; }
  }
  .demo-meta {
    position: relative; z-index: 1;
    display: flex; align-items: center; gap: 14px;
    margin-bottom: clamp(14px, 2vw, 20px);
  }
  .demo-state { font-size: 15px; font-weight: 500; color: var(--light); }
  .demo-cadence {
    flex: 1; margin-left: 4px;
    color: oklch(70% 0.004 90); font-family: var(--font-mono); font-size: 11px;
    font-variant-numeric: tabular-nums; letter-spacing: 0.04em;
  }

  /* Light switch controls removed from the page; the product owns on/off
     via `nocturne pause` / `nocturne resume`. */

  .keyboard {
    position: relative; z-index: 1;
    display: flex; flex-direction: column;
    gap: clamp(3px, 0.5vw, 6px);
  }
  html:not(.js) .keyboard { display: none; }
  .keyboard-fallback {
    display: block; width: 100%; height: auto;
    border-radius: 4px; border: 1px solid var(--hairline);
  }
  .key-row { display: flex; gap: clamp(3px, 0.5vw, 6px); }
  .key-row:first-child .key { height: clamp(18px, 2.2vw, 28px); } /* half-height function row */
  .key {
    position: relative; flex: var(--key-size, 1) 1 0; min-width: 0;
    height: clamp(26px, 3.2vw, 42px);
    border-radius: 3px;
    background: var(--keycap);
    border: 1px solid var(--key-edge);
    box-shadow: inset 0 1px 0 oklch(28% 0.005 90);
    display: flex; align-items: center; justify-content: center;
  }
  .key-label {
    color: var(--light);
    font-family: var(--font-sans); font-size: clamp(5px, 0.72vw, 9px); font-weight: 500;
    line-height: 1; opacity: var(--backlight);
  }

  /* Backlight cadences - only the shared --backlight channel changes.
     Geometry stays fixed. Values mirror src/effects.mjs. */
  @property --backlight { syntax: "<number>"; inherits: true; initial-value: 0.18; }

  .keyboard[data-state="thinking"] { animation: bk-thinking 4.8s infinite var(--ease); }
  .keyboard[data-state="tool"] { animation: bk-tool 1.8s infinite ease-in-out; }
  .keyboard[data-state="permission"] { animation: bk-permission 540ms infinite steps(1, end); }
  .keyboard[data-state="waiting"] { animation: bk-waiting 2.5s infinite steps(1, end); }
  .keyboard[data-state="done"] { animation: bk-done 1.2s 1 var(--ease) forwards; }
  .keyboard[data-state="error"] { animation: bk-error 760ms 1 steps(1, end) forwards; }

  @keyframes bk-thinking {              /* breath 4.8s: 38% inhale, 12% hold, 42% exhale, 8% rest */
    0%  { --backlight: 0.05; }
    38% { --backlight: 0.86; }
    50% { --backlight: 0.86; }
    92% { --backlight: 0.05; }
    100%{ --backlight: 0.05; }
  }
  @keyframes bk-tool {                  /* sine 1.8s, 0.10-0.32 */
    0%, 100% { --backlight: 0.14; }
    50% { --backlight: 0.40; }
  }
  @keyframes bk-permission {            /* 540ms blink, 59% on (high contrast) */
    0%, 58% { --backlight: 1; }
    59%, 100% { --backlight: 0.08; }
  }
  @keyframes bk-waiting {               /* double tap every 2.5s (140ms on) */
    0%, 5% { --backlight: 0.92; }
    6%, 100% { --backlight: 0.10; }
  }
  @keyframes bk-done {                  /* completionExhale 1.2s one-shot */
    0%  { --backlight: 0.16; }
    25%, 35% { --backlight: 0.80; }
    100% { --backlight: 0.12; }
  }
  @keyframes bk-error {                 /* 4 x (90ms on / 90ms off) stutter one-shot */
    0%, 11%, 24%, 35%, 48% { --backlight: 1; }
    12%, 23%, 36%, 47%, 60%, 100% { --backlight: 0.06; }
  }

  /* Demo toggles */
  .demo-toggles { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: clamp(16px, 2.4vw, 24px); }
  .demo-toggles button {
    position: relative; min-height: 40px; padding: 0; border: 0; background: transparent;
    color: var(--muted); font-size: 13px; cursor: pointer; touch-action: manipulation;
    transition: color 160ms var(--ease);
  }
  .demo-toggles button[aria-pressed="true"] { color: var(--ink); }
  .demo-toggles button[aria-pressed="true"]::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: 2px; height: 2px; background: var(--signal);
  }

  /* ---------- Code blocks (terminal panels, always dark) ---------- */
  .code-block {
    position: relative;
    border-radius: var(--radius);
    background: oklch(9% 0.004 90);
    border: 1px solid oklch(20% 0.005 90);
    min-width: 0;
  }
  .code-block pre {
    overflow-x: auto;
    padding: 26px 92px 26px 24px;
    color: oklch(90% 0.004 90);
    font-family: var(--font-mono); font-size: 13px; line-height: 1.8; tab-size: 2;
  }
  .copy-button {
    position: absolute; top: 14px; right: 14px;
    min-width: 54px; min-height: 34px; padding: 0 12px;
    border: 1px solid oklch(28% 0.006 90); border-radius: var(--radius);
    background: oklch(15% 0.004 90); color: oklch(80% 0.004 90);
    font-size: 12px; cursor: pointer; touch-action: manipulation;
    transition: color 160ms var(--ease), border-color 160ms var(--ease);
  }
  .copy-button:hover { color: var(--signal); border-color: var(--signal); }
  .copy-button:active { transform: translateY(1px); }
  .copy-status { position: absolute; right: 14px; bottom: 8px; color: var(--signal); font-size: 11px; }

  /* ---------- Footer ---------- */
  .site-footer { border-top: 1px solid var(--hairline); margin-top: clamp(40px, 6vw, 80px); }
  .footer-inner {
    display: flex; min-height: 110px; align-items: center; justify-content: space-between; gap: 28px;
    color: var(--muted); font-size: 13px;
  }
  .footer-inner nav { display: flex; flex-wrap: wrap; gap: 12px 26px; }
  .footer-inner a { text-underline-offset: 4px; color: var(--muted); text-decoration: none; transition: color 160ms var(--ease); }
  .footer-inner a:hover { color: var(--ink); }
}

@layer pages {
  /* ---------- Hero ---------- */
  .hero {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(420px, 6fr);
    align-items: center;
    gap: clamp(40px, 7vw, 110px);
    min-height: calc(100dvh - 69px);
    padding-block: clamp(48px, 7vw, 96px) clamp(40px, 5vw, 72px);
  }
  .hero-copy .eyebrow { margin-bottom: 26px; }
  .hero-copy h1 { max-width: 12ch; }
  .hero-lede {
    max-width: 30ch; margin-top: 28px;
    color: var(--muted); font-size: clamp(16px, 1.5vw, 20px); line-height: 1.55;
  }
  .hero-actions { display: flex; align-items: center; gap: 22px; margin-top: 36px; }
  .hero-stage { width: 100%; }

  /* ---------- Host line ---------- */
  .host-line { border-block: 1px solid var(--hairline); }
  .host-line-inner {
    display: flex; min-height: 88px; align-items: center; justify-content: space-between; gap: 28px;
  }
  .host-line p { color: var(--muted); font-size: 14px; font-family: var(--font-mono); letter-spacing: 0.02em; }
  .host-line ul { display: flex; gap: clamp(26px, 5vw, 64px); font-size: 15px; font-weight: 500; }

  /* ---------- Install ---------- */
  .install-core, .install-adapters, .install-verify {
    display: grid; grid-template-columns: minmax(120px, 3fr) minmax(0, 9fr);
    gap: clamp(28px, 4vw, 64px);
    padding-block: clamp(32px, 4vw, 48px);
    border-bottom: 1px solid var(--hairline);
  }
  .install-verify:last-of-type { border-bottom: 0; }
  .install-core h3, .install-adapters h3, .install-verify h3 {
    margin: 0;
    font-family: var(--font-mono); font-size: 12px; font-weight: 500;
    letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted);
  }
  .install-tabs { display: flex; flex-wrap: wrap; gap: 8px 24px; margin-bottom: 20px; }
  .install-tabs button {
    position: relative; min-height: 40px; padding: 0; border: 0; background: transparent;
    color: var(--muted); font-size: 13px; cursor: pointer;
    transition: color 160ms var(--ease);
  }
  .install-tabs button[aria-selected="true"] { color: var(--ink); }
  .install-tabs button[aria-selected="true"]::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: 2px; height: 2px; background: var(--signal);
  }
  .install-panels { min-width: 0; }
  .install-verify .code-block-compact pre { min-height: 0; }

  /* ---------- Local facts (quiet spec line) ---------- */
  .fact-strip {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px;
    background: var(--hairline);
    border-block: 1px solid var(--hairline);
  }
  .fact-strip li {
    display: flex; flex-direction: column; gap: 6px;
    padding: 22px clamp(16px, 2vw, 32px);
    background: var(--canvas);
  }
  .fact-strip span {
    color: var(--muted); font-size: 11px; font-family: var(--font-mono);
    letter-spacing: 0.08em; text-transform: uppercase;
  }
  .fact-strip strong { font-size: 15px; font-weight: 500; color: var(--ink); }

  /* ---------- Closing (quiet) ---------- */
  .closing { padding-block: clamp(64px, 9vw, 120px); }
  .closing-line {
    margin: 0; color: var(--muted);
    font-size: clamp(15px, 1.5vw, 19px); font-style: normal;
    letter-spacing: 0.01em;
  }
}

@layer responsive {
  @media (hover: hover) {
    .button-primary:hover { background: var(--signal); border-color: var(--signal); color: var(--canvas); }
    .text-link:hover { color: var(--signal); border-color: var(--signal); }
    .primary-nav a:hover { color: var(--ink); }
  }

  @media (max-width: 1000px) {
    .install-core, .install-adapters, .install-verify {
      grid-template-columns: minmax(0, 1fr); gap: 20px;
    }
    .fact-strip { grid-template-columns: repeat(2, 1fr); }
  }

  @media (max-width: 880px) {
    .hero {
      grid-template-columns: minmax(0, 1fr);
      min-height: auto; gap: 48px; padding-top: 40px;
    }
  }

  @media (max-width: 760px) {
    html { scroll-behavior: auto; }
    h1 { font-size: clamp(2.4rem, 12vw, 3.6rem); }
    h2 { font-size: clamp(1.9rem, 9vw, 3rem); }
    .section-space { padding-block: 64px; }

    .nav-shell { min-height: 60px; flex-wrap: wrap; gap: 0; }
    .js .menu-button { display: inline-flex; align-items: center; }
    .primary-nav {
      width: 100%; flex-direction: column; align-items: flex-start; gap: 0;
      padding: 8px 0 16px;
    }
    .js .primary-nav { display: none; }
    .js .primary-nav[data-open="true"] { display: flex; }
    .primary-nav a, .nav-toggle { width: 100%; min-height: 44px; justify-content: flex-start; }

    .hero { padding-top: 24px; gap: 32px; }
    .stage { padding: 14px; }
    .demo-meta { margin-bottom: 12px; }

    .host-line-inner { flex-direction: column; align-items: flex-start; justify-content: center; min-height: 100px; gap: 12px; }
    .host-line ul { width: 100%; justify-content: space-between; gap: 12px; }

    .code-block pre { padding: 60px 16px 20px; font-size: 11px; line-height: 1.7; }
    .copy-button { top: 10px; right: 10px; }

    .footer-inner { flex-direction: column; align-items: flex-start; justify-content: center; padding-block: 28px; }
  }

  @media (max-width: 430px) {
    :root { --page-pad: 18px; }
    .hero-actions { gap: 16px; flex-wrap: wrap; }
    .button { padding-inline: 18px; }
    .key { height: 22px; }
    .key-row:first-child .key { height: 16px; }
    .key-label { font-size: 5px; }
    .demo-toggles { gap: 4px 16px; }
    .fact-strip { grid-template-columns: 1fr; }
  }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      scroll-behavior: auto !important;
      animation-duration: 1ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 1ms !important;
    }
    .key-label { opacity: 0.5 !important; }
    .wordmark-dot, .stage-glow { opacity: 0.5 !important; }
  }

  @media print {
    .menu-button, .demo-toggles, .copy-button, .nav-toggle, .hero-actions { display: none; }
    body { background: white; color: black; }
    .hero { min-height: auto; }
  }
}
