/* The Lexiverse, Evren's Lexi — a futuristic word scanner (js/menu.js + the
   #counter device button). Reference: the Claude-design device — dark shell,
   periwinkle glow, a screen with a sweeping scanline and a bleeping LED.
   Violet is the device's own metal; the words inside stay gold. */

/* ---------- The device button (top right) ---------- */

#counter {
  position: fixed;
  z-index: 40; /* above the overlays: the scanner opens from anywhere */
  top: max(3vh, env(safe-area-inset-top, 0px) + 14px);
  right: 4vw;
  display: flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.45em 0.8em;
  border: 1px solid rgba(150, 148, 220, 0.55);
  border-radius: 12px;
  background: rgba(18, 16, 44, 0.55);
  box-shadow: 0 0 14px rgba(116, 112, 200, 0.18), inset 0 0 12px rgba(116, 112, 200, 0.08);
  opacity: 0;
  transition: opacity 1s ease, border-color 0.3s ease, box-shadow 0.3s ease;
  pointer-events: none;
}
/* Visible from the first word she counts, but sealed until Evren names her
   (engine.js, `locked`). She still lights up and still counts; she simply
   does not open yet. */
#counter.show { opacity: 0.92; }
#counter.show:not(.locked) { pointer-events: auto; cursor: pointer; }
#counter.show:not(.locked):hover {
  opacity: 1;
  border-color: rgba(185, 180, 232, 0.9);
  box-shadow: 0 0 20px rgba(140, 135, 220, 0.35), inset 0 0 12px rgba(116, 112, 200, 0.12);
}

/* The little machine: a screen holding the count, a scanline, a bleeping LED. */
.dv-device {
  position: relative;
  display: inline-flex;
  padding: 3px;
  border: 1px solid rgba(185, 180, 232, 0.7);
  border-radius: 6px;
}
.dv-screen {
  position: relative;
  overflow: hidden;
  min-width: 2em;
  padding: 0.12em 0.3em;
  border-radius: 4px;
  background: rgba(28, 24, 64, 0.9);
  font-family: var(--sans);
  font-size: 0.8rem;
  text-align: center;
  color: #B9E8D8;
  text-shadow: 0 0 8px rgba(140, 232, 200, 0.7);
}
.dv-scanline {
  position: absolute;
  left: 0; right: 0;
  height: 30%;
  background: linear-gradient(rgba(185, 180, 232, 0), rgba(185, 180, 232, 0.28), rgba(185, 180, 232, 0));
  animation: dv-scan 2.6s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes dv-scan {
  from { top: -30%; }
  to   { top: 100%; }
}
/* ---------- Lexi wakes up ---------- */

/* Now and then the screen stops being a readout and becomes a face. She is
   eyes and nothing else: two soft azure blocks on a dark screen, the way a
   little robot looks at you. They open, they blink, one winks, they close,
   and the count comes back. js/lexi.js adds `awake` for the length of the
   animation and nothing else changes.

   Three nested elements carry three separate transforms, so a glance, a
   blink, and a wink can all run at once without overwriting each other:
   .dv-face looks around, .dv-eyes blinks both, .dv-eye winks one. */
.dv-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
}
.dv-eyes { display: flex; gap: 0.32em; }
/* Solid azure, no glow: the screen behind her already carries the device's
   light, and a halo around the eyes only muddies them. */
.dv-eye {
  width: 0.44em; height: 0.5em;
  border-radius: 0.15em;
  background: #74B0FF;
}

/* One wake cycle on the button, every animation sharing the same clock. */
#counter.awake .dv-face  { animation: lexi-face  4.2s ease forwards; }
#counter.awake #counter-num { animation: lexi-num 4.2s ease forwards; }
#counter.awake .dv-eyes  { animation: lexi-sleep 4.2s ease forwards; }
#counter.awake .dv-eye:last-child { animation: lexi-wink 4.2s ease forwards; }

