:root {
  --bg: #1a1a2e;
  --panel: #16213e;
  --ink: #f5f5f5;
  --accent: #0a84ff;
  --accent-2: #f6a100;
  --accent-3: #10b981;
  --danger: #ef4444;
  --border: #2d3a4f;
  --muted: #c8d0dc;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f0f1a 100%);
}

.app {
  max-width: 100%;
  margin: 0 auto;
  height: 100vh;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top-bar {
  flex-shrink: 0;
}

.top-bar h1 {
  margin: 0;
  font-size: clamp(1.3rem, 1rem + 1vw, 1.8rem);
  color: #ffffff;
}

.top-bar p {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 22px rgba(22, 49, 68, 0.08);
  overflow: hidden;
}

.panel-head {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, #1e2a3a 0%, #243447 100%);
}

.panel-head h2 {
  margin: 0.1rem 0;
  color: #ffffff;
  font-size: 1rem;
}

.panel-head p {
  margin: 0.1rem 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.head-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

/* Mode Selection */
.mode-panel {
  padding: 1.25rem;
  margin-bottom: 0.75rem;
  overflow-y: auto;
  max-height: calc(100vh - 100px);
}

.mode-panel h2 {
  margin: 0 0 0.75rem;
  text-align: center;
  color: #ffffff;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.25rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-btn:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(10, 132, 255, 0.15);
}

.mode-btn.completed {
  border-color: var(--accent-3);
  background: linear-gradient(135deg, #1a3a2e 0%, #1e4035 100%);
}

.mode-icon {
  font-size: 2rem;
  margin-bottom: 0.4rem;
}

.mode-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
}

.mode-desc {
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.25rem;
}

.streak-display {
  text-align: center;
  padding: 0.6rem;
  background: linear-gradient(90deg, #4a4520 0%, #5a5025 100%);
  border-radius: 8px;
  font-size: 1rem;
  color: #ffd700;
}

/* Difficulty Selection */
.difficulty-panel {
  padding: 1.25rem;
  margin-bottom: 0.75rem;
}

.difficulty-panel h2 {
  margin: 0 0 0.75rem;
  text-align: center;
  color: #ffffff;
}

.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.diff-btn {
  display: flex;
  flex-direction: column;
  padding: 0.85rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  cursor: pointer;
  transition: all 0.2s ease;
}

.diff-btn:hover {
  border-color: var(--accent);
  background: #1e3a4a;
}

.diff-btn[data-difficulty="easy"] { border-left: 4px solid #10b981; }
.diff-btn[data-difficulty="medium"] { border-left: 4px solid #f59e0b; }
.diff-btn[data-difficulty="hard"] { border-left: 4px solid #ef4444; }
.diff-btn[data-difficulty="mixed"] { border-left: 4px solid #8b5cf6; }

.diff-label {
  font-weight: 700;
  font-size: 1rem;
  color: #ffffff;
}

.diff-desc {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

/* Start Panel */
.start-panel {
  padding: 1.25rem;
  margin-bottom: 0.75rem;
}

.start-panel h2 {
  margin: 0 0 0.6rem;
  color: #ffffff;
}

.start-form {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.start-form label {
  font-weight: 700;
  color: var(--muted);
}

.start-form input {
  min-width: 200px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  font-size: 1rem;
  background: #1a1a2e;
  color: #ffffff;
}

.start-form input::placeholder {
  color: #6b7280;
}

.back-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}

.back-btn:hover {
  background: #252538;
  color: var(--ink);
}

/* Game Grid - Fixed to viewport height */
.game-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.photo-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.photo-wrap {
  margin: 0;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.image-loader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  z-index: 5;
}

.image-loader.hidden {
  display: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#locationPhoto {
  width: 100%;
  flex: 1;
  min-height: 0;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  opacity: 0;
  transition: opacity 0.3s ease;
}

#locationPhoto.loaded {
  opacity: 1;
}

#photoCaption {
  font-size: 0.85rem;
  line-height: 1.3;
  color: var(--muted);
  flex-shrink: 0;
}

/* Timer - Fixed contrast */
.timer {
  font-size: 1rem;
  font-weight: 700;
  padding: 0.35rem 0.7rem;
  background: #4a4520;
  border-radius: 8px;
  color: #ffd700;
}

.timer.warning {
  background: #5c2020;
  color: #ff6b6b;
  animation: pulse 0.5s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.05); }
}

.mode-badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  background: var(--accent);
  color: white;
  border-radius: 20px;
  font-weight: 600;
}

.mode-badge.daily {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

/* Map Panel - Fixed to viewport */
.map-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#map {
  width: 100%;
  flex: 1;
  min-height: 0;
}

.controls {
  padding: 0.6rem 0.8rem;
  border-top: 1px solid var(--border);
  background: #1e2a3a;
  flex-shrink: 0;
}

#statusText {
  margin: 0 0 0.5rem;
  font-weight: 600;
  color: #ffffff;
  font-size: 0.9rem;
}

.buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Buttons */
button {
  border: 0;
  border-radius: 8px;
  padding: 0.5rem 0.8rem;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s ease;
  font-size: 0.85rem;
}

button:hover:not([disabled]) {
  filter: brightness(1.08);
}

button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

#nextBtn {
  background: var(--accent-2);
}

#restartBtn, .practice-btn-alt {
  background: #117a37;
}

.hint-btn {
  background: #8b5cf6;
}

.hint-btn[disabled] {
  background: #a78bfa;
}

#shareBtn {
  background: #1d9bf0;
}

.view-btn {
  background: var(--accent);
}

/* Completed Panel */
.completed-panel {
  padding: 1.5rem;
  text-align: center;
  margin-bottom: 0.75rem;
}

.completed-panel h2 {
  margin: 0 0 0.75rem;
  color: var(--accent-3);
}

.completed-panel p {
  margin: 0.4rem 0;
  color: var(--muted);
}

#nextDailyTimer {
  font-size: 1rem;
  font-weight: 600;
  color: #ffd700;
  margin-top: 0.75rem;
}

.completed-panel button {
  margin: 0.4rem;
}

/* Scoreboard */
.scoreboard {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 100px);
}

.scoreboard-tabs {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.tab-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.tab-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.scoreboard-wrap {
  padding: 0.75rem;
  overflow-x: auto;
  overflow-y: auto;
  flex: 1;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}

th {
  color: #ffffff;
}

thead {
  background: #1e2a3a;
  position: sticky;
  top: 0;
}

tr.highlight {
  background: #3d3510;
}

tr.highlight td {
  color: #ffd700;
}

/* Responsive */
@media (max-width: 900px) {
  .game-grid {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .mode-grid {
    grid-template-columns: 1fr;
  }
}

/* Ensure hidden attribute works with grid elements */
[hidden] {
  display: none !important;
}

/* Daily Scores Section on Main Page */
.daily-scores-section {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.daily-scores-section h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  color: #ffffff;
  text-align: center;
}

.daily-scores-wrap {
  max-height: 200px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.daily-scores-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.daily-scores-wrap th,
.daily-scores-wrap td {
  padding: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.daily-scores-wrap th {
  color: #ffffff;
}

.daily-scores-wrap td {
  color: var(--muted);
}

.daily-scores-wrap thead {
  background: #1e2a3a;
  position: sticky;
  top: 0;
}

.daily-scores-wrap tbody tr:hover {
  background: rgba(10, 132, 255, 0.1);
}
