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

:root {
  --bg: #0a0a0c;
  --bg-surface: rgba(255, 255, 255, 0.04);
  --bg-glass: rgba(255, 255, 255, 0.06);
  --text: #e8e6e3;
  --text-dim: #8a8680;
  --text-marble: #d4d0cc;
  --accent: rgba(255, 255, 255, 0.7);
  --accent-glow: rgba(255, 255, 255, 0.08);
  --gold: #c9b896;
  --gold-glow: rgba(201, 184, 150, 0.2);
  --theme-color: #b8c4b0;
  --theme-glow: rgba(184, 196, 176, 0.15);
  --bonus-color: #b0a4be;
  --error: #c47070;
  --border: rgba(255, 255, 255, 0.08);
  --border-light: rgba(255, 255, 255, 0.12);
}

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

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding: 6px 12px;
}

/* ── Header ─────────────────────────────────────────────────────────── */

#header {
  text-align: center;
  margin-bottom: 2px;
  width: 100%;
}

#logo-link {
  display: inline-block;
}

#logo {
  height: 56px;
  width: auto;
  margin-bottom: 2px;
  filter: drop-shadow(0 2px 8px rgba(255, 255, 255, 0.06));
  transition: opacity 0.15s;
}

#logo:hover {
  opacity: 0.8;
}

#theme-line {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  min-height: 24px;
}

#theme-hint {
  font-size: 15px;
  color: var(--text-marble);
  font-weight: 500;
  font-style: normal;
  letter-spacing: 0.5px;
}

#theme-sep {
  color: var(--text-dim);
  font-size: 14px;
}

#word-count {
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 1px;
  min-width: 36px;
}

#found-count {
  color: var(--text);
  font-weight: 600;
}

/* ── Game Area ──────────────────────────────────────────────────────── */

#game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

#trace-display {
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0;
}

#current-trace {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 4px;
  color: var(--text);
  text-transform: uppercase;
  text-shadow: 0 0 12px rgba(255, 255, 255, 0.1);
}

#grid-canvas {
  touch-action: none;
  cursor: pointer;
}

#found-words {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  margin-top: 4px;
  max-width: 100%;
  min-height: 24px;
}

.found-word {
  padding: 4px 10px;
  border-radius: 0;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  animation: wordPop 0.3s ease-out;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.found-word.theme {
  background: linear-gradient(135deg, #e8e4e0, #d8d4cf);
  color: #2a2a2a;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.found-word.spangram {
  background: linear-gradient(135deg, #f0ece8, #e2ddd6);
  color: #1a1a1a;
  border: 1px solid rgba(255, 255, 255, 0.5);
  font-weight: 600;
}

.found-word.placeholder {
  background: linear-gradient(135deg, rgba(216, 212, 207, 0.25), rgba(200, 196, 190, 0.18));
  color: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.12);
  min-width: 50px;
  font-size: 10px;
}

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

/* ── Controls ───────────────────────────────────────────────────────── */

#controls {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  margin-bottom: 6px;
}

.btn {
  padding: 9px 22px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 0;
  background: linear-gradient(135deg, #d8d4cf, #c8c3bc);
  color: #2a2a2a;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #e8e4e0, #d8d4cf);
  border-color: rgba(255, 255, 255, 0.6);
}

.btn:disabled {
  background: linear-gradient(135deg, rgba(216, 212, 207, 0.3), rgba(200, 195, 188, 0.2));
  color: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.1);
  cursor: not-allowed;
}

#hint-btn:not(:disabled) {
  background: linear-gradient(135deg, #d8d4cf, #c8c3bc);
  color: #2a2a2a;
}

/* ── Type Bar ───────────────────────────────────────────────────────── */

#type-bar {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 6px;
  width: 100%;
  max-width: 320px;
}

#type-input {
  flex: 1;
  padding: 9px 14px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.15s;
}

#type-input::placeholder {
  color: rgba(255, 255, 255, 0.2);
  text-transform: none;
  letter-spacing: 0.5px;
}

#type-input:focus {
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.08);
}

#type-submit {
  padding: 9px 16px;
}

/* ── Completion Overlay ─────────────────────────────────────────────── */

#completion-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.4s ease;
  backdrop-filter: blur(6px);
}

#completion-card {
  background: rgba(20, 20, 24, 0.9);
  border: 1px solid rgba(201, 184, 150, 0.3);
  border-radius: 12px;
  padding: 32px 40px;
  text-align: center;
  box-shadow: 0 0 40px rgba(201, 184, 150, 0.08);
  max-width: 340px;
  backdrop-filter: blur(12px);
}

#completion-card h2 {
  color: var(--gold);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 2px;
  margin-bottom: 12px;
}

#completion-message {
  color: var(--text-marble);
  font-size: 15px;
  margin-bottom: 14px;
}

#completion-stats {
  color: var(--text-dim);
  font-size: 13px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── No Puzzle ──────────────────────────────────────────────────────── */

#no-puzzle {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 16px;
  letter-spacing: 0.5px;
}

/* ── Utility ────────────────────────────────────────────────────────── */

.hidden {
  display: none !important;
}

/* ── Toast Notifications ────────────────────────────────────────────── */

.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.5px;
  z-index: 200;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 1.5s forwards;
  pointer-events: none;
  backdrop-filter: blur(8px);
}

.toast.error {
  background: rgba(196, 112, 112, 0.85);
  color: white;
  border: 1px solid rgba(196, 112, 112, 0.4);
}

.toast.bonus {
  background: rgba(176, 164, 190, 0.85);
  color: white;
  border: 1px solid rgba(176, 164, 190, 0.4);
}

.toast.hint {
  background: rgba(201, 184, 150, 0.85);
  color: #1a1a1a;
  border: 1px solid rgba(201, 184, 150, 0.4);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ── Responsive ─────────────────────────────────────────────────────── */

@media (max-height: 700px) {
  #logo { height: 48px; }
  #theme-display { padding: 5px 12px; }
  #trace-display { height: 24px; }
  #current-trace { font-size: 16px; }
  .btn { padding: 7px 16px; font-size: 12px; }
}