@keyframes lexi-face  { 0% { opacity: 0; } 10%, 86% { opacity: 1; } 100% { opacity: 0; } }
@keyframes lexi-num   { 0% { opacity: 1; } 10%, 86% { opacity: 0; } 100% { opacity: 1; } }
/* Open, a blink to say she is really awake, then closed again at the end. */
@keyframes lexi-sleep {
  0%, 18%   { transform: none; }
  24%, 27%  { transform: scaleY(0.12); }
  33%, 80%  { transform: none; }
  92%, 100% { transform: scaleY(0.12); }
}
/* The wink: the right eye alone drops, after the blink and before she sleeps. */
@keyframes lexi-wink  { 0%, 48% { transform: none; } 56%, 66% { transform: scaleY(0.12); } 74%, 100% { transform: none; } }
/* A blink on its own clock, for the face that never sleeps (her own page). */
@keyframes lexi-blink { 0%, 92% { transform: none; } 95%, 97% { transform: scaleY(0.12); } 100% { transform: none; } }

.dv-led {
  position: absolute;
  top: -3px; right: -3px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #74B0FF;
  box-shadow: 0 0 7px 1px rgba(116, 176, 255, 0.9);
  animation: dv-bleep 1.8s steps(1) infinite;
}
@keyframes dv-bleep {
  0%, 100% { opacity: 1; }
  55% { opacity: 0.25; }
  65% { opacity: 1; }
  75% { opacity: 0.25; }
}

/* Her name rides beside the device only while Evren is introducing her
   (engine.js adds `named` until portalReady). After that the scanner and its
   count say everything, and the corner gets its space back. */
.dv-labels { display: none; flex-direction: column; line-height: 1.25; text-align: left; }
#counter.named .dv-labels { display: flex; }
#counter-word {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: #B9B4E8;
  text-shadow: 0 0 10px rgba(150, 148, 220, 0.5);
}
@media (hover: hover) { #counter-word { cursor: help; } }
#counter-sub {
  font-family: var(--sans);
  font-size: 0.58rem;
  letter-spacing: 0.12em;
  color: var(--lavender);
  opacity: 0.75;
}

/* ---------- The open device: the scanner page ---------- */

#menu {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(11, 10, 31, 0.84);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  display: flex; align-items: center; justify-content: center;
  padding: 5vh 5vw;
  opacity: 0;
  transition: opacity 0.35s ease;
  cursor: pointer;
}
#menu.show { opacity: 1; }

.dv-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1080px;
  max-height: 88vh;
  cursor: auto;
  padding: 1.1em 1.4em 1.2em;
  border: 1px solid rgba(150, 148, 220, 0.5);
  border-radius: 18px;
  background:
    radial-gradient(120% 90% at 20% 0%, rgba(74, 60, 140, 0.18), transparent 60%),
    rgba(16, 14, 40, 0.92);
  box-shadow: 0 0 34px rgba(116, 112, 200, 0.22), inset 0 0 24px rgba(116, 112, 200, 0.07);
  overflow: hidden;
}
/* A faint scanline sweeps the whole device, slowly. The machine is on. */
.dv-shell::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 90px;
  background: linear-gradient(rgba(185, 180, 232, 0), rgba(185, 180, 232, 0.05), rgba(185, 180, 232, 0));
  animation: dv-scan 7s linear infinite;
  pointer-events: none;
}

/* Header. Three tracks with the side ones sized alike, so Lexi lands on the
   true centre of the device no matter how wide the search beside her is. */
.dv-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 0.9em;
  padding-bottom: 0.9em;
  border-bottom: 1px solid rgba(150, 148, 220, 0.25);
  flex-shrink: 0;
}
.dv-name {
  justify-self: center;
  font-family: var(--sans);
  font-size: 0.8rem;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: #B9B4E8;
  text-shadow: 0 0 10px rgba(150, 148, 220, 0.5);
}
.dv-head-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.9em;
}

/* Lexi in the corner of her page: the same device as the button that opened
   it, twice the size, and her face never sleeps here. */
.dv-lexi { justify-self: start; }
.dv-lexi .dv-screen {
  width: 2.2em;
  height: 1.45em;
  min-width: 0;
  padding: 0;
  font-size: 1.5rem;
}
.dv-lexi .dv-face { opacity: 1; }
/* While you are reading her pages she has nothing to do, so she lives: a
   glance right, a glance left, a blink, and a wink now and then. Three
   clocks, none of them a multiple of another, so she never falls into a
   pattern you can predict. */
