/* ==========================================================================
   WITHIN / THE WALK — shared design tokens and base behaviour
   Three-layer tokens: primitive → semantic → component.
   Pages reference ONLY the semantic/component names (--paper, --ink, --accent-ink …).
   ========================================================================== */

:root {
  /* ---- 1. Primitive tokens: Apple-style neutral system ---- */
  --within-white:      #FFFFFF;
  --within-gray-50:    #F5F5F7;   /* Apple light gray surface */
  --within-gray-100:   #E8E8ED;
  --within-gray-500:   #86868B;   /* footer / tertiary text on dark only */
  --within-gray-600:   #5E5E63;   /* secondary text: 5.6:1 on white, 5.2:1 on gray-50 */
  --within-gray-900:   #1D1D1F;   /* primary text */
  --within-black:      #000000;
  --within-blue-500:   #0071E3;   /* Apple action blue (fills) */
  --within-blue-600:   #0066CC;   /* Apple link blue on light: 5.1:1 on white */
  --within-blue-300:   #2997FF;   /* link blue on black: 6.4:1 */
  --within-blue-hover: #0077ED;
  --within-green-600:  #1D7A46;
  --within-red-600:    #C8102E;

  --within-font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --within-font-text:    -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --within-font-fa: 'Vazirmatn', -apple-system, BlinkMacSystemFont, "Inter", sans-serif;

  /* 8-pt spacing scale */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px; --space-7: 48px; --space-8: 64px; --space-9: 96px;

  /* type scale (Apple: 12 / 14 / 17 / 21 / 28 / 40 / 56 / 80) */
  --text-xs: 12px; --text-sm: 14px; --text-base: 17px; --text-md: 21px;

  /* motion */
  --dur-fast: 150ms; --dur-base: 250ms; --dur-slow: 450ms;
  --ease-out: cubic-bezier(.25,.1,.25,1);

  /* ---- 2. Semantic tokens (what pages use) ---- */
  --paper:    var(--within-white);
  --paperalt: var(--within-gray-50);
  --card:     var(--within-white);
  --ink:      var(--within-gray-900);
  --inksoft:  var(--within-gray-600);
  --accent:   var(--within-blue-500);     /* decorative accent: rules, icons, numerals */
  --accent-ink: var(--within-blue-600);   /* accent used AS TEXT */
  --line:     rgba(0,0,0,0.10);
  --dark:     var(--within-black);
  --night:    var(--within-black);
  --mat:      var(--within-black);
  --green:    var(--within-green-600);
  --red:      var(--within-red-600);
  --focus:    var(--within-blue-500);

  /* ---- 3. Component tokens ---- */
  --cta-bg: var(--within-blue-500);
  --cta-fg: #FFFFFF;
  --cta-bg-hover: var(--within-blue-hover);
  --button-radius: 980px;
  --input-border: rgba(0,0,0,0.18);
  --input-border-focus: var(--accent-ink);
  --nav-height: 48px;
}

/* Dark (black) surfaces: Apple's #F5F5F7 text, blue-300 links, 16% hairlines */
.within-on-dark {
  --paper: var(--within-gray-50);
  --card: #1D1D1F;
  --accent-ink: var(--within-blue-300);
  --inksoft: #A1A1A6;
  --line: rgba(255,255,255,0.16);
  --focus: var(--within-gray-50);
  --input-border-focus: var(--within-blue-300);
  color: var(--paper);
}

/* Virtual Exhibition uses a deeper night */
.within-root[data-tone="exhibition"] {
  --dark: var(--within-black);
}

/* ==========================================================================
   Base behaviour
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body { margin: 0; }

.within-root {
  font-family: var(--within-font-text);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { text-wrap: balance; }
p { text-wrap: pretty; }
img { max-width: 100%; }

::selection { background: rgba(0,113,227,0.22); }

/* Accent used as text must be the contrast-safe tone */
.within-root a { color: var(--accent-ink); }

/* Interaction: every control is clickable, keyboard-visible, and animates briefly */
.within-root button,
.within-root [type="submit"],
.within-root summary { cursor: pointer; font-family: inherit; }

.within-root a,
.within-root button,
.within-root summary {
  transition: color var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              opacity var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
.within-root a:hover { opacity: .85; }
.within-root button:hover:not(:disabled) { filter: brightness(1.06); }
.within-root button:active:not(:disabled) { transform: translateY(1px); }
.within-root button:disabled { cursor: not-allowed; opacity: .55; }

/* Visible focus on EVERY operable control — never removed without replacement */
.within-root :focus { outline: none; }
.within-root :focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
  border-radius: 2px;
}
.within-root button:focus-visible,
.within-root a[style*="border-radius:100px"]:focus-visible { border-radius: var(--button-radius); }

