:root {
  --bg: #f5efe4;
  --panel: #fffaf2;
  --ink: #222017;
  --muted: #5f5a4d;
  --accent: #cf5c36;
  --accent-2: #0d6e6e;
  --good: #1f7a46;
  --bad: #b42318;
  --line: rgba(34, 32, 23, 0.15);
  --shadow: 0 20px 45px rgba(32, 26, 14, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Be Vietnam Pro", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 15%, #ffd08f, transparent 35%),
    radial-gradient(circle at 85% 80%, #8dd7d7, transparent 32%), var(--bg);
  min-height: 100vh;
}

body:not(.app-ready) .app-shell {
  visibility: hidden;
}

.bg-orb {
  position: fixed;
  z-index: 0;
  border-radius: 999px;
  opacity: 0.18;
  filter: blur(2px);
}

.login-loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(245, 239, 228, 0.72);
  backdrop-filter: blur(8px);
}

.login-loading-card {
  min-width: 220px;
  padding: 24px 28px;
  border-radius: 18px;
  background: rgba(255, 250, 242, 0.96);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-align: center;
  color: var(--ink);
  font-weight: 700;
}

.login-spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 4px solid rgba(207, 92, 54, 0.18);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

.orb-1 {
  width: 320px;
  height: 320px;
  background: #dd5f2d;
  top: -80px;
  right: -70px;
}

.orb-2 {
  width: 260px;
  height: 260px;
  background: #0d6e6e;
  bottom: -70px;
  left: -60px;
}

.app-shell {
  position: relative;
  z-index: 2;
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 16px 28px;
}

.panel {
  display: none;
  background: color-mix(in srgb, var(--panel), white 12%);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 22px;
  animation: rise 0.4s ease;
}

.main-nav {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(4px);
  border-radius: 12px;
  border: 1px solid var(--line);
}

.nav-link {
  border: 0;
  background: transparent;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.2s;
}

.nav-link:hover {
  background: rgba(207, 92, 54, 0.1);
  color: var(--accent);
}

.nav-link.active {
  background: var(--accent);
  color: #fff;
}

.panel.active {
  display: block;
}

.login-panel {
  display: none !important;
  max-width: 420px;
  margin: 60px auto !important;
  padding: 32px !important;
  text-align: left;
}

.login-panel.active {
  display: block !important;
}

.login-container {
  display: block;
}

.login-form {
  display: grid;
  gap: 10px;
  margin: 20px 0;
  justify-items: stretch;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 48px;
}

.password-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  font-size: 1rem;
  line-height: 1;
}

.password-toggle:hover {
  color: var(--accent);
}

.login-error {
  background: #fce6e3;
  border: 1px solid #b42318;
  border-radius: 10px;
  padding: 10px;
  color: #7a1f13;
  margin-top: 12px;
  font-size: 0.9rem;
}

.login-subtitle {
  color: var(--muted);
  margin-bottom: 20px;
}

.login-hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 24px;
  padding: 12px 14px;
  background: white;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  line-height: 1.4;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.04);
}

.login-hint-icon {
  font-size: 1.2rem;
  margin-top: 2px;
}

.login-hint-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.login-hint-title {
  font-weight: 700;
  color: var(--accent);
}

.login-hint-details {
  color: var(--muted);
  font-weight: 500;
}

.login-hint code {
  background: #fff5f2;
  padding: 1px 4px;
  border-radius: 4px;
  color: var(--accent);
  font-weight: 700;
  font-family: inherit;
  border: 1px solid rgba(207, 92, 54, 0.08);
}

.setup-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.setup-header h1 {
  margin: 0;
}

.user-info {
  margin-top: 4px;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.95rem;
}

h1,
h2,
h3 {
  margin-top: 0;
  font-family: "Space Grotesk", sans-serif;
}

.search-section {
  margin-bottom: 24px;
}

.search-description {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 10px;
  font-weight: 500;
}

.search-box {
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--panel);
  font-size: 0.95rem;
  transition: all 0.2s;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(207, 92, 54, 0.1);
  outline: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 400px;
  overflow-y: auto;
  background: white;
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  z-index: 100;
  padding: 8px;
}

.search-item {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
}

.search-item:last-child {
  border-bottom: none;
}

.search-item:hover {
  background: #fff5f2;
}

