/* Popups theme (space/glass) — now styles ALL popups */
:root {
  --popup-bg-1: rgba(14, 18, 42, 0.92);
  --popup-bg-2: rgba(29, 12, 48, 0.88);
  --popup-border: rgba(120, 180, 255, 0.45);
  --text-primary: #e9f1ff;
  --text-muted: #cbd4ff;
  --accent: #78b8ff;
  --success: #72ffd6;
  --danger: #ff6b6b;
}

/* This container sits inside the scaled .game-root and holds our popups */
#popup-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* Allow clicks to pass through to the canvas */
  z-index: 1000;
}

/*
  Make popups inside the container clickable again.
  Change position to 'absolute' to position them relative to the container.
*/
#popup-container > * {
  pointer-events: all;
  position: absolute !important;
}

/* Base style for ALL alert popups */
.alert-popup {
  display: none; /* <-- FIX: Hide popups by default */
  font-family: "Play", system-ui, -apple-system, "Segoe UI", Roboto, Arial,
    sans-serif;

  position: absolute;
  top: 53%;
  left: 50%;
  transform: translate(-50%, -50%);

  /* Responsive width; content decides height */
  width: clamp(360px, 44vw, 560px);
  max-width: 92vw;
  height: auto;
  overflow: visible;

  color: var(--text-primary);
  background: linear-gradient(135deg, var(--popup-bg-1), var(--popup-bg-2))
      padding-box,
    linear-gradient(
        120deg,
        rgba(110, 200, 255, 0.35),
        rgba(179, 136, 255, 0.35),
        rgba(255, 77, 109, 0.35)
      )
      border-box;
  border: 1px solid transparent;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.06), 0 0 25px rgba(120, 180, 255, 0.25);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: clamp(16px, 3vw, 28px);
  text-align: center;
  z-index: 1002;
}

.alert-popup h1,
.alert-popup h2 {
  margin: 0 0 12px;
  letter-spacing: 0.6px;
  font-weight: 700;
  font-size: clamp(24px, 3.8vw, 36px);
  color: #eaf2ff;
  text-shadow: 0 0 10px rgba(128, 180, 255, 0.45);
}

/* Shared button style for all popups */
.alert-popup button {
  font-family: "Play", system-ui, -apple-system, "Segoe UI", Roboto, Arial,
    sans-serif;
  color: var(--text-primary);
  background: linear-gradient(180deg, #28315f, #1f2550);
  border: 1px solid var(--popup-border);
  border-radius: 14px;
  padding: 12px 20px;
  margin: 10px 8px 0;
  min-width: min(280px, 80%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    0 12px 26px rgba(0, 0, 0, 0.35), 0 0 18px rgba(120, 180, 255, 0.3);
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
  cursor: pointer;
}
.alert-popup button:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, #32407e, #262e67);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 14px 28px rgba(0, 0, 0, 0.42), 0 0 22px rgba(120, 180, 255, 0.36);
}
.alert-popup button:active {
  transform: translateY(0);
}

/* Small muted paragraphs inside popups */
.alert-popup p {
  color: var(--text-muted);
  font-size: clamp(14px, 2vw, 18px);
  line-height: 1.45;
}

/* --- Welcome & How-To-Play Specifics --- */

/* How To Play is wider by design */
#howToPlayPopup {
  width: 680px;
}

#howToPlayPopup p {
  text-align: left;
  padding: 0 0 0 55px;
}

/* Subtitle in Welcome popup */
#welcomePopup .inner {
  color: #c8d2ff;
  margin-bottom: 14px;
}

/* JLPT buttons row */
#jlptSelect .jlpt-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 8px 0 6px;
}

/* JLPT buttons */
#jlptSelect .jlpt-btn {
  font-family: "Play", system-ui, -apple-system, "Segoe UI", Roboto, Arial,
    sans-serif;
  color: #e9f1ff;
  background: linear-gradient(180deg, #242c55, #1a1f3f);
  border: 1px solid rgba(120, 180, 255, 0.4);
  border-radius: 12px;
  padding: 10px 16px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05),
    0 8px 18px rgba(0, 0, 0, 0.35), 0 0 12px rgba(108, 168, 255, 0.25);
  transition: transform 0.12s ease, box-shadow 0.2s ease;
  cursor: pointer;
  /* FIX: Override generic button styles to set a specific width */
  width: 125px;
  min-width: 125px;
}

