/* ============================================
   Pocket Dystopia - Styles
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
  /* Dark mode (default) */
  --bg-primary: #080A0D;
  --bg-secondary: #0D1117;
  --bg-elevated: #161B22;
  --bg-overlay: #1E2329;
  --text-primary: #E6EDF3;
  --text-secondary: #8B949E;
  --text-tertiary: #4A5568;
  --text-inverse: #080A0D;
  --accent-cyan: #00E5FF;
  --accent-cyan-muted: #00ACC1;
  --accent-cyan-dim: #006064;
  --accent-amber: #FFB020;
  --accent-amber-muted: #E09000;
  --accent-amber-dim: #804D00;
  --accent-red: #FF4D4D;
  --accent-red-muted: #CC3333;
  --accent-red-dim: #801A1A;
  --accent-green: #4ADE80;
  --accent-green-muted: #22C55E;
  --border-default: #30363D;
  --border-subtle: #21262D;
  --border-accent: #00E5FF;

  /* Lock state — Apple HIG systemRed (dark) */
  --accent-lock: #FF453A;
  --accent-lock-glow: rgba(255, 69, 58, 0.35);

  /* Spacing */
  --space-2xs: 2px;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;
  --space-3xl: 48px;
  --space-4xl: 64px;

  /* Border Radii */
  --radius-none: 0px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 24px;

  /* Typography */
  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Space Mono', 'Courier New', monospace;
}

/* Light mode */
[data-theme="light"] {
  --bg-primary: #FFFFFF;
  --bg-secondary: #F6F8FA;
  --bg-elevated: #FFFFFF;
  --bg-overlay: #F0F2F5;
  --text-primary: #1F2937;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --text-inverse: #FFFFFF;
  --accent-cyan: #0891B2;
  --accent-cyan-muted: #06B6D4;
  --accent-amber: #D97706;
  --accent-red: #DC2626;
  --accent-green: #16A34A;
  --border-default: #D1D5DB;
  --border-subtle: #E5E7EB;
  --border-accent: #0891B2;
  /* Apple HIG systemRed (light) */
  --accent-lock: #FF3B30;
  --accent-lock-glow: rgba(255, 59, 48, 0.25);
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  /* HIG Body: 17pt */
  font: 400 1.0625rem/1.47 var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* --- CRT Scanline Overlay (subtle; dialed down for readability) --- */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: linear-gradient(rgba(18,16,16,0) 50%, rgba(0,0,0,0.06) 50%);
  background-size: 100% 3px;
  pointer-events: none;
  z-index: 999;
  opacity: 0.6;
  mix-blend-mode: multiply;
}

@media (prefers-reduced-motion: reduce) {
  body::before { display: none; }
}

/* --- Skip Link --- */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-lg);
  background: var(--accent-cyan);
  color: var(--text-inverse);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-sm);
  font: 700 0.875rem/1.4 var(--font-body);
  text-decoration: none;
  z-index: 1000;
}

.skip-link:focus {
  top: var(--space-lg);
}

/* --- Typography Classes --- */
/* HIG-aligned type scale
   Large Title 34 / Title1 28 / Title2 22 / Title3 20 /
   Headline 17 bold / Body 17 / Callout 16 / Subhead 15 /
   Footnote 13 / Caption1 12 / Caption2 11 */
.text-display {
  /* Scales between Title1 (28pt) and Large Title (34pt)+ for impact */
  font: 700 clamp(1.75rem, 5.5vw, 2.5rem)/1.12 var(--font-display);
  letter-spacing: 3px;
}

.text-heading {
  /* Title3: 20pt */
  font: 700 1.25rem/1.25 var(--font-display);
}

.text-subheading {
  /* Headline: 17pt bold */
  font: 700 1.0625rem/1.29 var(--font-body);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.text-body {
  /* Body: 17pt */
  font: 400 1.0625rem/1.47 var(--font-body);
}

.text-caption {
  /* Footnote: 13pt */
  font: 400 0.8125rem/1.38 var(--font-body);
}

.text-micro {
  /* Caption2: 11pt */
  font: 400 0.6875rem/1.36 var(--font-body);
}

/* --- Material Symbols --- */
.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24;
  font-size: 20px;
  vertical-align: middle;
  user-select: none;
}

