/* ==========================================================================
   Progetto Fortuna - App Stylesheet
   Mobile-first, tema cosmico minimalista
   ========================================================================== */

/* --- Custom Properties --- */
:root {
  --bg-primary: #f8f9fb;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #eef0f4;
  --text-primary: #1a1a2e;
  --text-secondary: #555570;
  --text-muted: #8888a0;
  --accent: #6c5ce7;
  --accent-light: #5a4bd1;
  --accent-glow: rgba(108, 92, 231, 0.15);
  --success: #0fa89e;
  --warning: #e6a817;
  --danger: #e04848;
  --fortune-low: #e04848;
  --fortune-mid: #e6a817;
  --fortune-high: #0fa89e;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --border: #dde0e6;
  --transition: 0.2s ease;
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* --- Custom Scrollbar (webkit) --- */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* --- Header --- */
#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--bg-secondary);
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

#app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-primary);
}

/* Fortune Bar */
#fortune-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

#fortune-bar.hidden {
  display: none;
}

.fortune-bar-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.fortune-bar-track {
  flex: 1;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.fortune-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--fortune-low), var(--fortune-mid), var(--fortune-high));
  transition: width var(--transition);
  position: relative;
}

.fortune-bar-fill::after {
  content: '';
  position: absolute;
  right: 0;
  top: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
}

.fortune-bar-value {
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  min-width: 42px;
  text-align: right;
  flex-shrink: 0;
}

/* --- Main Content --- */
#view-container {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* --- Footer --- */
#app-footer {
  position: sticky;
  bottom: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

#app-footer.hidden {
  display: none;
}

#qrng-status {
  display: flex;
  align-items: center;
  gap: 6px;
}

#qrng-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}

#qrng-status.online::before {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

#qrng-status.offline::before {
  background: var(--danger);
}

/* --- Cards --- */
.card {
  background-color: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.4;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  min-height: 48px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.btn-primary:hover {
  background: var(--accent-light);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: transparent;
  color: var(--accent-light);
  border: 1px solid var(--accent);
}

.btn-secondary:hover {
  background: var(--accent-glow);
}

.btn-large {
  width: 100%;
  padding: 18px 24px;
  min-height: 56px;
  font-size: 1.05rem;
  border-radius: var(--radius);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  opacity: 0.85;
}

/* --- Slider (Range Input) --- */
.slider-group {
  margin-bottom: 20px;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.slider-label-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.slider-label-value {
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-light);
  min-width: 24px;
  text-align: right;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-card);
  box-shadow: 0 0 8px var(--accent-glow);
  cursor: pointer;
  transition: box-shadow var(--transition);
}

input[type="range"]::-webkit-slider-thumb:active {
  box-shadow: 0 0 16px var(--accent-glow);
  transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-card);
  box-shadow: 0 0 8px var(--accent-glow);
  cursor: pointer;
}

/* --- Test UI Components --- */

/* Test Container */
.test-container {
  text-align: center;
  padding: 10px 0;
}

.test-container .test-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.test-container .test-description {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.5;
}

.test-area {
  margin-bottom: 24px;
}

/* Test Result */
.test-result {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.test-result .result-score {
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin-bottom: 4px;
  animation: resultReveal 0.6s ease-out;
}

.test-result .result-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Test Choice Grid (envelopes, colors, map) */
.test-choice-grid {
  display: grid;
  gap: 12px;
  margin: 0 auto;
  max-width: 320px;
}

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

.test-choice-grid.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.test-choice-grid.cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.choice-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 0.95rem;
  color: var(--text-primary);
  user-select: none;
  -webkit-user-select: none;
  padding: 12px;
}

.choice-item:hover {
  border-color: var(--accent);
  background: var(--bg-card);
}

.choice-item:active {
  transform: scale(0.95);
}

.choice-item.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--text-primary);
  box-shadow: 0 0 16px var(--accent-glow);
}

.choice-item.correct {
  border-color: var(--success);
  background: rgba(0, 206, 201, 0.15);
  color: var(--success);
}

.choice-item.wrong {
  border-color: var(--danger);
  background: rgba(255, 107, 107, 0.1);
  color: var(--danger);
  opacity: 0.6;
}

/* Coin Flip */
.coin-flip {
  width: 120px;
  height: 120px;
  margin: 20px auto;
  perspective: 600px;
}

.coin-flip .coin {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.8s ease;
}

.coin-flip .coin.flipping {
  animation: coinSpin 0.8s ease-out;
}

.coin-flip .coin-face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.4rem;
  backface-visibility: hidden;
}