.dv-lexi .dv-face { animation: lexi-look 11s ease-in-out infinite; }
.dv-lexi .dv-eyes { animation: lexi-blink 6.5s ease-in-out infinite; }
.dv-lexi .dv-eye:last-child { animation: lexi-wink-idle 17s ease-in-out infinite; }
@keyframes lexi-look {
  0%, 16%   { transform: none; }
  24%, 38%  { transform: translateX(0.11em); }
  46%, 60%  { transform: none; }
  68%, 82%  { transform: translateX(-0.11em); }
  90%, 100% { transform: none; }
}
@keyframes lexi-wink-idle {
  0%, 93%     { transform: none; }
  95.5%, 97%  { transform: scaleY(0.12); }
  100%        { transform: none; }
}

.dv-search {
  width: min(16em, 26vw);
  padding: 0.45em 0.9em;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--cream);
  background: rgba(28, 24, 64, 0.7);
  border: 1px solid rgba(150, 148, 220, 0.4);
  border-radius: 999px;
  outline: none;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}
.dv-search::placeholder { color: rgba(154, 147, 184, 0.7); font-style: italic; }
.dv-search:focus {
  border-color: rgba(185, 180, 232, 0.85);
  box-shadow: 0 0 12px rgba(140, 135, 220, 0.3);
}
.dv-close {
  background: none;
  border: 1px solid rgba(150, 148, 220, 0.4);
  border-radius: 50%;
  width: 2em; height: 2em;
  color: var(--lavender);
  cursor: pointer;
  transition: border-color 0.25s ease, color 0.25s ease;
}
.dv-close:hover { border-color: #B9B4E8; color: var(--cream); }

/* Galaxy tabs: each wears its own color. */
.dv-galaxies {
  display: flex;
  gap: 0.5em;
  padding: 0.9em 0 0.2em;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.dv-galaxy {
  --gc: #E8C16A;
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  padding: 0.35em 1em;
  color: var(--gc);
  background: none;
  border: 1px solid color-mix(in srgb, var(--gc) 40%, transparent);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}
.dv-galaxy:hover { border-color: var(--gc); }
.dv-galaxy.active {
  border-color: var(--gc);
  background: color-mix(in srgb, var(--gc) 12%, transparent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--gc) 30%, transparent);
}
.dv-galaxy.soon { opacity: 0.38; }

/* Before the levels: the whole sky, and Evren's own dark. Neither is a level,
   so neither wears a level's pill. A hairline separates them from the galaxies. */
.dv-scope {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-family: var(--sans);
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  padding: 0.35em 0.9em;
  color: var(--lavender);
  background: none;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: color 0.25s ease, background 0.25s ease, border-color 0.25s ease;
}
.dv-scope:hover { color: var(--cream); background: rgba(150, 148, 220, 0.08); }
.dv-scope.active {
  color: #B9B4E8;
  border-color: rgba(185, 180, 232, 0.6);
  background: rgba(116, 112, 200, 0.14);
}
/* "all" carries a little sky of its own. */
.dv-scope.all::before {
  content: '';
  width: 13px; height: 13px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 32%, rgba(232, 193, 106, 0.95) 0 1.1px, transparent 1.6px),
    radial-gradient(circle at 68% 40%, rgba(232, 193, 106, 0.85) 0 1px, transparent 1.5px),
    radial-gradient(circle at 48% 72%, rgba(232, 193, 106, 0.9) 0 1.1px, transparent 1.6px),
    rgba(28, 24, 64, 0.7);
  border: 1px solid rgba(185, 180, 232, 0.45);
}
/* The Void: a dark mouth with a thin ring, the way it looks from inside. */
.dv-void-orb {
  position: relative;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #000 0%, #0B0A1F 45%, rgba(42, 27, 74, 0.9) 80%, rgba(154, 147, 184, 0.3) 100%);
  border: 1px solid rgba(154, 147, 184, 0.5);
  box-shadow: inset 0 0 5px #000;
  flex-shrink: 0;
}
.dv-void-orb::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  width: 22px; height: 8px;
  border: 1px solid rgba(154, 147, 184, 0.45);
  border-radius: 50%;
  transform: translate(-50%, -50%) rotate(-18deg);
  animation: dv-void-tilt 9s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes dv-void-tilt {
  from { transform: translate(-50%, -50%) rotate(-12deg); }
  to   { transform: translate(-50%, -50%) rotate(-26deg); }
}
.dv-scope.void.active .dv-void-orb { box-shadow: inset 0 0 5px #000, 0 0 12px rgba(154, 147, 184, 0.5); }

/* The seam between what is not a level and what is. */
.dv-tab-sep {
  width: 1px;
  align-self: stretch;
  margin: 0.15em 0.45em;
  background: linear-gradient(rgba(150, 148, 220, 0), rgba(150, 148, 220, 0.35), rgba(150, 148, 220, 0));
}

@media (prefers-reduced-motion: reduce) {
  .dv-void-orb::after { animation: none; }
}

/* Planets: circles, like planets. The name whispers on hover. */
.dv-planets {
  display: flex;
  align-items: flex-start;
  gap: 1.1em;
  padding: 0.8em 0.2em 0.4em;
  min-height: 3.6em;
  flex-shrink: 0;
}
.dv-orb-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4em;
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0;
  animation: menu-word-in 0.5s ease forwards;
}
.dv-orb {
  --pc: #E8C16A;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #F3EAD8, var(--pc) 55%, #14102e 130%);
  box-shadow: 0 0 10px 2px color-mix(in srgb, var(--pc) 45%, transparent);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.dv-orb-cell:hover .dv-orb { transform: scale(1.18); box-shadow: 0 0 16px 4px color-mix(in srgb, var(--pc) 65%, transparent); }

/* All and the Void own no planets: the row steps aside for them. */
.dv-planets.hidden { display: none; }
.dv-orb-cell.active .dv-orb {
  box-shadow: 0 0 18px 5px color-mix(in srgb, var(--pc) 75%, transparent);
  outline: 1px solid color-mix(in srgb, var(--pc) 80%, transparent);
  outline-offset: 3px;
}
/* The name (and the scanned count) appear only on hover or selection. */
.dv-orb-name {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.3;
  font-family: var(--serif);
  font-size: 0.8rem;
  color: var(--cream);
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  white-space: nowrap;
}
.dv-orb-cell:hover .dv-orb-name,
.dv-orb-cell.active .dv-orb-name { opacity: 1; transform: none; }
.dv-orb-count {
  font-family: var(--sans);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  color: var(--lavender);
}
.dv-soon {
  font-family: var(--sans);
  font-style: italic;
  font-size: 0.8rem;
  color: var(--lavender);
  opacity: 0.7;
  align-self: center;
}

/* Sections (words | chunks) and sorting (a–z | newest). */
.dv-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1em;
  padding: 0.4em 0 0.7em;
  flex-shrink: 0;
}
.dv-sections, .dv-sorts { display: flex; gap: 0.4em; }
.dv-sec, .dv-sort {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  padding: 0.3em 0.9em;
  color: var(--lavender);
  background: none;
  border: 1px solid rgba(150, 148, 220, 0.3);
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.25s ease, border-color 0.25s ease, background 0.25s ease;
}
.dv-sec:hover, .dv-sort:hover { border-color: rgba(185, 180, 232, 0.7); }
.dv-sec.active, .dv-sort.active {
  color: #B9B4E8;
  border-color: rgba(185, 180, 232, 0.85);
  background: rgba(116, 112, 200, 0.12);
}

