/* =========================================================================
   Vandit's Workshop — Sketchbook skin.
   Warm paper, blue graph grid, hand-drawn boxes, ink wires, Caveat accents.
   ========================================================================= */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

:root {
  color-scheme: light;
  --maxw: 720px;
  --radius-sketch-card: 225px 14px 245px 14px / 14px 235px 14px 255px;
  --radius-sketch-panel: 235px 16px 255px 16px / 16px 245px 16px 255px;
  --space: clamp(1rem, 2.5vw, 2rem);
  --topbar-h: 60px;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-hand: "Caveat", "Bricolage Grotesque", cursive;

  --bg: #f6f1e2;
  --bg-2: #efe8d3;
  --grid: rgba(43, 95, 191, .15);
  --ink: #25211a;
  --muted: #756c59;
  --card-bg: #fffdf6;
  --card-bd: #2a2620;
  --card-shadow: 4px 4px 0 #2a2620;
  --accent: #1f5fbf;        /* pen blue */
  --accent-2: #c0392b;      /* marker red */
  --wire: #2a2620;
  --tag-bg: #eef3ff;
  --tag-ink: #1f5fbf;
  --topbar-bg: rgba(246, 241, 226, .82);
  --shadow-pop: 8px 8px 0 #2a2620;
}

@media (prefers-reduced-motion: no-preference) {
  .tool, .mini-nav button, .hero-links a, .tag, .card, .panel {
    transition: background-color .25s var(--ease), color .25s var(--ease),
                border-color .25s var(--ease), box-shadow .25s var(--ease);
  }
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-display);
  font-weight: 440;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  min-height: 100vh;
}

/* graph paper painted on a fixed layer behind everything — always paints,
   so it can't flake on first load the way a body background-image can. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  /* own compositing layer so the transformed #world layer can't re-sample it
     and leave a faint rectangle ("invisible box") around the content */
  transform: translateZ(0);
}
/* keep content above the grid — but NOT the modal <dialog>, whose top-layer
   centering must not be overridden by position:relative */
body > *:not(dialog) { position: relative; z-index: 1; }

a { color: var(--accent); text-decoration: none; }

/* ---------- skip link ---------- */
.skip-link {
  position: fixed; top: 8px; left: 8px; z-index: 200;
  background: var(--ink); color: var(--bg);
  padding: .5rem .9rem; border-radius: 8px; font-weight: 600;
  transform: translateY(-150%); transition: transform .2s var(--ease);
}
.skip-link:focus { transform: translateY(0); }

/* ---------- topbar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 100; height: var(--topbar-h);
  display: flex; align-items: center; gap: 1rem;
  padding: 0 clamp(1rem, 3vw, 2rem);
  background: var(--topbar-bg); backdrop-filter: blur(12px);
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
}
.brand {
  font-weight: 700; font-size: 1.15rem; letter-spacing: -.02em; color: var(--ink);
  display: inline-flex; align-items: center; gap: .45rem;
}
.brand-mark { color: var(--accent); transform: translateY(1px); }

.mini-nav { display: flex; gap: .25rem; margin-left: auto; }
.mini-nav button {
  font: inherit; font-size: .92rem; color: var(--muted);
  background: none; border: 0; cursor: pointer;
  padding: .4rem .75rem; border-radius: 99px;
}
.mini-nav button:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 8%, transparent); }
.mini-nav button.is-active { color: var(--accent); font-weight: 700; }

.topbar-tools { display: flex; gap: .4rem; }
.tool {
  width: 38px; height: 38px; display: grid; place-items: center;
  font-size: 1.05rem; cursor: pointer; color: var(--ink);
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  border: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
  border-radius: 10px;
}
.tool:hover { border-color: var(--accent); color: var(--accent); }

/* =========================================================================
   LINEAR LAYOUT (default; also the mobile + no-JS experience)
   ========================================================================= */
.viewport { padding-top: var(--topbar-h); }
#world {
  max-width: var(--maxw); margin: 0 auto;
  padding: clamp(2rem, 6vw, 4.5rem) var(--space) 4rem;
  display: flex; flex-direction: column; gap: 2.5rem;
}

