:root {
  --bg-color: #0F172A;
  --bg-gradient: linear-gradient(135deg, #0F172A 0%, #1E1B4B 100%);
  --text-main: #F8FAFC;
  --text-muted: #94A3B8;
  
  --board-bg: rgba(15, 23, 42, 0.6);
  --board-border: rgba(255, 255, 255, 0.1);
  
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
  
  --tile-red: #EF4444;
  --tile-blue: #3B82F6;
  --tile-green: #10B981;
  --tile-yellow: #F59E0B;
  --tile-purp: #8B5CF6;
  --tile-teal: #14B8A6;
  --tile-shadow: 0 4px 0 rgba(0,0,0,0.3), inset 0 2px 0 rgba(255,255,255,0.2);
  
  --line-color: rgba(59, 130, 246, 0.6);
  --primary: #3B82F6;
  --primary-hover: #2563EB;
}

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

body {
  font-family: 'Outfit', sans-serif;
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  width: 100%;
  max-width: 1000px;
  height: 100vh;
  padding: 20px;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Glassmorphism */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  box-shadow: var(--glass-shadow);
}

.glass-heavy {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

/* Screens */
.screen {
  width: 100%;
  max-width: 500px;
  padding: 40px;
  display: flex;
  flex-direction: column;
  gap: 30px;
  text-align: center;
  position: absolute;
  transition: opacity 0.3s, transform 0.3s;
}

#game-screen {
  max-width: 900px;
  height: 100%;
  padding: 20px 0;
  display: grid;
  grid-template-columns: 1fr 300px;
  grid-template-rows: auto 1fr;
  gap: 20px;
  text-align: left;
}

.screen.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.95);
}

.screen.active {
  opacity: 1;
  transform: scale(1);
  z-index: 10;
}

/* Start Screen */
.logo {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 20px;
}

.letter-tile {
  width: 50px;
  height: 50px;
  border-radius: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.8rem;
  font-weight: 800;
  color: white;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  box-shadow: var(--tile-shadow);
  text-transform: uppercase;
}

h2 { font-size: 1.8rem; font-weight: 600; color: var(--text-muted); }

/* Leaderboard */
.leaderboard-preview {
  padding: 20px;
}

.leaderboard-preview h3 {
  margin-bottom: 15px;
  font-size: 1.2rem;
  color: var(--primary);
}

#leaderboard-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#leaderboard-list li {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 5px;
}

.rank { color: var(--text-muted); width: 20px; }
.name { font-weight: 600; flex: 1; text-align: left; padding-left: 10px;}
.score { font-family: monospace; font-size: 1.1rem; color: var(--tile-yellow); }

/* Buttons */
.btn {
  border: none;
  border-radius: 8px;
  padding: 12px 24px;
  font-family: inherit;
  font-weight: 600;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
  color: white;
}

.primary-btn { background: var(--primary); box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4); }
.primary-btn:hover { background: var(--primary-hover); transform: translateY(-2px); }
.secondary-btn { background: rgba(255,255,255,0.1); border: 1px solid var(--glass-border); }
.secondary-btn:hover { background: rgba(255,255,255,0.15); transform: translateY(-2px); }

.icon-btn { display: inline-flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.1); border: 1px solid var(--glass-border); padding: 10px 15px; }
.icon-btn:hover { background: rgba(255,255,255,0.2); }
.icon-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.text-btn { background: transparent; padding: 10px; color: var(--text-muted); text-decoration: underline; font-size: 0.9rem; }
.text-btn:hover { color: white; }

.btn-pulse { animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); } 70% { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); } 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); } }

/* Game Header */
.game-header {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  padding: 15px 30px;
}

