/* ============================================================================
   Topic Randomizer
   Visual language translated from mosbyfiles.com — tokens below are the real
   values pulled from that site's stylesheet, not approximations.
   ========================================================================== */

/* --- Fonts ---------------------------------------------------------------
   Mosby sets its display type in Founders Grotesk X-Condensed Bold and its
   body/tags in Signifier Light. Both are commercial Klim faces, so we stand in
   the closest open (SIL OFL) equivalents, self-hosted for offline use:
     Founders Grotesk X-Cond Bold -> Archivo variable at wdth 62 / wght 700
     Signifier Light              -> Newsreader variable at a light weight
   ------------------------------------------------------------------------ */

@font-face {
  font-family: 'Archivo';
  src: url('../fonts/archivo-latin.woff2') format('woff2');
  font-weight: 400 700;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Archivo';
  src: url('../fonts/archivo-latin-ext.woff2') format('woff2');
  font-weight: 400 700;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Newsreader';
  src: url('../fonts/newsreader-latin.woff2') format('woff2');
  font-weight: 200 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Newsreader';
  src: url('../fonts/newsreader-latin-ext.woff2') format('woff2');
  font-weight: 200 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* --- Tokens -------------------------------------------------------------- */

:root {
  /* mosbyfiles.com core palette */
  --paper: #fdfaf7;   /* --color-light */
  --ink:   #191919;   /* --color-dark  */
  --gray:  #787a7f;   /* --color-gray  */

  /* the site's primary/contrast indirection — swapping these inverts a section */
  --primary:  var(--ink);
  --contrast: var(--paper);

  /* folder-tab accents, lifted from the per-section vars in their markup */
  --tab-red:    #d71e1e;
  --tab-blue:   #1e4bd7;
  --tab-yellow: #ffe927;
  --tab-purple: #581e70;
  --tab-teal:   #0c7866;
  --tab-black:  #000000;

  --radius: 4px;                             /* their dominant radius */
  --ease:   cubic-bezier(.33, 1, .68, 1);    /* their signature easing */
  --tilt:   -3deg;                           /* --stack-rotation-angle */
  --shadow: 0 -1px 8px rgb(0 0 0 / .15);     /* --stack-shadow */
  --folder-shadow: 1px 0 8px rgb(0 0 0 / .15);

  --gutter: 48px;                            /* --container-offset at desktop */

  --display: 'Archivo', 'Helvetica Neue', Arial, sans-serif;
  --serif:   'Newsreader', Georgia, 'Times New Roman', serif;
}

@media (max-width: 1024px) { :root { --gutter: 30px; } }
@media (max-width: 480px)  { :root { --gutter: 18px; } }

/* Condensed uppercase display, as the site sets it: line-height 1, no tracking. */
.u-display {
  font-family: var(--display);
  font-weight: 700;
  font-stretch: 62%;
  line-height: 1;
  text-transform: uppercase;
}

/* --- Reset --------------------------------------------------------------- */

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

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

body {
  margin: 0;
  /* Definite, not min-height: the wheel derives its size from the grid row it
     is given, and a percentage height only resolves against an ancestor chain
     that is itself definite. With min-height the chain stays indefinite and
     the wheel silently falls back to sizing off its width. */
  height: 100svh;
  display: flex;
  flex-direction: column;
  background-color: var(--primary);
  color: var(--contrast);
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 300;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--tab-yellow);
  outline-offset: 3px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

/* --- Custom cursor ------------------------------------------------------
   Mosby hides the native cursor (cursor:none) and paints its own. The
   difference blend keeps it legible over both the dark ground and the paper
   panels without needing two colours.
   ---------------------------------------------------------------------- */

.cursor { display: none; }

@media (pointer: fine) {
  body { cursor: none; }
  .folder__input { cursor: text; }

  .cursor {
    display: block;
    position: fixed;
    top: 0; left: 0;
    width: 12px; height: 12px;
    margin: -6px 0 0 -6px;
    border-radius: 50%;
    background: var(--paper);
    mix-blend-mode: difference;
    pointer-events: none;
    z-index: 999;
    opacity: 0;
    transition: width .3s var(--ease), height .3s var(--ease),
                margin .3s var(--ease), opacity .2s var(--ease);
  }
  .cursor.is-live { opacity: 1; }
  .cursor.is-hot {
    width: 44px; height: 44px;
    margin: -22px 0 0 -22px;
  }
}

/* --- Masthead ------------------------------------------------------------ */

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  /* Wraps rather than overflowing: the meta is nowrap, and on narrow phones
     the title leaves it too little room to sit alongside. */
  flex-wrap: wrap;
  gap: 6px 24px;
  padding: 14px var(--gutter) 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--contrast) 22%, transparent);
}

.masthead__title {
  font-family: var(--display);
  font-weight: 700;
  font-stretch: 62%;
  line-height: 1;
  text-transform: uppercase;
  font-size: clamp(1.6rem, 1.1rem + 1.5vw, 2.5rem);
  margin: 0;
  display: flex;
  align-items: center;
  gap: .5em;
}

