/* Final Run Completion Popup - single, clean definition */

/* Global Body Styling (Matches level1.css) */
body {
  font-family: Arial, sans-serif;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #f2f2f2;
  min-height: 100vh;
}

#final-run-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: none; /* JS will change this to "flex" */
  justify-content: center;
  align-items: center;
  z-index: 99999;
}

/* Popup box */
#final-run-modal .final-run-box {
  background: #fff;
  width: 350px;
  max-width: 92%;
  padding: 22px;
  border-radius: 10px;
  text-align: center;
  font-family: Arial, sans-serif;
}

/* Comment textarea */
#final-run-modal textarea {
  width: 100%;
  height: 80px;
  margin: 10px 0;
  padding: 8px;
  font-size: 15px;
  resize: none;
}

/* Buttons */
#submit-final-score,
#play-again {
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  font-size: 16px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

#submit-final-score {
  background: #16a34a;
  color: white;
}

#play-again {
  background: #1e3a8a;
  color: white;
}

/* Header Styles */
.header {
  padding: 15px 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  gap: 12px;
  background: transparent;
  border-bottom: 2px solid #e5e5e5;
  width: 100%;
  box-sizing: border-box;
}

.header .logo {
  width: 77px;
  height: 64px;
  object-fit: contain;
  display: block;
}

.text-blue {
  color: rgb(59, 130, 246);
}

.text-red {
  color: rgb(239, 68, 68);
}

.back-btn {
  text-decoration: none;
  color: rgb(239, 68, 68);
  font-weight: bold;
  font-size: 16px;
  padding: 8px 16px;
  border: 2px solid rgb(239, 68, 68);
  border-radius: 6px;
  transition: all 0.2s;
  position: absolute;
  right: 20px;
  top: 30px;
}

.back-btn:hover {
  background: #f0f0f0;
  border-color: #ccc;
}

@media (max-width: 600px) {
  .back-btn {
    position: static;
    display: inline-block;
    margin-top: 10px;
  }

  .header {
    flex-direction: column;
    gap: 10px;
  }

  .home-link {
    flex-direction: column;
    text-align: center;
    gap: 5px;
  }

  .hidden-on-mobile {
    display: none !important;
  }

  .level-mission-panel {
    width: 100%;
    margin: 10px 0 6px;
    padding: 10px;
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .mission-copy {
    min-width: 0;
    text-align: left;
  }

  .mission-title {
    font-size: 18px;
  }

  .mission-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .mission-stat:first-child {
    grid-column: auto;
  }

  .mission-stat {
    min-height: 46px;
    padding: 7px 8px;
    gap: 3px;
  }

  .mission-label {
    font-size: 10px;
  }

  .mission-value {
    font-size: 16px;
  }

  .completion-summary {
    grid-template-columns: 1fr;
  }
}

.home-link,
.home-link:visited {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

/* Mission HUD */
.level-mission-panel {
  width: min(1100px, calc(100% - 24px));
  margin: 16px auto 6px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-sizing: border-box;
  background: #ffffff;
  border: 1px solid #dbe3ef;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.mission-copy {
  min-width: 220px;
  text-align: left;
}

.mission-title {
  margin: 0 0 4px;
  color: #111827;
  font-size: 22px;
  line-height: 1.15;
}

.mission-objective {
  margin: 0;
  color: #475569;
  font-size: 14px;
  line-height: 1.35;
}

.mission-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(96px, 1fr));
  gap: 8px;
  flex: 1;
}

.mission-stat {
  min-height: 52px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  box-sizing: border-box;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}

.mission-label {
  color: #64748b;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

.mission-value {
  color: #0f172a;
  font-size: 17px;
  line-height: 1.1;
}

/* Level Completion Popup (Generic) */
#level-complete {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: none; /* Hidden by default */
  justify-content: center;
  align-items: center;
  z-index: 99999;
}

#level-complete .modal-content,
#level-complete .popup {
  background: #fff;
  width: 350px;
  max-width: 92%;
  padding: 22px;
  border-radius: 10px;
  text-align: center;
  font-family: Arial, sans-serif;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

#level-complete h2 {
  margin-top: 0;
  color: #333;
  line-height: 1.18;
}

#level-complete .completion-title,
#level-complete .rank-status {
  display: block;
}

#level-complete .rank-status {
  margin-top: 8px;
  color: #16a34a;
  font-size: 0.82em;
  font-weight: 700;
  line-height: 1.25;
}

.completion-stars {
  display: flex;
  justify-content: center;
  gap: 4px;
  min-height: 34px;
  margin: 8px 0 10px;
}

.completion-star {
  color: #cbd5e1;
  font-size: 30px;
  line-height: 1;
}

.completion-star.is-earned {
  color: #f59e0b;
  text-shadow: 0 2px 6px rgba(245, 158, 11, 0.25);
}

