/* ============================================================
   EmojiHunt - Styles
   ============================================================ */

:root {
  --bg: #0a0a0f;
  --surface: #161622;
  --border: #1e1e3a;
  --accent: #a855f7;
  --accent-glow: #c084fc;
  --success: #22c55e;
  --error: #ef4444;
  --text: #f0f0f0;
  --text-muted: #888899;
  --stars: #fbbf24;
  --grid-size: 12;
}

/* ---- Reset & Base ---- */

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---- Screens ---- */

.screen {
  width: 100%;
  max-width: 500px;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
}

.screen.hidden, .modal.hidden {
  display: none;
}

/* ---- Terminal Welcome Screen ---- */

.terminal {
  display: flex;
  flex-direction: column;
  flex: 1;
  margin: 16px 0;
  border: 1px solid #2a3a2a;
  border-radius: 8px;
  overflow: hidden;
  background: #0c100c;
  box-shadow:
    0 0 40px rgba(34, 197, 94, 0.04),
    inset 0 0 80px rgba(0, 0, 0, 0.3);
  position: relative;
}

/* Scanline overlay */
.terminal::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.15) 2px,
    rgba(0, 0, 0, 0.15) 4px
  );
  pointer-events: none;
  z-index: 2;
}

.terminal-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: #111611;
  border-bottom: 1px solid #2a3a2a;
}

.terminal-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.terminal-dot.red { background: #ff5f57; }
.terminal-dot.yellow { background: #febc2e; }
.terminal-dot.green { background: #28c840; }

.terminal-title {
  margin-left: 8px;
  font-family: 'Courier New', 'Consolas', monospace;
  font-size: 12px;
  color: #5a6a5a;
  letter-spacing: 0.05em;
}

.terminal-body {
  flex: 1;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  font-family: 'Courier New', 'Consolas', monospace;
  position: relative;
  z-index: 1;
}

.ascii-art {
  color: var(--accent);
  font-size: clamp(6.5px, 2.1vw, 11px);
  line-height: 1.2;
  text-align: center;
  margin-bottom: 20px;
  text-shadow: 0 0 10px rgba(168, 85, 247, 0.4);
  white-space: pre;
}

.boot-lines {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.boot-line {
  font-size: 13px;
  color: #7aff7a;
  line-height: 1.6;
  letter-spacing: 0.02em;
}

.boot-line .ok {
  color: #28c840;
  font-weight: 700;
}

.boot-line.dim {
  color: #4a6a4a;
}

.blink-line .cursor {
  animation: blink 1s step-end infinite;
}

.terminal-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.btn-terminal {
  background: transparent;
  border: 1px solid #2a5a2a;
  color: #7aff7a;
  font-family: 'Courier New', 'Consolas', monospace;
  font-size: 14px;
  font-weight: 700;
  padding: 12px 16px;
  text-align: left;
  border-radius: 4px;
  letter-spacing: 0.03em;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.btn-terminal:hover {
  background: rgba(40, 200, 64, 0.08);
  border-color: #28c840;
  box-shadow: 0 0 12px rgba(40, 200, 64, 0.15);
}

.btn-terminal:active {
  background: rgba(40, 200, 64, 0.15);
}

.btn-terminal-dim {
  background: transparent;
  border: 1px solid #1a2a1a;
  color: #4a6a4a;
  font-family: 'Courier New', 'Consolas', monospace;
  font-size: 13px;
  font-weight: 400;
  padding: 10px 16px;
  text-align: left;
  border-radius: 4px;
  letter-spacing: 0.03em;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-terminal-dim:hover {
  color: #7aff7a;
  border-color: #2a5a2a;
}

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

/* ---- Rules Card (used in help modal) ---- */

.rules-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rule {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  line-height: 1.4;
}

.rule-icon {
  font-size: 20px;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}

/* ---- Buttons ---- */

.btn {
  border: none;
  border-radius: 10px;
  padding: 14px 24px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
  transition: transform 0.1s, opacity 0.2s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-glow);
}

.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

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

.icon-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}

.icon-btn:hover {
  background: var(--border);
}

/* ---- Game Header ---- */

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  flex-shrink: 0;
}

.game-title {
  font-size: 18px;
  font-weight: 700;
}

.header-actions {
  display: flex;
  gap: 4px;
}

/* ---- Target Bar ---- */

.target-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
  flex-shrink: 0;
  gap: 8px;
}

.target-display {
  display: flex;
  align-items: center;
  gap: 8px;
}

.target-label {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 600;
}

.target-emoji {
  font-size: 28px;
  line-height: 1;
}

.timer {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 60px;
  text-align: center;
}

.btn-hint {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 13px;
  width: auto;
  flex-shrink: 0;
  white-space: nowrap;
}

.btn-hint:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---- Grid ---- */

.grid-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 4px 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-size), 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  width: 100%;
  max-width: 500px;
  aspect-ratio: 1;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(16px, 2.2vw, 28px);
  cursor: pointer;
  transition: opacity 0.3s ease, transform 0.15s ease;
  position: relative;
  aspect-ratio: 1;
  line-height: 1;
}