/* Form fields */
.within-input, .within-in {
  font-family: inherit;
  color: var(--ink);
  min-height: 44px;
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.within-input:focus-visible, .within-in:focus-visible {
  outline: none;
  border-color: var(--input-border-focus);
  box-shadow: 0 1px 0 0 var(--input-border-focus);
}
.within-in:focus-visible { box-shadow: 0 0 0 4px rgba(0,113,227,0.25); }
.within-input::placeholder, .within-in::placeholder { color: var(--inksoft); opacity: .8; }

/* Touch targets: text links in nav/footers and small buttons get a 44px hit area
   without changing their visual size */
.within-hit { position: relative; }
.within-hit::after { content: ""; position: absolute; inset: -10px -8px; }

/* Primary CTA component */
.within-cta {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 44px; padding: 0 22px;
  background: var(--cta-bg); color: var(--cta-fg);
  border: 0; border-radius: var(--button-radius);
  font-family: inherit; font-size: 17px; letter-spacing: -0.01em; font-weight: 400;
  text-decoration: none; cursor: pointer;
}
.within-cta:hover { background: var(--cta-bg-hover); filter: none; }

/* Skip link */
.within-skip {
  position: absolute; inset-inline-start: 16px; top: -100px; z-index: 10000;
  padding: 12px 18px; border-radius: 8px;
  background: var(--ink); color: var(--paper); font-size: 14px; text-decoration: none;
}
.within-skip:focus-visible { top: 12px; outline-color: var(--within-blue-300); }

/* Screen-reader-only text */
.within-sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Mobile menu (CSS-only, <details>) */
.within-menu { display: none; position: relative; }
.within-menu summary { list-style: none; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 50%; border: 1px solid currentColor; color: inherit; }
.within-menu summary::-webkit-details-marker { display: none; }
.within-menu[open] summary .within-menu-open { display: none; }
.within-menu:not([open]) summary .within-menu-close { display: none; }
.within-menu-panel {
  position: absolute; inset-inline-end: 0; top: calc(100% + 12px); min-width: 240px;
  display: flex; flex-direction: column;
  background: rgba(255,255,255,0.92); color: var(--within-gray-900); backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid rgba(0,0,0,0.08); border-radius: 18px; padding: 8px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.18);
}
.within-menu-panel a { display: block; padding: 12px 14px; min-height: 44px; color: var(--within-gray-900); text-decoration: none; font-size: 17px; border-radius: 12px; }
.within-menu-panel a:hover { background: var(--within-gray-50); opacity: 1; }
@media (max-width: 1240px) { .within-menu { display: block; } }

/* Persian / RTL */
[dir="rtl"] .within-root, .within-root[dir="rtl"] { font-family: var(--within-font-fa); }
[dir="rtl"] .within-fa { font-family: var(--within-font-fa) !important; letter-spacing: 0 !important; line-height: 2 !important; }

/* Reduced motion: render final states immediately, no marquee / corridor / breathing */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .within-marquee, .within-corridor-card { animation: none !important; }
  [data-reveal] { opacity: 1 !important; transform: none !important; }
}

/* No paper grain in this system */
.within-grain { display: none !important; }

/* Print: no fixed layers */
@media print {
  .within-grain, .within-menu, .within-skip { display: none !important; }
}

/* ==========================================================================
   System pieces (added in the clean-up pass): tiles, text links, type rhythm
   ========================================================================== */
:root { --radius-tile: 18px; --radius-card: 24px; --shadow-tile: 0 1px 2px rgba(0,0,0,0.04), 0 12px 32px -16px rgba(0,0,0,0.14); }

/* Rounded surface tiles instead of hairline grids */
.within-tile {
  background: var(--card);
  border-radius: var(--radius-tile);
  box-shadow: var(--shadow-tile);
  transition: transform var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
}
.within-tile:hover { transform: translateY(-2px); box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 20px 40px -18px rgba(0,0,0,0.2); }
.within-on-dark .within-tile { background: #1D1D1F; box-shadow: none; }
.within-on-dark .within-tile:hover { background: #2A2A2D; }

/* "Learn more ›" text links */
.within-textlink {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--accent-ink); text-decoration: none;
  font-size: 17px; line-height: 1.3; letter-spacing: -0.01em;
  min-height: 44px;
}
.within-textlink:hover { text-decoration: underline; text-underline-offset: 4px; opacity: 1; }

/* Type rhythm: tighter display tracking, calmer measure */
.within-root h1, .within-root h2 { letter-spacing: -0.015em; }
.within-root h2 { margin-top: 0; }

/* Everything that is clickable animates the same way */
.within-root a:hover { opacity: 1; }
