/* --- Core Design System --- */
:root {
  --primary-color: #005A36; /* Blackmores signature dark green */
  --primary-glow: rgba(0, 90, 54, 0.4);
  --accent-color: #10B981;  /* Emerald accent */
  --gold-color: #EAB308;    /* Gold for scores */
  --danger-color: #EF4444;  /* Red for delete/errors */
  --bg-color: #080E17;      /* Very deep slate/navy background */
  --card-bg: rgba(13, 24, 41, 0.75);
  --border-color: rgba(255, 255, 255, 0.07);
  --text-primary: #F8FAFC;
  --text-secondary: #94A3B8;
  --font-family: 'Kanit', 'Outfit', system-ui, -apple-system, sans-serif;
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 25px rgba(16, 185, 129, 0.2);
  --radius-lg: 20px;
  --radius-md: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  position: relative;
}

/* --- Decorative background blobs --- */
.background-decor {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  z-index: 0;
  opacity: 0.15;
  pointer-events: none;
}

.blur-1 {
  width: 400px;
  height: 400px;
  background-color: var(--primary-color);
  top: -10%;
  left: -10%;
}

.blur-2 {
  width: 500px;
  height: 500px;
  background-color: var(--accent-color);
  bottom: -10%;
  right: -10%;
}

/* --- Main Layout --- */
.app-container {
  width: 100%;
  max-width: 1000px;
  padding: 20px;
  z-index: 1;
  position: relative;
}

/* --- Views Toggling --- */
.view {
  display: none;
  width: 100%;
}

.view.active {
  display: block;
}