.icon-filled {
  font-variation-settings: 'FILL' 1, 'wght' 300, 'GRAD' 0, 'opsz' 24;
}

/* --- Focus Indicators --- */
:focus-visible {
  outline: 2px solid var(--accent-cyan);
  outline-offset: 2px;
}

/* --- Buttons --- */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: var(--space-sm);
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: color 0.2s ease, background 0.2s ease;
}

.btn-icon:hover {
  color: var(--text-primary);
  background: var(--bg-overlay);
}

.btn-icon:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  min-height: 44px;
  padding: var(--space-md) var(--space-xl);
  background: var(--accent-cyan);
  color: var(--text-inverse);
  border: none;
  border-radius: var(--radius-md);
  /* HIG Headline: 17pt */
  font: 700 1.0625rem/1.29 var(--font-body);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}

.btn-primary:hover {
  background: var(--accent-cyan-muted);
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  min-height: 44px;
  padding: var(--space-md) var(--space-xl);
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  /* HIG Headline: 17pt */
  font: 700 1.0625rem/1.29 var(--font-body);
  cursor: pointer;
  transition: background 0.2s ease;
}

.btn-secondary:hover {
  background: var(--bg-overlay);
}

/* --- Layout --- */
.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

@media (min-width: 600px) {
  .app-container {
    padding: 0 var(--space-2xl);
  }
}

@media (min-width: 1024px) {
  .app-container {
    padding: 0 var(--space-3xl);
  }
}

/* --- Intro Screen --- */
.intro-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  gap: var(--space-3xl);
  padding: var(--space-4xl) var(--space-lg);
}

.intro-subtitle {
  line-height: 1.8;
}

.intro-screen .text-display {
  color: var(--accent-cyan);
  text-shadow: 0 0 30px rgba(0, 229, 255, 0.3);
}

.intro-subtitle {
  color: var(--text-secondary);
  max-width: 400px;
}

.intro-load {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  width: 100%;
  max-width: 280px;
}

.intro-load input {
  width: 100%;
  min-height: 36px;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  /* HIG Subhead: 15pt — still above iOS zoom threshold of 16pt on inputs? No:
     use 16px to avoid iOS focus zoom while keeping visual scale small. */
  font: 400 1rem/1.31 var(--font-body);
}

.intro-load input::placeholder {
  color: var(--text-tertiary);
  font-size: 0.8125rem;
}

.intro-load #load-btn {
  min-height: 36px;
  padding: var(--space-xs) var(--space-md);
  /* HIG Footnote bold: 13pt */
  font: 700 0.8125rem/1.3 var(--font-body);
  border-radius: var(--radius-sm);
}

.intro-load #load-btn .material-symbols-outlined {
  font-size: 16px;
}

.intro-load .error-msg {
  color: var(--accent-red);
  /* HIG Caption2: 11pt */
  font-size: 0.6875rem;
  min-height: 1.2em;
}

/* --- Die --- */
.die-container {
  position: relative;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  /* Isolate the CTA with generous breathing room on either side */
  margin-block: var(--space-2xl);
}

.die-wrapper {
  position: relative;
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: die-float 3s ease-in-out infinite;
}

.die-shape {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.die-shape svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 20px rgba(0, 229, 255, 0.4));
  animation: glow-pulse 4s ease-in-out infinite;
}

.die-hint {
  color: var(--text-tertiary);
  /* HIG Footnote: 13pt */
  font-size: 0.8125rem;
  margin-top: var(--space-sm);
}

@keyframes die-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes glow-pulse {
  0%, 100% { filter: drop-shadow(0 0 15px rgba(0, 229, 255, 0.3)); }
  50% { filter: drop-shadow(0 0 30px rgba(0, 229, 255, 0.6)); }
}