.hero { text-align: left; }
.eyebrow { font-family: var(--font-hand); color: var(--accent-2); font-size: 1.4rem; line-height: 1; margin-bottom: .2rem; }
.hero h1 {
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(2.8rem, 9vw, 5rem); line-height: .95; letter-spacing: -.03em;
}
.tagline { font-size: clamp(1.05rem, 2.5vw, 1.35rem); color: var(--muted); max-width: 30ch; margin-top: 1rem; }
.tagline b { color: var(--ink); }
.hero-links { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.4rem; }
.hero-links a { border: 1.5px solid currentColor; padding: .45rem .9rem; border-radius: 99px; font-weight: 600; font-size: .95rem; }
.hero-links a:hover { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.hint { font-family: var(--font-hand); color: var(--muted); margin-top: 1.6rem; font-size: 1.05rem; display: none; }

.region-label { font-family: var(--font-display); font-weight: 800; letter-spacing: -.02em; font-size: 1.8rem; margin-bottom: .25rem; }
.region { display: grid; gap: 1.1rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.region-label { grid-column: 1 / -1; }

/* ---------- cards (hand-drawn boxes) ---------- */
.card {
  position: relative; display: block; color: inherit;
  background: var(--card-bg); padding: 1.1rem 1.2rem 1.2rem;
  border: 2px solid var(--card-bd);
  border-radius: var(--radius-sketch-card);
  box-shadow: var(--card-shadow);
}
.card-kind { font-family: var(--font-hand); color: var(--accent-2); font-size: .95rem; line-height: 1; display: inline-block; margin-bottom: .35rem; text-transform: lowercase; }
.card h3 { font-family: var(--font-hand); font-weight: 700; font-size: 1.7rem; line-height: 1.1; letter-spacing: -.01em; margin-bottom: .4rem; }
.card p { color: var(--muted); font-size: .95rem; }
.card .links { margin-top: .7rem; }
.card .links a { font-weight: 700; }
.card .links a:hover { color: var(--accent-2); }

/* ---------- panels (about / contact) ---------- */
.panel {
  background: var(--card-bg); border: 2px solid var(--card-bd);
  border-radius: var(--radius-sketch-panel);
  padding: 1.5rem 1.6rem; box-shadow: var(--card-shadow);
}
.panel h2 { font-family: var(--font-hand); font-weight: 700; font-size: 2.1rem; letter-spacing: -.02em; margin-bottom: .6rem; }
.panel p { color: var(--muted); }
.contact-list { list-style: none; display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.contact-list { flex-direction: column; gap: .35rem; }
.contact-list a { font-weight: 600; }

/* ---------- About: power-packed prose + reach-out line ---------- */
.panel .about-body { color: var(--ink); line-height: 1.5; }
.about-body b { font-weight: 700; }
.panel .about-cta { margin-top: .9rem; color: var(--ink); font-weight: 600; line-height: 1.45; }
.about-cta a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

/* ---------- footer ---------- */
.footer { text-align: center; padding: 2rem 1rem 3rem; color: var(--muted); }
.footer a { font-weight: 600; }

/* tags inside detail dialog */
.tag { display: inline-block; font-size: .78rem; padding: .2rem .6rem; border-radius: 99px; background: var(--tag-bg); color: var(--tag-ink); margin: .15rem .2rem 0 0; }

/* =========================================================================
   CANVAS MODE (added when JS enhances on wide viewports: html.canvas-on)
   ========================================================================= */
html.canvas-on, html.canvas-on body { height: 100%; overflow: hidden; }
html.canvas-on .viewport { position: fixed; inset: 0; padding: 0; overflow: hidden; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
html.canvas-on .viewport:active { cursor: grabbing; }
html.canvas-on #world { position: absolute; top: 0; left: 0; max-width: none; margin: 0; padding: 0; display: block; transform-origin: 0 0; will-change: transform; }
html.canvas-on .node { position: absolute; }
html.canvas-on .card { width: 232px; }
html.canvas-on .hero { width: 430px; }
html.canvas-on .panel { width: 320px; }
html.canvas-on #about { width: 360px; }
html.canvas-on .region { display: contents; }
html.canvas-on .region-label { display: none; }
html.canvas-on .hint { display: block; }
html.canvas-on .footer { display: none; }

/* gentle alternating tilt for the cards on the canvas (individual transform
   props so entrance + hover compose with the tilt) */
.canvas-on .card:nth-child(4n+1) { rotate: -2.2deg; }
.canvas-on .card:nth-child(4n+2) { rotate: 1.6deg; }
.canvas-on .card:nth-child(4n+3) { rotate: -1deg; }
.canvas-on .card:nth-child(4n)   { rotate: 2.4deg; }

@media (prefers-reduced-motion: no-preference) {
  html.canvas-on .card { transition: translate .2s var(--ease), rotate .2s var(--ease), box-shadow .2s var(--ease); }
}
html.canvas-on .card:hover { box-shadow: var(--shadow-pop); z-index: 5; translate: -2px -4px; rotate: 0deg; }

html:not(.canvas-on) #fit-btn { display: none; }

/* ---------- entrance choreography (played once on canvas mount) ---------- */
@media (prefers-reduced-motion: no-preference) {
  html.canvas-on #world.will-enter .node { opacity: 0; }
  html.canvas-on #world.is-entered .node { animation: nodeIn .55s var(--ease) both; }
  @keyframes nodeIn { from { opacity: 0; translate: 0 18px; } to { opacity: 1; translate: 0 0; } }
  html.canvas-on .wires path { transition: stroke-dashoffset 1.1s var(--ease) .15s; }
  html.canvas-on .hint { animation: hintFade .8s var(--ease) 6s both; }
  @keyframes hintFade { to { opacity: 0; visibility: hidden; } }
}

.card:focus-visible, .tool:focus-visible, .mini-nav button:focus-visible,
.hero-links a:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent-2); outline-offset: 3px; border-radius: 6px;
}

/* ---------- SVG wire layer (drawn by world.js) ---------- */
/* faint + thin so the wires read as subtle connections, never bold slashes */
.wires { position: absolute; overflow: visible; pointer-events: none; z-index: 0; opacity: .26; }
.wires path { fill: none; stroke: var(--wire); stroke-width: 1.4; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.node { z-index: 1; }

/* =========================================================================
   Detail dialog
   ========================================================================= */
dialog.detail {
  border: none; padding: 0; background: transparent; color: var(--ink);
  position: fixed; inset: 0; margin: auto;            /* center in viewport */
  width: calc(100% - 2rem); max-width: 440px; height: fit-content;
}
dialog.detail::backdrop { background: color-mix(in srgb, var(--bg-2) 70%, transparent); backdrop-filter: blur(4px); }
.detail-inner {
  position: relative; background: var(--card-bg); border: 2px solid var(--card-bd);
  border-radius: var(--radius-sketch-panel);
  padding: 1.6rem 1.7rem; box-shadow: var(--shadow-pop);
  max-height: calc(100vh - 4rem); overflow-y: auto;
}
.detail-inner h3 { font-family: var(--font-hand); font-weight: 700; font-size: 2.2rem; letter-spacing: -.01em; margin-bottom: .5rem; }
.detail-inner p { color: var(--muted); }
.detail-inner p + p { margin-top: .6rem; }
.detail-inner b { color: var(--ink); font-weight: 700; }
.detail-inner .tags { margin-top: .85rem; }
.card-detail { display: none; }
.detail-close {
  position: absolute; top: .6rem; right: .6rem; width: 34px; height: 34px; border-radius: 8px;
  border: 0; background: color-mix(in srgb, var(--ink) 8%, transparent); color: var(--ink);
  font-size: 1.2rem; cursor: pointer; line-height: 1;
}
.detail-close:hover { background: var(--accent); color: var(--bg); }

@media (prefers-reduced-motion: no-preference) {
  dialog.detail[open] { animation: pop .25s var(--ease); }
  @keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
}
