@layer reset, base, components, responsive;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, p, ul { margin: 0; }
  button, input, select { font: inherit; }
  button, a, input, select { -webkit-tap-highlight-color: transparent; }
  button, select { cursor: pointer; }
  a { color: inherit; text-decoration: none; }
  button { color: inherit; }
  img, svg { max-width: 100%; display: block; }
  [hidden] { display: none !important; }
}

@layer base {
  :root {
    color-scheme: light;
    --brand: #34538b;
    --brand-ink: #34538b;
    --paper: #f8f9fc;
    --panel: #fff;
    --ink: #1c283d;
    --muted: #59677b;
    --line: #dce2ec;
    --wash: #edf1f8;
    --wash-strong: #e1e8f3;
    --focus: #34538b;
    --shadow: 0 22px 60px #182c4d12;
    --sans: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    --serif: Georgia, 'Times New Roman', serif;
    --mono: Consolas, 'Liberation Mono', monospace;
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.65;
    background: var(--paper);
    color: var(--ink);
    scroll-behavior: smooth;
    scroll-padding-top: 2rem;
  }
  :root[data-theme='dark'] {
    color-scheme: dark;
    --brand-ink: #a9bfe7;
    --paper: #131b28;
    --panel: #1a2535;
    --ink: #edf1fa;
    --muted: #a8b6cd;
    --line: #344158;
    --wash: #202f46;
    --wash-strong: #2c3d58;
    --focus: #b6cdf5;
    --shadow: 0 22px 60px #0002;
  }
  body { min-width: 0; }
  ::selection { background: var(--brand); color: #fff; }
  :focus-visible { outline: 3px solid var(--focus); outline-offset: 5px; border-radius: 2px; }
  h1, h2 { font-family: var(--serif); font-weight: 400; }
  h1 { font-size: clamp(3.3rem, 6.7vw, 6.4rem); line-height: 1.04; letter-spacing: -.055em; }
  h1 em { color: var(--brand-ink); font-weight: 400; }
  h2 { font-size: clamp(1.8rem, 3vw, 2.7rem); line-height: 1.17; letter-spacing: -.035em; }
  h3 { font-weight: 500; font-size: 1.18rem; line-height: 1.35; letter-spacing: -.025em; }
  .wrap { width: min(1180px, calc(100% - 112px)); margin-inline: auto; }
  .mono { font-family: var(--mono); }
  .eyebrow { font: 400 .67rem/1.6 var(--mono); letter-spacing: .11em; text-transform: uppercase; color: var(--brand-ink); }
  .status-dot { display: inline-block; height: 6px; width: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
  .skip-link { position: absolute; z-index: 10; left: 16px; top: 12px; padding: 12px; background: var(--panel); transform: translateY(-150%); }
  .skip-link:focus { transform: none; }
  .text-link { display: inline-flex; align-items: center; gap: 14px; font-size: .8rem; border-bottom: 1px solid transparent; padding-block: 5px; }
  .text-link:hover { border-color: var(--brand-ink); color: var(--brand-ink); }
  .link-arrow { font-size: 1.1rem; font-family: var(--sans); display: inline-block; transition: transform .2s ease; }
  .button { display: inline-flex; justify-content: center; align-items: center; gap: 24px; padding: 13px 21px; min-height: 46px; border: 1px solid transparent; border-radius: 5px; font-size: .8rem; transition: background .2s, transform .2s; }
  .button:hover { transform: translateY(-2px); }
  .button-primary { background: var(--brand); color: #fff; }
  .button-primary:hover { background: #294573; }
  .button-secondary { background: var(--panel); border-color: var(--line); }
  .button-quiet { background: transparent; padding-inline: 8px; }
  .button-quiet:hover { background: var(--wash); }
  .text-button { background: transparent; border: 0; font-size: .72rem; padding: 8px 0 8px 12px; }
}

@layer components {
  .site-header { display: flex; justify-content: space-between; align-items: center; gap: 30px; padding-block: 29px; }
  .brand { display: inline-flex; align-items: center; gap: 11px; font-size: 1.48rem; letter-spacing: -.06em; font-weight: 500; white-space: nowrap; }
  .brand-dot { color: var(--brand-ink); }
  .brand-mark { display: grid; place-items: center; width: 33px; height: 33px; border-radius: 7px; background: var(--brand); color: #fff; font: 400 27px/1 var(--serif); letter-spacing: -2px; padding-right: 3px; }
  .header-right, #navigation { display: flex; align-items: center; gap: 29px; }
  #navigation a { font-size: .79rem; color: var(--muted); padding-block: 9px; position: relative; }
  #navigation a::after { content: ''; position: absolute; height: 2px; inset: auto 0 0; background: var(--brand-ink); transform: scaleX(0); transform-origin: left; transition: transform .2s; }
  #navigation a:hover, #navigation a[aria-current] { color: var(--ink); }
  #navigation a[aria-current]::after, #navigation a:hover::after { transform: scaleX(1); }
  .theme-toggle { display: grid; place-items: center; background: transparent; border: 1px solid var(--line); border-radius: 50%; width: 34px; height: 34px; font-size: 21px; line-height: 1; }
  .theme-toggle:hover { background: var(--wash); }
  .menu-toggle { display: none; background: transparent; border: 0; font-size: .8rem; padding: 10px 0; gap: 12px; }
  .hero { display: grid; grid-template-columns: 1.08fr 1fr; align-items: center; gap: 65px; padding-block: 72px 81px; }
  .hero-copy, .hero-terminal { min-width: 0; }
  .hero-eyebrow { display: flex; align-items: center; gap: 9px; }
  .hero h1 { margin-block: 25px 26px; }
  .hero-intro { max-width: 385px; font-size: .95rem; line-height: 1.8; color: var(--muted); }
  .hero-actions { display: flex; align-items: center; gap: 15px; flex-wrap: wrap; margin-top: 29px; }
  .hero-terminal { padding-top: 24px; }
  .terminal { background: #17253d; color: #e2eafa; border-radius: 10px; box-shadow: var(--shadow); transform: rotate(1.3deg); overflow: hidden; font-family: var(--mono); }
  .terminal-bar { display: flex; gap: 15px; align-items: center; padding: 14px 18px; border-bottom: 1px solid #34435d; color: #b3c1d9; font-size: .63rem; }
  .terminal-dots { display: flex; gap: 5px; }
  .terminal-dots i { width: 6px; height: 6px; border-radius: 50%; background: #91a5c8; }
  .terminal-language { margin-left: auto; color: #a4b5d1; }
  .terminal-code { padding: 27px 26px 22px; font-size: .75rem; line-height: 2; overflow-wrap: anywhere; }
  .code-lines { margin-block: 22px 25px; }
  .code-keyword, .terminal-prompt { color: #b5ccf6; }
  .code-string { color: #e6d6b0; }
  .code-comment { color: #a9b9d2; font-size: .66rem; }
  .last-prompt { margin-top: 7px; }
  .terminal-status { border-top: 1px solid #34435d; padding: 8px 18px; display: flex; justify-content: space-between; font-size: .58rem; color: #b3c1d9; }
  .terminal-status span:first-child { display: inline-flex; align-items: center; gap: 7px; }
  .terminal-footnote { text-align: right; color: var(--muted); font-size: .62rem; margin-top: 22px; }
  .topics { border-block: 1px solid var(--line); padding-block: 17px; display: flex; justify-content: space-between; gap: 20px; font: .68rem/1.6 var(--mono); color: var(--muted); flex-wrap: wrap; }
  .topics-title { color: var(--ink); }
  .topics small { color: var(--brand-ink); font: inherit; margin-right: 5px; }
  .section { padding-top: 57px; }
  .section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
  .section-heading h2 { margin-top: 9px; }
  .editorial-note { color: var(--muted); font-size: .71rem; line-height: 1.7; }
  .section > .editorial-note { margin-top: -7px; margin-bottom: 23px; }
  .project-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 24px; }
  .project-card { min-width: 0; display: block; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); transition: box-shadow .2s, transform .2s; }
  .project-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
  .project-card:hover .link-arrow, .article-row:hover .link-arrow { transform: translate(2px, -2px); }
  .project-visual { height: 222px; display: flex; justify-content: center; align-items: center; padding: 28px; background: var(--wash); position: relative; overflow: hidden; }
  .chat-preview { width: 100%; max-width: 337px; transform: rotate(-3deg); display: flex; flex-direction: column; gap: 10px; font: .7rem/1.5 var(--mono); }
  .chat-label { color: var(--muted); font-size: .6rem; display: flex; align-items: center; gap: 7px; padding-left: 5px; }
  .chat-message { padding: 12px 16px; border-radius: 10px; max-width: 92%; }
  .question { background: var(--brand); color: #fff; align-self: flex-end; border-bottom-right-radius: 2px; }
  .answer { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-bottom-left-radius: 2px; align-self: flex-start; }
  .answer span { display: block; font-size: .59rem; color: var(--muted); margin-top: 5px; }
  .workflow-visual { flex-direction: column; gap: 21px; background: var(--wash-strong); }
  .workflow { display: flex; align-items: center; gap: 11px; font: .65rem var(--mono); max-width: 100%; }
  .workflow > span { display: grid; gap: 8px; padding: 13px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; min-width: 0; }
  .workflow small { color: var(--brand-ink); font-size: .55rem; }
  .workflow i { font-style: normal; color: var(--muted); }
  .workflow-caption { font: .58rem var(--mono); color: var(--muted); }
  .project-caption { padding: 24px; }
  .card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; justify-content: space-between; }
  .project-state { font: .6rem/1.5 var(--mono); color: var(--muted); padding: 4px 7px; border-radius: 4px; background: var(--wash); white-space: nowrap; }
  .project-caption h3 { margin-block: 11px 9px; display: flex; justify-content: space-between; align-items: start; gap: 15px; }
  .project-caption p { color: var(--muted); font-size: .79rem; max-width: 350px; }
  .tags { display: flex; flex-wrap: wrap; gap: 13px; margin-top: 20px; }
  .tags span { font: .6rem/1.4 var(--mono); color: var(--muted); }
  .tags span::before { content: '#'; color: var(--brand-ink); }
  .home-notebook { display: grid; grid-template-columns: .85fr 1.15fr; gap: 57px; margin-top: 72px; }
  .home-notebook h2 { font-size: clamp(1.6rem, 2.4vw, 2.1rem); }
  .pattern-tool { background: var(--wash); padding: 24px; border: 1px solid var(--line); border-radius: 7px; }
  .lab-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 15px; }
  .pattern-preview { width: 100%; aspect-ratio: 1.85; display: grid; place-items: center; padding-block: 22px; }
  .pattern-preview svg { width: 100%; height: 100%; max-height: 420px; }
  .compact { padding: 16px 20px; }
  .compact .pattern-preview { aspect-ratio: 2.7; padding-block: 8px; }
  .lab-caption { color: var(--muted); font-size: .62rem; }
  .section-intro { color: var(--muted); font-size: .8rem; margin-block: 19px 11px; }
  .article-row { display: grid; grid-template-columns: 22px 1fr 17px; gap: 14px; align-items: start; border-top: 1px solid var(--line); padding-block: 18px; }
  .article-row > .link-arrow { margin-top: 16px; }
  .article-row h3 { font-size: .91rem; margin-block: 5px; line-height: 1.5; }
  .article-row:hover h3 { color: var(--brand-ink); }
  .article-row p { color: var(--muted); font-size: .73rem; }
  .article-index { color: var(--muted); font-size: .65rem; padding-top: 3px; }
  .article-time { color: var(--muted); text-transform: none; letter-spacing: 0; }
  .article-row .eyebrow { font-size: .59rem; }
  .about-strip { display: grid; grid-template-columns: .5fr 1fr 1fr; gap: 30px; align-items: start; border-block: 1px solid var(--line); padding-block: 36px; margin-top: 72px; }
  .about-strip h2 { font-size: 1.9rem; }
  .about-strip > .eyebrow { padding-top: 7px; }
  .about-strip p { color: var(--muted); font-size: .8rem; margin-bottom: 13px; }
  .site-footer { display: flex; align-items: center; flex-wrap: wrap; gap: 23px; padding-block: 34px; margin-top: 45px; font-size: .68rem; color: var(--muted); }
  .footer-brand { font-size: 1.45rem; gap: 0; color: var(--ink); }
  .site-footer p { margin-right: auto; }
  .site-footer a:not(.brand):hover { color: var(--brand-ink); }
  .copyright { font: .6rem var(--mono); }
  .page-intro { padding-block: 73px 57px; }
  .page-intro h1 { margin-block: 22px 27px; max-width: 900px; }
  .page-intro > p:not(.eyebrow) { max-width: 560px; color: var(--muted); font-size: 1rem; }
  .portfolio-section > .editorial-note { margin-top: 24px; max-width: 680px; }
  .next-section { border-top: 1px solid var(--line); margin-top: 65px; padding-block: 35px 0; }
  .next-section h2 { margin-block: 12px 14px; max-width: 660px; }
  .next-section > p { max-width: 600px; color: var(--muted); font-size: .9rem; margin-bottom: 14px; }
  .lab-section .pattern-tool { padding: 28px; }
  .lab-controls { display: flex; gap: 25px; align-items: end; flex-wrap: wrap; padding-block: 22px; border-top: 1px solid var(--line); }
  .lab-controls label { display: grid; gap: 8px; font-size: .75rem; min-width: 115px; }
  .lab-controls label:has(input[type='range']) { flex: 1; position: relative; }
  [data-density-label] { position: absolute; top: 0; right: 0; }
  .lab-controls select { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 11px 30px 11px 12px; color: var(--ink); font-size: .85rem; min-height: 44px; }
  .lab-controls input[type='color'] { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 4px; padding: 5px; background: var(--panel); cursor: pointer; }
  .lab-controls input[type='range'] { height: 44px; width: 100%; margin: 0; accent-color: var(--brand); }
  .lab-controls .button { min-height: 44px; }
  .lab-notes { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 30px; }
  .lab-notes h3 { font-size: 1rem; margin-bottom: 10px; }
  .lab-notes p { font-size: .83rem; color: var(--muted); max-width: 440px; }
  .blog-section { max-width: 850px; }
  .blog-section .article-row { padding-block: 26px; }
  .blog-section .article-row h3 { font-size: 1.3rem; }
  .blog-section .article-row p { font-size: .88rem; }
  .draft-notice { background: var(--wash); color: var(--muted); border-left: 2px solid var(--brand-ink); padding: 15px 20px; font-size: .75rem; line-height: 1.7; }
  .blog-section .draft-notice { margin-bottom: 30px; }
  .detail-page { max-width: 890px; padding-top: 44px; }
  .back-link { color: var(--muted); font-size: .72rem; }
  .back-link:hover { color: var(--brand-ink); }
  .detail-header { margin-block: 42px; }
  .detail-header .card-meta { justify-content: flex-start; }
  .detail-header h1 { font-size: clamp(2.7rem, 5.5vw, 4.5rem); margin-block: 22px; line-height: 1.1; }
  .detail-lead { font-size: 1.07rem; color: var(--muted); max-width: 720px; }
  .detail-page > .project-visual { border-radius: 8px; height: 290px; }
  .reading-content { max-width: 670px; margin-inline: auto; }
  .reading-content section { margin-block: 42px; position: relative; }
  .reading-content h2 { font-size: 1.8rem; margin-bottom: 16px; }
  .reading-content p { color: var(--muted); font-size: 1rem; line-height: 1.95; }
  .reading-number { color: var(--brand-ink); display: block; margin-bottom: 9px; font-size: .65rem; }
  .detail-page > .draft-notice { margin-block: 30px 23px; }
  .draft-notice .status-dot { margin-right: 8px; color: var(--brand-ink); }
  .byline { display: flex; align-items: center; gap: 12px; font-size: .8rem; margin-top: 30px; }
  .byline small { display: block; font: .62rem var(--mono); color: var(--muted); margin-top: 3px; }
  .avatar { display: grid; place-items: center; background: var(--wash-strong); color: var(--brand-ink); font: 1.5rem var(--serif); width: 40px; height: 40px; border-radius: 50%; }
  .related-note { border-top: 1px solid var(--line); margin-top: 35px; padding-top: 25px; }
  .related-note > a { display: block; font: 1.6rem/1.3 var(--serif); margin-top: 10px; }
  .related-note > a:hover { color: var(--brand-ink); }
  .about-content { display: grid; grid-template-columns: .55fr 1.2fr; gap: 80px; align-items: start; }
  .about-monogram { background: var(--brand); color: #fff; border-radius: 7px; min-height: 300px; display: grid; place-items: center; font: 150px var(--serif); letter-spacing: -.08em; }
  .about-content .reading-content section:first-child { margin-top: 0; }
  .not-found .button { margin-top: 25px; }
}

@layer responsive {
  @media (min-width: 1500px) { .hero { padding-block: 95px 100px; } }
  @media (max-width: 1060px) {
    .wrap { width: calc(100% - 72px); }
    .hero { gap: 35px; padding-top: 50px; }
    .hero h1 { font-size: 5rem; }
    .terminal-code { padding: 22px 19px; font-size: .66rem; }
    .terminal-language { display: none; }
    .home-notebook { gap: 32px; }
    .workflow { gap: 7px; }
    .workflow > span { padding: 12px 9px; }
    .about-strip { grid-template-columns: 1fr 1fr; }
    .about-strip > .eyebrow { grid-column: 1 / -1; }
    .copyright { width: 100%; }
  }
  @media (max-width: 760px) {
    .wrap { width: calc(100% - 40px); }
    .site-header { padding-block: 20px; flex-wrap: wrap; gap: 16px; position: relative; }
    .brand { font-size: 1.3rem; }
    .brand-mark { width: 29px; height: 29px; font-size: 24px; }
    .header-right { gap: 17px; }
    .theme-toggle { width: 32px; height: 32px; }
    .menu-toggle { display: inline-flex; }
    #navigation { display: none; position: absolute; top: calc(100% - 2px); left: 0; right: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 14px 18px; z-index: 5; box-shadow: var(--shadow); gap: 4px; }
    #navigation.is-open { display: grid; }
    #navigation a { min-height: 44px; padding: 11px 4px; }
    #navigation a::after { display: none; }
    #navigation a[aria-current] { color: var(--brand-ink); }
    .hero { grid-template-columns: 1fr; gap: 30px; padding-block: 39px 40px; }
    .hero h1 { font-size: clamp(3.6rem, 11vw, 5.5rem); margin-block: 21px; }
    .hero-intro { max-width: 420px; font-size: .9rem; }
    .hero-eyebrow { font-size: .59rem; letter-spacing: .07em; }
    .hero-terminal { padding: 0; }
    .terminal { transform: none; }
    .terminal-code { font-size: .74rem; padding: 23px; }
    .terminal-language { display: block; }
    .terminal-footnote { font-size: .59rem; }
    .topics { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; font-size: .59rem; }
    .topics-title { grid-column: 1 / -1; }
    .section { padding-top: 40px; }
    .section-heading { gap: 12px; align-items: flex-start; flex-wrap: wrap; }
    .section-heading .text-link { font-size: .71rem; padding-top: 12px; }
    .project-grid, .home-notebook, .lab-notes, .about-content { grid-template-columns: 1fr; }
    .project-grid { gap: 22px; }
    .project-visual { height: 205px; padding: 23px; }
    .project-caption { padding: 21px; }
    .project-caption h3 { font-size: 1.16rem; }
    .card-meta { gap: 8px; }
    .project-state { font-size: .58rem; }
    .workflow { gap: 10px; }
    .workflow > span { padding: 13px; }
    .home-notebook { gap: 42px; margin-top: 45px; }
    .home-notebook h2 { font-size: 2rem; }
    .article-row { padding-block: 19px; }
    .about-strip { grid-template-columns: 1fr; gap: 21px; margin-top: 45px; padding-block: 28px; }
    .about-strip h2 { font-size: 2.1rem; }
    .site-footer { margin-top: 22px; gap: 15px 22px; padding-block: 27px; }
    .site-footer p { width: 100%; order: 1; }
    .site-footer .copyright { order: 2; }
    .footer-brand { margin-right: auto; }
    .page-intro { padding-block: 39px 35px; }
    .page-intro h1 { font-size: clamp(3.4rem, 10vw, 4.8rem); }
    .page-intro > p:not(.eyebrow) { font-size: .9rem; }
    .lab-section .pattern-tool { padding: 17px; }
    .lab-toolbar { flex-wrap: wrap; gap: 7px; }
    .pattern-preview { aspect-ratio: 1.2; padding-block: 18px; }
    .compact .pattern-preview { aspect-ratio: 2.2; }
    .lab-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 19px; }
    .lab-controls label { min-width: 0; }
    .lab-controls .button { width: 100%; font-size: .72rem; padding-inline: 10px; }
    .lab-notes { gap: 24px; }
    .next-section { margin-top: 40px; }
    .detail-page { padding-top: 25px; }
    .detail-header { margin-block: 30px; }
    .detail-header h1 { font-size: 2.85rem; }
    .detail-lead { font-size: .98rem; }
    .reading-content p { font-size: .95rem; }
    .reading-content h2 { font-size: 1.65rem; }
    .blog-section .article-row h3 { font-size: 1.1rem; }
    .blog-section .article-row p { font-size: .79rem; }
    .about-content { gap: 32px; }
    .about-monogram { min-height: 210px; font-size: 120px; }
  }
  @media (max-width: 360px) {
    .wrap { width: calc(100% - 32px); }
    .hero h1 { font-size: 3.2rem; }
    .header-right { gap: 10px; }
    .brand { font-size: 1.15rem; gap: 7px; }
    .hero-eyebrow { letter-spacing: 0; }
    .topics { grid-template-columns: 1fr; }
    .terminal-code { font-size: .64rem; padding: 19px; }
    .terminal-language { display: none; }
    .workflow { gap: 6px; font-size: .6rem; }
    .workflow > span { padding: 9px; }
  }
  @media (pointer: coarse) { .theme-toggle { min-width: 44px; min-height: 44px; } .text-button { min-height: 44px; } }
  @media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
}
