/* === Google Fonts === */
@import url('https://fonts.googleapis.com/css2?family=Oxanium:wght@300;400;600;700;800&family=Kanit:wght@400;600&display=swap');

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

:root {
  --bg: #1e1e1e;
  --surface: #2a2a2a;
  --tile-bg: #333;
  --tile-border: #555;
  --tile-selected: #ff66c4;
  --tile-correct: #1b8a1f;
  --tile-invalid: #c0392b;
  --tile-adjacent: #ff66c4;
  --text: #ffffff;
  --text-muted: #b3b3ff;
  --accent: #ff66c4;
  --accent-glow: rgba(255, 102, 196, 0.35);
  --tile-size: min(18vw, 90px);
  --gap: 6px;
  --radius: 5px;
  --font-main: 'Oxanium', 'Segoe UI', system-ui, sans-serif;
  --font-ui: 'Kanit', 'Segoe UI', system-ui, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-main);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  touch-action: none;
}

/* === Loading screen === */
#loading-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; font-family: var(--font-main); color: var(--text-muted);
  z-index: 999;
}
#loading-screen.hidden { display: none; }

/* === Header === */
#header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid #3a3a3a;
}

#logo {
  font-family: var(--font-main);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  background: linear-gradient(135deg, #ff66c4, #b3b3ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

#header-right { display: flex; gap: 8px; align-items: center; }

#header-right button {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 600;
  background: transparent;
  border: 1px solid #555;
  color: var(--text);
  padding: 5px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, background 0.2s;
}
#header-right button:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

#btn-new-game {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #1e1e1e !important;
  box-shadow: 0 0 10px var(--accent-glow);
}
#btn-new-game:hover {
  box-shadow: 0 0 18px var(--accent-glow);
}

#btn-end-game {
  border-color: #c0392b !important;
  color: #e74c3c !important;
}
#btn-end-game:hover {
  background: rgba(192, 57, 43, 0.15) !important;
  border-color: #e74c3c !important;
}

/* === Main layout === */
#main {
  display: flex;
  flex: 1;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

@media (max-width: 600px) {
  #main { flex-direction: column; }
  #info-panel { max-height: 35vh; }
}

/* === Game panel === */
#game-panel {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  flex-shrink: 0;
}

#score-bar {
  display: flex; gap: 16px; font-size: 0.9rem;
  font-family: var(--font-ui);
  color: var(--text-muted);
}
#score-display {
  color: var(--text);
  font-weight: 600;
}

/* === Grid area (grid + big word tracker side by side) === */
#grid-area {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

/* === Grid === */
#grid {
  display: grid;
  grid-template-columns: repeat(4, var(--tile-size));
  grid-template-rows: repeat(4, var(--tile-size));
  gap: var(--gap);
  user-select: none;
}

.tile {
  display: flex; align-items: center; justify-content: center;
  background: var(--tile-bg);
  border-radius: var(--radius);
  font-family: var(--font-main);
  font-size: calc(var(--tile-size) * 0.38);
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  border: 2px solid var(--tile-border);
  color: var(--text);
  transition: background 0.12s, border-color 0.15s, transform 0.08s,
              box-shadow 0.15s, border-radius 0.6s ease, color 0.4s, opacity 0.4s;
  touch-action: none;
}

/* Dead letter progression — corners round off as remaining uses decrease */
.tile[data-uses="3"] { border-radius: var(--radius) 50% var(--radius) var(--radius); }
.tile[data-uses="2"] { border-radius: var(--radius) 50% 50% var(--radius); }
.tile[data-uses="1"] { border-radius: 50% 50% 50% var(--radius); }
.tile[data-uses="0"] {
  border-radius: 50%;
  background: #3a3a3a;
  border-color: #4a4a4a;
  color: #555;
  cursor: default;
}
.tile:hover {
  border-color: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}
.tile.selected {
  background: var(--tile-selected);
  border-color: var(--tile-selected);
  color: #1e1e1e;
  transform: scale(0.94);
  box-shadow: 0 0 14px var(--accent-glow);
}
.tile.adjacent {
  border-color: var(--tile-adjacent);
  border-style: dashed;
  opacity: 0.85;
}
.tile.correct {
  background: var(--tile-correct);
  border-color: var(--tile-correct);
  color: #fff;
  box-shadow: 0 0 10px rgba(27, 138, 31, 0.5);
}
.tile.invalid {
  background: var(--tile-invalid);
  border-color: var(--tile-invalid);
  color: #fff;
}
.tile.dead { opacity: 0.3; }

/* === Big word tracker === */
#big-word-tracker {
  width: 20px;
  height: calc(4 * var(--tile-size) + 3 * var(--gap));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
#big-word-tracker[hidden] { display: none; }

#tracker-crown {
  font-size: 13px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.5s ease;
  filter: grayscale(1);
}
#tracker-crown.visible {
  opacity: 1;
  filter: none;
  animation: crown-pop 0.4s ease-out;
}
@keyframes crown-pop {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

#tracker-bar-outer {
  flex: 1;
  width: 20px;
  background: var(--tile-bg);
  border: 1px solid var(--tile-border);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}

