:root {
  --sw-yellow:    #FFE81F;             /* the iconic Star Wars logo yellow */
  --sw-yellow-soft: rgba(255, 232, 31, 0.55);
  --sw-yellow-dim: rgba(255, 232, 31, 0.18);
  --jedi:         #58c4ff;              /* lightsaber blue */
  --sith:         #ff4040;              /* lightsaber red */
  --rebellion:    #ff8c00;              /* X-wing orange */
  --empire:       #5fff5f;              /* Imperial green */
  --space:        #07090e;
  --ink:          #e8eaed;
  --shadow:       rgba(0, 0, 0, 0.7);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: #000;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Background image (per location) ------------------------------- */
.bg {
  position: fixed; inset: 0;
  z-index: 0;
  background-color: #000;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-image: radial-gradient(ellipse at center, #0a1428 0%, #000 80%);
  transition: background-image 600ms ease;
}
.bg-overlay {
  position: fixed; inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.35) 35%, rgba(0,0,0,0.75) 100%),
    radial-gradient(ellipse at center, rgba(0,0,0,0.05) 0%, rgba(0,0,0,0.55) 100%);
}

/* Starfield (subtle, layered shadows on a tiny element) --------- */
.starfield {
  position: fixed; inset: 0;
  z-index: 1;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 20% 30%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 80% 12%, #ffffff99 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 65% 80%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 40% 60%, #cdd9ff 50%, transparent 51%),
    radial-gradient(1px 1px at 90% 70%, #ffffff80 50%, transparent 51%),
    radial-gradient(1px 1px at 12% 88%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 32% 18%, #b8d2ff 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 55% 50%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 70% 35%, #ffffff70 50%, transparent 51%),
    radial-gradient(1px 1px at 5% 50%, #fff 50%, transparent 51%);
  background-size: 100% 100%;
  opacity: 0.8;
  mix-blend-mode: screen;
}

#app {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: auto;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  padding-left: max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
  -webkit-tap-highlight-color: transparent;
}

.screen {
  display: none;
  max-width: 1100px;
  margin: 0 auto;
  animation: fade 240ms ease;
}
.screen.active { display: block; }

@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.title {
  font-size: 56px;
  text-align: center;
  margin: 24px 0 4px;
  color: var(--sw-yellow);
  letter-spacing: 4px;
  text-transform: uppercase;
  font-weight: 900;
  font-family: "Helvetica Neue", "Arial Black", sans-serif;
  text-shadow:
    0 0 20px rgba(255, 232, 31, 0.45),
    0 4px 24px rgba(0, 0, 0, 0.95);
}
.subtitle {
  text-align: center;
  margin: 0 0 28px;
  color: #c8d2e0;
  font-style: italic;
  letter-spacing: 0.5px;
}

.card {
  background: rgba(7, 9, 14, 0.85);
  border: 1px solid var(--sw-yellow-soft);
  border-radius: 10px;
  padding: 28px;
  box-shadow: 0 18px 40px var(--shadow), 0 0 24px rgba(255, 232, 31, 0.06) inset;
  backdrop-filter: blur(2px);
}
.card.center { text-align: center; }

.label {
  display: block;
  margin: 14px 0 6px;
  font-size: 12px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--sw-yellow);
  font-weight: bold;
}
.input {
  width: 100%;
  padding: 12px 14px;
  font-size: 18px;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border: 1px solid var(--sw-yellow-soft);
  border-radius: 6px;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.input:focus { border-color: var(--sw-yellow); box-shadow: 0 0 0 3px rgba(255, 232, 31, 0.15); }

/* Faction selector --------------------------------------------- */
.faction-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}
.faction-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 8px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(255, 232, 31, 0.35);
  color: var(--ink);
  border-radius: 8px;
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}
.faction-btn:hover { transform: translateY(-2px); border-color: var(--sw-yellow); }
.faction-btn.selected {
  border-color: var(--sw-yellow);
  background: rgba(255, 232, 31, 0.10);
  box-shadow: 0 0 0 3px rgba(255, 232, 31, 0.2) inset, 0 0 16px rgba(255, 232, 31, 0.25);
}
.faction-crest {
  font-size: 38px;
  line-height: 1;
  display: inline-flex;
  width: 66px; height: 66px;
  align-items: center; justify-content: center;
  border-radius: 50%;
  border: 2px solid currentColor;
  background: rgba(0, 0, 0, 0.6);
}
.faction-crest.jedi      { color: var(--jedi);      box-shadow: 0 0 16px rgba(88, 196, 255, 0.55); }
.faction-crest.sith      { color: var(--sith);      box-shadow: 0 0 16px rgba(255, 64, 64, 0.55); }
.faction-crest.rebellion { color: var(--rebellion); box-shadow: 0 0 16px rgba(255, 140, 0, 0.55); }
.faction-crest.empire    { color: var(--empire);    box-shadow: 0 0 16px rgba(95, 255, 95, 0.55); }
.faction-name { font-weight: bold; letter-spacing: 1px; text-transform: uppercase; font-size: 13px; }