/* the little hairline between the two words — a print-masthead tic */
.masthead__rule {
  display: block;
  width: clamp(24px, 5vw, 72px);
  height: 1px;
  background: currentColor;
  opacity: .5;
}

.masthead__meta {
  margin: 0;
  font-size: clamp(.75rem, 0rem + .833vw, 1rem);
  color: var(--gray);
  display: flex;
  align-items: baseline;
  gap: .6em;
  white-space: nowrap;
}

.masthead__sep { opacity: .5; }

/* --- Shared controls ----------------------------------------------------- */

.linkbtn {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: inherit;
  font-family: var(--serif);
  font-size: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: .25em;
  text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
  transition: color .25s var(--ease), text-decoration-color .25s var(--ease);
}
.linkbtn:hover {
  color: var(--contrast);
  text-decoration-color: currentColor;
}
.folder .linkbtn:hover { color: var(--ink); }

@media (pointer: fine) { .linkbtn { cursor: none; } }

.btn {
  font-family: var(--display);
  font-weight: 700;
  font-stretch: 62%;
  line-height: 1;
  text-transform: uppercase;
  font-size: 1.125rem;
  padding: 1em 1.5em .85em;
  border-radius: var(--radius);
  border: 1px solid currentColor;
  cursor: pointer;
  background: transparent;
  transition: background-color .3s var(--ease), color .3s var(--ease);
}
@media (pointer: fine) { .btn { cursor: none; } }

.btn--solid { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn--solid:hover { background: var(--tab-red); border-color: var(--tab-red); }
.btn--ghost { color: var(--ink); }
.btn--ghost:hover { background: var(--ink); color: var(--paper); }

/* --- Stage --------------------------------------------------------------- */

.stage {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
  /* Bounded explicitly: an implicit auto row would size to its content, which
     is the very thing we want to derive FROM the row height. */
  grid-template-rows: minmax(0, 1fr);
  gap: clamp(20px, 3vw, 48px);
  align-items: stretch;
  min-height: 0;
  /* The bottom padding is sized to house the spin hint, which is lifted out of
     the flow below so it costs the wheel no height of its own. */
  padding: clamp(10px, 1.2vw, 16px) var(--gutter) clamp(32px, 2.6vw, 36px);
}

.folder { align-self: center; }

@media (max-width: 900px) {
  /* Stacked: the page is meant to scroll, so release the fixed viewport height. */
  body { height: auto; min-height: 100svh; }

  .stage {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;   /* rows size to content */
    align-items: stretch;
  }
}

/* --- Wheel bay ----------------------------------------------------------- */

.wheelbay {
  position: relative;   /* anchors the out-of-flow hint below */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-width: 0;
  min-height: 0;
}

/* The wheel is almost always height-bound, not width-bound, so size it off the
   viewport minus the chrome above and below it (masthead + stage padding +
   hint + gap) rather than off a guessed vh fraction. The 100% term keeps it
   inside its grid column on wide-but-short windows and when stacked on mobile. */
/* Sized from the row the grid actually hands it, rather than from a hand-tuned
   `100svh - chrome` formula that has to be re-derived every time the masthead
   or the padding changes. height:100% takes all the row offers, aspect-ratio
   derives the width from it, and max-width:100% pulls both back down when the
   column — not the viewport — is the tighter constraint. */
.wheelbay__frame {
  position: relative;
  height: 100%;
  width: auto;
  max-width: 100%;
  max-height: 1400px;
  aspect-ratio: 1;
}

@media (max-width: 900px) {
  /* Stacked layout: the row is auto-height here, so height:100% has nothing to
     resolve against. Drive it from the width instead. */
  .wheelbay__frame {
    height: auto;
    width: 100%;
    max-width: min(100%, 900px);
    margin-bottom: 34px;   /* room for the out-of-flow hint above the panel */
  }
}

.wheel {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;      /* we own the drag gesture */
  user-select: none;
}
@media (pointer: fine) { .wheel { cursor: none; } }

/* The hub doubles as the keyboard-accessible spin control. */
.spinhit {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  /* Kept in sync with HUB_RATIO in js/wheel.js — labels are laid out around
     this circle, so changing one without the other makes them collide. */
  width: 17%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  box-shadow: 0 1px 6px rgb(0 0 0 / .25);
  transition: transform .35s var(--ease), background-color .35s var(--ease),
              color .35s var(--ease);
}
@media (pointer: fine) { .spinhit { cursor: none; } }

.spinhit__label {
  font-family: var(--display);
  font-weight: 700;
  font-stretch: 62%;
  line-height: 1;
  text-transform: uppercase;
  font-size: clamp(.9rem, 1.8vw, 1.5rem);
}

.spinhit:hover:not(:disabled) {
  transform: translate(-50%, -50%) scale(1.06);
  background: var(--tab-red);
  color: var(--paper);
  border-color: var(--tab-red);
}
.spinhit:disabled { opacity: .45; cursor: not-allowed; }

.wheelbay.is-spinning .spinhit { pointer-events: none; opacity: .55; }

/* Out of the flow, hanging off the bottom of the frame, so it costs the wheel
   no height. Its containing block is .wheelbay__frame, so top:100% tracks the
   wheel wherever it ends up. Room below comes from the stage's bottom padding
   on desktop and from the frame's own margin when stacked. */
.wheelbay__hint {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 10px 0 0;
  text-align: center;
  font-size: .8125rem;
  color: var(--gray);
  letter-spacing: .01em;
}

/* --- Folder panel -------------------------------------------------------
   The archive motif: a paper card with a manila tab riding on top of it.
   ---------------------------------------------------------------------- */

.folder {
  display: flex;
  flex-direction: column;
  min-width: 0;
  filter: drop-shadow(var(--folder-shadow));
}

.folder__tabs {
  display: flex;
  padding-left: 18px;
}

.folder__tab {
  font-family: var(--display);
  font-weight: 700;
  font-stretch: 62%;
  line-height: 1;
  text-transform: uppercase;
  font-size: 1.125rem;
  color: var(--paper);
  background: var(--tab-red);
  padding: .7em 1.6em .55em;
  border-radius: var(--radius) var(--radius) 0 0;
  /* the angled shoulders of a real file tab */
  clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 100%, 0 100%);
}