.cell:hover {
  background: #1c1c30;
}

.cell.faded {
  opacity: 0.08;
  pointer-events: none;
}

.cell.wrong {
  animation: shake 0.2s ease;
}

.cell.wrong::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--error);
  opacity: 0.3;
  border-radius: 2px;
  animation: flash 0.3s ease forwards;
}

.cell.found {
  transform: scale(1.8);
  z-index: 10;
  background: transparent;
  filter: drop-shadow(0 0 12px var(--success));
}

.grid.dimmed .cell:not(.found) {
  opacity: 0.2;
  pointer-events: none;
}

/* ---- Stars Bar ---- */

.stars-bar {
  display: flex;
  justify-content: center;
  padding: 12px 0;
  flex-shrink: 0;
}

.stars-display {
  display: flex;
  gap: 4px;
  font-size: 22px;
}

.star {
  transition: opacity 0.3s;
}

.star.dimmed {
  opacity: 0.2;
}

/* ---- Modals ---- */

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.close-btn {
  font-size: 18px;
  color: var(--text-muted);
}

/* ---- Results Modal ---- */

.results-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.results-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent-glow);
}

.results-stars {
  font-size: 32px;
  display: flex;
  gap: 4px;
}

.results-stars .star-pop {
  animation: starPop 0.3s ease backwards;
}

.results-info {
  font-size: 16px;
  color: var(--text);
}

.results-stats-line {
  font-size: 13px;
  color: var(--text-muted);
}

.results-journey {
  font-size: 24px;
  letter-spacing: 2px;
  padding: 8px 0;
  word-break: break-all;
}

.results-streak {
  font-size: 16px;
  color: var(--stars);
  font-weight: 600;
}

.results-countdown {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.copy-toast {
  font-size: 13px;
  color: var(--success);
  font-weight: 600;
  padding: 4px 0;
  transition: opacity 0.3s;
}

.copy-toast.hidden {
  display: none;
}

/* ---- Stats Modal ---- */

.stats-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.stat-item {
  text-align: center;
}

.stat-value {
  font-size: 24px;
  font-weight: 800;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stats-section-title {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-align: left;
}

.stats-distribution {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  width: 100%;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.dist-label {
  width: 20px;
  text-align: right;
  flex-shrink: 0;
  font-weight: 600;
}

.dist-bar-container {
  flex: 1;
  height: 20px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}

.dist-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  min-width: 20px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
  font-size: 11px;
  font-weight: 700;
  color: white;
  transition: width 0.5s ease;
}

.dist-bar.highlight {
  background: var(--success);
}

.stats-times {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* ---- Animations ---- */

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

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

@keyframes flash {
  0% { opacity: 0.4; }
  100% { opacity: 0; }
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes starPop {
  0% { transform: scale(0); opacity: 0; }
  70% { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes fadeInCell {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

/* ---- Reduced Motion ---- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---- Responsive ---- */

@media (max-width: 380px) {
  .target-bar {
    padding: 8px 10px;
    gap: 6px;
  }

  .target-emoji {
    font-size: 24px;
  }

  .timer {
    font-size: 16px;
    min-width: 50px;
  }

  .btn-hint {
    padding: 6px 8px;
    font-size: 12px;
  }

  .ascii-art {
    font-size: 5.5px;
  }

  .boot-line {
    font-size: 11px;
  }

  .terminal-body {
    padding: 14px 12px;
  }
}