.coin-flip .coin-heads {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: #fff;
}

.coin-flip .coin-tails {
  background: linear-gradient(135deg, var(--warning), #e0b84e);
  color: #fff;
  transform: rotateY(180deg);
}

.coin-flip .coin.show-tails {
  transform: rotateY(180deg);
}

/* Timer Circle (Momento test) */
.timer-circle {
  width: 160px;
  height: 160px;
  margin: 20px auto;
  position: relative;
}

.timer-circle svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer-circle .track {
  fill: none;
  stroke: var(--bg-input);
  stroke-width: 6;
}

.timer-circle .progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 440;
  stroke-dashoffset: 440;
  transition: stroke-dashoffset 0.1s linear;
  filter: drop-shadow(0 0 6px var(--accent-glow));
}

.timer-circle .timer-value {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.timer-circle .timer-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Sequence Input (bit sequence test) */
.sequence-input {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.sequence-input .bit-btn {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--text-muted);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.sequence-input .bit-btn:active {
  transform: scale(0.9);
}

.sequence-input .bit-btn.active-0 {
  border-color: var(--danger);
  background: rgba(255, 107, 107, 0.15);
  color: var(--danger);
}

.sequence-input .bit-btn.active-1 {
  border-color: var(--success);
  background: rgba(0, 206, 201, 0.15);
  color: var(--success);
}

.sequence-display {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin: 12px 0;
  min-height: 32px;
  flex-wrap: wrap;
}

.sequence-display .bit {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sequence-display .bit-0 {
  background: rgba(255, 107, 107, 0.15);
  color: var(--fortune-low);
}

.sequence-display .bit-1 {
  background: rgba(0, 206, 201, 0.15);
  color: var(--fortune-high);
}

/* Maze Path (Bivio test) */
.maze-path {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin: 16px 0;
}

.maze-path .maze-node {
  width: 100%;
  max-width: 300px;
}

.maze-path .maze-choices {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.maze-path .maze-btn {
  flex: 1;
  max-width: 140px;
  padding: 16px;
  border-radius: var(--radius);
  border: 2px solid var(--text-muted);
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.maze-path .maze-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.maze-path .maze-btn:active {
  transform: scale(0.95);
  background: var(--accent-glow);
}

.maze-path .maze-btn.chosen {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--accent-light);
}

.maze-path .maze-step-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Queue Lanes (Coda test) */
.queue-lanes {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin: 16px 0;
}

.queue-lane {
  flex: 1;
  max-width: 100px;
  background: var(--bg-input);
  border-radius: var(--radius);
  border: 2px solid transparent;
  padding: 12px 8px;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.queue-lane:hover {
  border-color: var(--accent);
}

.queue-lane:active {
  transform: scale(0.95);
}

.queue-lane.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.queue-lane .lane-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.queue-lane .lane-people {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.queue-lane .person-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-muted);
}

.queue-lane.fastest .lane-label {
  color: var(--success);
}

.queue-lane.slowest .lane-label {
  color: var(--danger);
}

/* --- Fortune Index Display --- */
.fortune-display {
  text-align: center;
  padding: 32px 0;
}

.fortune-value {
  font-size: 3.5rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--fortune-low), var(--fortune-mid), var(--fortune-high));
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: fortuneGradient 3s ease infinite;
}

.fortune-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.fortune-description {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* --- Results Breakdown --- */
.results-breakdown {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.result-family {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
}

.result-family-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 80px;
}

.result-family-bar {
  flex: 1;
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  overflow: hidden;
}

.result-family-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.6s ease-out;
}

.result-family-score {
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  min-width: 36px;
  text-align: right;
}

/* Sparkline mini */
.sparkline {
  display: inline-block;
  vertical-align: middle;
}

.sparkline svg {
  display: block;
}

.sparkline .sparkline-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
}

.sparkline .sparkline-area {
  fill: var(--accent-glow);
}

/* --- History List --- */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: background var(--transition);
  cursor: pointer;
}

.history-item:hover {
  background: var(--bg-input);
}

.history-date {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 50px;
}

.history-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
}

.history-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--fortune-low), var(--fortune-mid), var(--fortune-high));
  transition: width 0.4s ease-out;
}

.history-value {
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  min-width: 36px;
  text-align: right;
}

/* --- Form Elements --- */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 12px 14px;
  min-height: 48px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.form-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239898b0' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

/* --- Utility Classes --- */
.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

.text-muted {
  color: var(--text-muted);
}

.text-accent {
  color: var(--accent-light);
}

.text-success {
  color: var(--success);
}

.text-warning {
  color: var(--warning);
}

