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

html, body {
  height: 100dvh;
  overflow: hidden;
  font-family: 'SF Mono', ui-monospace, 'Cascadia Code', 'Fira Code', Menlo, Monaco, Consolas, monospace;
  background: rgb(var(--d, 3,7,18));
  color: rgb(var(--a, 168,139,250));
  -webkit-user-select: none;
  user-select: none;
}

/* Canvas fills viewport */
#scene-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* Screens overlay the canvas */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10;
}

.screen.active {
  display: flex;
}

.screen-content {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* HUD overlay — passes taps through to canvas except on interactive elements */
#hud {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  display: none;
  flex-direction: column;
}

#hud.active {
  display: flex;
}

#hud > * {
  pointer-events: auto;
}

/* Start Screen */
#screen-start {
  background: rgb(var(--d, 3,7,18));
}

#screen-start .screen-content {
  justify-content: center;
  min-height: 100dvh;
  gap: 24px;
}

.title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: rgb(var(--a));
}

.title-dim {
  opacity: 0.5;
}

.best-score {
  color: rgb(var(--a));
  opacity: 0.5;
  font-size: 0.85rem;
  min-height: 1.5em;
}

.loading-status {
  color: rgb(var(--a));
  opacity: 0.5;
  font-size: 0.75rem;
}

.btn-primary {
  background: transparent;
  color: rgb(var(--a));
  border: 2px solid rgb(var(--a));
  padding: 14px 44px;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 2px;
  text-transform: uppercase;
  transition: background 0.2s, color 0.2s;
}

.btn-primary:hover {
  background: rgb(var(--a));
  color: rgb(var(--d));
}

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

.btn-small {
  background: transparent;
  color: rgb(var(--a));
  border: 1px solid rgba(var(--a), 0.4);
  padding: 6px 14px;
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 1px;
  text-transform: uppercase;
  pointer-events: auto;
}

.classic-link {
  color: rgb(var(--a));
  opacity: 0.4;
  font-size: 0.7rem;
  text-decoration: none;
  letter-spacing: 1px;
}

.classic-link:hover {
  opacity: 0.8;
}

/* HUD elements */
.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
}

.timer {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: rgb(var(--a));
}

.timer.warning {
  opacity: 0.7;
}

.timer.danger {
  animation: pulse 0.5s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { opacity: 1; }
  to { opacity: 0.4; }
}

.word-preview {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  min-height: 2rem;
  padding: 0 16px;
  color: rgb(var(--a));
  pointer-events: none;
}

.word-preview.flash-valid {
  color: rgb(var(--a));
  text-shadow: 0 0 12px rgb(var(--a));
}

.word-preview.flash-invalid {
  opacity: 0.3;
}

.hud-bottom {
  margin-top: auto;
  max-height: 30vh;
  display: flex;
  flex-direction: column;
  padding: 0 16px 16px;
}

.found-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  opacity: 0.5;
  padding: 6px 0;
  border-top: 1px solid rgba(var(--a), 0.2);
}

.found-words {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  overflow-y: auto;
  flex: 1;
  align-content: flex-start;
  padding: 4px 0;
}

/* Word Chips */
.word-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 1px;
  border: none;
  cursor: pointer;
}

.word-chip.found {
  color: white;
}

.word-chip.found.tier-common      { background: #6b5a1e; }
.word-chip.found.tier-uncommon    { background: #1e6b30; }
.word-chip.found.tier-rare        { background: #1a4f80; }
.word-chip.found.tier-epic        { background: #5b2d8e; }
.word-chip.found.tier-legendary   { background: #8a5300; }
.word-chip.found.tier-pearlescent { background: #007a80; }

.word-chip.missed {
  background: rgba(var(--a), 0.05);
  color: rgba(var(--a), 0.3);
}

.word-mult {
  font-size: 0.55rem;
  font-weight: 700;
  opacity: 0.85;
  margin-left: 1px;
}

.word-pts {
  font-size: 0.6rem;
  opacity: 0.5;
}

/* Review Screen */
#screen-review {
  background: rgba(var(--d), 0.95);
  overflow-y: auto;
}

.review-layout {
  gap: 16px;
  padding-bottom: 100px;
}

.review-title {
  font-size: 1.3rem;
  font-weight: 700;
  padding-top: 12px;
  color: rgb(var(--a));
}

.review-stats {
  display: flex;
  gap: 24px;
  justify-content: center;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: rgb(var(--a));
}

.stat-label {
  font-size: 0.65rem;
  opacity: 0.4;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.review-words {
  width: 100%;
}

.sort-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.sort-btn {
  background: transparent;
  color: rgb(var(--a));
  border: 1px solid rgba(var(--a), 0.2);
  padding: 4px 12px;
  font-size: 0.75rem;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 1px;
}

.sort-btn.active {
  border-color: rgb(var(--a));
  background: rgba(var(--a), 0.15);
}

.review-word-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.hint-text {
  position: fixed;
  bottom: 35%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.75rem;
  opacity: 0.4;
  letter-spacing: 1px;
  pointer-events: none;
  z-index: 6;
  transition: opacity 0.5s;
}

/* Animations */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.screen.active .screen-content {
  animation: slideIn 0.3s ease-out;
}

/* Word chip pop-in */
@keyframes chipPop {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

.word-chip.pop-in {
  animation: chipPop 0.3s cubic-bezier(0.2, 0.8, 0.3, 1.4) both;
}

/* Score glow on update */
.found-count-glow {
  transition: text-shadow 0.3s;
}

.found-count-glow.glow {
  text-shadow: 0 0 12px rgb(var(--a));
}

/* Preview valid flash — bright glow pulse */
.word-preview.flash-valid {
  color: rgb(var(--a));
  text-shadow: 0 0 16px rgb(var(--a));
}

/* Found count bump */
@keyframes countBump {
  0% { transform: scale(1); }
  40% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

.bump {
  display: inline-block;
  animation: countBump 0.3s cubic-bezier(0.2, 0.8, 0.3, 1.4);
}

/* Timer tick pulse at low time */
@keyframes timerTick {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.timer.danger {
  animation: pulse 0.5s ease-in-out infinite alternate, timerTick 1s ease-in-out infinite;
}

/* Scrollbar */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(var(--a), 0.2); }
