/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #060B18;
  --bg-light: #0D1B30;
  --text: #EDF2F7;
  --gold: #C8960C;
  --gold-bright: #FFD700;
  --gold-light: #FFE066;
  --gold-dark: #8B6914;
  --gold-glow: rgba(255, 215, 0, 0.25);
  --grid-line: rgba(100, 170, 230, 0.3);
  --cell-bg: #0D1B30;
  --cell-challenge: #162A4A;
  --blue-glow: rgba(60, 140, 220, 0.4);
}

body {
  font-family: 'Outfit', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 30% 20%, rgba(20, 60, 120, 0.25) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(10, 40, 100, 0.2) 0%, transparent 50%);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow: hidden;
}

#app {
  width: 100%;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* === Logo === */
header { text-align: center; }

.logo {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 32px 14px;
}

/* L-shaped gold corner brackets */
.logo-corner {
  position: absolute;
  width: 24px;
  height: 24px;
}
.logo-corner::before,
.logo-corner::after {
  content: "";
  position: absolute;
  background: linear-gradient(180deg, var(--gold-light), var(--gold), var(--gold-dark));
}

.logo-tl { top: 0; left: 0; }
.logo-tl::before { top: 0; left: 0; width: 24px; height: 3px; }
.logo-tl::after  { top: 0; left: 0; width: 3px; height: 24px; }

.logo-tr { top: 0; right: 0; }
.logo-tr::before { top: 0; right: 0; width: 24px; height: 3px; }
.logo-tr::after  { top: 0; right: 0; width: 3px; height: 24px; }

.logo-bl { bottom: 0; left: 0; }
.logo-bl::before { bottom: 0; left: 0; width: 24px; height: 3px; }
.logo-bl::after  { bottom: 0; left: 0; width: 3px; height: 24px; }

.logo-br { bottom: 0; right: 0; }
.logo-br::before { bottom: 0; right: 0; width: 24px; height: 3px; }
.logo-br::after  { bottom: 0; right: 0; width: 3px; height: 24px; }

h1 {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 3.6rem;
  font-weight: 400; /* Bebas Neue only has 400 */
  letter-spacing: 12px;
  line-height: 1;
  background: linear-gradient(
    180deg,
    var(--gold-light) 0%,
    var(--gold) 35%,
    var(--gold-bright) 50%,
    var(--gold-dark) 80%,
    var(--gold) 100%
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 2px 10px rgba(255, 215, 0, 0.3));
}

.logo-subtitle {
  font-family: 'Outfit', sans-serif;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 4px;
  color: var(--gold);
  margin-top: 4px;
  opacity: 0.85;
}

/* === Grid === */
#grid-container {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0;
  width: 100%;
  background: var(--bg);
  border: 2px solid var(--grid-line);
}

.cell {
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: default;
  position: relative;
  overflow: hidden;
  padding: 2px 4px;
  border: 1px solid var(--grid-line);
  background: var(--cell-bg);
  transition: transform 0.2s, box-shadow 0.2s, background 0.3s;
}

.cell-label {
  font-family: 'Outfit', sans-serif;
  font-size: clamp(0.5rem, 1.4vw, 0.8rem);
  font-weight: 700;
  word-break: break-word;
  line-height: 1.15;
  opacity: 0;
  color: var(--text);
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
  transition: opacity 0.3s;
  pointer-events: none;
}

/* Only challengeable cells show labels */
.cell.challengeable .cell-label { opacity: 1; }

/* Owned cells: no label */
.cell.owned .cell-label { opacity: 0; }

/* === Player-owned cells === */
.cell.owned {
  background: linear-gradient(135deg, #C8960C, #A07008);
  border-color: var(--gold);
}

/* Merge borders between adjacent owned cells */
.cell.owned.merge-top    { border-top-color: transparent; }
.cell.owned.merge-bottom { border-bottom-color: transparent; }
.cell.owned.merge-left   { border-left-color: transparent; }
.cell.owned.merge-right  { border-right-color: transparent; }

/* Bright edge glow on territory boundary */
.cell.owned.edge-top    { border-top: 2px solid var(--gold-bright); }
.cell.owned.edge-bottom { border-bottom: 2px solid var(--gold-bright); }
.cell.owned.edge-left   { border-left: 2px solid var(--gold-bright); }
.cell.owned.edge-right  { border-right: 2px solid var(--gold-bright); }

/* === Challengeable cells === */
.cell.challengeable {
  cursor: pointer;
  background: var(--cell-challenge);
  border-color: rgba(100, 170, 230, 0.5);
  animation: pulse 2s ease-in-out infinite;
}
.cell.challengeable:hover {
  transform: scale(1.08);
  box-shadow: 0 0 20px var(--blue-glow);
  z-index: 2;
  background: #1C3660;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 transparent; }
  50% { box-shadow: inset 0 0 12px var(--blue-glow); }
}

/* Non-interactive cells */
.cell.inactive { opacity: 0.35; }

/* === Score Bar === */
#score-bar {
  width: 100%;
  text-align: center;
}
#score-text {
  font-family: 'Outfit', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  display: block;
  color: rgba(237, 242, 247, 0.6);
  letter-spacing: 1px;
}
#progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
}
#progress-fill {
  height: 100%;
  width: 2.78%;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* === Overlays === */
.hidden { display: none !important; }

#duel-overlay, #win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 20, 0.88);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