/* This rule is no longer needed */
/*
#jlptSelect #btnJLPTN5,
#jlptSelect #btnJLPTN4 {
  width: 119px;
}
*/

#jlptSelect .jlpt-btn:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, #2e376b, #202758);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 10px 22px rgba(0, 0, 0, 0.4), 0 0 16px rgba(108, 168, 255, 0.35);
}
#jlptSelect .jlpt-btn:active {
  transform: translateY(0);
}
#jlptSelect .jlpt-btn.selected {
  background: #a04343;
  /*border-color: #66bb6a;*/
  box-shadow: 0 0 0 3px #6d45454d inset;
}
#jlptSelect .jlpt-btn:disabled {
  background: linear-gradient(180deg, #1a1f3f, #14173a);
  border-color: rgba(120, 180, 255, 0.25);
  color: #9aa7c7;
  box-shadow: none;
  cursor: not-allowed;
  opacity: 0.6;
}

/* Error text */
#jlptError {
  color: var(--danger);
  font-weight: 700;
  margin: 13px;
  text-shadow: 0 0 10px rgba(255, 84, 84, 0.35);
}

/* Settings Toggles */
#welcomePopup .settings-row {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
#welcomePopup .settings-label {
  color: var(--text-primary);
  font-weight: 700;
}
/* iOS-style switch */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}
.switch input {
  display: none;
}
.switch .slider {
  position: absolute;
  cursor: pointer;
  top: 3px;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #3b426e;
  transition: 0.2s;
  border-radius: 28px;
  width: 45px;
  height: 21px;
}
.switch .slider:before {
  position: absolute;
  content: "";
  height: 15px;
  width: 15px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
}
.switch input:checked + .slider {
  background-color: #a04343;
}
.switch input:checked + .slider:before {
  transform: translateX(22px);
}

/* --- Question Popup --- */

/* Question popup (#popup) — themed and centered */
#popup {
  display: none; /* shown via JS */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

  width: clamp(360px, 42vw, 500px);
  max-width: 92vw;
  height: auto;

  color: var(--text-primary);
  background: linear-gradient(135deg, var(--popup-bg-1), var(--popup-bg-2))
      padding-box,
    linear-gradient(
        120deg,
        rgba(110, 200, 255, 0.35),
        rgba(179, 136, 255, 0.35),
        rgba(255, 77, 109, 0.35)
      )
      border-box;
  border: 1px solid transparent;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.06), 0 0 25px rgba(120, 180, 255, 0.25);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: clamp(16px, 3vw, 28px);
  text-align: center;
  z-index: 1003;
}
#popup h2 {
  margin: 0 0 12px;
  font-weight: 800;
  font-size: clamp(28px, 4vw, 42px);
  color: #eaf2ff;
}

/* Options in question popup (match button style) */
#popup .option {
  font-family: "Play", system-ui, -apple-system, "Segoe UI", Roboto, Arial,
    sans-serif;
  color: var(--text-primary);
  background: linear-gradient(180deg, #28315f, #1f2550);
  border: 1px solid var(--popup-border);
  border-radius: 14px;
  padding: 12px 20px;
  margin: 10px 8px 0;
  min-width: min(280px, 80%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    0 12px 26px rgba(0, 0, 0, 0.35), 0 0 18px rgba(120, 180, 255, 0.3);
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
  cursor: pointer;
}
#popup .option:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, #32407e, #262e67);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 14px 28px rgba(0, 0, 0, 0.42), 0 0 22px rgba(120, 180, 255, 0.36);
}