/* Die face fizzle (CRT static on each face swap) */
@keyframes die-fizzle {
  0% {
    opacity: 0.3;
    filter: blur(2.5px) brightness(2) hue-rotate(-12deg) contrast(1.3);
    transform: translateX(-2px) skewX(4deg);
    clip-path: inset(40% 0 40% 0);
  }
  20% {
    opacity: 1;
    filter: blur(1px) brightness(1.6) hue-rotate(6deg);
    transform: translateX(3px);
    clip-path: inset(0 0 55% 0);
  }
  40% {
    opacity: 0.5;
    filter: blur(0.5px) brightness(1.2);
    transform: translateX(-2px);
    clip-path: inset(25% 0 15% 0);
  }
  60% {
    opacity: 1;
    filter: brightness(1.25);
    transform: translateX(1px);
    clip-path: inset(0);
  }
  100% {
    opacity: 1;
    filter: none;
    transform: none;
  }
}

.die-shape.die-fizzle {
  animation: die-fizzle 260ms steps(8, end) both;
}

/* Dramatic shake during an active roll */
@keyframes die-shake {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  10% { transform: translate(-5px, -3px) rotate(-2deg); }
  20% { transform: translate(6px, 2px) rotate(2deg); }
  30% { transform: translate(-4px, 4px) rotate(-3deg); }
  40% { transform: translate(5px, -4px) rotate(2deg); }
  50% { transform: translate(-6px, 3px) rotate(-2deg); }
  60% { transform: translate(4px, -2px) rotate(3deg); }
  70% { transform: translate(-3px, 5px) rotate(-2deg); }
  80% { transform: translate(6px, 1px) rotate(2deg); }
  90% { transform: translate(-4px, -3px) rotate(-1deg); }
}

.die-container.die-shaking {
  animation: die-shake 110ms linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .die-shape.die-fizzle,
  .die-container.die-shaking {
    animation: none;
  }
}

/* Die tumble animations */
@keyframes tumble-x {
  0% { transform: perspective(400px) rotateX(0deg); }
  100% { transform: perspective(400px) rotateX(360deg); }
}

@keyframes tumble-x-neg {
  0% { transform: perspective(400px) rotateX(0deg); }
  100% { transform: perspective(400px) rotateX(-360deg); }
}

@keyframes tumble-y {
  0% { transform: perspective(400px) rotateY(0deg); }
  100% { transform: perspective(400px) rotateY(360deg); }
}

@keyframes tumble-y-neg {
  0% { transform: perspective(400px) rotateY(0deg); }
  100% { transform: perspective(400px) rotateY(-360deg); }
}

@keyframes tumble-diag {
  0% { transform: perspective(400px) rotate3d(1, 1, 0, 0deg); }
  100% { transform: perspective(400px) rotate3d(1, 1, 0, 360deg); }
}

.die-tumble-x .die-shape { animation: tumble-x 650ms ease-in-out; }
.die-tumble-x-neg .die-shape { animation: tumble-x-neg 650ms ease-in-out; }
.die-tumble-y .die-shape { animation: tumble-y 650ms ease-in-out; }
.die-tumble-y-neg .die-shape { animation: tumble-y-neg 650ms ease-in-out; }
.die-tumble-diag .die-shape { animation: tumble-diag 650ms ease-in-out; }

/* --- Top Bar --- */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: var(--space-md);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  background: var(--bg-primary);
  z-index: 100;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.top-bar-title {
  /* Reset button-specific defaults so it visually matches a logo */
  appearance: none;
  background: none;
  border: none;
  padding: var(--space-xs) var(--space-sm);
  margin: 0;
  cursor: pointer;
  font: 700 1rem/1 var(--font-display);
  color: var(--accent-cyan);
  letter-spacing: 2px;
  border-radius: var(--radius-sm);
  transition: opacity 0.2s ease, text-shadow 0.2s ease;
}

.top-bar-title:hover {
  text-shadow: 0 0 12px rgba(0, 229, 255, 0.45);
}

.top-bar-title:active {
  opacity: 0.8;
}

/* --- Screen-reader-only utility --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Roll button die icon (cycling d6 faces) --- */
.roll-die-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.roll-die-icon svg {
  width: 100%;
  height: 100%;
}

