@layer base, layout, components, motion;

@layer base {
  :root {
    color-scheme: light;
    --page: #fff;
    --ink: #101112;
    --muted: #686b70;
    --line: #dddfe1;
    --soft: #f3f4f5;
    --radius: 16px;
    --gutter: clamp(20px, 3.7vw, 64px);
    --header-height: 100px;
    font-family: Arial, Helvetica, sans-serif;
    font-synthesis: none;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
  }
  :root[data-theme='dark'] {
    color-scheme: dark;
    --page: #131415;
    --ink: #f5f5f2;
    --muted: #aaaeb3;
    --line: #36383c;
    --soft: #202225;
  }
  * { box-sizing: border-box; }
  html { scrollbar-gutter: stable; scroll-behavior: smooth; }
  body { margin: 0; background: var(--page); color: var(--ink); }
  button, a { -webkit-tap-highlight-color: transparent; }
  button { font: inherit; color: inherit; cursor: pointer; }
  a { color: inherit; text-decoration: none; }
  button { background: none; border: 0; }
  button:disabled { cursor: default; }
  h1, h2, h3, p { margin: 0; }
  img { display: block; max-width: 100%; height: auto; }
  svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
  [hidden] { display: none !important; }
  :focus-visible { outline: 2px solid var(--ink); outline-offset: 6px; }
  #main:focus, #fabric-title:focus { outline: none; }
  ::selection { color: var(--page); background: var(--ink); }
  .skip-link { position: fixed; top: 12px; left: 20px; transform: translateY(-150%); padding: 12px 20px; z-index: 100; background: var(--ink); color: var(--page); border-radius: 8px; }
  .skip-link:focus { transform: translateY(0); }
  .visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
}

@layer layout {
  .site-header { height: var(--header-height); margin: 0 var(--gutter); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; border-bottom: 1px solid transparent; position: relative; z-index: 5; }
  body[data-view='detail'] .site-header { position: sticky; top: 0; border-bottom-color: var(--line); background: var(--page); }
  .header-side { min-width: 0; }
  .header-end { display: flex; justify-content: flex-end; }
  .brand { display: block; padding: 8px; }
  .brand img { width: 136px; height: auto; filter: invert(1); }
  [data-theme='dark'] .brand img { filter: none; }
  .catalog-view { padding: 0 var(--gutter); max-width: 1640px; margin: auto; }
  .catalog-heading { text-align: center; padding: clamp(28px, 4vw, 62px) 0 clamp(44px, 5vw, 76px); }
  .catalog-heading h1 { font-size: clamp(37px, 5.8vw, 82px); letter-spacing: -.055em; line-height: 1.02; font-weight: 750; }
  .catalog-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 56px 28px; }
  .catalog-grid.single { grid-template-columns: 1fr; max-width: 490px; margin: auto; }
  .catalog-footer { border-top: 1px solid var(--line); margin-top: 64px; padding: 24px 0 30px; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.7; }
  .detail-view { padding: 0 var(--gutter) 36px; max-width: 1780px; margin: auto; }
  .detail-top { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 34px 0 36px; }
  .eyebrow { text-transform: uppercase; font-size: 13px; font-weight: 700; letter-spacing: .11em; margin-bottom: 6px; }
  .detail-top h1 { font-size: clamp(64px, 7.8vw, 112px); font-weight: 750; letter-spacing: -.065em; line-height: .98; }
  .material-gallery { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
  .feature-section { margin-top: 48px; }
  .feature-heading { font-size: clamp(30px, 3vw, 46px); letter-spacing: -.045em; font-weight: 700; margin-bottom: 24px; }
  .feature-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
  .detail-footer { margin-top: 36px; padding-top: 22px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 20px; }
  .material-notes { font-size: 14px; line-height: 1.7; }
  .material-notes span + span::before { content: ' · '; color: var(--muted); padding: 0 5px; }
  .image-note { color: var(--muted); font-size: 12px; line-height: 1.7; margin-top: 10px; }
  .loading-message, .no-script, .error-message { text-align: center; padding: 48px 20px; grid-column: 1/-1; color: var(--muted); line-height: 1.7; }
  .error-message button { text-decoration: underline; margin-top: 12px; }
}