#popup #hiragana,
#popup #meaning {
  position: relative;
  min-height: 22px;
  color: var(--text-muted);
  margin-top: 60px;
  font-weight: 600;
}
#popup .reveal-blocker {
  position: absolute;
  inset: 0;
  background: rgb(26 32 64);
  border: 1px dashed rgba(120, 180, 255, 0.6);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 13px; /* Increased font size */
  text-shadow: 0 0 8px rgba(120, 180, 255, 0.3);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease;
  width: 50%;
  margin: 0 auto;
  padding: 15px 0px;
}
#popup .reveal-blocker:hover {
  background: rgba(36, 44, 88, 1);
  border-color: rgba(179, 136, 255, 1);
}

/* Game Over and Victory Popups */
#gameOverPopup,
#victoryPopup {
  text-align: center;
}

/* Game Over popup title */
#gameOverPopup h2 {
  color: var(--danger);
  text-shadow: 0 0 12px rgba(255, 84, 84, 0.45);
  font-weight: 900;
  font-size: clamp(30px, 5vw, 48px);
}

#victoryPopup h2 {
  font-size: 29px;
  color: #4caf50;
  margin-bottom: 10px;
}

#victoryPopup p {
  font-size: 30px;
  margin-bottom: 20px;
}

#gameOverPopup button,
#victoryPopup button {
  min-width: 150px;
}

/* Victory popup accents */
#victoryPopup h2,
#victoryPopup #victoryMessage {
  color: var(--success) !important;
  text-shadow: 0 0 12px rgba(114, 255, 214, 0.45);
  font-weight: 800;
}
#victoryPopup #victoryTime {
  color: var(--text-primary);
  font-weight: 700;
}

/* Incorrect Answer popup accents */
#incorrectAnswerPopup h2 {
  color: var(--danger);
  text-shadow: 0 0 12px rgba(255, 84, 84, 0.45);
  font-weight: 800;
}
#incorrectStatusText {
  color: var(--danger) !important;
  text-shadow: 0 0 10px rgba(255, 84, 84, 0.35);
  font-weight: 800;
}

/* “Hit by red ship” message may share incorrect popup styles; buttons covered by base rule */

/* Ensure all themed popups render above canvas */
#popup,
#victoryPopup,
#gameOverPopup,
#incorrectAnswerPopup {
  z-index: 1003;
}

/* Cool themed radios (match popup look, but keep native layout) */
#jlptSelect .pretty-radio {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--popup-border);
  background: linear-gradient(180deg, #28315f, #1f2550);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    0 0 10px rgba(120, 180, 255, 0.15);
  vertical-align: -2px;
  margin-right: 8px;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.2s ease, border-color 0.2s ease,
    background 0.2s ease;
}

#jlptSelect .pretty-radio:hover {
  transform: scale(1.06);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 0 14px rgba(120, 180, 255, 0.28);
}

#jlptSelect .pretty-radio:checked {
  border-color: var(--accent);
  background: radial-gradient(
      circle at 50% 50%,
      var(--accent) 0 50%,
      transparent 51%
    ),
    linear-gradient(180deg, #28315f, #1f2550);
  box-shadow: 0 0 12px rgba(120, 180, 255, 0.35),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

#jlptSelect .pretty-radio:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
#jlptSelect .pretty-radio:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  filter: grayscale(60%);
}

/* Slightly stronger label color for readability (keeps your inline layout) */
#jlptSelect #jlptCategoryGroup label {
  color: var(--text-primary) !important;
  font-weight: 700;
  cursor: pointer;
}
#jlptSelect #jlptCategoryGroup label.disabled {
  color: var(--text-muted) !important;
  cursor: not-allowed;
  opacity: 0.6;
}
/* License badge pill under Welcome controls */
.license-badge {
  display: inline-block;
  margin-top: 26px; /* push it further down */
  padding: 12px 18px;
  color: var(--text-primary);
  border: 2px solid #ffffff; /* white border */
  border-radius: 6px; /* squared corners (no pill) */
  background: rgba(14, 18, 42, 0.75);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35), 0 0 18px rgba(120, 180, 255, 0.25),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  font-weight: 700;
  font-size: 10px;
}