.search-item-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 4px;
}

.search-item-content {
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-no-results {
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.subtitle {
  color: var(--muted);
  max-width: 760px;
}

.setup-form {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 10px;
  font: inherit;
}

.set-meta {
  margin-top: 4px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}

.exam-sets-list {
  margin-top: 12px;
  margin-bottom: 8px;
  display: grid;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.exam-set-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.exam-set-card:hover {
  background: #faf8f2;
  border-color: var(--accent);
}

.exam-set-card.attempted {
  background: linear-gradient(180deg, #fff7ea 0%, #fff 100%);
  border-color: rgba(207, 92, 54, 0.4);
  box-shadow: inset 4px 0 0 rgba(207, 92, 54, 0.65);
}

.exam-set-card.drafted {
  background: linear-gradient(180deg, #eef6ff 0%, #fff 100%);
  border-color: #0d6e6e;
  box-shadow: inset 4px 0 0 #0d6e6e, 0 4px 12px rgba(13, 110, 110, 0.1);
  position: relative;
}

.exam-set-card.drafted::after {
  content: "📝";
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 1.2rem;
}

.draft-summary-alert {
  margin-top: 10px;
  padding: 8px 12px;
  background: #e7f4ff;
  border: 1px solid #0d6e6e;
  border-radius: 8px;
  color: #0d6e6e;
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-5deg); }
  to { opacity: 1; transform: translateY(0); }
}

.exam-set-card.selected {
  background: #ffe6bd;
  border-color: var(--accent);
}

.exam-set-title {
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
  font-size: 0.95rem;
}

.exam-set-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.exam-set-meta-label {
  font-weight: 600;
}

.exam-set-meta-value {
  color: var(--accent);
}

.exam-set-status {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-top: 4px;
}

.exam-set-status.new {
  background: #e8f5e9;
  color: #1f7a46;
}

.exam-set-status.done {
  background: #fff3e0;
  color: #e67e22;
}

.exam-set-status.draft {
  background: #e7f4ff;
  color: #0d6e6e;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease, filter 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.btn-primary {
  background: linear-gradient(100deg, var(--accent), #eaa43a);
  color: #20190f;
}

.btn-soft {
  background: #efe9db;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-danger {
  background: #fce6e3;
  color: #7a1f13;
  border: 1px solid rgba(122, 31, 19, 0.3);
}

.history-box {
  border-top: 1px dashed var(--line);
  margin-top: 18px;
  padding-top: 14px;
}

.history-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.history-container {
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 12px;
  min-height: 44px;
  background: #fff;
}

.history-container.empty {
  color: var(--muted);
}

.exam-topbar {
  display: flex;
  gap: 14px;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
}

.meta-line {
  margin: 6px 0 0;
  color: var(--muted);
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.exam-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 14px;
}

.question-nav-wrap {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #fff;
}

.question-nav {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  max-height: 420px;
  overflow: auto;
  padding-right: 2px;
}

.nav-btn {
  border: 1px solid var(--line);
  background: #faf8f2;
  border-radius: 8px;
  padding: 8px 0;
  font-weight: 700;
  cursor: pointer;
}

.nav-btn.current {
  background: #ffe6bd;
  border-color: #d88a2b;
}

.nav-btn.answered {
  background: #dcf7e7;
  border-color: #2b8f57;
}

.nav-btn.correct {
  background: #d4f1e0;
  border-color: #1f7a46;
}

.nav-btn.wrong {
  background: #fce6e3;
  border-color: #b42318;
}

.nav-btn.unanswered {
  background: #e8e4db;
  border-color: #9b9487;
}

.legend {
  display: grid;
  gap: 5px;
  margin-top: 10px;
  font-size: 0.9rem;
  color: var(--muted);
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
}

.dot.current {
  background: #e0902d;
}

.dot.answered {
  background: #2b8f57;
}

.dot.empty {
  background: #b9b3a8;
}

.dot.correct {
  background: #1f7a46;
}

.dot.wrong {
  background: #b42318;
}

.dot.unanswered {
  background: #9b9487;
}

.question-area {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
  min-height: 420px;
}

.question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.badge,
.difficulty {
  display: inline-block;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.85rem;
  font-weight: 700;
}

.badge {
  background: #ede6d6;
}

.difficulty {
  background: #e3f2f2;
  color: #0c4d4d;
}

.question-content {
  font-size: 1.08rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.option-content-text {
  white-space: pre-wrap;
}


.answer-area {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.option-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fbfaf7;
}

.option-item input {
  width: auto;
  margin-top: 3px;
}

.option-item.feedback-correct {
  background: #d4f1e0;
  border-color: #1f7a46;
  border-width: 2px;
}

.option-item.feedback-wrong {
  background: #fce6e3;
  border-color: #b42318;
  border-width: 2px;
}

.option-item.feedback-correct-indicator {
  border: 2px dashed #1f7a46;
  background: #f0faf4;
}


.question-footer {
  margin-top: 16px;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.result-stats {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 14px 0;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 12px;
}

.stat-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.stat-value {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.3rem;
  margin-top: 4px;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.result-details {
  display: grid;
  gap: 10px;
}

.result-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 12px;
}

.result-item.good {
  border-left: 5px solid var(--good);
}

.result-item.bad {
  border-left: 5px solid var(--bad);
}

.result-status.good {
  color: var(--good);
  font-weight: 700;
}

.result-status.bad {
  color: var(--bad);
  font-weight: 700;
}

.review-summary {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.review-stat {
  flex: 1;
  min-width: 120px;
}

.review-stat-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.review-stat-value {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  margin-top: 2px;
}

.review-answer-section {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.review-answer-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fbfaf7;
}

.review-answer-block.user-correct {
  background: #d4f1e0;
  border-color: #1f7a46;
}

.review-answer-block.user-wrong {
  background: #fce6e3;
  border-color: #b42318;
}

.review-answer-block.correct-answer {
  background: #d4f1e0;
  border-color: #1f7a46;
  border-left: 5px solid #1f7a46;
}

.review-answer-label {
  display: block;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 4px;
  color: var(--ink);
}

.review-answer-content {
  margin-left: 0;
}

.history-summary {
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.summary-stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
}

.summary-value {
  display: block;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  margin-top: 4px;
}

.history-container {
  display: grid;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.history-row {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.history-row-info {
  font-size: 0.95rem;
}

.history-row-number {
  display: block;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 2px;
}

.history-row-details {
  display: grid;
  gap: 2px;
  color: var(--muted);
  font-size: 0.85rem;
}

.history-row-detail-item {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.history-row-detail-item strong {
  color: var(--ink);
}

.history-row-actions {
  display: flex;
  gap: 4px;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(32, 26, 14, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  max-width: 600px;
  max-height: 80vh;
  overflow: auto;
  width: 90%;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.leaderboard-panel {
  display: none;
}

.leaderboard-panel.active {
  display: block;
}

.leaderboard-box {
  border-top: 1px dashed var(--line);
  margin-top: 24px;
  padding-top: 20px;
}

.leaderboard-actions {
  margin-bottom: 12px;
}

.leaderboard-table-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.95rem;
}

.leaderboard-table th {
  background: #faf8f2;
  padding: 12px;
  font-weight: 700;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.leaderboard-table td {
  padding: 12px;
  border-bottom: 1px solid rgba(34, 32, 23, 0.05);
}

.leaderboard-table tr:last-child td {
  border-bottom: 0;
}

.leaderboard-table tr:nth-child(1) td:first-child { color: #d4af37; font-weight: 800; font-size: 1.2rem; } /* Gold */
.leaderboard-table tr:nth-child(2) td:first-child { color: #aaa9ad; font-weight: 800; font-size: 1.1rem; } /* Silver */
.leaderboard-table tr:nth-child(3) td:first-child { color: #b08d57; font-weight: 800; font-size: 1.05rem; } /* Bronze */

.leaderboard-table tr:hover {
  background: #fffdf9;
}
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.modal-header h3 {
  margin: 0;
}

.modal-body {
  padding: 14px;
}

.attempt-detail-stat {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.attempt-detail-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  text-align: center;
}

.attempt-detail-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.attempt-detail-value {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink);
  margin-top: 2px;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 980px) {
  .exam-layout {
    grid-template-columns: 1fr;
  }

  .result-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .panel {
    padding: 14px;
  }

  .question-nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .result-stats {
    grid-template-columns: 1fr;
  }
}