.completion-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0 6px;
}

.completion-summary div {
  padding: 9px 8px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}

.completion-summary strong,
.completion-summary span {
  display: block;
}

.completion-summary strong {
  color: #64748b;
  font-size: 11px;
  line-height: 1;
  text-transform: uppercase;
}

.completion-summary span {
  margin-top: 5px;
  color: #111827;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.1;
}

#level-complete button {
  width: 100%;
  margin-top: 16px;
  padding: 18px 16px;
  min-height: 64px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.01em;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  background: #16a34a;
  color: white;
}

#level-complete a[href*="buymeacoffee"],
#level-complete img[alt*="Coffee"],
#level-complete p[style*="4BB543"],
#share-score-btn {
  display: none !important;
}

/* Status Bar & Icons */
#status-bar {
  --status-item-gap: 5px;
  --status-time-row-height: 14px;
  --status-hint-align-offset: calc(var(--status-item-gap) + var(--status-time-row-height));
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 1000;
  margin-top: 10px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--status-item-gap);
  flex-wrap: nowrap;
  padding: 5px 0;
  background: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  border-bottom: 0;
  box-shadow: none;
  box-sizing: border-box;
}

.char-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--status-item-gap);
  position: relative;
}

.char-status img {
  width: 50px;
  height: 50px;
  object-fit: cover;
  border-radius: 50%;
  border: 2px solid transparent;
  background: white;
  transition: all 0.3s ease;
}

.char-status.found img {
  opacity: 0.5;
  filter: grayscale(100%);
  border-color: #22c55e;
}

.char-status .time {
  font-size: 12px;
  font-weight: bold;
  color: #16a34a;
  line-height: var(--status-time-row-height);
  min-height: var(--status-time-row-height); /* Prevent Layout Shift */
}

/* Checkmark (Tick) Styles */
.char-status .checkmark {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #22c55e;
  color: #fff;
  font-weight: bold;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 50%;
  display: none; /* Hidden until found */
  pointer-events: none;
  z-index: 10;
}

.char-status.found .checkmark {
  display: block;
}

/* Hint Button */
.hint-control {
  position: relative;
  display: flex;
  align-items: center;
  align-self: center;
  margin-bottom: var(--status-hint-align-offset);
}

.hint-button {
  min-height: 44px;
  padding: 0 16px;
  border: 2px solid #1d4ed8;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(37, 99, 235, 0.22);
  white-space: nowrap;
}

.hint-button:hover:not(:disabled),
.hint-button:focus-visible {
  background: #1d4ed8;
  outline: none;
}

.hint-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  box-shadow: none;
}

.hint-text-short {
  display: none;
}

.hint-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 180px;
  background: #fff;
  border-radius: 8px;
  padding: 6px 0;
  box-shadow: 0 4px 22px rgba(0, 0, 0, 0.25);
  z-index: 1002;
  font-family: Arial, sans-serif;
}

.hint-menu[hidden] {
  display: none;
}

.hint-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  padding: 10px 14px;
  color: #333;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}

.hint-menu-item:hover,
.hint-menu-item:focus-visible {
  background: #f4f4f4;
  outline: none;
}

.hint-menu-item + .hint-menu-item {
  border-top: 1px solid #e5e5e5;
}

.hint-menu-item img {
  width: 28px !important;
  height: 28px !important;
  object-fit: contain;
}

.hint-highlight {
  position: absolute;
  pointer-events: none;
  border: 4px solid #ff2d8d;
  border-radius: 999px;
  background: rgba(255, 45, 141, 0.1);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.95),
    0 0 0 8px rgba(17, 24, 39, 0.48),
    0 0 24px rgba(255, 45, 141, 0.9);
  z-index: 20;
  animation: hint-pulse 1.2s ease-in-out infinite;
}

.hint-highlight[hidden] {
  display: none;
}

@keyframes hint-pulse {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.06);
  }
}

/* Click Menu Styling (Missing in game.css previously) */
.click-menu {
  position: absolute;
  background: white;
  border-radius: 12px;
  padding: 6px 0;
  display: none;
  z-index: 9999; /* High z-index to sit on top of everything */
  width: 180px;
  box-shadow: 0 4px 22px rgba(0, 0, 0, 0.25);
  font-family: Arial, sans-serif;
}

.click-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 16px;
  text-align: left;
  color: #333;
}

.click-menu button img {
  width: 28px !important; /* Force small icon in menu */
  height: 28px !important;
  object-fit: contain;
}

.click-menu button:hover {
  background: #f4f4f4;
}

.click-menu button + button {
  border-top: 1px solid #e5e5e5;
}

/* Level Leaderboard Section */
/* Level Leaderboard Section - Matches leaderboard.css */
#level-leaderboard-section {
  width: 100%; /* Ensure it takes full width up to max-width */
  max-width: 900px; /* Increased from 800px */
  margin: 40px auto;
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