#tracker-bar-fill {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 0%;
  background: linear-gradient(to top, #1b8a1f, #4caf50);
  border-radius: 4px;
  transition: height 0.9s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tracker-marker {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: rgba(179, 179, 255, 0.45);
  pointer-events: none;
}

#tracker-label {
  font-family: var(--font-main);
  font-size: 7px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.3;
}

/* === Hint button === */
#btn-hint:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
#btn-hint:not(:disabled) {
  border-color: #ffa500;
  color: #ffa500;
}
#btn-hint:not(:disabled):hover {
  box-shadow: 0 0 10px rgba(255, 165, 0, 0.4);
}

/* === Hint display (inside definition panel) === */
.hint-circles {
  font-size: 1rem;
  letter-spacing: 0.15em;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 4px;
}
.hint-length {
  font-size: 0.75rem;
  color: #888;
  margin-top: 4px;
}
.hint-note {
  font-size: 0.75rem;
  color: #ffa500;
  margin-top: 2px;
}

/* === Current word display === */
#current-word-display {
  font-family: var(--font-main);
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  min-height: 2rem;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: 0 0 12px var(--accent-glow);
}

#message-display {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  color: var(--text-muted);
  min-height: 1.2rem;
}

/* === Action bar === */
#action-bar { display: flex; gap: 8px; }

#action-bar button {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid #555;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}
#action-bar button:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

#btn-submit {
  background: var(--accent);
  border-color: var(--accent);
  color: #1e1e1e;
  box-shadow: 0 0 10px var(--accent-glow);
}
#btn-submit:hover {
  box-shadow: 0 0 18px var(--accent-glow);
}

/* === Info panel === */
#info-panel {
  flex: 1; display: flex; flex-direction: column; gap: 8px;
  overflow: hidden; min-width: 180px;
}

#found-words-header {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

#found-words-list {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column;
  gap: 4px; font-size: 0.85rem;
}

/* Scrollbar styling */
#found-words-list::-webkit-scrollbar { width: 4px; }
#found-words-list::-webkit-scrollbar-track { background: transparent; }
#found-words-list::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }

.found-word-item {
  padding: 5px 8px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid #3a3a3a;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-main);
  transition: border-color 0.2s, background 0.2s;
}
.found-word-item:hover {
  border-color: var(--accent);
  background: #333;
}
.found-word-item.new { animation: pop-in 0.25s ease-out; }

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

/* Medal score colours */
.medal-pink   { color: #ff66c4; text-shadow: 0 0 6px rgba(255,102,196,0.6); }
.medal-purple { color: #b3b3ff; text-shadow: 0 0 6px rgba(179,179,255,0.6); }
.medal-gold   { color: #ffa500; text-shadow: 0 0 6px rgba(255,165,0,0.6); }

/* === Definition panel === */
#definition-display {
  font-family: var(--font-main);
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.6;
  padding: 10px;
  background: var(--surface);
  border: 1px solid #3a3a3a;
  border-radius: var(--radius);
  min-height: 48px;
  max-height: 120px;
  overflow-y: auto;
}
.def-line { margin-top: 4px; }
.def-line:first-of-type { margin-top: 6px; }

/* === Modal === */
#modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
#modal-overlay.hidden { display: none; }

#modal-content {
  background: var(--surface);
  border: 1px solid #444;
  border-radius: 10px;
  padding: 24px;
  max-width: 420px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.6);
}

.modal-title {
  font-family: var(--font-main);
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  margin-bottom: 16px;
  color: var(--accent);
  text-shadow: 0 0 10px var(--accent-glow);
}

.modal-close {
  float: right;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  transition: color 0.2s;
}
.modal-close:hover { color: var(--accent); }

/* === End-game word reveal === */
.endgame-section-title {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin: 14px 0 6px;
}
.endgame-word-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 4px;
}
.endgame-word {
  font-family: var(--font-main);
  font-size: 0.8rem;
  padding: 3px 7px;
  border-radius: var(--radius);
  border: 1px solid #3a3a3a;
}
.endgame-word.found {
  background: rgba(27, 138, 31, 0.18);
  border-color: rgba(27, 138, 31, 0.45);
  color: #4caf50;
}
.endgame-word.missed {
  background: rgba(192, 57, 43, 0.12);
  border-color: rgba(192, 57, 43, 0.35);
  color: #e57373;
}

/* === Settings / Leaderboard === */
.setting-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #3a3a3a;
  font-family: var(--font-ui);
  font-size: 0.9rem;
}

.setting-row select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid #555;
  border-radius: var(--radius);
  padding: 4px 8px;
  font-family: var(--font-ui);
}

.leaderboard-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.leaderboard-table th,
.leaderboard-table td {
  padding: 7px 8px;
  text-align: left;
  border-bottom: 1px solid #3a3a3a;
  font-family: var(--font-ui);
}
.leaderboard-table th { color: var(--text-muted); font-weight: 600; letter-spacing: 0.05em; }
.leaderboard-table tr:hover td { background: #333; }