/* The bank: a responsive grid; only this scrolls, and it scrolls quietly. */
.dv-list {
  flex: 1;
  min-height: 8em;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(13.5em, 1fr));
  gap: 0.15em 0.9em;
  align-content: start;
  padding: 0.2em 0.5em 1.2em 0.1em;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 12px, #000 calc(100% - 24px), transparent 100%);
          mask-image: linear-gradient(to bottom, transparent 0, #000 12px, #000 calc(100% - 24px), transparent 100%);
}
/* The scanner's own scrollbar: a thin violet beam. */
.dv-list::-webkit-scrollbar { width: 5px; }
.dv-list::-webkit-scrollbar-track { background: rgba(150, 148, 220, 0.08); border-radius: 999px; }
.dv-list::-webkit-scrollbar-thumb {
  background: linear-gradient(rgba(185, 180, 232, 0.65), rgba(116, 112, 200, 0.45));
  border-radius: 999px;
}
.dv-list::-webkit-scrollbar-thumb:hover { background: rgba(185, 180, 232, 0.85); }
.dv-list { scrollbar-width: thin; scrollbar-color: rgba(160, 155, 225, 0.55) rgba(150, 148, 220, 0.08); }

.dv-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "dot tr pos" ".  en  en";
  align-items: baseline;
  column-gap: 0.5em;
  padding: 0.45em 0.6em;
  border-radius: 10px;
  cursor: pointer;
  opacity: 0;
  animation: menu-word-in 0.5s ease forwards;
  transition: background 0.2s ease;
}
.dv-row:hover { background: rgba(150, 148, 220, 0.07); }
.dv-dot {
  grid-area: dot;
  width: 5px; height: 5px;
  border-radius: 50%;
  align-self: center;
}
.dv-tr {
  grid-area: tr;
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--gold);
}
.dv-pos {
  grid-area: pos;
  font-family: var(--sans);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  color: var(--lavender);
  opacity: 0.75;
  border: 1px solid rgba(154, 147, 184, 0.3);
  border-radius: 6px;
  padding: 0.08em 0.45em;
}
/* Meaning stays hidden until the learner reaches for it: recall first. */
.dv-en {
  grid-area: en;
  font-family: var(--sans);
  font-style: italic;
  font-size: 0.74rem;
  color: var(--lavender);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.dv-row:hover .dv-en, .dv-row.open .dv-en { opacity: 1; }

/* The fog: what the planet teaches but the scanner has not read yet. */
.dv-row.locked { cursor: default; }
.dv-row.locked .dv-tr {
  filter: blur(4px);
  opacity: 0.45;
  color: var(--lavender);
  user-select: none;
}
.dv-row.locked .dv-dot { background: rgba(154, 147, 184, 0.4) !important; box-shadow: none !important; }
.dv-row.locked .dv-en { opacity: 0.4; }
.dv-row.locked:hover { background: none; }

.dv-empty {
  grid-column: 1 / -1;
  padding: 1.6em 0.4em;
  font-family: var(--sans);
  font-style: italic;
  font-size: 0.82rem;
  color: var(--lavender);
  opacity: 0.75;
}

/* On a phone the search shortens, the shell breathes less, and the way out
   goes where a thumb looks for it: the top right corner of the device, not
   wherever the wrapped header happens to drop it. */
@media (max-width: 560px) {
  .dv-shell { padding: 0.9em 0.9em 1em; }
  /* Lexi and her name share the top row, both measured against the whole
     device: her face on the left edge, her name on the true middle. The
     search takes the row below them. */
  .dv-head {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.6em 0.7em;
  }
  .dv-lexi { grid-area: 1 / 1; justify-self: start; }
  .dv-name { grid-area: 1 / 1; justify-self: center; }
  .dv-head-tools { width: 100%; }
  .dv-search { width: 100%; }
  .dv-close {
    position: absolute;
    top: 0.6em; right: 0.6em;
    z-index: 2;
    width: 2.2em; height: 2.2em;
    background: rgba(16, 14, 40, 0.9);
  }
}

@media (prefers-reduced-motion: reduce) {
  .dv-scanline, .dv-shell::after { animation: none; opacity: 0; }
  .dv-led { animation: none; }
  /* On the button she keeps her eyes closed (js/lexi.js never wakes her
     either). On her own page she stays, but she stops looking around. */
  #counter .dv-face { display: none; }
  .dv-lexi .dv-face, .dv-lexi .dv-eyes, .dv-lexi .dv-eye { animation: none; }
}
