/* 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;
  }
}

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

/* 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;
}

#level-complete button {
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  font-size: 16px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  background: #16a34a;
  color: white;
}

/* Status Bar & Icons (Desktop Default) */
#status-bar {
  margin-top: 10px;
  display: flex;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 10px;
  background: transparent; /* Removed #f8fafc */
  border-bottom: 0; /* Also removed border to look cleaner if no bg */
}

.char-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  position: relative;
}

.char-status img {
  width: 50px;
  height: 50px;
  object-fit: contain;
  border-radius: 8px;
  border: 2px solid transparent;
  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;
  min-height: 1.2em; /* 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;
}

/* 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 0;
  padding: 10px;
  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: contain;
}

/* 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;
    backdrop-filter: none;
    border-radius: 0;
    padding: 5px 0; /* Slight padding for breathing room */
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 10px;
    z-index: 1000;
    margin-top: 10px; /* Reduced margin since it's sticky */
    box-shadow: none;

    /* 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;
  }

  /* 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;
}
