/* Kiokura — shared style for every page.
   Values come from docs/design/DESIGN-GUIDE.md (approved 2026-10-22);
   docs/design/preview.html shows every component. */

/* ------------------------------------------------------------ fonts */

@font-face {
  font-family: "Inter";
  src: url("../fonts/InterVariable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ----------------------------------------------------------- tokens */

:root {
  --dark-bg: #020308;
  --dark-surface-1: #090a0e;
  --dark-surface-2: #0f1116;
  --dark-surface-3: #171920;
  --dark-surface-4: #24262e;
  --dark-text: #fafafd;
  --dark-text-2: #ffffffad;
  --dark-text-3: #ffffff70;
  --dark-border: #ffffff1a;

  --light-bg: #ffffff;
  --light-surface-1: #f9f9fa;
  --light-surface-2: #e9eaef;
  --light-surface-3: #dddee5;
  --light-text: #020308;
  --light-text-2: #343642;
  --light-text-3: #74767a;
  --light-border: #e9eaef;

  --accent: #1f69ff;   /* only for "+ Create Analysis" */
  --success: #1f7a4d;
  --success-bright: #30a46c;  /* Copy: tick + sparkles (owner, 2026-10-22) */
  --like: #e5484d;            /* the ♥ and its sparkles (owner, 2026-10-22) */

  --radius-s: 10px;
  --radius-m: 16px;
  --radius-l: 24px;
  --radius-xl: 32px;

  --nav-width: 248px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Each page picks its theme with <body class="theme-dark"> or "theme-light".
   Components read these semantic variables, so they work on both. */
.theme-dark {
  --bg: var(--dark-bg);
  --surface: var(--dark-surface-2);
  --surface-raised: var(--dark-surface-3);
  --text: var(--dark-text);
  --text-2: var(--dark-text-2);
  --text-3: var(--dark-text-3);
  --border: var(--dark-border);
  --btn-primary-bg: #ffffff;
  --btn-primary-text: var(--dark-bg);
  color-scheme: dark;
}
.theme-light {
  --bg: var(--light-bg);
  --surface: var(--light-surface-1);
  --surface-raised: var(--light-surface-2);
  --text: var(--light-text);
  --text-2: var(--light-text-2);
  --text-3: var(--light-text-3);
  --border: var(--light-border);
  --btn-primary-bg: var(--dark-bg);
  --btn-primary-text: #ffffff;
  color-scheme: light;
}

/* ------------------------------------------------------------- base */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: -0.011em;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* -------------------------------------------------------- typography */

.display { font-variation-settings: "opsz" 32; font-weight: 600; letter-spacing: -0.03em; line-height: 1.1; margin: 0; }
.h1 { font-size: clamp(32px, 4.5vw, 56px); }
.h2 { font-size: clamp(26px, 3vw, 36px); }
.h3 { font-size: 22px; }
.overline { font-size: 12px; font-weight: 550; text-transform: uppercase; letter-spacing: 0.17em; margin: 0; color: var(--text-2); }
.body-s { font-size: 14px; line-height: 20px; }
.body-l { font-size: 18px; line-height: 28px; }
.text-2 { color: var(--text-2); }
.text-3 { color: var(--text-3); }

/* ---------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 600 15px/1 var(--font); letter-spacing: -0.01em;
  padding: 12px 18px; border-radius: var(--radius-s); border: 1px solid transparent;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: opacity .15s ease, background-color .15s ease, border-color .15s ease;
}
.btn:hover { opacity: .88; }
.btn-primary { background: var(--btn-primary-bg); color: var(--btn-primary-text); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { opacity: 1; background: var(--surface); }
.btn-accent { background: var(--accent); color: #fff; }
.btn .chev { font-size: 18px; line-height: 0; margin-top: -2px; }

.icon-btn {
  width: 48px; height: 48px; border-radius: 50%; display: inline-grid; place-items: center;
  border: 1px solid var(--border); background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500;
  padding: 4px 10px; border-radius: 99px; border: 1px solid var(--border); color: var(--text-2);
}
.pill svg { width: 13px; height: 13px; }

/* ------------------------------------------- app frame + navigation */

.app { display: grid; grid-template-columns: var(--nav-width) 1fr; min-height: 100vh; }

/* The navigation panel is always dark (DESIGN-GUIDE.md, point A). */
.nav {
  --bg: var(--dark-surface-1); --text: var(--dark-text); --text-2: var(--dark-text-2);
  --text-3: var(--dark-text-3); --border: var(--dark-border);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--bg); color: var(--text); border-right: 1px solid var(--border);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 4px;
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 18px; letter-spacing: -0.02em;
        padding: 4px 8px 20px; text-decoration: none; }
.logo-mark { width: 28px; height: 28px; border-radius: 8px; background: #fff; color: var(--dark-bg);
             display: grid; place-items: center; font-size: 15px; font-weight: 700; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-s);
            color: var(--text-2); text-decoration: none; font-size: 14px; font-weight: 500; }
.nav-link:hover { color: var(--text); background: var(--dark-surface-2); }
.nav-link.active { background: var(--dark-surface-3); color: var(--text); }
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-link .count { margin-left: auto; color: var(--text-3); }
.nav-divider { height: 1px; background: var(--border); margin: 14px 4px; }
.nav .btn-accent { margin: 4px 0; }

.main { min-width: 0; padding: 28px 32px 64px; }
.main-inner { max-width: 1180px; margin: 0 auto; }

/* Phone: the panel folds behind a ☰ button. */
.topbar { display: none; }
.nav-toggle { display: none; }
@media (max-width: 767px) {
  .app { grid-template-columns: 1fr; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    position: sticky; top: 0; z-index: 20; padding: 12px 16px;
    background: var(--dark-surface-1); color: var(--dark-text); border-bottom: 1px solid var(--dark-border);
  }
  .topbar .logo { padding: 0; }
  .nav-toggle {
    display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: var(--radius-s);
    border: 1px solid var(--dark-border); background: transparent; color: var(--dark-text); cursor: pointer;
  }
  .nav { position: fixed; inset: 0 auto 0 0; z-index: 30; width: min(var(--nav-width), 85vw);
         transform: translateX(-100%); transition: transform .2s ease; }
  .nav.open { transform: none; box-shadow: 0 0 0 100vmax #02030899; }
  .nav .logo { display: none; }
  .main { padding: 20px 16px 48px; }
}

/* ------------------------------------------------------------ cards */

.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
@media (max-width: 1100px) { .cards { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px)  { .cards { grid-template-columns: 1fr; } }
.card { text-decoration: none; color: inherit; display: block; }
.card-cover { position: relative; aspect-ratio: 4 / 3; border-radius: var(--radius-l); overflow: hidden;
              background: var(--light-surface-2); display: grid; place-items: center; }
.card-cover img { width: 100%; height: 100%; object-fit: cover; }
.card-cover .brand-logo { width: 72px; height: 72px; border-radius: 18px; background: #fff; display: grid; place-items: center;
                          font-weight: 700; font-size: 22px; color: var(--light-text-2); border: 1px solid var(--light-surface-3); overflow: hidden; }
.card-status { position: absolute; top: 12px; left: 12px; font-size: 11px; font-weight: 600; padding: 4px 9px; border-radius: 99px; }
.card-status.published { background: #fff; color: var(--success); }
.card-status.draft { background: var(--dark-bg); color: #fff; }
.card-meta { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-top: 12px; }
.card-title { font-size: 17px; font-weight: 500; letter-spacing: -0.015em; }
.card-category { font-size: 14px; margin-top: 2px; color: var(--text-2); }
.card-pills { display: flex; gap: 6px; flex-shrink: 0; }

/* ---------------------------------------------------------- sparkles */
/* Tiny four-pointed stars that fly out and fade (static/js/sparkles.js). */
.sparkle {
  position: fixed; left: var(--x); top: var(--y); width: var(--size); height: var(--size);
  margin: calc(var(--size) / -2) 0 0 calc(var(--size) / -2);
  background: var(--color); pointer-events: none; z-index: 100;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  animation: sparkle .6s ease-out var(--delay) both;
}
@keyframes sparkle {
  0%   { transform: translate(0, 0) scale(.2) rotate(0deg); opacity: 0; }
  25%  { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1) rotate(90deg); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .sparkle { display: none; } }

/* ------------------------------------------------------ login + home */

.auth-card { max-width: 420px; margin: 8vh auto 0; padding: 32px; border: 1px solid var(--border); border-radius: var(--radius-l); background: var(--bg); }
.auth-card .display { margin-bottom: 8px; }
.auth-form { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }
.auth-label { font-size: 13px; font-weight: 600; }
.auth-input { font: 400 15px var(--font); padding: 12px 14px; border: 1px solid var(--light-surface-3); border-radius: var(--radius-s);
              background: var(--bg); color: var(--text); }
.auth-input:focus { border-color: var(--light-text-3); outline: none; }
.auth-submit { margin-top: 8px; }
.auth-error { margin: 12px 0 0; padding: 10px 12px; border-radius: var(--radius-s); background: #e5484d14; color: #b4232a; font-size: 14px; }
.auth-code { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 20px 0; padding: 18px;
             border: 1px solid var(--border); border-radius: var(--radius-m); background: var(--surface); text-align: center; }
.auth-code strong { font-variation-settings: "opsz" 32; font-size: 44px; font-weight: 600; letter-spacing: 0.08em; line-height: 1.1; }
.auth-waiting { display: flex; align-items: center; gap: 8px; }
.auth-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success-bright); flex-shrink: 0; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .auth-dot { animation: none; } }
.home { max-width: 640px; margin: 12vh auto 0; text-align: center; }
.home .display { margin: 12px 0 16px; }
.home .btn { margin-top: 12px; }
.nav-logout { margin: 0; }
.nav-logout .nav-link { width: 100%; border: 0; background: transparent; font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; text-align: left; }

/* ---------------------------------------------------- profile dashboard */
/* docs/design/preview.html section 4: big rounded photo, name/profession/bio,
   big numbers on the right, then the 4 latest analyses. */

.profile-top { display: flex; justify-content: flex-end; min-height: 38px; }
.profile { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 28px; margin: 8px 0 44px; }
.profile-identity { display: flex; align-items: flex-end; gap: 24px; min-width: 0; }
.profile-photo { width: 132px; height: 132px; flex-shrink: 0; border-radius: 34px; object-fit: cover;
                 background: linear-gradient(135deg, var(--dark-surface-4), var(--dark-surface-3));
                 border: 1px solid var(--border); display: grid; place-items: center;
                 color: var(--text-2); font-size: 36px; font-weight: 600; letter-spacing: -0.02em; }
.profile-profession { margin: 6px 0 0; color: var(--text-2); }
.profile-bio { margin: 4px 0 0; max-width: 520px; }
.stats { display: flex; flex-wrap: wrap; gap: 32px; margin: 0; }
.stat dt { color: var(--text-2); font-size: 14px; margin-bottom: 6px; }
.stat dd { margin: 0; font-variation-settings: "opsz" 32; font-size: 40px; font-weight: 600; letter-spacing: -0.03em; line-height: 1; }
.stat-private dt { color: var(--text-3); }
.latest-title { margin-bottom: 14px; }
.see-all { display: flex; justify-content: center; margin-top: 28px; }
@media (max-width: 767px) {
  .profile { align-items: flex-start; }
  .profile-identity { flex-direction: column; align-items: flex-start; gap: 16px; }
  .profile-photo { width: 96px; height: 96px; border-radius: 26px; font-size: 28px; }
  .stats { gap: 20px 28px; }
  .stat dd { font-size: 32px; }
}

/* ------------------------------------------------- all analyses page */

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 20px; }
.search-field, .select-field { position: relative; display: flex; align-items: center; }
.search-field { flex: 1 1 240px; }
.search-field svg { position: absolute; left: 12px; width: 18px; height: 18px; color: var(--text-3); pointer-events: none; }
.filters input, .filters select {
  font: 500 14px var(--font); color: var(--text-2); background: var(--bg);
  border: 1px solid var(--light-surface-3); border-radius: var(--radius-s); padding: 10px 14px; height: 42px;
}
.filters input { width: 100%; padding-left: 38px; }
.filters input::placeholder { color: var(--text-3); }
.filters select { appearance: none; padding-right: 34px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 18px, calc(100% - 13px) 18px; background-size: 5px 5px; background-repeat: no-repeat; }
.filters input:focus, .filters select:focus { border-color: var(--light-text-3); outline: none; }
.results-count { margin: 0 0 16px; }
.results-count a { color: var(--text-2); }
.cards { list-style: none; padding: 0; margin: 0; }
.card:hover .card-cover { box-shadow: 0 0 0 1px var(--light-surface-3); }
.card:hover .card-title { text-decoration: underline; text-underline-offset: 3px; }
.card-disabled { cursor: default; opacity: .85; }
.card-cover .brand-logo img { width: 100%; height: 100%; object-fit: cover; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
@media (max-width: 600px) { .select-field { flex: 1 1 calc(50% - 5px); } .select-field select { width: 100%; } }

/* -------------------------------------------------------- page bits */

.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 28px; }
.empty {
  border: 1px dashed var(--border); border-radius: var(--radius-l); padding: 48px 24px; text-align: center; color: var(--text-2);
}
.empty .display { color: var(--text); margin-bottom: 8px; }
.mt-16 { margin-top: 16px; }
.empty .btn { margin-top: 16px; }

/* ---------------------------------------------------- analysis page */

.article { max-width: 760px; margin: 0 auto; }
.brandline { display: flex; align-items: center; gap: 10px; }
.brand-chip { width: 28px; height: 28px; border-radius: 8px; background: var(--light-surface-2); display: grid; place-items: center;
              font-size: 12px; font-weight: 700; color: var(--light-text-2); object-fit: cover; }
.article-title { margin: 14px 0 12px; }
.article-byline { margin: 0; letter-spacing: 0.02em; }
/* Owner, 2026-10-22: Share sits on the byline's line, right-aligned; red ♥ below; no separator lines. */
.byline-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.btn-small { padding: 8px 14px; font-size: 14px; }
.like-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; margin: 6px 0 24px -9px; padding: 0;
            border: 0; border-radius: 50%; background: transparent; color: var(--like); cursor: pointer;
            transition: transform .15s ease, background-color .15s ease; }
.like-btn:hover { background: #e5484d14; }
.like-btn:active { transform: scale(.88); }
.like-btn svg { width: 24px; height: 24px; fill: none; transition: fill .15s ease; }
.like-btn[aria-pressed="true"] svg { fill: currentColor; }

.takeaways { background: var(--surface); border-radius: var(--radius-m); padding: 20px 24px; }
.takeaways ul { margin: 10px 0 0; padding-left: 20px; }
.takeaways li + li { margin-top: 6px; }

.numbers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 16px; }
.numbers:has(> :nth-child(3):last-child) { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 600px) { .numbers, .numbers:has(> :nth-child(3):last-child) { grid-template-columns: repeat(2, 1fr); } }
.number { border: 1px solid var(--border); border-radius: var(--radius-m); padding: 16px; }
.number-value { font-variation-settings: "opsz" 32; font-size: 30px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.15; }

.article-section { margin-top: 40px; }
.article-section > .overline { margin-bottom: 12px; }
.video { position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius-m); overflow: hidden; background: var(--dark-surface-3); }
.video iframe, .video video { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* Document box (owner, 2026-10-22): like the video — a rounded box the PDF scrolls inside,
   with "Page x of y" and a fullscreen button. */
.doc-viewer { position: relative; display: flex; flex-direction: column; height: min(80vh, 900px);
              border: 1px solid var(--border); border-radius: var(--radius-m); overflow: hidden; background: var(--light-surface-2); }
.doc-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-shrink: 0;
               padding: 8px 8px 8px 16px; background: var(--bg); border-bottom: 1px solid var(--border); }
.doc-page { color: var(--text-3); font-variant-numeric: tabular-nums; }
.doc-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 16px; }
.doc-viewer:fullscreen { height: 100vh; border: 0; border-radius: 0; }
.doc-viewer.is-fullscreen .pdf { max-width: 1000px; margin: 0 auto; }