.text-danger {
  color: var(--danger);
}

.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state-text {
  font-size: 0.9rem;
  line-height: 1.5;
}

/* --- Loading Spinner --- */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--bg-input);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 20px auto;
}

/* --- Divider --- */
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* --- Badge --- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-accent {
  background: var(--accent-glow);
  color: var(--accent-light);
}

.badge-success {
  background: rgba(0, 206, 201, 0.15);
  color: var(--success);
}

.badge-warning {
  background: rgba(253, 203, 110, 0.15);
  color: var(--warning);
}

.badge-danger {
  background: rgba(255, 107, 107, 0.15);
  color: var(--danger);
}

/* --- Progress Steps --- */
.progress-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin: 16px 0;
}

.progress-step {
  width: 24px;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-input);
  transition: background var(--transition);
}

.progress-step.completed {
  background: var(--accent);
}

.progress-step.current {
  background: var(--accent-light);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* --- Animations --- */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-12px);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes resultReveal {
  0% {
    opacity: 0;
    transform: scale(0.5);
  }
  60% {
    transform: scale(1.05);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

@keyframes coinSpin {
  0% {
    transform: rotateY(0deg);
  }
  100% {
    transform: rotateY(720deg);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes fortuneGradient {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* View transition animation */
.view-enter {
  animation: fadeIn 0.3s ease-out forwards;
}

.view-exit {
  animation: fadeOut 0.2s ease-in forwards;
}

/* Pulse for results */
.pulse {
  animation: pulse 1.5s ease-in-out infinite;
}

/* --- Home View --- */
.home-container {
  text-align: center;
  padding: 20px 0;
}

.home-hero {
  margin-bottom: 32px;
}

.home-logo {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 900;
  color: #fff;
  box-shadow: 0 0 30px var(--accent-glow);
}

.home-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.home-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.home-info {
  margin: 24px 0;
  text-align: left;
}

.home-info-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.home-info-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-light);
  flex-shrink: 0;
}

.home-history {
  margin-top: 32px;
  text-align: left;
}

.home-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

/* --- History Row (compact) --- */
.history-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.history-bar-track {
  flex: 1;
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  overflow: hidden;
}

.history-divergence {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 40px;
  text-align: right;
}

/* --- Fortune Display (results) --- */
.fortune-display-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.fortune-display-value {
  font-size: 3rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin-bottom: 12px;
  animation: resultReveal 0.6s ease-out;
}

.fortune-display-bar {
  max-width: 280px;
  margin: 0 auto;
}

.fortune-display-bar-track {
  height: 8px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: visible;
  position: relative;
}

.fortune-display-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s ease-out;
}

.fortune-display-bar-marker {
  position: absolute;
  top: -4px;
  width: 2px;
  height: 16px;
  background: var(--text-muted);
  transform: translateX(-50%);
}

.fortune-display-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* --- Results View --- */
.results-container {
  padding: 10px 0;
}

.results-title {
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 24px;
  color: var(--text-primary);
}

.results-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.results-family-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.results-family-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.results-family-role {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-left: auto;
}

.results-family-scores {
  margin-bottom: 8px;
}

.results-score-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  padding: 4px 0;
  color: var(--text-secondary);
}

.results-bar {
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  overflow: hidden;
}

.results-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.6s ease-out;
}

.results-divergence-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  text-align: center;
  border: 1px solid var(--border);
}