.actions {
  margin-top: 20px;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.actions.center { justify-content: center; }

button.primary, button.ghost {
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  font-weight: bold;
  padding: 12px 22px;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 100ms ease, background 120ms ease, box-shadow 120ms ease;
}
button.primary {
  background: var(--sw-yellow);
  color: #000;
  border: 1px solid var(--sw-yellow);
  box-shadow: 0 0 12px rgba(255, 232, 31, 0.35);
}
button.primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 0 18px rgba(255, 232, 31, 0.55);
}
button.primary:disabled {
  opacity: 0.4; cursor: not-allowed;
  background: #333;
  border-color: #444;
  color: #888;
  box-shadow: none;
}
button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--sw-yellow-soft);
}
button.ghost:hover { background: rgba(255, 232, 31, 0.10); border-color: var(--sw-yellow); }

button.hint-btn {
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0.8px;
  padding: 10px 18px;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 100ms ease, background 120ms ease;
  background: rgba(88, 196, 255, 0.12);
  color: var(--ink);
  border: 1px dashed rgba(88, 196, 255, 0.6);
}
button.hint-btn:hover:not(:disabled) { background: rgba(88, 196, 255, 0.22); }
button.hint-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* HUD ---------------------------------------------------------- */
.hud {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: center;
  background: rgba(0, 0, 0, 0.78);
  border: 1px solid var(--sw-yellow-dim);
  border-radius: 8px;
  padding: 10px 16px;
  margin-bottom: 18px;
  font-size: 14px;
  gap: 12px;
}
.hud-center { text-align: center; }
.hud-right  { text-align: right; }
.hud-name    { font-weight: bold; color: var(--sw-yellow); letter-spacing: 1px; text-transform: uppercase; font-size: 13px; }
.hud-faction { margin-left: 8px; opacity: 0.85; font-style: italic; }
.hud-location { font-weight: bold; color: var(--sw-yellow); display: block; letter-spacing: 0.6px; }
.hud-progress { font-size: 11px; opacity: 0.85; letter-spacing: 0.5px; }
.hud-lives  { color: #ff7a7a; margin-right: 12px; }
.hud-score  { color: var(--sw-yellow); font-weight: bold; }

/* Stage --------------------------------------------------------- */
.stage {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
  align-items: start;
}
.yoda {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  position: sticky; top: 0;
}
.yoda img {
  width: 220px;
  height: 280px;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid var(--sw-yellow-soft);
  box-shadow: 0 8px 28px var(--shadow), 0 0 20px rgba(95, 255, 95, 0.18);
  background: #0d1119;
}
.yoda-name {
  font-size: 12px;
  color: var(--sw-yellow);
  letter-spacing: 1.4px;
  text-transform: uppercase;
}

.dialogue {
  background: rgba(7, 9, 14, 0.86);
  border: 1px solid var(--sw-yellow-soft);
  border-radius: 10px;
  padding: 22px;
  min-height: 360px;
  position: relative;
}
.preamble {
  font-style: italic;
  color: var(--sw-yellow);
  margin-bottom: 12px;
  font-size: 15px;
  opacity: 0.85;
}
.question-label {
  display: inline-block;
  margin-bottom: 8px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: #000;
  background: var(--sw-yellow);
  border-radius: 3px;
}
.question-text {
  font-size: 22px;
  color: var(--ink);
  margin-bottom: 18px;
  line-height: 1.4;
  font-weight: 500;
}
.answer-context {
  display: none;
  margin-top: 12px;
  padding: 12px 14px;
  background: rgba(108, 220, 122, 0.10);
  border-left: 3px solid #6cdc7a;
  border-radius: 4px;
  font-size: 16px;
  line-height: 1.5;
  color: #d8f5dc;
}
.answer-context.shown { display: block; }
.answer-context .ctx-label {
  display: block;
  font-size: 10px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: #6cdc7a;
  margin-bottom: 4px;
  font-weight: bold;
}
.hint-line {
  background: rgba(88, 196, 255, 0.10);
  border-left: 3px solid var(--jedi);
  padding: 8px 12px;
  margin-bottom: 14px;
  font-style: italic;
  color: #cce5ff;
  display: none;
}
.hint-line.shown { display: block; }

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.choice {
  text-align: left;
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--ink);
  border: 1px solid var(--sw-yellow-dim);
  border-radius: 6px;
  font-family: inherit;
  font-size: 16px;
  cursor: pointer;
  transition: background 120ms ease, transform 80ms ease, border-color 120ms ease;
}
.choice:hover:not(:disabled) {
  background: rgba(255, 232, 31, 0.12);
  border-color: var(--sw-yellow-soft);
}
.choice:disabled { cursor: default; opacity: 0.85; }
.choice .letter {
  display: inline-block;
  width: 24px; height: 24px;
  text-align: center;
  line-height: 24px;
  background: var(--sw-yellow);
  color: #000;
  border-radius: 50%;
  margin-right: 10px;
  font-weight: bold;
  font-size: 13px;
}
.choice.correct {
  background: rgba(60, 180, 70, 0.45);
  border-color: #6cdc7a;
}
.choice.incorrect {
  background: rgba(180, 40, 40, 0.5);
  border-color: #ff6b6b;
}

