/* ── Modal (blocking overlay) ──────────────────────────────── */
.modal[hidden] {
  display: none !important;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: var(--scrim-modal);
  backdrop-filter: blur(4px);
}
.modal__dialog {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(100%, 440px);
  max-height: min(88vh, 560px);
  overflow: hidden;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  opacity: 0; transform: translateY(10px) scale(.99);
  transition: opacity .25s var(--ease-out-expo), transform .38s var(--ease-out-expo);
}
.modal.is-visible .modal__dialog,
.modal:not(.is-out) .modal__dialog { opacity: 1; transform: translateY(0) scale(1); }
.modal.is-out .modal__dialog { opacity: 0; transform: translateY(10px) scale(.99); }
.modal.is-out .modal__backdrop { opacity: 0; }
.modal__backdrop { transition: opacity .2s ease-out; }
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}
.modal__header h2 {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
}
.modal__body {
  padding: var(--space-6);
  overflow: auto;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.55;
}
.modal__body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
  color: var(--text-primary);
}
.modal__footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
}

/* ── Reading popup (focused, calm, near-black) ──────────────── */
/* For purposeful reading of longer copy. A near-black navy panel (tinted,
   never pure black) with the azure faceted frame, so the eyes settle away
   from the busy console. Built on the closed-bevel ring (.fbevel). */
.modal--reader .modal__backdrop { background: var(--scrim-modal); }
.reader {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  width: min(680px, 92vw); max-height: min(84vh, 720px);
  /* Closed-bevel ring: rim = accent, fill = near-black navy. */
  --poly: polygon(var(--bevel) 0, 100% 0, 100% calc(100% - var(--bevel)),
    calc(100% - var(--bevel)) 100%, 0 100%, 0 var(--bevel));
  --bevel-line: var(--reader-rim, var(--banner-azure));
  --bevel-fill: var(--banner-fill-deep);
  --bevel-w: 1px;
  box-shadow: var(--shadow-modal), 0 0 36px -8px var(--reader-glow, var(--accent-glow));
  opacity: 0; transform: translateY(10px) scale(.99);
  transition: opacity .3s var(--ease-out-expo), transform .42s var(--ease-out-expo);
}
.reader.is-in { opacity: 1; transform: translateY(0) scale(1); }
.modal.is-out .reader {
  opacity: 0; transform: translateY(10px) scale(.99);
  transition: opacity .2s var(--ease-out-expo), transform .3s var(--ease-out-expo);
}
.modal.is-out .reader__rule { transform: scaleX(0); transition: transform .15s ease-out; }
.reader--azure  { --reader-rim: var(--banner-azure);  --reader-glow: var(--banner-azure-glow); }
.reader--gold   { --reader-rim: var(--banner-gold);   --reader-glow: var(--banner-gold-glow); }
.reader--violet { --reader-rim: var(--banner-violet); --reader-glow: var(--banner-violet-glow); }
.reader__head {
  padding: var(--space-6) var(--space-6) var(--space-4);
  text-align: center;
}
.reader__kicker {
  display: block; font-size: var(--text-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: .26em; color: var(--reader-rim, var(--banner-azure));
}
.reader__title {
  font-size: var(--text-2xl); font-weight: 600; color: var(--banner-text);
  letter-spacing: .02em; margin-top: var(--space-2);
}
.reader__sub {
  font-size: var(--text-sm); color: var(--banner-text-faint); margin-top: 6px;
}
.reader__rule {
  display: block; height: 1px; width: 140px; margin: var(--space-4) auto 0;
  background: var(--reader-rim, var(--accent));
  transform: scaleX(0); transform-origin: center;
  transition: transform .5s .12s var(--ease-out-expo);
}
.reader.is-in .reader__rule { transform: scaleX(1); }
.reader__body {
  padding: var(--space-2) var(--space-8) var(--space-6);
  overflow: auto;
}
.reader__sec { margin-top: var(--space-6); max-width: 68ch; margin-inline: auto; }
.reader__sec:first-child { margin-top: var(--space-2); }
.reader__h {
  font-size: var(--text-sm); font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--reader-rim, var(--banner-azure));
  margin-bottom: 6px;
}
.reader__p { font-size: var(--text-base); color: var(--banner-text-dim); line-height: 1.7; }
.reader__foot {
  display: flex; justify-content: center;
  padding: var(--space-2) var(--space-6) var(--space-6);
}
@media (prefers-reduced-motion: reduce) {
  .reader { transition: opacity .01ms; transform: none; }
  .reader__rule { transition: none; transform: scaleX(1); }
}