.btn-primary .roll-die-icon { color: var(--text-inverse); }

.top-bar-right {
  display: flex;
  align-items: center;
  gap: var(--space-2xs);
}

.top-bar-right .btn-icon {
  min-width: 36px;
  min-height: 36px;
  padding: var(--space-xs);
}

/* Left-handed mode */
[data-left-handed="true"] .top-bar {
  flex-direction: row-reverse;
}

[data-left-handed="true"] .top-bar-left {
  flex-direction: row-reverse;
}

[data-left-handed="true"] .top-bar-right {
  flex-direction: row-reverse;
}

[data-left-handed="true"] .card-header {
  flex-direction: row-reverse;
}

[data-left-handed="true"] .card-header-actions {
  flex-direction: row-reverse;
}

[data-left-handed="true"] .trait-line {
  flex-direction: row-reverse;
}

/* --- Controls Bar --- */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) 0;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.view-toggle {
  display: flex;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-default);
}

.view-toggle button {
  padding: var(--space-sm) var(--space-lg);
  background: none;
  border: none;
  color: var(--text-secondary);
  /* HIG Subhead: 15pt */
  font: 700 0.9375rem/1.33 var(--font-body);
  cursor: pointer;
  min-height: 44px;
  transition: background 0.2s ease, color 0.2s ease;
}

.view-toggle button.active {
  background: var(--accent-cyan);
  color: var(--text-inverse);
}

.mood-select {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.mood-select select {
  /* Strip native chrome so we can size padding consistently */
  appearance: none;
  -webkit-appearance: none;
  padding: var(--space-sm) var(--space-lg);
  /* Extra right padding = space for our custom chevron + matching gutter */
  padding-right: calc(var(--space-lg) + 20px);
  background-color: var(--bg-elevated);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'><path d='M2 4l4 4 4-4' stroke='%238B949E' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right var(--space-lg) center;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  /* HIG Subhead: 15pt */
  font: 400 0.9375rem/1.33 var(--font-body);
  min-height: 44px;
  cursor: pointer;
}

/* --- Results Container --- */
.results-screen {
  display: none;
}

.results-screen.active {
  display: block;
}

.intro-screen.hidden {
  display: none;
}

.cards-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  padding: var(--space-lg) 0 var(--space-3xl);
}

@media (min-width: 1024px) {
  .cards-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: var(--space-lg);
  }

  .cards-grid .card:nth-child(n+3) {
    /* Squad, Setting, Obstacles span bottom row */
  }

  .cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* --- Cards --- */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color 0.3s ease;
}

.card.locked {
  border-color: var(--accent-lock);
  box-shadow: 0 0 0 1px var(--accent-lock), 0 0 16px var(--accent-lock-glow);
}

.card.locked .lock-icon {
  color: var(--accent-lock);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg);
  cursor: pointer;
  min-height: 56px;
  gap: var(--space-sm);
}

.card-header-title {
  /* Reset button defaults — still reads as a heading visually */
  appearance: none;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  text-align: left;
  cursor: pointer;
  /* HIG Headline: 17pt */
  font: 700 1.0625rem/1.29 var(--font-body);
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--accent-cyan);
  flex: 1;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.card-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2xs);
}

.card-header-actions .btn-icon {
  min-width: 32px;
  min-height: 32px;
  padding: var(--space-xs);
}

.card-header-actions .btn-icon .material-symbols-outlined {
  font-size: 18px;
}

.card-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease, opacity 0.25s ease;
  opacity: 0;
}

.card.expanded .card-content {
  max-height: 500px;
  opacity: 1;
}

.card-body {
  padding: 0 var(--space-lg) var(--space-lg);
}

.card-summary {
  padding: 0 var(--space-lg) var(--space-lg);
  color: var(--text-secondary);
  /* HIG Subhead: 15pt */
  font-size: 0.9375rem;
  display: none;
}

.card:not(.expanded) .card-summary {
  display: block;
}

