:root {
  --bg: #f4f1ec;
  --ink: #2a2622;
  --ink-soft: #5b5650;
  --accent: #b5482e;
  --accent-soft: #e8c8b8;
  --card-bg: #ffffff;
  --border: #e4ddd2;
  --green: #3f7a4f;
  --green-bg: #e6f2e8;
  --red: #e14d4d;
  --red-bg: #fff1f1;
  --radius: 16px;
  --shadow: 0 4px 20px rgba(42, 38, 34, 0.06), 0 1px 3px rgba(42, 38, 34, 0.08);
}

/* Dark Mode Variables */
body.dark-mode {
  --bg: #18181b;
  --card-bg: #27272a;
  --ink: #f4f4f5;
  --ink-soft: #a1a1aa;
  --border: #3f3f46;
  --accent: #f97316;
  --accent-soft: rgba(249, 115, 22, 0.15);
  --error: #ef4444;
  --green: #4ade80;
  --green-bg: rgba(74, 222, 128, 0.1);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.1);
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background-color: var(--bg);
  color: var(--ink);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.bg-decor {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 15% 10%, var(--accent-soft) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, #cdd8c5 0%, transparent 35%);
  opacity: 0.5;
}

.screen {
  display: none;
  min-height: 100vh;
}
.screen.active {
  display: flex;
  flex-direction: column;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* Dark Mode UI Component Overrides */
body.dark-mode .variant-btn {
  background: linear-gradient(145deg, #27272a, #18181b);
  border-color: #3f3f46;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}
body.dark-mode .variant-btn:hover {
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.5), 0 4px 8px rgba(0, 0, 0, 0.4);
  border-color: rgba(249, 115, 22, 0.5);
}
body.dark-mode .report-item {
  background: #27272a;
}
body.dark-mode .report-item-content .a-text {
  background: #18181b;
}
body.dark-mode input, body.dark-mode textarea {
  background: #18181b;
  color: var(--ink);
  border-color: var(--border);
}
body.dark-mode input:focus, body.dark-mode textarea:focus {
  border-color: var(--accent);
}
body.dark-mode .btn-secondary {
  background: #3f3f46;
  color: #f4f4f5;
}
body.dark-mode .btn-secondary:hover {
  background: #52525b;
}
body.dark-mode .type-chip {
  background: #18181b;
  color: var(--ink);
  border-color: var(--border);
}
body.dark-mode .type-chip:hover {
  border-color: var(--accent);
}
body.dark-mode .type-chip.active {
  background: var(--ink);
  color: #18181b;
  border-color: var(--ink);
}
body.dark-mode .modal {
  background: var(--card-bg);
}
body.dark-mode .bar-bg {
  background: var(--border) !important;
}
body.dark-mode .passage {
  background: #18181b;
  border-color: rgba(249, 115, 22, 0.4);
}

body.dark-mode .card {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Login */
#screen-login.active {
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  padding: 40px 36px;
  text-align: center;
}
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.brand-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Georgia, serif;
}
.brand-icon.small {
  width: 34px;
  height: 34px;
  font-size: 16px;
  border-radius: 10px;
}
.brand h1 {
  font-size: 22px;
  margin: 0;
  font-weight: 800;
}
.subtitle {
  color: var(--ink-soft);
  margin: 0 0 28px;
  font-size: 15px;
}
#login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}
#login-form label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
}
input, textarea {
  font-family: inherit;
  font-size: 15px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: #fbfaf8;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
  resize: vertical;
}
input:focus, textarea:focus {
  border-color: var(--accent);
}

