:root {
  --bg: #121213;
  --bg-secondary: #1a1a1b;
  --surface: #3a3a3c;
  --text: #f0f0f0;
  --text-muted: #818384;
  --green: #538d4e;
  --green-light: #6aaa64;
  --yellow: #b59f3b;
  --red: #c9413a;
  --gold: #d4a843;
  --tile-size: min(20vw, 80px);
  --tile-gap: 6px;
  --board-size: calc(var(--tile-size) * 4 + var(--tile-gap) * 3);
}

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

html, body {
  height: 100dvh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
}

/* Screens */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  overflow-y: auto;
}

.screen.active {
  display: flex;
}

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

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

.title {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: 2px;
}

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

.best-score {
  color: var(--text-muted);
  font-size: 1rem;
  min-height: 1.5em;
}

.loading-status {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.btn-primary {
  background: var(--green);
  color: white;
  border: none;
  padding: 16px 48px;
  font-size: 1.2rem;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: var(--green-light);
}

.btn-primary:disabled {
  background: var(--surface);
  color: var(--text-muted);
  cursor: not-allowed;
}

.btn-small {
  background: var(--surface);
  color: var(--text-muted);
  border: none;
  padding: 6px 16px;
  font-size: 0.85rem;
  border-radius: 4px;
  cursor: pointer;
}

/* Game Screen */
.game-layout {
  min-height: 100dvh;
  gap: 12px;
  padding-top: 12px;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.timer {
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: color 0.3s;
}

.timer.warning {
  color: var(--yellow);
}

.timer.danger {
  color: var(--red);
  animation: pulse 0.5s ease-in-out infinite alternate;
}

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

/* Word Preview */
.word-preview {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  min-height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}

.word-preview.flash-valid {
  color: var(--green-light);
}

.word-preview.flash-invalid {
  color: var(--red);
}

/* Board */
.board-container {
  position: relative;
  width: var(--board-size);
}

.board {
  display: grid;
  grid-template-columns: repeat(4, var(--tile-size));
  grid-template-rows: repeat(4, var(--tile-size));
  gap: var(--tile-gap);
  touch-action: none;
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border-radius: 6px;
  font-size: calc(var(--tile-size) * 0.45);
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.1s, transform 0.1s;
}

.tile.selected {
  background: var(--green);
  transform: scale(1.05);
}

.tile.path-highlight {
  background: var(--gold);
  transform: scale(1.08);
}

@keyframes tileFlashGold {
  0%, 15% { background: var(--gold); transform: scale(1.08); }
  100% { background: var(--surface); transform: scale(1); }
}

@keyframes tileFlashRed {
  0%, 15% { background: #5c2a2a; }
  100% { background: var(--surface); }
}

.tile.flash-gold {
  animation: tileFlashGold 0.5s ease-out;
}

.tile.flash-red {
  animation: tileFlashRed 0.35s ease-out;
}

.path-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.path-line {
  fill: none;
  stroke: rgba(106, 170, 100, 0.6);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#review-path-overlay .path-line {
  stroke: rgba(212, 168, 67, 0.6);
}

/* Found Words */
.found-section {
  width: 100%;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.found-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 8px 0 4px;
  border-bottom: 1px solid var(--surface);
}

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

/* Word Chips */
.word-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
  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: var(--surface);
  color: var(--text-muted);
}

.word-pts {
  font-size: 0.65rem;
  opacity: 0.7;
  margin-left: 2px;
}

/* Review Screen */
.review-layout {
  gap: 16px;
  padding-bottom: 100px;
}

.review-title {
  font-size: 1.5rem;
  font-weight: 700;
  padding-top: 12px;
}

.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.5rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.length-breakdown {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 0;
}

.length-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}

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

.length-value {
  font-weight: 600;
}

.tier-common .length-value   { color: #d4b44a; }
.tier-uncommon .length-value { color: #39e75f; }
.tier-rare .length-value     { color: #4da6ff; }
.tier-epic .length-value     { color: #a855f7; }
.tier-legendary .length-value { color: #ff9f1a; }
.tier-pearlescent .length-value { color: #00e5ff; }

.review-words {
  width: 100%;
}

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

.sort-btn {
  background: var(--surface);
  color: var(--text-muted);
  border: none;
  padding: 6px 16px;
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}

.sort-btn.active {
  background: var(--green);
  color: white;
}

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

/* 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;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 4px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--surface);
  border-radius: 2px;
}