/* ── Boot splash (title screen) ─────────────────────────────── */
.splash {
  position: fixed; inset: 0; z-index: 700;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  opacity: 0; transition: opacity .26s var(--ease-out-quint);
}
.splash.is-visible { opacity: 1; }
.splash__bg {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(47,217,255,.10) 0%, transparent 55%),
    radial-gradient(100% 90% at 50% 120%, rgba(176,21,176,.12) 0%, transparent 60%);
}
.splash__inner {
  position: relative; text-align: center;
  transform: translateY(8px); opacity: 0;
  transition: transform .42s .06s var(--ease-out-expo), opacity .42s .06s var(--ease-out-expo);
}
.splash.is-visible .splash__inner { transform: translateY(0); opacity: 1; }
.splash__kicker {
  display: block; font-size: var(--text-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: .34em; color: var(--accent);
}
.splash__title {
  font-size: clamp(3rem, 11vw, 6rem); font-weight: 300; color: var(--text-primary);
  letter-spacing: .14em; margin: var(--space-3) 0 var(--space-2);
  text-shadow: 0 0 40px rgba(47,217,255,.25);
}
.splash__tag { font-size: var(--text-lg); color: var(--text-secondary); letter-spacing: .04em; }
.splash__prompt {
  margin-top: var(--space-8); font-size: var(--text-sm); font-weight: 600;
  text-transform: uppercase; letter-spacing: .22em; color: var(--text-muted);
  animation: splashPulse 1.8s var(--ease-out-quint) infinite;
}
.splash__caret { color: var(--accent); margin-right: 6px; }
@keyframes splashPulse { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .splash__prompt { animation: none; opacity: .8; }
}

/* ── First-run coach-mark ───────────────────────────────────── */
/* Shown once on first visit to teach the keyboard model + quick menu. */
.coach {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
  opacity: 0; transition: opacity .2s ease-out;
}
.coach.is-visible { opacity: 1; }
.coach__scrim { position: absolute; inset: 0; background: var(--scrim-modal); backdrop-filter: blur(4px); }
.coach__card {
  position: relative; z-index: 1; width: min(100%, 420px);
  background: var(--surface-1); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-modal); padding: var(--space-6);
  clip-path: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
  transform: translateY(10px);
  transition: transform .24s cubic-bezier(0.25, 1, 0.5, 1); /* ease-out-quart, no overshoot */
}
.coach.is-visible .coach__card { transform: translateY(0); }
.coach__kicker {
  font-size: var(--text-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: .2em; color: var(--accent);
}
.coach__title {
  font-size: var(--text-xl); font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; margin: 6px 0 var(--space-4);
}
.coach__keys { list-style: none; display: flex; flex-direction: column; gap: var(--space-3); }
.coach__keys li {
  display: flex; align-items: center; gap: 8px;
  font-size: var(--text-sm); color: var(--text-secondary);
}
.coach__keys li span { margin-left: 4px; }
.coach__keys kbd {
  font-family: inherit; font-size: 11px; font-weight: 700; color: var(--text-primary);
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: 3px; padding: 2px 7px; line-height: 1.4; white-space: nowrap;
}
.coach__keys kbd + span { color: var(--text-secondary); }
.coach__note { font-size: var(--text-xs); color: var(--text-muted); margin: var(--space-4) 0 var(--space-4); }
.coach__card .btn { width: 100%; }

/* ── Card ──────────────────────────────────────────────────── */
/*
 * GOTCHA: backdrop-filter creates a stacking context — dropdowns inside
 * a card can be clipped by a later card's stacking context. Fix by adding
 * position: relative; z-index: 10 to the card that owns the open dropdown.
 *
 * Default: static surface (no hover lift — avoids generic “dashboard demo”).
 * Use .card--interactive for raised hover + entrance motion.
 */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
  backdrop-filter: blur(10px);
  transition: border-color var(--dur), box-shadow var(--dur);
}
.card:hover {
  border-color: var(--border-strong);
  box-shadow: 0 8px 20px var(--scrim-soft);
}
.card--interactive {
  transition:
    transform var(--dur) ease-out,
    box-shadow var(--dur) ease-out,
    border-color var(--dur);
  animation: fadeIn 0.35s ease-out both;
}
.card--interactive:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-card);
  border-color: var(--border-strong);
}
.card--enter {
  animation: fadeIn 0.35s ease-out both;
}
.card--flat:hover {
  box-shadow: none;
}

