:root {
  color-scheme: dark;
  --bg: #0b1020;
  --panel: rgba(255, 255, 255, 0.06);
  --panel2: rgba(255, 255, 255, 0.09);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.68);
  --border: rgba(255, 255, 255, 0.12);
  --primary: #7c5cff;
  --primary2: #4dd6ff;
  --danger: #ff4d6d;
  --good: #4dff97;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: radial-gradient(1200px 800px at 20% 10%, rgba(124, 92, 255, 0.25), transparent 60%),
    radial-gradient(900px 700px at 90% 15%, rgba(77, 214, 255, 0.18), transparent 55%),
    radial-gradient(900px 700px at 50% 100%, rgba(255, 77, 109, 0.12), transparent 55%),
    var(--bg);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
}

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 18px 36px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.95), rgba(77, 214, 255, 0.75));
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.title {
  font-weight: 800;
  font-size: 18px;
  line-height: 1.2;
}

.subtitle {
  color: var(--muted);
  font-size: 13px;
}

.main {
  display: grid;
  gap: 14px;
}

.panel {
  background: linear-gradient(180deg, var(--panel), transparent);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(10px);
}

.hidden {
  display: none !important;
}

h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.muted {
  color: var(--muted);
}

.upload {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

input[type="file"] {
  padding: 10px;
  border-radius: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  min-width: 260px;
}

.difficulty {
  padding: 9px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  font-weight: 600;
}

.btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.95), rgba(77, 214, 255, 0.6));
  border-color: rgba(255, 255, 255, 0.22);
}

.btn.danger {
  background: rgba(255, 77, 109, 0.14);
  border-color: rgba(255, 77, 109, 0.26);
}

.status {
  margin-top: 12px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.18);
  min-height: 44px;
}

.topRow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 720px) {
  .topRow {
    grid-template-columns: 1fr;
  }
}

.hpCard {
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.11);
}

.hpLabel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 8px;
}

.hpText {
  color: var(--text);
}

.hpBar {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.hpFill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  transition: width 0.25s ease;
}

.hpFill.player {
  background: linear-gradient(90deg, rgba(255, 77, 109, 0.9), rgba(255, 77, 109, 0.5));
}

.hpFill.boss {
  background: linear-gradient(90deg, rgba(77, 255, 151, 0.85), rgba(77, 255, 151, 0.45));
}

.metaRow {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.18);
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
}

.endScreen {
  margin-top: 18px;
  padding: 18px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: radial-gradient(circle at top, rgba(124, 92, 255, 0.22), rgba(0, 0, 0, 0.7));
  text-align: left;
}

.endTitle {
  font-size: 20px;
  font-weight: 900;
  margin-bottom: 6px;
}

.endSubtitle {
  margin-bottom: 10px;
}

.endStats {
  margin-bottom: 14px;
  line-height: 1.5;
}

.questionCard {
  margin-top: 12px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.prompt {
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 12px;
  line-height: 1.35;
}

.answers {
  display: grid;
  gap: 10px;
}

.option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.option:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.18);
}

.option input {
  margin-top: 2px;
}

.option.correct {
  border-color: rgba(77, 255, 151, 0.35);
  background: rgba(77, 255, 151, 0.08);
}

.option.wrong {
  border-color: rgba(255, 77, 109, 0.35);
  background: rgba(255, 77, 109, 0.08);
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
  flex-wrap: wrap;
}

.result {
  margin-top: 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.2);
  padding: 12px;
  line-height: 1.4;
}

/* ── Auth area in header ───────────────────────────────────────────── */
.authArea {
  display: flex;
  align-items: center;
  gap: 8px;
}

.authUser {
  color: var(--muted);
  font-size: 13px;
}

.authOpenBtn,
.authLogoutBtn {
  font-size: 13px;
  padding: 7px 12px;
}

/* ── Auth modal ────────────────────────────────────────────────────── */
.authOverlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.authOverlay.hidden {
  display: none !important;
}

.authModal {
  position: relative;
  background: #131726;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 20px;
  padding: 28px 24px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.authModalClose {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

.authModalClose:hover {
  color: var(--text);
}

.authTabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.authTab {
  background: none;
  border: none;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  padding: 6px 12px 10px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.authTab.active {
  color: var(--text);
  border-bottom-color: var(--primary);
}

.authForm {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.authLabel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.authInput {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease;
}

.authInput:focus {
  border-color: rgba(124, 92, 255, 0.6);
}

.authError {
  font-size: 13px;
  color: var(--danger);
  padding: 8px 10px;
  background: rgba(255, 77, 109, 0.08);
  border: 1px solid rgba(255, 77, 109, 0.22);
  border-radius: 10px;
}

.authSubmit {
  width: 100%;
  padding: 11px;
}

.authLink {
  color: var(--primary2);
  cursor: pointer;
  text-decoration: underline;
}

/* ── End screen save message ───────────────────────────────────────── */
.endSaveMsg {
  font-size: 13px;
  margin-bottom: 14px;
}

/* ── History section ───────────────────────────────────────────────── */
.historySection {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.historySectionHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.historySectionTitle {
  font-weight: 800;
  font-size: 15px;
}

.historyRefreshBtn {
  font-size: 12px;
  padding: 5px 10px;
}

.historyLoading {
  font-size: 13px;
  padding: 8px 0;
}

.historyList {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.historyRow {
  display: grid;
  grid-template-columns: 80px 1fr 60px 110px 55px 40px;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
}

@media (max-width: 600px) {
  .historyRow {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto auto;
  }
}

.historyDate {
  color: var(--muted);
  white-space: nowrap;
}

.historySource {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.historyDiff {
  font-weight: 700;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 6px;
  text-align: center;
  text-transform: capitalize;
}

.historyDiff--easy   { background: rgba(77, 255, 151, 0.12); color: #4dff97; }
.historyDiff--medium { background: rgba(77, 214, 255, 0.12); color: #4dd6ff; }
.historyDiff--hard   { background: rgba(255, 200, 77, 0.12); color: #ffc84d; }
.historyDiff--elite  { background: rgba(255, 77, 109, 0.12); color: #ff4d6d; }

.historyAccuracy {
  color: var(--muted);
  white-space: nowrap;
}

.historyDur {
  color: var(--muted);
  white-space: nowrap;
}

.historyWinner {
  font-weight: 700;
  font-size: 11px;
  text-align: center;
}

.historyWin  { color: #4dff97; }
.historyLoss { color: #ff4d6d; }