.stat-group {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-label { font-size: 0.8rem; color: var(--text-muted); letter-spacing: 1px; }
.stat-value { font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer { color: var(--tile-yellow); }
.timer.danger { color: var(--tile-red); animation: dangerPulse 1s infinite; }
.mult { color: var(--tile-teal); transition: color 0.3s, transform 0.3s; }
.mult.active { color: #fff; text-shadow: 0 0 10px var(--tile-teal); transform: scale(1.1); }

@keyframes dangerPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* Game Board */
.game-board-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

.word-preview {
  height: 40px;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 4px;
  text-transform: uppercase;
  margin-bottom: 15px;
  color: white;
  text-shadow: 0 2px 10px rgba(255,255,255,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.word-preview.valid { color: var(--tile-green); text-shadow: 0 0 15px rgba(16, 185, 129, 0.5); }
.word-preview.invalid { color: var(--tile-red); animation: shake 0.4s; }

@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

.grid-container {
  display: grid;
  grid-template-columns: repeat(5, 60px);
  grid-template-rows: repeat(5, 60px);
  gap: 10px;
  background: var(--board-bg);
  padding: 15px;
  border-radius: 16px;
  border: 1px solid var(--board-border);
  position: relative;
  z-index: 10;
  touch-action: none;
}

.game-tile {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.8rem;
  font-weight: 800;
  color: white;
  text-transform: uppercase;
  background: var(--tile-blue);
  box-shadow: var(--tile-shadow);
  cursor: pointer;
  position: relative;
  transition: transform 0.1s, filter 0.2s;
}

.game-tile::after {
  content: attr(data-pts);
  position: absolute;
  bottom: 4px;
  right: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  opacity: 0.8;
}

.game-tile.selected {
  transform: scale(0.9);
  filter: brightness(1.2);
  box-shadow: 0 2px 0 rgba(0,0,0,0.3), inset 0 2px 0 rgba(255,255,255,0.4), 0 0 15px var(--primary);
  z-index: 5;
}

.game-tile.fade { opacity: 0.5; }

.controls {
  margin-top: 20px;
  display: flex;
  gap: 15px;
  align-items: center;
}

/* Connection Layer */
.connection-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  pointer-events: none;
}

.conn-line {
  stroke: var(--line-color);
  stroke-width: 8px;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  filter: drop-shadow(0 0 8px var(--line-color));
}

/* Side Panel */
.side-panel {
  padding: 20px;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.side-panel h3 {
  margin-bottom: 15px;
  font-size: 1.1rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 10px;
}

.words-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 5px;
}

.words-list::-webkit-scrollbar { width: 6px; }
.words-list::-webkit-scrollbar-track { background: transparent; }
.words-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }

.words-list li {
  display: flex;
  justify-content: space-between;
  background: rgba(0,0,0,0.2);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.95rem;
  animation: slideIn 0.3s ease-out;
}

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

.words-list li .w-text { font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }
.words-list li .w-pts { color: var(--tile-yellow); font-family: monospace; }

.combo-feedback {
  position: absolute;
  top: calc(50% - 20px);
  left: calc(50% - 100px);
  width: 200px;
  text-align: center;
  font-size: 2rem;
  font-weight: 800;
  color: var(--tile-yellow);
  text-shadow: 0 4px 10px rgba(245, 158, 11, 0.5);
  pointer-events: none;
  opacity: 0;
  z-index: 20;
  transform: translateY(20px);
  transition: opacity 0.2s, transform 0.2s;
}

.combo-feedback.show {
  opacity: 1;
  transform: translateY(0);
  animation: floatUp 1s forwards ease-out;
}

@keyframes floatUp { 0% { opacity: 1; transform: translateY(0) scale(1); } 100% { opacity: 0; transform: translateY(-50px) scale(1.2); } }


/* Result Screen */
.final-stats {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 20px;
}

.final-score-box {
  background: rgba(0,0,0,0.3);
  padding: 20px;
  border-radius: 12px;
}

.final-score-box span { color: var(--text-muted); text-transform: uppercase; font-size: 0.9rem; letter-spacing: 1px; }
.score-huge { font-size: 4rem; font-weight: 800; color: var(--tile-yellow); text-shadow: 0 0 20px rgba(245, 158, 11, 0.4); }

.mini-stats {
  display: flex;
  justify-content: space-around;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.mini-stats .highlight { color: white; font-weight: 600; font-size: 1.1rem; }

.input-group {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.input-group input {
  flex: 1;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--glass-border);
  color: white;
  padding: 10px 15px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 1.2rem;
  text-align: center;
  text-transform: uppercase;
}

.input-group input:focus { outline: none; border-color: var(--primary); }
.hs-entry { margin-bottom: 20px; background: rgba(245, 158, 11, 0.1); border: 1px solid rgba(245, 158, 11, 0.3); padding: 15px; border-radius: 12px; }

.post-game-analysis { margin-bottom: 20px; text-align: left; }
.post-game-analysis h3 { font-size: 1rem; color: var(--text-muted); margin-bottom: 5px; }
.description { font-size: 0.85rem; color: rgba(255,255,255,0.5); margin-bottom: 15px; }

.pill-container { display: flex; flex-wrap: wrap; gap: 8px; max-height: 100px; overflow-y: auto; padding-right: 5px;}
.pill-container::-webkit-scrollbar { width: 4px; }
.pill-container::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px;}

.word-pill { background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); padding: 4px 10px; border-radius: 15px; font-size: 0.8rem; font-family: monospace; }
.word-pill .pts { color: var(--tile-green); margin-left: 4px; }

.action-buttons { display: flex; justify-content: center; gap: 15px; }

/* Colors */
.col-red { background: var(--tile-red); }
.col-blue { background: var(--tile-blue); }
.col-green { background: var(--tile-green); }
.col-yellow { background: var(--tile-yellow); }
.col-purp { background: var(--tile-purp); }
.col-teal { background: var(--tile-teal); }

/* Mobile */
@media (max-width: 850px) {
  #game-screen {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    max-width: 500px;
    margin: 0 auto;
    overflow-y: auto;
    height: auto;
    padding-bottom: 50px;
  }
  
  #app {
    height: auto;
    min-height: 100vh;
    align-items: flex-start;
  }

  .grid-container {
    grid-template-columns: repeat(5, 14vw);
    grid-template-rows: repeat(5, 14vw);
    gap: 2vw;
    padding: 3vw;
  }

  .game-tile { font-size: 1.4rem; }
  
  .side-panel { min-height: 250px; }
}

@media (max-width: 400px) {
  .grid-container {
    grid-template-columns: repeat(5, 16vw);
    grid-template-rows: repeat(5, 16vw);
    gap: 1.5vw;
    padding: 2vw;
  }
  .game-tile { font-size: 1.2rem; }
}