.folder__body {
  background: var(--paper);
  color: var(--ink);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.folder__label {
  font-family: var(--display);
  font-weight: 700;
  font-stretch: 62%;
  line-height: 1;
  text-transform: uppercase;
  font-size: .8125rem;
  color: var(--gray);
}

.folder__input {
  width: 100%;
  min-height: clamp(240px, 38vh, 420px);
  resize: vertical;
  background: transparent;
  border: 0;
  border-top: 1px solid color-mix(in srgb, var(--ink) 18%, transparent);
  padding: 14px 0 0;
  font-family: var(--serif);
  font-size: 1.125rem;
  font-weight: 300;
  line-height: 1.65;
  color: var(--ink);
}
.folder__input:focus { outline: none; }
.folder__input::placeholder { color: color-mix(in srgb, var(--ink) 35%, transparent); }
.folder__body:focus-within { box-shadow: inset 0 0 0 1px var(--ink); }

.folder__foot {
  display: flex;
  gap: 20px;
  font-size: .875rem;
  color: var(--gray);
  border-top: 1px solid color-mix(in srgb, var(--ink) 18%, transparent);
  padding-top: 12px;
}

/* --- Verdict (winner) ---------------------------------------------------
   Mosby inverts whole sections by swapping --primary/--contrast. We do the
   same here rather than inventing a separate modal palette.
   ---------------------------------------------------------------------- */

.verdict {
  --primary: var(--paper);
  --contrast: var(--ink);

  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--primary);
  color: var(--contrast);
  display: grid;
  place-items: center;
  padding: var(--gutter);

  /* The resting state is deliberately NOT left to animation-fill-mode. If the
     animation never ticks — throttled tab, embedded webview, an engine that
     skips it — `both` would pin opacity at 0 and leave a full-screen
     click-blocker you cannot see. Base styles hold the visible state; the
     animation only decorates the way in. */
  opacity: 1;
  animation: verdict-in .5s var(--ease);
}
.verdict[hidden] { display: none; }

@keyframes verdict-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.verdict__sheet {
  max-width: 1100px;
  width: 100%;
  text-align: center;
  opacity: 1;
  transform: none;
  animation: sheet-in .65s var(--ease);
}

/* echoes --stack-rotation-angle: the sheet settles like a dropped file */
@keyframes sheet-in {
  from { opacity: 0; transform: rotate(var(--tilt)) translateY(24px) scale(.96); }
  to   { opacity: 1; transform: rotate(0) translateY(0) scale(1); }
}

.verdict__kicker {
  margin: 0 0 .5em;
  font-family: var(--display);
  font-weight: 700;
  font-stretch: 62%;
  line-height: 1;
  text-transform: uppercase;
  font-size: clamp(.75rem, 0rem + .833vw, 1rem);
  color: var(--gray);
}

.verdict__name {
  /* the real display clamp from mosbyfiles.com */
  font-family: var(--display);
  font-weight: 700;
  font-stretch: 62%;
  line-height: 1;
  text-transform: uppercase;
  font-size: clamp(4rem, 2.25rem + 5.833vw, 7.5rem);
  margin: 0 0 .35em;
  padding-bottom: .05em;
  overflow-wrap: anywhere;
  border-bottom: 1px solid color-mix(in srgb, var(--contrast) 25%, transparent);
}

/* long names shouldn't blow out of the viewport */
.verdict__name.is-long  { font-size: clamp(2.66rem, 1.49rem + 3.9vw, 5rem); }
.verdict__name.is-epic  { font-size: clamp(2rem, 1.429rem + 2.857vw, 4rem); }

.verdict__acts {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 2rem;
}

/* --- Motion preferences -------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .verdict, .verdict__sheet { animation-duration: .01ms; }
  .cursor { transition: none; }
  .spinhit { transition: none; }
}