/* ── Button press feedback ─────────────────────────────────── */
button:active,
.btn:active,
.nav-link:active,
.auth-toggle:active,
.auth-tab:active,
.auth-submit:active,
.auth-logout:active {
  transform: scale(0.98);
  transition-duration: var(--dur-fast);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Micro-interactions ────────────────────────────────────── */
/* Subtle glow lift on interactive cards for a more tactile feel. */
.card:hover, .cpanel:hover, .cclass:hover {
  box-shadow: 0 8px 24px var(--scrim-soft), 0 0 0 1px rgba(42,168,255,.08);
}

/* Links and interactive text get a gentler color transition. */
a, .btn, .nav-link, .ctab, .crow, .cscope, .ctag {
  transition:
    color var(--dur),
    background-color var(--dur),
    border-color var(--dur),
    box-shadow var(--dur),
    transform var(--dur-fast);
}

/* Active / pressed state for all clickable surfaces. */
.cpanel:active, .cclass:active, .ctag:active, .cscope:active {
  transform: scale(0.995);
}

/* Smooth focus ring animation for keyboard users. */
:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
  transition: outline-offset var(--dur-fast);
}

/* ── Skeleton loading ──────────────────────────────────────── */
@keyframes shimmer { to { background-position: -200% 0; } }
.skeleton {
  background: linear-gradient(90deg, var(--surface-1) 25%, var(--surface-2) 50%, var(--surface-1) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius);
}

/* ── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  max-width: min(360px, calc(100vw - var(--space-8)));
  background: var(--surface-toast);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--banner-text);
  box-shadow: var(--shadow-card);
  pointer-events: none;
  transform: translateY(8px);
  opacity: 0;
  transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}
.toast.visible {
  opacity: 1;
  transform: translateY(0);
}
/* Action toast (e.g. post-reset Undo) needs to be clickable, so it opts
   back into pointer events and lays its message + button out in a row. */
.toast--action {
  pointer-events: auto;
  display: flex; align-items: center; gap: var(--space-4);
}
.toast__msg { flex: 1; }
.toast__action {
  flex-shrink: 0;
  background: var(--accent); color: var(--ink-on-accent);
  border: none; border-radius: var(--radius-sm);
  padding: 6px 14px; font-family: inherit; font-size: var(--text-xs);
  font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  cursor: pointer; transition: background var(--dur);
}
.toast__action:hover { background: var(--accent-bright); }
.toast__action:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 2px; }

/* ── Footer ────────────────────────────────────────────────── */
.info-footer {
  text-align: center;
  padding: var(--space-6) var(--space-6) 28px;
  color: var(--text-muted);
  font-size: .78em;
  line-height: 1.8;
  border-top: 1px solid var(--border-subtle);
  margin-top: var(--space-8);
}
@media (max-width: 760px) {
  .info-footer__hint { display: none; }
}
.footer-link {
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--dur);
}
.footer-link:hover,
.footer-link:focus-visible {
  color: var(--text-secondary);
  text-decoration: underline;
}

/* ── Focus styles ──────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}

/* Visually-hidden, still announced by screen readers. */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ── Skip link ─────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: 1000;
  padding: var(--space-2) var(--space-4);
  background: var(--accent-bright);
  color: var(--ink-on-accent);
  font-weight: 600;
  font-size: var(--text-sm);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  text-decoration: none;
  transition: top var(--dur);
}
.skip-link:focus { top: 0; }

/* ── Reduced motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .card--interactive:hover { transform: none; }
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 600px) {
  .header-bar { padding: 0 var(--space-4); }
  .container { padding: var(--space-4); }
  .toast {
    left: var(--space-4);
    right: var(--space-4);
    max-width: none;
  }
  /* Prevent iOS from zooming into form fields on focus. */
  input, textarea, select, [type="search"] { font-size: 1rem; }
}

/* ── Closed bevel (faceted boxes with a stroked diagonal) ─────
 * A clip-path cut corner leaves the diagonal edge unstroked, which reads
 * as "broken / torn off". To close it with a line we paint a true beveled
 * RING: the element's own background is the rim colour (clipped to the outer
 * polygon), and an inset ::before re-fills the interior with the panel colour
 * (clipped to the same polygon, so the 1px gap traces every edge, diagonals
 * included). Direct children ride above the fill via z-index.
 *
 * Usage: add .fbevel and set --poly to the corner polygon. Override
 * --bevel-line for a state accent (cyan/green/gold) instead of a side stripe.
 */
.fbevel {
  position: relative;
  background: var(--bevel-line, var(--dbh-edge));
  clip-path: var(--poly);
}
.fbevel::before {
  content: "";
  position: absolute; inset: var(--bevel-w, 1px); z-index: 0;
  background: var(--bevel-fill, var(--dbh-panel));
  clip-path: var(--poly);
  pointer-events: none;
  transition: background var(--dur);
}
.fbevel > * { position: relative; z-index: 1; }