/* --- Trait Lines --- */
.trait-line {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-xs) 0;
  border-left: 2px solid transparent;
  padding-left: var(--space-sm);
  transition: border-color 0.2s ease;
  min-height: 28px;
}

/* Keep the prefix / label visually on the first text line even when
   the trait wraps to multiple lines. We match the *pixel* line-height of the
   17pt body text so the smaller 13pt label glyphs center optically within
   the same line box as the body text. */
.trait-prefix,
.trait-label {
  line-height: 1.5625rem; /* = 17px × 1.47, matches .trait-text line box */
}

.trait-line.trait-locked {
  border-left-color: var(--accent-lock);
  border-left-width: 2px;
}

.trait-line.trait-locked .trait-lock {
  color: var(--accent-lock);
}

.trait-prefix {
  color: var(--accent-cyan-muted);
  font-weight: 700;
  flex-shrink: 0;
  min-width: 16px;
}

.trait-text {
  flex: 1;
  color: var(--text-primary);
}

.trait-label {
  color: var(--accent-amber);
  font-weight: 700;
  flex-shrink: 0;
  text-transform: uppercase;
  /* HIG Footnote: 13pt */
  font-size: 0.8125rem;
  letter-spacing: 0.5px;
}

.trait-lock {
  opacity: 0;
  transition: opacity 0.2s ease;
  flex-shrink: 0;
  min-width: 24px;
  min-height: 24px;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: var(--radius-sm);
}

.trait-lock .material-symbols-outlined {
  font-size: 14px;
}

.trait-line:hover .trait-lock,
.trait-line .trait-lock.visible {
  opacity: 1;
}

.lock-icon {
  transition: transform 0.2s ease, color 0.2s ease;
}

.lock-icon:active {
  transform: scale(0.85);
}

/* --- Footer --- */
.footer {
  text-align: center;
  padding: var(--space-xl) 0;
  color: var(--text-tertiary);
  /* HIG Footnote: 13pt */
  font-size: 0.8125rem;
}

.footer [aria-label="love"] {
  color: var(--accent-red);
  font-size: 1em;
  margin: 0 0.15em;
}

.footer-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 0.2s ease;
}

.footer-link:hover,
.footer-link:focus-visible {
  color: var(--accent-cyan);
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: var(--space-lg);
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl);
  max-width: 500px;
  width: 100%;
  position: relative;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-xl);
}

.modal-title {
  font: 700 1.25rem/1.3 var(--font-display);
  color: var(--text-primary);
}

.modal textarea {
  width: 100%;
  min-height: 100px;
  padding: var(--space-md);
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font: 400 0.625rem/1.4 var(--font-body);
  resize: vertical;
  margin-bottom: var(--space-lg);
}

.modal-actions {
  display: flex;
  gap: var(--space-sm);
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: var(--space-xl);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-xl);
  color: var(--text-primary);
  font: 400 0.875rem/1.4 var(--font-body);
  z-index: 600;
  pointer-events: none;
  transition: all 0.3s ease;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* --- Trait Fizzle (CRT static on regenerate) --- */
@keyframes trait-fizzle {
  0% {
    opacity: 0;
    filter: blur(3px) brightness(2) contrast(1.4) hue-rotate(-10deg);
    transform: translateX(-3px) skewX(6deg);
    clip-path: inset(40% 0 40% 0);
  }
  15% {
    opacity: 1;
    filter: blur(1.5px) brightness(1.6) hue-rotate(8deg);
    transform: translateX(4px);
    clip-path: inset(0 0 60% 0);
  }
  30% {
    opacity: 0.35;
    filter: blur(0.5px) brightness(1.2);
    transform: translateX(-2px);
    clip-path: inset(20% 0 10% 0);
  }
  50% {
    opacity: 1;
    filter: brightness(1.35) contrast(1.1);
    transform: translateX(1px);
    clip-path: inset(0 0 0 0);
  }
  70% {
    opacity: 0.8;
    filter: brightness(0.9);
    transform: translateX(-1px);
  }
  100% {
    opacity: 1;
    filter: none;
    transform: none;
    clip-path: inset(0);
  }
}