#level-leaderboard-section h2 {
  text-align: center;
  color: #333;
  margin-bottom: 20px;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.level-leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.level-leaderboard-table thead {
  background: #f8fafc;
  border-bottom: 2px solid #e2e8f0;
}

.level-leaderboard-table th {
  padding: 16px;
  text-align: left;
  font-weight: 600;
  color: #475569;
  text-transform: uppercase;
  font-size: 14px;
  letter-spacing: 0.5px;
}

.level-leaderboard-table td {
  padding: 16px;
  border-bottom: 1px solid #f1f5f9;
  color: #1e293b;
  font-size: 15px;
}

.level-leaderboard-table tr:last-child td {
  border-bottom: none;
}

.level-leaderboard-table tr:hover {
  background-color: #f8fafc;
}

/* Rank column styling */
.level-leaderboard-table td:first-child {
  font-weight: bold;
  color: #64748b;
  width: 60px;
  text-align: center;
}

.level-leaderboard-table th:first-child {
  text-align: center;
}

/* Top 3 Ranks Colors */
.level-leaderboard-table tr:nth-child(1) td:first-child {
  color: #eab308; /* Gold */
  font-size: 1.2em;
}

.level-leaderboard-table tr:nth-child(2) td:first-child {
  color: #94a3b8; /* Silver */
  font-size: 1.1em;
}

.level-leaderboard-table tr:nth-child(3) td:first-child {
  color: #b45309; /* Bronze */
  font-size: 1.1em;
}

/* Comment column */
.level-leaderboard-table td:nth-child(4) {
  color: #64748b;
  font-style: italic;
  max-width: 250px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Popup Comment Box */
#level-comment {
  width: 100%;
  height: 60px;
  margin: 15px auto;
  padding: 10px;
  display: block;
  box-sizing: border-box;
  border: 1px solid #ddd;
  border-radius: 6px;
  resize: vertical;
  font-family: inherit;
}

#level-submission-error {
  color: red;
  font-size: 14px;
  margin-bottom: 10px;
  display: none;
}

#message {
  margin-top: 15px;
  font-size: 20px;
  font-weight: bold;
  color: green;
  min-height: 28px;
  text-align: center;
  width: 100%;
}

/* Game Container Defaults */
#game-container {
  position: relative;
  overflow: auto; /* Allow scrolling for large images */
  max-width: 100%;
  margin: 0 auto;
  border: 1px solid #ddd;
}

/* Standard Scene Image Styling */
#scene {
  display: block;
  cursor: crosshair;
  max-width: 100%;
  height: auto;
}

/* Force Icon Size globally first, to override any defaults */
.char-status img {
  width: 50px !important;
  height: 50px !important;
  object-fit: cover;
  border-radius: 50%;
  background: white;
}

/* Responsive Game Container & Status Bar */
@media (max-width: 768px) {
  #game-container {
    overflow-x: auto;
    max-width: 100vw;
    display: block; /* Override inline-block */
    -webkit-overflow-scrolling: touch;
  }

  #scene {
    /* Keep original size to preserve hitboxes, but allow scrolling */
    max-width: none; /* Allow horizontal scroll on mobile */
  }

  #status-bar {
    position: -webkit-sticky; /* Safari support */
    position: sticky;
    top: 0; /* Stick to the very top */
    width: 100%;
    background: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    border-bottom: 0;
    border-radius: 0;
    padding: 5px 0; /* Slight padding for breathing room */
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    justify-content: center;
    gap: var(--status-item-gap);
    z-index: 1000;
    margin-top: 10px; /* Reduced margin since it's sticky */
    box-shadow: none;
    box-sizing: border-box;

    /* Reset fixed positioning properties */
    bottom: auto;
    left: auto;
    transform: none;
    max-width: none;
  }

  .char-status img {
    width: 50px; /* Decreased size */
    height: 50px; /* Decreased size */
    border-radius: 50%; /* Make circular */
    object-fit: cover; /* Ensure image covers the circle */
    background: white; /* Optional: add background if transparent images look weird */
  }

  .header {
    justify-content: center;
    text-align: center;
  }

  .header h1 {
    text-align: center;
    width: 100%;
  }
}