.reaction {
  margin-top: 8px;
  padding: 12px 14px;
  border-radius: 6px;
  font-size: 17px;
  display: none;
}
.reaction.shown { display: block; }
.reaction.correct {
  background: rgba(60, 180, 70, 0.20);
  border-left: 3px solid #6cdc7a;
}
.reaction.incorrect {
  background: rgba(180, 40, 40, 0.20);
  border-left: 3px solid #ff6b6b;
}

.dialogue-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 14px;
  gap: 10px;
}

.hidden { display: none !important; }

/* Transition / End screens ------------------------------------- */
#screen-transition .card,
#screen-end .card {
  margin-top: 80px;
}
.transition-meta {
  margin: 14px 0;
  color: var(--sw-yellow-soft);
  font-style: italic;
  letter-spacing: 0.4px;
}
.end-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 18px 0;
}
.end-stats > div {
  background: rgba(255, 232, 31, 0.06);
  border: 1px solid var(--sw-yellow-dim);
  border-radius: 6px;
  padding: 14px 8px;
}
.stat-label {
  display: block;
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--sw-yellow-soft);
  margin-bottom: 4px;
}
.stat-value {
  display: block;
  font-size: 26px;
  color: var(--sw-yellow);
  font-weight: bold;
  letter-spacing: 1px;
}

/* Leaderboard -------------------------------------------------- */
.lb-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}
.lb-table th, .lb-table td {
  padding: 10px 8px;
  border-bottom: 1px solid rgba(255, 232, 31, 0.18);
  text-align: left;
}
.lb-table th {
  font-size: 12px;
  letter-spacing: 1.2px;
  color: var(--sw-yellow);
  text-transform: uppercase;
}
.lb-table tr:hover td { background: rgba(255, 232, 31, 0.05); }
.lb-faction-Jedi      { color: var(--jedi); }
.lb-faction-Sith      { color: var(--sith); }
.lb-faction-Rebellion { color: var(--rebellion); }
.lb-faction-Empire    { color: var(--empire); }

/* Level reward -------------------------------------------------- */
.transition-reward {
  margin: 20px 0 8px;
  padding: 18px 20px;
  background: rgba(255, 232, 31, 0.07);
  border: 1px solid var(--sw-yellow);
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 0 20px rgba(255, 232, 31, 0.12) inset;
}
.reward-header {
  font-size: 11px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--sw-yellow-soft);
  margin-bottom: 10px;
}
.reward-emoji { font-size: 52px; line-height: 1; margin-bottom: 10px; }
.reward-name  { font-size: 20px; font-weight: bold; color: var(--sw-yellow); margin-bottom: 8px; letter-spacing: 0.8px; }
.reward-desc  { font-size: 15px; color: var(--ink); opacity: 0.85; font-style: italic; line-height: 1.5; }

/* Invite button ------------------------------------------------- */
.btn-invite { width: 100%; margin-top: 4px; }
body:not(.mobile-ua) .btn-invite { display: none !important; }

/* Loader -------------------------------------------------------- */
.loader {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.78);
  z-index: 100;
  gap: 14px;
  color: var(--sw-yellow);
  font-size: 13px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.spinner {
  width: 48px; height: 48px;
  border: 4px solid rgba(255, 232, 31, 0.2);
  border-top-color: var(--sw-yellow);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Mobile-UA — phones get no Yoda sprite ------------------------ */
body.mobile-ua .yoda { display: none; }
body.mobile-ua .stage { grid-template-columns: 1fr; }

/* Mobile ------------------------------------------------------- */
@media (max-width: 760px) {
  .stage { grid-template-columns: 1fr; }
  .yoda { flex-direction: row; position: static; }
  .yoda img { width: 100px; height: 130px; }
  .choices { grid-template-columns: 1fr; }
  .faction-grid { grid-template-columns: repeat(2, 1fr); }
  .end-stats { grid-template-columns: 1fr; }
  .title { font-size: 36px; letter-spacing: 3px; }
  .hud { grid-template-columns: 1fr; text-align: center; }
  .hud-right, .hud-center { text-align: center; }
}