.btn {
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  padding: 12px 20px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.btn:hover { 
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.btn:active { 
  transform: translateY(0) scale(0.98); 
  box-shadow: none;
}
.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover {
  background: #f97316;
  box-shadow: 0 4px 16px rgba(249, 115, 22, 0.3);
}
.btn-secondary {
  background: var(--ink);
  color: white;
}
.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1.5px solid var(--border);
}
.btn-icon {
  background: transparent;
  color: var(--ink-soft);
  border: none;
  padding: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.btn-icon:hover {
  background: var(--green-bg);
  color: var(--ink);
  transform: rotate(15deg) scale(1.1);
}
body.dark-mode .btn-icon:hover {
  background: #3f3f46;
}
.hidden { display: none !important; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 32px;
  flex-wrap: wrap;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  white-space: nowrap;
}
.type-filter {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}
.type-chip {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: white;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.15s;
}
.type-chip:hover {
  border-color: var(--accent);
}
.type-chip.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

/* Task */
.task-wrap {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 12px 24px 48px;
  animation: fadeSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.task-card {
  width: 100%;
  max-width: 680px;
  padding: 32px;
}
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.task-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.badge {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
}
#task-title {
  font-weight: 700;
  color: var(--ink-soft);
  font-size: 14px;
}
.passage {
  background: #fbfaf8;
  border-left: 3px solid var(--accent-soft);
  padding: 16px 18px;
  border-radius: 10px;
  font-size: 15px;
  line-height: 1.65;
  margin-bottom: 20px;
  white-space: pre-wrap;
}
.question {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  line-height: 1.5;
}
textarea#answer-input {
  width: 100%;
  margin-bottom: 18px;
}
.actions {
  display: flex;
  gap: 12px;
}
.feedback {
  margin-top: 24px;
  padding: 16px;
  border-radius: 10px;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  animation: popIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.feedback.correct {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid #cfe6d4;
}
.feedback.incorrect {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid #f0d4c8;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeOverlay 0.3s ease forwards;
}
@keyframes fadeOverlay {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  width: 100%;
  max-width: 480px;
  position: relative;
  padding: 32px;
  animation: popIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-close {
  position: absolute;
  top: 16px;
  right: 18px;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--ink-soft);
}
.modal h2 {
  margin: 0 0 18px;
  font-size: 19px;
}
.stats-total {
  font-size: 15px;
  color: var(--ink-soft);
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.stats-total strong {
  color: var(--ink);
  font-size: 20px;
}
.stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 14px;
}
.stats-row .bar-bg {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin: 0 12px;
  overflow: hidden;
}
.stats-row .bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
}

/* Variants Grid Premium Design */
#variants-view .card {
  background: transparent;
  box-shadow: none;
  border: none;
  padding: 0;
}
#variants-view h2 {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 8px;
  text-align: center;
}
#variants-view .subtitle {
  text-align: center;
  margin-bottom: 32px;
  font-size: 16px;
}

.variants-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}

.variant-btn {
  position: relative;
  background: linear-gradient(145deg, #ffffff, #fdfbf9);
  border: 1px solid rgba(181, 72, 46, 0.15);
  border-radius: 16px;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-family: inherit;
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(42, 38, 34, 0.04), inset 0 0 0 1px rgba(255, 255, 255, 0.8);
  overflow: hidden;
}

.variant-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), #d16b54);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.variant-btn:hover {
  transform: translateY(-4px) scale(1.02);
  border-color: rgba(181, 72, 46, 0.3);
  box-shadow: 0 12px 24px rgba(181, 72, 46, 0.08), 0 4px 8px rgba(42, 38, 34, 0.04);
}

.variant-btn:hover::before {
  opacity: 1;
}

.variant-btn:active {
  transform: translateY(0) scale(0.98);
}

.variant-btn .v-title {
  font-weight: 800;
  font-size: 18px;
  color: var(--ink);
}

.variant-btn .v-progress {
  font-size: 13px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg);
  color: var(--ink-soft);
  transition: all 0.3s ease;
}

.variant-btn:hover .v-progress {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Toggle Switch */
.toggle-container {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  margin-bottom: 24px;
}
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--border);
  transition: .3s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
}
input:checked + .slider {
  background-color: var(--accent);
}
input:checked + .slider:before {
  transform: translateX(20px);
}
.slider.round {
  border-radius: 24px;
}
.slider.round:before {
  border-radius: 50%;
}
.toggle-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-soft);
}

/* Report Details */
.report-details {
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: left;
}
.report-item {
  background: #fbfaf8;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.report-item summary {
  padding: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  outline: none;
  list-style: none;
}
.report-item summary::-webkit-details-marker {
  display: none;
}
.report-item summary::before {
  content: "▶";
  font-size: 12px;
  color: var(--ink-soft);
  transition: transform 0.2s;
}
.report-item[open] summary::before {
  transform: rotate(90deg);
}
.report-item.correct summary {
  background: var(--green-bg);
  color: var(--green);
}
.report-item.incorrect summary {
  background: var(--red-bg);
  color: var(--red);
}
.report-item-content {
  padding: 16px;
  border-top: 1px solid var(--border);
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink);
}
.report-item-content .q-text {
  font-weight: 600;
  margin-bottom: 8px;
}
.report-item-content .a-text {
  background: white;
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
}
.report-item-content .f-text {
  font-weight: 600;
}

@media (max-width: 600px) {
  .topbar { padding: 14px 16px; }
  .task-wrap { padding: 8px 12px 32px; }
  .task-card { padding: 22px; }
}