@layer components {
  .theme-toggle { display: flex; border: 1px solid var(--line); border-radius: 99px; padding: 3px; gap: 2px; }
  .theme-toggle button { width: 43px; height: 37px; border-radius: 50px; display: grid; place-items: center; transition: background .2s, color .2s; }
  .theme-toggle button[aria-pressed='true'] { color: var(--page); background: var(--ink); }
  .theme-toggle svg { width: 21px; height: 21px; }
  .back-button { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 0; font-size: 15px; font-weight: 600; }
  .back-button svg { transition: transform .2s; }
  .back-button:hover svg { transform: translateX(-4px); }
  .fabric-card { display: block; }
  .fabric-card .image-wrap { position: relative; border-radius: var(--radius); overflow: hidden; background: #eee; }
  .fabric-card .cover { width: 100%; aspect-ratio: 1.25; object-fit: cover; transition: transform .65s cubic-bezier(.2,.7,.2,1); }
  .fabric-card:hover .cover { transform: scale(1.035); }
  .open-circle { position: absolute; right: 16px; bottom: 16px; display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid #c7c7c7; border-radius: 50%; background: #fffffff2; color: #161718; transition: background .2s, color .2s; }
  .fabric-card:hover .open-circle { color: #fff; background: #161718; border-color: #161718; }
  .card-name { font-size: 23px; letter-spacing: -.04em; margin: 18px 0 18px; line-height: 1.15; font-weight: 700; }
  .prices { display: grid; grid-template-columns: auto auto; gap: 0; }
  .price { padding: 0 26px; }
  .price:first-child { padding-left: 0; }
  .price + .price { border-left: 1px solid var(--line); }
  .price:last-child { padding-right: 0; }
  .price-label { display: block; font-size: 14px; margin-bottom: 4px; }
  .price-amount { display: block; font-size: 27px; font-weight: 700; letter-spacing: -.045em; white-space: nowrap; }
  .detail-prices .price { padding: 0 30px; }
  .detail-prices .price:first-child { padding-left: 0; }
  .detail-prices .price:last-child { padding-right: 0; }
  .detail-prices .price-label { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
  .detail-prices .price-amount { font-size: clamp(30px, 3.2vw, 49px); }
  .unit-note { text-align: right; color: var(--muted); font-size: 12px; margin-top: 10px; }
  .photo-button { position: relative; padding: 0; display: block; width: 100%; background: #efefef; border-radius: var(--radius); overflow: hidden; }
  .photo-button img { width: 100%; aspect-ratio: 1.45; object-fit: cover; transition: transform .7s cubic-bezier(.2,.7,.2,1); }
  .photo-button:hover img { transform: scale(1.025); }
  .zoom-cue { position: absolute; display: grid; place-items: center; right: 12px; bottom: 12px; border-radius: 50%; width: 32px; height: 32px; background: #ffffffdc; color: #151515; opacity: 0; transform: translateY(5px); transition: opacity .2s, transform .2s; }
  .zoom-cue svg { width: 16px; height: 16px; }
  .photo-button:hover .zoom-cue, .photo-button:focus-visible .zoom-cue { opacity: 1; transform: translateY(0); }
  .photo-title { font-size: clamp(20px, 1.75vw, 27px); letter-spacing: -.035em; margin-top: 13px; font-weight: 700; }
  .backlight-open { display: inline-flex; align-items: center; gap: 7px; min-height: 44px; padding: 8px 0; color: var(--muted); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
  .backlight-open:hover { color: var(--ink); }
  .feature-card .photo-button img { aspect-ratio: 1.5; }
  .feature-description { font-size: 15px; line-height: 1.5; margin-top: 6px; color: var(--muted); }
  .gallery-thumbnails { display: none; }
  .other-fabrics { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; min-height: 44px; white-space: nowrap; }
  .other-fabrics svg { width: 20px; }
  .image-viewer { --ink: #fff; --page: #151617; position: fixed; inset: 0; width: 100vw; max-width: none; height: 100dvh; max-height: none; margin: 0; border: 0; padding: 24px 32px; background: #151617; color: #fff; overflow: hidden; }
  .image-viewer[open] { display: flex; flex-direction: column; }
  .image-viewer::backdrop { background: #151617; }
  .viewer-header { display: flex; justify-content: space-between; gap: 20px; align-items: center; flex-shrink: 0; }
  .viewer-fabric { color: #aeb0b3; font-size: 12px; margin-bottom: 4px; }
  .viewer-header h2 { font-size: 22px; letter-spacing: -.03em; }
  .icon-button { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: #ffffff10; flex-shrink: 0; }
  .icon-button:hover { background: #ffffff24; }
  .viewer-stage { min-height: 0; flex: 1; display: grid; grid-template-columns: 48px minmax(0, 1fr) 48px; align-items: center; gap: 20px; padding: 24px 0; }
  .viewer-viewport { position: relative; min-width: 0; min-height: 0; align-self: stretch; flex: 1; overflow: hidden; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
  .viewer-viewport.is-zoomed { cursor: grab; touch-action: none; }
  .viewer-viewport.is-dragging { cursor: grabbing; }
  .viewer-image-stack { position: absolute; left: 50%; top: 50%; width: 100%; height: 100%; transform: translate(-50%, -50%); transform-origin: center; pointer-events: none; }
  .viewer-image-stack img { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; object-fit: contain; user-select: none; -webkit-user-drag: none; }
  .viewer-zoom, .viewer-backlight { display: grid; grid-template-columns: auto minmax(80px, 1fr) 44px auto; align-items: center; gap: 12px; width: min(100%, 560px); margin: 0 auto 12px; flex-shrink: 0; font-size: 12px; }
  .viewer-zoom label, .viewer-backlight label { color: #d4d6d8; }
  .viewer-zoom input, .viewer-backlight input { width: 100%; min-width: 0; height: 44px; margin: 0; padding: 0; accent-color: #fff; cursor: pointer; }
  .viewer-backlight input:disabled { opacity: .4; cursor: default; }
  .viewer-zoom output, .viewer-backlight output { text-align: right; font-variant-numeric: tabular-nums; }
  .viewer-backlight { grid-template-columns: auto minmax(80px, 1fr) 44px; row-gap: 0; }
  .viewer-backlight p { grid-column: 1 / -1; color: #aeb0b3; font-size: 11px; line-height: 1.4; }
  #viewer-zoom-reset { min-height: 44px; padding: 8px 12px; border: 1px solid #ffffff35; border-radius: 9px; font-size: 12px; }
  #viewer-zoom-reset:hover:enabled { background: #ffffff15; }
  #viewer-zoom-reset:disabled { opacity: .4; }
  .viewer-footer { display: flex; justify-content: space-between; color: #aeb0b3; font-size: 12px; padding: 0 68px 4px; flex-shrink: 0; }
  .viewer-arrow:disabled { opacity: .25; }
}

@layer motion {
  .transition-cover { position: fixed; z-index: 30; pointer-events: none; object-fit: cover; max-width: none; transform-origin: top left; }
  body.is-transitioning { overflow: hidden; }
  .reveal { animation: reveal .55s both cubic-bezier(.2,.7,.2,1); }
  .reveal:nth-child(2) { animation-delay: .07s; }
  .reveal:nth-child(3) { animation-delay: .14s; }
  @keyframes reveal { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
  @keyframes viewerIn { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: scale(1); } }
  .image-viewer[open] { animation: viewerIn .2s ease-out; }
}

@media (min-width: 1800px) {
  .site-header { max-width: 1652px; margin: 0 auto; }
}
@media (max-width: 1000px) {
  .catalog-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-top { padding: 30px 0; }
  .material-gallery, .feature-grid { gap: 14px; }
  .detail-prices .price { padding: 0 20px; }
  .back-long { display: none; }
  .photo-button img { aspect-ratio: 1.15; }
}
@media (max-width: 700px) {
  :root { --header-height: 80px; --radius: 12px; --gutter: 22px; }
  .brand img { width: 100px; }
  .brand { padding: 7px; }
  .theme-toggle { padding: 2px; gap: 0; }
  .theme-toggle button { width: 32px; height: 34px; }
  .theme-toggle svg { width: 18px; height: 18px; }
  .back-button { gap: 4px; font-size: 13px; }
  .back-button svg { width: 18px; }
  .catalog-heading { padding: 30px 0 36px; }
  .catalog-heading h1 { font-size: clamp(32px, 8.1vw, 50px); }
  .catalog-grid { gap: 32px 14px; }
  .catalog-grid.single { max-width: 460px; }
  .catalog-grid:not(.single) .card-name { font-size: 17px; margin: 12px 0; }
  .catalog-grid:not(.single) .prices { grid-template-columns: 1fr; gap: 6px; }
  .catalog-grid:not(.single) .price { display: flex; justify-content: space-between; gap: 6px; border: 0; padding: 0; }
  .catalog-grid:not(.single) .price-label { font-size: 11px; margin: 0; }
  .catalog-grid:not(.single) .price-amount { font-size: 14px; letter-spacing: -.03em; }
  .catalog-grid:not(.single) .open-circle { width: 32px; height: 32px; right: 10px; bottom: 10px; }
  .catalog-footer { margin-top: 42px; padding-bottom: 22px; font-size: 11px; }
  .card-name { font-size: 25px; }
  .detail-top { display: block; padding: 26px 0 25px; }
  .detail-top h1 { font-size: 65px; }
  .eyebrow { font-size: 11px; margin-bottom: 7px; }
  .detail-prices { margin-top: 25px; }
  .detail-prices .prices { grid-template-columns: 1fr 1fr; }
  .detail-prices .price { padding: 0 22px; }
  .detail-prices .price-label { font-size: 14px; }
  .detail-prices .price-amount { font-size: clamp(29px, 8.5vw, 42px); }
  .unit-note { margin-top: 8px; font-size: 11px; }
  .material-gallery { display: flex; overflow-x: auto; gap: 14px; scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain; border-radius: var(--radius); }
  .material-gallery::-webkit-scrollbar { display: none; }
  .gallery-item { flex: 0 0 100%; min-width: 0; scroll-snap-align: start; }
  .photo-button img { aspect-ratio: 1.12; }
  .photo-title { margin-top: 13px; font-size: 23px; }
  .gallery-thumbnails { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 11px; margin-top: 17px; }
  .gallery-thumbnail { padding: 0; text-align: left; border-radius: 10px; font-size: 12px; }
  .gallery-thumbnail img { width: 100%; aspect-ratio: 1.2; object-fit: cover; border-radius: 10px; border: 2px solid transparent; padding: 3px; }
  .gallery-thumbnail[aria-pressed='true'] img { border-color: var(--ink); }
  .gallery-thumbnail span { display: block; margin: 7px 4px 0; }
  .zoom-cue { opacity: 1; transform: none; }
  .feature-section { margin-top: 36px; padding-top: 28px; border-top: 1px solid var(--line); }
  .feature-heading { font-size: 31px; margin-bottom: 20px; }
  .feature-grid { grid-template-columns: 1fr; gap: 30px; }
  .feature-card .photo-button img { aspect-ratio: 1.5; }
  .feature-description { font-size: 14px; }
  .detail-footer { display: block; margin-top: 30px; padding-top: 20px; }
  .material-notes { font-size: 12px; }
  .image-note { font-size: 11px; }
  .other-fabrics { display: flex; justify-content: center; border: 1px solid var(--line); border-radius: 12px; width: 100%; margin-top: 24px; padding: 14px; }
  .image-viewer { padding: 18px 16px; }
  .viewer-header h2 { font-size: 21px; }
  .viewer-stage { position: relative; display: flex; padding: 22px 0 64px; }
  .viewer-arrow { position: absolute; bottom: 2px; z-index: 1; }
  #viewer-prev { left: calc(50% - 58px); }
  #viewer-next { right: calc(50% - 58px); }
  .viewer-footer { padding: 16px 0 4px; }
  .viewer-zoom, .viewer-backlight { column-gap: 8px; margin-bottom: 0; }
  #viewer-zoom-reset { padding-inline: 8px; }
}
@media (max-width: 360px) {
  :root { --gutter: 16px; }
  .brand img { width: 82px; }
  .theme-toggle button { width: 29px; }
  .detail-top h1 { font-size: 58px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