/* Mobile Optimizations */
@media (max-width: 600px) {
  /* 1. Global Padding for Mobile */
  body {
    padding: 10px;
    box-sizing: border-box;
  }

  .hint-button {
    min-height: 40px;
    padding: 0 12px;
    font-size: 14px;
  }

  .hint-text-full {
    display: none;
  }

  .hint-text-short {
    display: inline;
  }

  .level-mission-panel {
    width: 100%;
    margin: 10px 0 6px;
    padding: 10px;
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .mission-copy {
    min-width: 0;
    text-align: left;
  }

  .mission-title {
    font-size: 18px;
  }

  .mission-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .mission-stat:first-child {
    grid-column: auto;
  }

  .mission-stat {
    min-height: 46px;
    padding: 7px 8px;
    gap: 3px;
  }

  .mission-label {
    font-size: 10px;
  }

  .mission-value {
    font-size: 16px;
  }

  .completion-summary {
    grid-template-columns: 1fr;
  }

  /* 2. Leaderboard Mobile Adjustments */
  #level-leaderboard-section {
    padding: 10px;
    margin: 20px auto;
    width: 100%;
    box-sizing: border-box;
  }

  .level-leaderboard-table th,
  .level-leaderboard-table td {
    padding: 8px 4px; /* Reduce padding */
    font-size: 12px; /* Smaller font */
  }

  /* Reduce Rank column width */
  .level-leaderboard-table td:first-child {
    width: 30px;
  }

  /* Constrain Comment column width further on mobile */
  .level-leaderboard-table td:nth-child(4) {
    max-width: 80px;
  }

  /* Optional: Hide Date column on very small screens if it still overflows */
  .level-leaderboard-table th:nth-child(5),
  .level-leaderboard-table td:nth-child(5) {
    display: none;
  }
}

/* Common Level Content Info Section */
#level-info {
  width: 100%;
  max-width: 800px;
  background: white;
  margin: 20px auto 40px auto;
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  box-sizing: border-box;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: #333;
  line-height: 1.6;
}

/* Header Styles */
/* .header h1 rule removed to revert "Play Online" color */

#level-info h1 {
  text-align: center;
  font-size: 24px;
  color: #1e293b; /* Reverted to original dark blue-gray */
  margin-bottom: 20px;
}

#level-info p {
  margin-bottom: 15px;
  font-size: 16px;
  color: #475569;
}

#level-info .final-link {
  font-weight: bold;
  text-align: center;
  margin-top: 25px;
}

#level-info .final-link a {
  color: #2563eb;
  text-decoration: none;
}

#level-info .final-link a:hover {
  text-decoration: underline;
}

@media (max-width: 600px) {
  #level-info {
    padding: 20px;
    margin: 20px 10px;
    width: auto;
  }

  #level-info h1 {
    font-size: 20px;
  }

  #level-info p {
    font-size: 15px;
  }
}

.linkclr {
  color: #2563eb;
  text-decoration: none;
  font-weight: bold;
}

.linkclr:hover {
  text-decoration: underline;
}

/* Player Name Modal (Global) */
.name-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.name-box {
  background: #fff;
  padding: 20px;
  border-radius: 8px;
  width: 280px;
  text-align: center;
}

.name-box h3 {
  margin-top: 0;
}

.name-box input {
  width: 90%;
  padding: 8px;
  margin: 10px 0;
  font-size: 16px;
  box-sizing: border-box;
}

.name-box button {
  padding: 8px 14px;
  background: rgb(59, 130, 246);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
}

/* SHARE FEATURE STYLES */
.share-btn {
  width: 100%;
  padding: 10px;
  font-size: 16px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  color: white;
  transition: background 0.2s;
}
.share-btn:hover {
  background: #1e40af !important;
}

/* Hidden Score Card for Screenshot Generation (1200x630 OG Standard) */
.share-card {
  width: 1200px;
  height: 630px;
  background: white;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  border: 20px solid #2563eb;
  box-sizing: border-box;
}

.sc-header {
  font-size: 80px;
  font-weight: 800;
  color: #2563eb;
  z-index: 10;
  margin-bottom: 20px;
  text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.1);
}

.sc-content {
  z-index: 10;
  background: rgba(255, 255, 255, 0.9);
  padding: 40px 80px;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

.sc-level {
  font-size: 40px;
  color: #64748b;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.sc-time {
  font-size: 120px;
  font-weight: 900;
  color: #ef4444; /* Red for emphasis */
  line-height: 1;
  margin: 10px 0;
}

.sc-rank {
  font-size: 50px;
  font-weight: 700;
  color: #16a34a; /* Green for success */
}

.sc-footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  background: #2563eb;
  color: white;
  font-size: 30px;
  padding: 15px 0;
  z-index: 10;
}

/* Footer Navigation Links */
.footer-nav {
  background-color: #f8f8f8;
  border-top: 1px solid #e5e5e5;
  padding: 30px 20px;
  margin-top: 60px;
  text-align: center;
  width: 100%;
  box-sizing: border-box;
}

.footer-nav .links {
  display: flex;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 15px;
}

.footer-nav a {
  color: #555;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}

.footer-nav a:hover {
  color: #ef4444; /* Waldo Red */
  text-decoration: underline;
}

.footer-copyright {
  color: black;
  font-size: 12px;
  margin-top: 10px;
}