#duel-modal, #win-modal {
  background: linear-gradient(170deg, #0F1F3A 0%, #0A1628 100%);
  border-radius: 16px;
  padding: 32px 28px;
  width: 100%;
  max-width: 480px;
  text-align: center;
  position: relative;
  border: 1px solid rgba(100, 170, 230, 0.15);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 30px rgba(60, 140, 220, 0.08);
}

/* === Confirm Screen === */
#confirm-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.6rem;
  letter-spacing: 3px;
  margin-bottom: 12px;
}
#confirm-category {
  font-family: 'Outfit', sans-serif;
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 24px;
  padding: 10px 20px;
  border-radius: 10px;
  display: inline-block;
  background: var(--cell-challenge);
  border: 2px solid rgba(100, 170, 230, 0.4);
  letter-spacing: 0.5px;
}
.confirm-buttons { display: flex; gap: 12px; justify-content: center; }

/* === Buttons === */
.btn {
  font-family: 'Outfit', sans-serif;
  padding: 14px 36px;
  border: none;
  border-radius: 12px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  letter-spacing: 0.5px;
}
.btn:hover { transform: scale(1.04); }
.btn:active { transform: scale(0.97); }

.btn-go {
  background: linear-gradient(135deg, var(--gold-bright), var(--gold), var(--gold-dark));
  color: #0A0E1A;
  box-shadow: 0 4px 16px var(--gold-glow);
}
.btn-cancel {
  background: rgba(255,255,255,0.07);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
}

/* === Question Screen === */
#question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  font-size: 0.8rem;
  font-weight: 600;
  color: rgba(237, 242, 247, 0.6);
}
#question-category-badge {
  font-family: 'Outfit', sans-serif;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--cell-challenge);
  border: 1px solid rgba(100, 170, 230, 0.3);
  color: var(--text);
}

#timer-bar {
  width: 100%;
  height: 5px;
  background: rgba(255,255,255,0.08);
  border-radius: 3px;
  margin-bottom: 24px;
  overflow: hidden;
}
#timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  border-radius: 3px;
  transition: width 0.1s linear;
}
#timer-fill.urgent { background: #E53E3E; }

#question-text {
  font-family: 'Outfit', sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 24px;
  line-height: 1.4;
}

#options-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-btn {
  width: 100%;
  padding: 15px 20px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-family: 'Outfit', sans-serif;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.option-btn:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.25);
  transform: scale(1.02);
}
.option-btn:active { transform: scale(0.98); }

.option-btn.correct {
  background: rgba(72, 187, 120, 0.25);
  border-color: #48BB78;
  animation: flash-correct 0.5s;
}
.option-btn.wrong {
  background: rgba(245, 101, 101, 0.25);
  border-color: #F56565;
  animation: flash-wrong 0.5s;
}
.option-btn.disabled {
  pointer-events: none;
  opacity: 0.5;
}

@keyframes flash-correct {
  0%, 100% { background: rgba(72,187,120,0.25); }
  50% { background: rgba(72,187,120,0.5); }
}
@keyframes flash-wrong {
  0%, 100% { background: rgba(245,101,101,0.25); }
  50% { background: rgba(245,101,101,0.5); }
}

/* === Result Screen === */
#result-icon { font-size: 3.5rem; margin-bottom: 12px; }
#result-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2rem;
  letter-spacing: 3px;
  margin-bottom: 6px;
}
#result-text {
  font-family: 'Outfit', sans-serif;
  font-size: 0.95rem;
  opacity: 0.65;
  margin-bottom: 28px;
}

/* === Win Screen === */
#win-modal { overflow: hidden; }
.win-title {
  font-family: 'Bebas Neue', sans-serif !important;
  font-size: 3.6rem !important;
  letter-spacing: 10px !important;
  background: linear-gradient(
    180deg,
    var(--gold-light) 0%,
    var(--gold) 35%,
    var(--gold-bright) 50%,
    var(--gold-dark) 80%,
    var(--gold) 100%
  ) !important;
  -webkit-background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  background-clip: text !important;
  filter: drop-shadow(0 2px 16px rgba(255, 215, 0, 0.4));
  margin-bottom: 8px;
}
#win-modal p {
  font-family: 'Outfit', sans-serif;
  font-size: 1.1rem;
  margin-bottom: 28px;
  opacity: 0.7;
}

/* === Confetti === */
#confetti-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  top: -10px;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(600px) rotate(720deg); opacity: 0; }
}

/* === Cell conquest animation === */
.cell.conquering {
  animation: conquer 0.6s ease-out;
}
@keyframes conquer {
  0% { transform: scale(1); }
  40% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* === Responsive === */
@media (max-width: 480px) {
  #app { gap: 12px; }
  h1 { font-size: 2.6rem; letter-spacing: 8px; }
  .logo { padding: 14px 24px 10px; }
  .logo-corner { width: 18px; height: 18px; }
  .logo-subtitle { font-size: 0.5rem; letter-spacing: 3px; }
  .cell-label { font-size: 0.45rem; }
  #question-text { font-size: 1.15rem; }
  .option-btn { font-size: 0.95rem; padding: 13px 16px; }
  #duel-modal { padding: 24px 18px; }
  #confirm-title { font-size: 1.3rem; }
  #confirm-category { font-size: 1.1rem; }
}

@media (min-width: 700px) {
  h1 { font-size: 4.2rem; letter-spacing: 14px; }
  .logo { padding: 22px 40px 16px; }
  .logo-corner { width: 30px; height: 30px; }
  .logo-subtitle { font-size: 0.75rem; letter-spacing: 5px; }
  .cell-label { font-size: 0.85rem; }
}