/* Fullscreen boxes (static/js/fullscreen.js): video and document share one button and one behaviour.
   .is-expanded = the CSS fullscreen used when the browser won't do real fullscreen. */
.box-fullscreen { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: var(--radius-s);
                  background: transparent; color: var(--text-2); cursor: pointer; flex-shrink: 0; }
.box-fullscreen:hover { background: var(--surface); color: var(--text); }
.box-fullscreen svg { width: 18px; height: 18px; }
.box-fullscreen .icon-collapse, .is-fullscreen .box-fullscreen .icon-expand { display: none; }
.is-fullscreen .box-fullscreen .icon-collapse { display: block; }
[data-fullscreen-box].is-expanded { position: fixed; inset: 0; z-index: 50; height: 100dvh; margin: 0; border: 0; border-radius: 0; }
.box-expanded body { overflow: hidden; }


.pdf { display: flex; flex-direction: column; gap: 12px; }
.pdf-page { width: 100%; background: #fff; border-radius: 6px; overflow: hidden; box-shadow: 0 1px 3px #02030814; }
.pdf-page canvas { display: block; width: 100%; height: 100%; }
.pdf-status { padding: 32px; text-align: center; margin: 0; }
@media (max-width: 600px) { .doc-viewer { height: 70vh; } .doc-scroll { padding: 10px; } }

/* Share window: title "Link", address centred, Copy centred, no ✕ (closes on Esc / outside click). */
.share-dialog { width: min(420px, calc(100vw - 32px)); border: 1px solid var(--light-border); border-radius: var(--radius-l);
                padding: 26px; text-align: center; background: #fff; color: var(--light-text); box-shadow: 0 20px 60px #0000001f; }
.share-dialog::backdrop { background: #02030866; backdrop-filter: blur(4px); }
.share-dialog .btn.is-copied { background: var(--success); }
.share-url { margin: 18px 0 20px; padding: 12px; border-radius: var(--radius-s); background: var(--light-surface-1);
             font-size: 14px; overflow-wrap: anywhere; user-select: all; }
