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

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

@layer base {
  :root { --paper: #fff; --ink: #222629; --muted: #697078; --line: #e5e7e9; --soft: #f5f6f7; --accent: #293f36; }
  html { background: var(--paper); color: var(--ink); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 16px; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: 90px; }
  body { min-width: 320px; font-size: .875rem; line-height: 1.5; }
  h1, h2, h3 { font-weight: 600; line-height: 1.3; }
  h1 { font-size: 1.625rem; letter-spacing: -.025em; }
  h2 { font-size: 1.125rem; }
  h3 { font-size: .875rem; }
  button { color: inherit; }
  button:disabled { opacity: .55; cursor: wait; }
  svg { flex-shrink: 0; }
  :focus-visible { outline: 2px solid #2764b8; outline-offset: 4px; }
  ::selection { background: #dce8e0; }
  .muted { color: var(--muted); }
  .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
  .skip-link { position: fixed; top: -80px; left: 20px; z-index: 50; padding: 12px 18px; background: var(--ink); color: white; }
  .skip-link:focus { top: 12px; }
}

@layer layout {
  .site-header, #main { width: 100%; max-width: 1440px; margin: 0 auto; padding-inline: 40px; }
  .site-header { height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); }
  .brand { display: inline-flex; align-items: center; flex-shrink: 0; }
  .brand-logo { width: 194px; height: auto; }
  .bag-button { display: inline-flex; align-items: center; gap: 8px; padding: 10px 0 10px 12px; white-space: nowrap; }
  .bag-button:hover { color: var(--accent); }
  #cart-count { display: inline-grid; place-items: center; min-width: 23px; height: 23px; padding: 0 6px; border-radius: 4px; background: var(--soft); font-size: .75rem; }
  #main { min-height: calc(100vh - 76px); padding-bottom: 48px; }
  .gallery { padding-top: 26px; }
  .archive-layout { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 30px; padding-top: 26px; }
  .archive-layout .gallery { padding-top: 0; }
  .archive-sidebar { padding-right: 22px; border-right: 1px solid var(--line); }
  .mobile-date-toggle, .mobile-selection-dock { display: none; }
  .sidebar-title { display: flex; align-items: center; gap: 8px; margin-bottom: 23px; font-size: .875rem; }
  .archive-year { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 12px; color: var(--muted); font-size: .75rem; }
  .archive-month { margin-bottom: 8px; }
  .month-toggle { display: flex; align-items: center; gap: 7px; width: 100%; padding: 10px 0; border: 0; background: none; text-align: left; font-size: .875rem; font-weight: 500; }
  .month-toggle[aria-expanded=true] > svg { transform: rotate(90deg); }
  .month-count { margin-left: auto; color: var(--muted); font-size: .75rem; font-weight: 400; }
  .month-days { display: flex; flex-direction: column; gap: 4px; margin: 3px -8px 12px 0; }
  .date-button { display: flex; align-items: center; gap: 8px; padding: 10px; border: 1px solid transparent; border-radius: 4px; background: none; text-align: left; font-size: .875rem; }
  .date-button:hover { background: var(--soft); }
  .date-button.selected { background: #edf2ee; color: var(--accent); }
  .day-number { min-width: 18px; font-weight: 500; }
  .day-name { color: var(--muted); font-size: .75rem; }
  .date-button.selected .day-name { color: var(--accent); }
  .date-count { margin-left: auto; color: var(--muted); font-size: .75rem; }
  .gallery-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 14px 24px; margin-bottom: 26px; }
  .gallery-filters { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; min-width: 0; }
  .select-wrap { position: relative; display: inline-flex; align-items: center; max-width: 100%; }
  .select-wrap::after { content: ''; position: absolute; right: 14px; width: 6px; height: 6px; border-right: 1px solid var(--muted); border-bottom: 1px solid var(--muted); transform: rotate(45deg); margin-top: -3px; pointer-events: none; }
  select { appearance: none; max-width: 100%; min-height: 42px; border: 1px solid #d9dde0; border-radius: 5px; padding: 9px 35px 9px 12px; color: var(--ink); background: white; font-size: .875rem; cursor: pointer; }
  select:hover { border-color: #a4aab0; }
  .photo-count { color: var(--muted); font-size: .75rem; white-space: nowrap; }
  .photo-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 28px 22px; }
  .photo-card { min-width: 0; }
  .photo-image { position: relative; aspect-ratio: 4 / 3; overflow: hidden; border-radius: 4px; background: var(--soft); }
  .photo-image > a { display: block; height: 100%; }
  .photo-image > a:focus-visible { outline-offset: -4px; }
  .photo-image img { height: 100%; object-fit: cover; }
  .photo-image:has(.select-photo.selected) { outline: 2px solid var(--accent); outline-offset: 3px; }
  .select-photo { position: absolute; top: 12px; right: 12px; display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid #ffffffa0; border-radius: 50%; background: #ffffffed; color: var(--ink); }
  .select-photo:hover { background: white; }
  .select-photo.selected { border-color: var(--accent); background: var(--accent); color: white; }
  .photo-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-top: 10px; }
  .photo-time, .photo-price { font-size: .875rem; }
  .photo-price { color: var(--muted); }
  .back-link { display: inline-flex; align-items: center; gap: 8px; margin: 27px 0; color: var(--muted); }
  .back-link:hover { color: var(--ink); }
  .detail-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); align-items: start; gap: 40px; }
  .detail-image { overflow: hidden; border-radius: 4px; background: var(--soft); }
  .detail-image img { height: min(70vh, 690px); object-fit: contain; }
  .detail-under-image { display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 15px; color: var(--muted); font-size: .75rem; }
  .detail-navigation { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 20px; }
  .detail-navigation a { padding-block: 6px; font-size: .875rem; }
  .detail-copy { padding-top: 8px; }
  .detail-copy h1 { margin-bottom: 10px; }
  .detail-date { color: var(--muted); }
  .detail-caption { margin: 23px 0; color: var(--muted); font-size: .75rem; }
  .detail-copy .primary-button { margin-bottom: 10px; }
  .checkout-link { display: block; padding: 9px 0; text-align: center; }
  .checkout-link:hover { text-decoration: underline; text-underline-offset: 3px; }
  .page-heading { margin: 0 0 28px; }
  .page-heading p { margin-top: 8px; color: var(--muted); }
  .checkout-layout { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(270px, 1fr); gap: 48px; align-items: start; }
  .checkout-item { display: flex; align-items: center; gap: 20px; padding: 19px 0; border-bottom: 1px solid var(--line); }
  .checkout-item:first-child { padding-top: 0; }
  .checkout-item > a { width: 130px; flex-shrink: 0; }
  .checkout-item img { aspect-ratio: 4 / 3; object-fit: cover; border-radius: 3px; }
  .checkout-item-copy { min-width: 0; flex: 1; }
  .checkout-item h3 { margin-bottom: 5px; }
  .checkout-item p { color: var(--muted); font-size: .75rem; line-height: 1.6; }
  .remove-button { padding: 9px 0 3px; border: 0; background: transparent; color: var(--muted); font-size: .75rem; text-decoration: underline; text-underline-offset: 3px; }
  .item-price { align-self: flex-start; padding-top: 3px; white-space: nowrap; }
  .order-summary { padding: 24px; border: 1px solid var(--line); border-radius: 5px; }
  .order-summary h2 { margin-bottom: 20px; }
  .summary-row { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; }
  .summary-total { font-size: 1rem; }
  .summary-total strong { font-size: 1.25rem; font-weight: 600; }
  .summary-total small { color: var(--muted); font-size: .75rem; font-weight: 400; }
  .order-summary .demo-note { margin: 20px 0; }
  .checkout-error { margin: 14px 0; color: #a33025; }
  .checkout-error:empty { display: none; }
  .success-page { max-width: 560px; margin: 0 auto; padding: 75px 0 45px; text-align: center; }
  .success-page h1 { margin-bottom: 15px; }
  .success-page > p { margin-bottom: 24px; color: var(--muted); }
  .success-page .primary-button { margin-bottom: 18px; }
  .success-page .back-link { display: flex; justify-content: center; margin-top: 20px; }
}

@layer components {
  .primary-button, .secondary-button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 44px; padding: 11px 18px; border: 1px solid var(--ink); border-radius: 5px; font-size: .875rem; font-weight: 500; }
  .primary-button { background: var(--ink); color: white; }
  .primary-button:hover { background: #3b4145; }
  .secondary-button { background: white; color: var(--ink); border-color: #d9dde0; }
  .secondary-button:hover { background: var(--soft); }
  .full-width { width: 100%; }
  .demo-note { color: var(--muted); font-size: .75rem; line-height: 1.6; }
  .loading-state, .empty-state { min-height: 330px; padding: 45px 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; color: var(--muted); text-align: center; }
  .empty-state h1, .empty-state h2 { color: var(--ink); }
  .empty-state p { max-width: 380px; }
  .spinner { width: 22px; height: 22px; border: 2px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin 1s linear infinite; }
  .toast { position: fixed; left: 50%; bottom: 24px; z-index: 20; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 5px; color: white; background: var(--ink); text-align: center; font-size: .875rem; opacity: 0; pointer-events: none; transform: translate(-50%, 10px); transition: opacity .15s, transform .15s; }
  .toast.visible { opacity: 1; transform: translate(-50%, 0); }
  .help-dialog { width: min(480px, calc(100% - 32px)); max-height: 90dvh; padding: 32px; border: 1px solid var(--line); border-radius: 6px; background: white; color: var(--ink); }
  .help-dialog::backdrop { background: #19202580; }
  .help-dialog h2 { margin-bottom: 18px; }
  .help-dialog p { margin-block: 14px; }
  .icon-button { display: grid; place-items: center; min-width: 44px; min-height: 44px; padding: 8px; border: 0; background: none; }
  .dialog-close { position: absolute; right: 10px; top: 5px; font-size: 1.5rem; }
  .noscript { padding: 24px; text-align: center; }
  @keyframes spin { to { transform: rotate(360deg); } }
}

@layer responsive {
  @media (max-width: 1000px) {
    .site-header, #main { padding-inline: 28px; }
    .archive-layout { grid-template-columns: 170px minmax(0, 1fr); gap: 24px; }
    .archive-sidebar { padding-right: 16px; }
    .photo-grid { gap: 25px 18px; }
    .detail-layout { grid-template-columns: minmax(0, 1.7fr) minmax(245px, 1fr); gap: 28px; }
    .checkout-layout { gap: 28px; }
  }
  @media (max-width: 760px) {
    .site-header, #main { padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }
    .site-header { position: sticky; top: 0; z-index: 10; height: calc(66px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); background: var(--paper); gap: 12px; }
    .brand { min-height: 44px; }
    .brand-logo { width: 166px; }
    .bag-button { min-height: 44px; padding-left: 8px; }
    #main { min-height: calc(100svh - 66px); padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
    select { min-height: 48px; font-size: 16px; }
    .primary-button, .secondary-button { min-height: 48px; font-size: 1rem; }
    .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .archive-layout { display: block; padding-top: 16px; }
    .archive-layout .gallery { padding-top: 0; }
    .archive-sidebar { padding: 0; margin-bottom: 12px; border: 0; }
    .sidebar-title { display: none; }
    .mobile-date-toggle { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 11px 14px; border: 1px solid #d9dde0; border-radius: 5px; background: var(--paper); text-align: left; font-size: 1rem; }
    .mobile-date-toggle span { flex: 1; }
    .mobile-date-toggle > svg:last-child { transform: rotate(90deg); }
    .mobile-date-toggle[aria-expanded=true] > svg:last-child { transform: rotate(-90deg); }
    .months-list { display: none; max-height: min(52svh, 420px); overflow-y: auto; overscroll-behavior-y: contain; margin-top: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 5px; }
    .dates-open .months-list { display: block; }
    .archive-year { margin: 4px 0; }
    .archive-month { margin-bottom: 4px; }
    .month-toggle { min-height: 44px; padding: 10px 4px; }
    .month-toggle[aria-expanded=true] { color: var(--accent); }
    .month-days { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 4px 0 12px; }
    .date-button { min-height: 44px; min-width: 0; padding: 9px 8px; border-color: var(--line); }
    .date-button.selected { border-color: #dbe5dd; }
    .day-number { min-width: 0; }
    .day-name { overflow: hidden; text-overflow: ellipsis; }
    .gallery-toolbar { gap: 12px; flex-wrap: nowrap; margin-bottom: 18px; }
    .gallery-filters { gap: 8px; }
    .gallery-filters .select-wrap { min-width: 0; }
    .select-photo { top: 6px; right: 6px; width: 44px; height: 44px; }
    .select-photo > svg { width: 19px; height: 19px; }
    .photo-meta { align-items: center; margin-top: 3px; }
    .photo-time { display: inline-flex; align-items: center; min-height: 44px; flex: 1; }
    .photo-price { white-space: nowrap; }
    .back-link { min-height: 44px; margin: 12px 0; }
    .detail-layout, .checkout-layout { grid-template-columns: minmax(0, 1fr); gap: 28px; }
    .detail-image img { height: auto; max-height: 58svh; }
    .detail-under-image { margin-top: 4px; }
    .detail-navigation { width: 100%; gap: 12px; }
    .detail-navigation a { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; min-width: 90px; }
    .detail-navigation a:last-child { margin-left: auto; }
    .detail-copy { max-width: 500px; width: 100%; padding: 0; }
    .detail-copy h1 { margin-bottom: 4px; }
    .detail-caption { margin: 12px 0 18px; }
    .checkout-link { min-height: 44px; }
    .remove-button { min-height: 44px; min-width: 64px; padding: 8px 0; text-align: left; font-size: .875rem; }
    .checkout-item h3 a { display: inline-flex; align-items: center; min-height: 32px; }
    .mobile-selection-dock:not([hidden]) { display: block; position: fixed; inset: auto 0 0; z-index: 15; padding: 12px max(20px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); border-top: 1px solid var(--line); background: var(--paper); }
    .mobile-selection-dock a { display: flex; align-items: center; gap: 12px; min-height: 50px; padding: 12px 16px; border-radius: 5px; background: var(--ink); color: white; font-size: .9375rem; }
    .mobile-selection-dock strong { margin-left: auto; font-weight: 600; white-space: nowrap; }
    .has-selection-dock #main { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
    .has-selection-dock .toast { bottom: calc(90px + env(safe-area-inset-bottom)); }
    .has-checkout-dock #main { padding-bottom: calc(var(--checkout-dock-height, 190px) + 28px); }
    .has-checkout-dock .toast { bottom: calc(var(--checkout-dock-height, 190px) + 12px); }
    .order-summary { position: fixed; inset: auto 0 0; z-index: 15; max-width: none; max-height: 55svh; overflow-y: auto; overscroll-behavior: contain; padding: 14px max(20px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); border-inline: 0; border-bottom: 0; border-radius: 0; background: var(--paper); }
    .order-summary .demo-note { margin: 3px 0 10px; }
    .checkout-error { max-height: 100px; overflow-y: auto; margin: 8px 0; }
    .help-dialog { overscroll-behavior: contain; }
  }
  @media (max-width: 480px) {
    .site-header, #main { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
    .brand-logo { width: 156px; }
    .gallery { padding-top: 20px; }
    .gallery-filters { flex: 1; }
    .gallery-filters .select-wrap { width: 100%; }
    .gallery-filters select { width: 100%; padding-left: 12px; }
    .photo-count { margin-left: auto; }
    .photo-grid { gap: 12px 12px; }
    .photo-meta { gap: 8px; }
    .detail-layout { gap: 14px; }
    .detail-copy h1 { font-size: 1.5rem; }
    .checkout-item { gap: 12px; }
    .checkout-item > a { width: 86px; }
    .checkout-item h3 { font-size: .875rem; }
    .success-page { padding-top: 45px; }
    .help-dialog { padding: 28px 22px; }
  }
  @media (pointer: coarse) {
    .select-photo { width: 44px; height: 44px; }
    .month-toggle, .date-button, .remove-button, .back-link, .bag-button { min-height: 44px; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  }
}