.results-divergence-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.results-divergence-value {
  font-size: 1.8rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.results-divergence-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.results-meta {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 16px 0;
}

/* --- Test Family Badges --- */
.test-family-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.test-family-badge.family-1 {
  background: rgba(108, 92, 231, 0.15);
  color: var(--accent-light);
}

.test-family-badge.family-2 {
  background: rgba(0, 206, 201, 0.15);
  color: var(--fortune-high);
}

.test-family-badge.family-3 {
  background: rgba(253, 203, 110, 0.15);
  color: var(--warning);
}

/* --- Test Actions & Transition --- */
.test-actions {
  margin-top: 16px;
}

.test-transition {
  text-align: center;
  padding: 16px 0;
}

.result-details {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 8px;
  line-height: 1.5;
}

.running-index-display {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 16px;
}

.running-index-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.running-index-value {
  font-size: 1.4rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* --- Checkpoint (end session prompt) --- */
.checkpoint-container {
  text-align: center;
  padding: 20px 0;
}

.checkpoint-container h3 {
  font-size: 1.1rem;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.checkpoint-container p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.checkpoint-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- Loading & Error --- */
.loading-container {
  text-align: center;
  padding: 48px 20px;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--bg-input);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 16px;
}

.loading-container p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.error-container {
  text-align: center;
  padding: 48px 20px;
}

.error-container h3 {
  color: var(--danger);
  margin-bottom: 8px;
}

.error-container p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* --- QRNG Status --- */
.qrng-active::before {
  background: var(--success) !important;
  box-shadow: 0 0 6px var(--success);
}

.qrng-fallback::before {
  background: var(--warning) !important;
}

/* --- Diary View --- */
.diary-container {
  padding: 10px 0;
}

.diary-title {
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.diary-subtitle {
  font-size: 0.8rem;
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.diary-slider-group {
  margin-bottom: 20px;
}

.diary-slider-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.diary-slider-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.diary-slider-value {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent-light);
  font-variant-numeric: tabular-nums;
}

.diary-slider-range-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
}

.diary-range-low,
.diary-range-high {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.diary-slider {
  width: 100%;
}

.diary-submit {
  margin-top: 24px;
}

/* --- History View (full) --- */
.history-container {
  padding: 0;
}

.history-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.history-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.history-loading {
  text-align: center;
  padding: 40px 0;
  color: var(--text-muted);
}

.history-empty {
  text-align: center;
  padding: 40px 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.history-stats {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.history-stat {
  flex: 1;
  min-width: 60px;
  text-align: center;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
}

.history-stat-value {
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.history-stat-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}

.history-chart {
  margin-bottom: 20px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px;
}

.history-svg {
  width: 100%;
  height: auto;
}

.history-day-card {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
}

.history-day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.history-day-date {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.history-day-index {
  font-size: 0.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.history-day-bar {
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 6px;
}

.history-day-details {
  display: flex;
  gap: 16px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* --- Button Variants --- */
.btn-full {
  width: 100%;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.8rem;
}

/* --- Fade In animation --- */
.fade-in {
  animation: fadeIn 0.3s ease-out;
}

/* --- Test Progress --- */
.test-progress {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.test-progress-count {
  font-weight: 700;
  color: var(--accent-light);
}

.test-score-counter {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

/* --- Map Grid (5x5) --- */
.map-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  max-width: 260px;
  margin: 0 auto;
}

.map-cell {
  aspect-ratio: 1;
  background: var(--bg-input);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.map-cell:hover {
  border-color: var(--accent);
}

.map-cell.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.map-cell.target {
  background: rgba(0, 206, 201, 0.2);
  border-color: var(--fortune-high);
}

.map-cell.overlap {
  background: rgba(0, 206, 201, 0.3);
  border-color: var(--success);
  box-shadow: 0 0 8px rgba(0, 206, 201, 0.3);
}

/* --- Dice Display --- */
.dice-container {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 16px 0;
}

.die {
  width: 48px;
  height: 48px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 2px solid var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text-primary);
  transition: all var(--transition);
}

.die.rolling {
  animation: diceShake 0.3s ease infinite;
}

@keyframes diceShake {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-5deg); }
  75% { transform: rotate(5deg); }
}

/* --- Card Display (Poker) --- */
.cards-container {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 16px 0;
}

.playing-card {
  width: 56px;
  height: 80px;
  background: var(--text-primary);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  position: relative;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: transform 0.3s ease;
}

.playing-card.face-down {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
}

.playing-card .card-value {
  font-size: 1rem;
  line-height: 1;
}

.playing-card .card-suit {
  font-size: 1.2rem;
  line-height: 1;
}

.playing-card.red {
  color: #d63031;
}

.playing-card.black {
  color: #2d3436;
}

/* --- Queue Race Animation --- */
.queue-race {
  margin: 16px 0;
}

.queue-lane-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.queue-lane-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 20px;
}

.queue-lane-track {
  flex: 1;
  height: 20px;
  background: var(--bg-input);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.queue-lane-fill {
  height: 100%;
  border-radius: 10px;
  transition: width 0.1s linear;
  background: var(--accent);
}

.queue-lane-fill.winner {
  background: var(--success);
}

/* --- Contact Input --- */
.contact-inputs {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 16px 0;
}

.contact-input-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.contact-input-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 16px;
}

.contact-input-group input {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
}

.contact-input-group input:focus {
  border-color: var(--accent);
}

/* --- Responsive --- */
@media (min-width: 481px) {
  #app {
    border-left: 1px solid rgba(255, 255, 255, 0.04);
    border-right: 1px solid rgba(255, 255, 255, 0.04);
  }
}

/* Safe area insets for notched devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #app-footer {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  #app-header {
    padding-top: calc(16px + env(safe-area-inset-top));
  }
}