/* --- Card Styles (Glassmorphism) --- */
.card {
  border-radius: var(--radius-lg);
  padding: 40px 35px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

.glass-card {
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.glass-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
}

/* --- Typographical Elements --- */
.title {
  font-size: 2.2rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #FFFFFF 30%, var(--accent-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 30px;
  font-weight: 300;
}

/* --- Forms & Inputs --- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.input-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-wrapper label {
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-weight: 400;
  padding-left: 4px;
}

.input-wrapper input {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: 1rem;
  transition: all 0.3s ease;
}

.input-wrapper input:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.2);
  background: rgba(15, 23, 42, 0.8);
}

/* --- Buttons --- */
.btn {
  font-family: var(--font-family);
  font-size: 1.05rem;
  font-weight: 500;
  padding: 14px 28px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
  color: white;
  box-shadow: 0 4px 15px rgba(0, 90, 54, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--text-secondary);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #FCA5A5;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.3);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}

.btn-link {
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 15px;
  padding: 6px;
  width: max-content;
  align-self: center;
}

.btn-link:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

/* --- Error Text --- */
.error-text {
  color: var(--danger-color);
  font-size: 0.9rem;
  text-align: center;
  background: rgba(239, 68, 68, 0.1);
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* --- Logo Wrapper --- */
.logo-wrapper {
  display: flex;
  justify-content: center;
  margin-bottom: 25px;
}

.brand-logo {
  max-width: 180px;
  height: auto;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.1);
}

/* --- EXAM LAYOUT --- */
.exam-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

.exam-header {
  border-radius: var(--radius-lg);
  padding: 20px 30px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 20px;
  position: relative;
}

/* Responsive grid for exam header when screen is larger */
@media (min-width: 768px) {
  .exam-header {
    grid-template-columns: 1fr auto 240px;
  }
}

.user-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.user-badge, .branch-badge {
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.user-badge {
  font-weight: 500;
  color: var(--text-primary);
}

/* Timer styles */
.timer-container {
  position: relative;
  width: 80px;
  height: 80px;
  display: flex;
  justify-content: center;
  align-items: center;
  justify-self: center;
}

.timer-ring {
  transform: rotate(-90deg);
}

.timer-ring-circle {
  stroke-dasharray: 213.62; /* 2 * PI * r (34) = ~213.62 */
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear, stroke 0.3s ease;
}

.timer-text {
  position: absolute;
  font-size: 1.5rem;
  font-weight: 600;
  font-family: 'Outfit', sans-serif;
  color: var(--text-primary);
}

.progress-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.progress-bar-bg {
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
  width: 0%;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Question box styles */
.question-card {
  padding: 40px;
}

.question-number {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--accent-color);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.question-text {
  font-size: 1.35rem;
  line-height: 1.6;
  margin-bottom: 30px;
  color: var(--text-primary);
  font-weight: 500;
}

/* Choices/options */
.options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 35px;
}

@media (min-width: 768px) {
  .options-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.option-card {
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 15px;
  transition: all 0.25s ease;
  position: relative;
}

.option-card:hover {
  background: rgba(15, 23, 42, 0.6);
  border-color: rgba(16, 185, 129, 0.4);
  transform: translateY(-2px);
}

.option-card.selected {
  background: rgba(0, 90, 54, 0.2);
  border-color: var(--accent-color);
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.15);
}

.option-index {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.option-card:hover .option-index {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.option-card.selected .option-index {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: white;
}

.option-text {
  font-size: 1rem;
  color: var(--text-primary);
  line-height: 1.4;
}

.exam-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.timer-warning {
  color: var(--danger-color);
  font-size: 0.95rem;
  font-weight: 500;
  animation: pulse 1s infinite alternate;
}

.btn-next {
  min-width: 140px;
  margin-left: auto;
}

/* --- SUCCESS VIEW --- */
.success-card {
  padding: 50px 40px;
}

.success-icon-wrapper {
  display: flex;
  justify-content: center;
  margin-bottom: 25px;
}

.success-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.15);
  border: 2px solid var(--accent-color);
  color: var(--accent-color);
  font-size: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow);
}

.text-glow {
  text-shadow: 0 0 15px rgba(234, 179, 8, 0.4);
}

.result-details {
  background: rgba(15, 23, 42, 0.5);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 30px;
  margin: 30px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 25px;
}

@media (min-width: 768px) {
  .result-details {
    flex-direction: row;
    justify-content: space-around;
  }
}

.profile-summary {
  display: flex;
  flex-direction: column;
  gap: 15px;
  text-align: left;
}

.summary-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary-row .label {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.summary-row .value {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text-primary);
}

.score-circle-wrapper {
  position: relative;
  width: 160px;
  height: 160px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.score-ring {
  transform: rotate(-90deg);
}

.score-ring-fill {
  stroke-dasharray: 427.25; /* 2 * PI * r (68) = ~427.25 */
  stroke-dashoffset: 427.25;
  transition: stroke-dashoffset 1.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.score-text {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.score-number {
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--gold-color);
  line-height: 1.1;
  font-family: 'Outfit', sans-serif;
  text-shadow: 0 0 10px rgba(234, 179, 8, 0.3);
}

.score-total {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.score-feedback {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--accent-color);
}

.success-actions {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

/* --- ADMIN VIEW --- */
.admin-layout {
  display: flex;
  flex-direction: column;
  gap: 25px;
}

.admin-header {
  border-radius: var(--radius-lg);
  padding: 25px 30px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

@media (min-width: 768px) {
  .admin-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 15px;
}

.admin-logo {
  max-width: 100px;
  border-radius: 6px;
}

.brand-title h2 {
  font-size: 1.5rem;
  font-weight: 600;
}

.brand-title p {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.admin-actions {
  display: flex;
  gap: 12px;
}

/* Stats dashboard */
.admin-stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

@media (min-width: 768px) {
  .admin-stats {
    grid-template-columns: repeat(3, 1fr);
  }
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 20px 25px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-title {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--accent-color);
  font-family: 'Outfit', sans-serif;
}

/* Table Card */
.table-card {
  padding: 30px;
}

.table-header {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 20px;
}

@media (min-width: 768px) {
  .table-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
}

.search-box input {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 10px 16px;
  border-radius: 8px;
  font-family: var(--font-family);
  font-size: 0.95rem;
  width: 260px;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent-color);
  background: rgba(15, 23, 42, 0.8);
}

.table-wrapper {
  overflow-x: auto;
}

.scores-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.scores-table th, .scores-table td {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.scores-table th {
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(15, 23, 42, 0.4);
}

.scores-table tbody tr {
  transition: background-color 0.2s ease;
}

.scores-table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-weight: 600;
  font-size: 0.85rem;
  font-family: 'Outfit', sans-serif;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.rank-1 {
  background: linear-gradient(135deg, #F59E0B, #D97706);
  color: #000;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.4);
}

.rank-2 {
  background: linear-gradient(135deg, #94A3B8, #475569);
  color: #000;
}

.rank-3 {
  background: linear-gradient(135deg, #B45309, #78350F);
  color: white;
}

.score-col {
  text-align: center;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--gold-color);
  font-family: 'Outfit', sans-serif;
}

.pct-col {
  text-align: center;
  font-family: 'Outfit', sans-serif;
  color: var(--accent-color);
  font-weight: 500;
}

.time-col {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-family: 'Outfit', sans-serif;
}

/* --- Utilities --- */
.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

.text-muted {
  color: var(--text-secondary);
}

/* --- Animations --- */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn 0.45s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes pulse {
  from {
    opacity: 0.6;
  }
  to {
    opacity: 1;
  }
}