.trait-fizzle {
  animation: trait-fizzle 460ms steps(10, end) both;
  will-change: opacity, filter, transform;
}

/* The short burst of "scanlines" feels more CRT-y on a dark bg */
.trait-fizzle .trait-text {
  background: linear-gradient(
    to bottom,
    transparent 0,
    transparent 3px,
    rgba(0, 229, 255, 0.08) 3px,
    rgba(0, 229, 255, 0.08) 4px
  );
  background-size: 100% 4px;
  animation: trait-fizzle-scan 460ms steps(10, end) both;
}

@keyframes trait-fizzle-scan {
  0%, 80% { background-position: 0 0; }
  20% { background-position: 0 4px; }
  40% { background-position: 0 -2px; }
  60% { background-position: 0 2px; }
  100% { background: none; }
}

@media (prefers-reduced-motion: reduce) {
  .trait-fizzle,
  .trait-fizzle .trait-text {
    animation: none;
    background: none;
  }
}

/* --- CRT Boot Animation --- */
@keyframes crt-boot {
  0% {
    transform: scaleY(0.005) scaleX(0.8);
    opacity: 0.5;
    filter: brightness(3);
  }
  20% {
    transform: scaleY(0.005) scaleX(0.9);
    opacity: 0.8;
  }
  40% {
    transform: scaleY(0.3) scaleX(1);
    opacity: 0.9;
    filter: brightness(1.5);
  }
  60% {
    transform: scaleY(0.7) scaleX(1);
    filter: brightness(1.2);
  }
  80% {
    transform: scaleY(0.95) scaleX(1);
    filter: brightness(1);
  }
  100% {
    transform: scaleY(1) scaleX(1);
    opacity: 1;
    filter: brightness(1);
  }
}

.crt-boot {
  animation: crt-boot 600ms cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Home button only visible on mobile (where the logo is hidden) */
.btn-home-mobile {
  display: none;
}

/* Flip the "back of hand" icon to preview the destination mode.
   In right-handed mode, the button switches to left-handed — so show a left hand. */
[data-left-handed="false"] #btn-left-hand .material-symbols-outlined {
  transform: scaleX(-1);
}

/* --- Responsive --- */
@media (max-width: 600px) {
  .top-bar-left {
    display: none;
  }

  .btn-home-mobile {
    display: inline-flex;
  }

  /* Let the nav span the full width so the die can push to the opposite edge */
  .top-bar-right {
    flex: 1;
  }

  /* Right-handed: die sticks to the right, rest of the nav on the left */
  #btn-roll-all {
    margin-left: auto;
  }

  /* Left-handed: container is row-reverse, so invert the auto-margin
     to push the die to the visual left instead. */
  [data-left-handed="true"] #btn-roll-all {
    margin-left: 0;
    margin-right: auto;
  }

  .text-display {
    letter-spacing: 2px;
  }

  .card-header {
    padding: var(--space-md);
  }

  .card-body {
    padding: 0 var(--space-md) var(--space-md);
  }
}

@media (min-width: 600px) and (max-width: 1024px) {
  .cards-grid {
    max-width: 700px;
    margin: 0 auto;
  }
}

/* Non-mobile: cards are always expanded; header title is not a disclosure */
@media (min-width: 768px) {
  .card .card-content {
    max-height: none;
    opacity: 1;
    overflow: visible;
  }

  .card .card-summary {
    display: none !important;
  }

  .card-header,
  .card-header-title {
    cursor: default;
  }
}

@media (min-width: 1024px) {
  .cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Desktop: hide controls that only make sense on mobile/cramped screens */
  #btn-left-hand,
  .view-toggle {
    display: none !important;
  }
}

/* --- Confirm Dialog --- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 700;
  padding: var(--space-lg);
}

.confirm-overlay.active {
  display: flex;
}

.confirm-dialog {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl);
  max-width: 400px;
  width: 100%;
  text-align: center;
}

.confirm-dialog p {
  margin-bottom: var(--space-xl);
  color: var(--text-primary);
}

.confirm-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
}