/* ── Today's Focus widget ────────────────────────────────────
 * A mission-style panel: strong faceted frame, left glyph, objective copy,
 * and a single action. No plain borders — the closed bevel carries the shape.
 */
.focus__card {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--space-5);
  align-items: center;
  margin-bottom: var(--space-6);
  padding: var(--space-6);
  background: var(--banner-azure);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 32px -10px var(--banner-azure-glow), var(--shadow-card);
  animation: focusEnter 0.55s var(--ease-out-expo) both;
}
.focus__card::before {
  content: ""; position: absolute; inset: 1px; z-index: 0;
  background: var(--banner-fill); border-radius: calc(var(--radius-lg) - 1px);
  pointer-events: none;
}
@keyframes focusEnter {
  from { opacity: 0; transform: translateY(10px) scale(0.995); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
/* Corner notch accent (same idiom as .cpanel::after). */
.focus__card::after {
  content: ""; position: absolute; left: 0; top: 0; z-index: 2;
  width: 10px; height: 10px; border-radius: 2px;
  background: var(--banner-azure);
  box-shadow: 0 0 8px var(--banner-azure-glow);
  pointer-events: none;
}
.focus__glyph {
  position: relative; z-index: 1;
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; flex-shrink: 0;
  color: var(--banner-azure); background: var(--banner-azure-soft);
  border-radius: var(--radius-md);
}
.focus__glyph svg { filter: drop-shadow(0 0 6px var(--banner-azure-glow)); }
.focus__main { position: relative; z-index: 1; min-width: 0; }
.focus__head {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-2);
}
.focus__kicker {
  font-size: var(--text-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: .2em; color: var(--banner-azure);
}
.focus__streak {
  font-size: var(--text-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: .1em; color: var(--banner-gold);
  padding: 3px 10px; background: var(--banner-gold-soft);
  border-radius: var(--radius-sm);
}
.focus__title {
  font-size: var(--text-xl); font-weight: 600; color: var(--banner-text); letter-spacing: .01em;
}
.focus__blurb {
  font-size: var(--text-sm); color: var(--banner-text-dim); line-height: 1.6; margin-top: 4px;
}
.focus__actions {
  display: flex; flex-direction: column; align-items: flex-end; gap: var(--space-3);
  min-width: 110px;
}
.focus__dismiss {
  background: transparent; border: none; color: var(--banner-text-faint);
  font-size: 1.25rem; line-height: 1; cursor: pointer; padding: 2px 6px;
  transition: color var(--dur), transform var(--dur-fast);
}
.focus__dismiss:hover { color: var(--banner-text); transform: scale(1.1); }
@media (max-width: 720px) {
  .focus__card { grid-template-columns: auto 1fr; }
  .focus__actions { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; }
}

/* ── Daily tip widget ────────────────────────────────────────
 * A compact console readout with a small faceted accent. Sits quietly below
 * the main dashboard but still reads as part of the game UI.
 */
.tip__card {
  position: relative;
  display: flex; align-items: flex-start; gap: var(--space-4);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-6);
  animation: fadeIn 0.45s var(--ease-out-expo) both;
}
.tip__card::before {
  content: ""; position: absolute; left: 0; top: 0; z-index: 2;
  width: 8px; height: 8px; border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  pointer-events: none;
}
.tip__icon {
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; color: var(--accent); background: var(--accent-soft);
  border-radius: var(--radius-sm);
}
.tip__main { flex: 1; min-width: 0; }
.tip__kicker {
  font-size: var(--text-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: .16em; color: var(--accent);
}
.tip__body {
  font-size: var(--text-sm); color: var(--text-secondary); line-height: 1.55; margin-top: 2px;
}
.tip__next {
  flex-shrink: 0; background: transparent; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 1.1rem; padding: 4px; transition: color var(--dur), transform var(--dur-fast);
}
.tip__next:hover { color: var(--accent); transform: rotate(90deg); }

/* ── Ambient background particles ──────────────────────────── */
.particles {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
}
.particle {
  position: absolute; border-radius: 50%;
  background: var(--accent); opacity: 0;
  animation: particleFloat linear infinite;
}
@keyframes particleFloat {
  0%   { transform: translateY(100vh) scale(0); opacity: 0; }
  10%  { opacity: 0.35; }
  90%  { opacity: 0.35; }
  100% { transform: translateY(-10vh) scale(1); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .particle { animation: none; }
}

