:root,
:root[data-theme="dark"] {
  --bg: #0f1a13;
  --secondary-bg: #16241a;
  --text: #eef5ee;
  --hint: #9db3a3;
  --accent: #3fae67;
  --gold: #d8b34a;
  --separator: rgba(255,255,255,0.08);
  --active-bg: #1c2e21;
}

:root[data-theme="light"] {
  --bg: #f6f7f2;
  --secondary-bg: #ffffff;
  --text: #16241a;
  --hint: #5b6b60;
  --accent: #2f8f57;
  --gold: #b3872c;
  --separator: rgba(0,0,0,0.08);
  --active-bg: #eef3ea;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, "Vazirmatn", sans-serif;
  min-height: 100vh;
  transition: background 0.2s ease, color 0.2s ease;
}

.wrap {
  position: relative;
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px 32px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.theme-toggle {
  position: absolute;
  top: 20px;
  left: 16px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--separator);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.screen { display: none; flex-direction: column; flex: 1; }
.screen.active { display: flex; }

.hero {
  text-align: center;
  padding: 20px 0 28px;
}

.hero.small { padding: 8px 0 24px; }

.hero-emoji {
  font-size: 44px;
  line-height: 1;
  margin-bottom: 10px;
}

.hero h1 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--gold), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  margin: 0;
  color: var(--hint);
  font-size: 14px;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: var(--secondary-bg);
  border: 1px solid var(--separator);
  border-radius: 14px;
  padding: 14px 14px;
  color: var(--text);
  font-family: inherit;
  text-align: right;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}

.card:active {
  transform: scale(0.98);
  background: var(--active-bg);
}

.card-icon {
  font-size: 24px;
  width: 42px;
  height: 42px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(63, 174, 103, 0.12);
  border-radius: 12px;
}

.card-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
}

.card-desc {
  font-size: 12.5px;
  color: var(--hint);
}

.chev {
  color: var(--gold);
  font-size: 20px;
  font-weight: 700;
  flex: none;
}

.option-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-btn {
  width: 100%;
  background: var(--secondary-bg);
  border: 1px solid var(--separator);
  border-radius: 14px;
  padding: 15px 16px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  text-align: right;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
}

.option-btn:active {
  transform: scale(0.98);
  background: var(--active-bg);
}

.option-btn.selected {
  border-color: var(--accent);
  color: var(--accent);
}

.hint-note {
  text-align: center;
  color: var(--hint);
  font-size: 12.5px;
  margin-top: 18px;
}

.profile-block {
  background: var(--secondary-bg);
  border: 1px solid var(--separator);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
}

.profile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.profile-row-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.profile-label {
  font-size: 12px;
  color: var(--hint);
}

.profile-value {
  font-size: 15px;
  font-weight: 700;
}

.mini-btn {
  flex: none;
  border: 1px solid var(--separator);
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
}

.mini-btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

#username-display-row.hidden,
#username-edit-area.hidden {
  display: none;
}

.username-form {
  display: flex;
  gap: 8px;
}

.username-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--separator);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  /* iOS Safari/WebView auto-zooms the whole page on focus if an input's
     font-size is under 16px — this is what caused the "jump" on tap. */
  font-size: 16px;
}

.username-input:focus {
  outline: none;
  border-color: var(--accent);
}

.field-error {
  margin: 8px 2px 0;
  font-size: 12.5px;
  color: #e0645a;
  min-height: 1em;
}

/* Friends / groups list rows */
.list-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--separator);
  border-radius: 10px;
  padding: 10px 12px;
}

.list-row-name {
  font-size: 14px;
  font-weight: 700;
}

.list-row-sub {
  font-size: 12px;
  color: var(--hint);
}

.list-row-actions {
  display: flex;
  gap: 6px;
  flex: none;
}

.list-row-actions .mini-btn {
  padding: 6px 10px;
  font-size: 12px;
}

.list-row.clickable { cursor: pointer; }

/* Exam runner */
.runner-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.runner-timer {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  background: var(--secondary-bg);
  border: 1px solid var(--separator);
  border-radius: 10px;
  padding: 6px 14px;
}

.runner-timer.low-time {
  color: #e0645a;
  border-color: #e0645a;
}

.subject-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 12px;
  padding-bottom: 2px;
}

.subject-tab {
  flex: none;
  background: var(--secondary-bg);
  border: 1px solid var(--separator);
  color: var(--hint);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.subject-tab.active {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.palette-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--separator);
  background: var(--secondary-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

.palette-btn.current { border-color: var(--accent); border-width: 2px; }
.palette-btn.answered { background: var(--accent); color: #fff; border-color: transparent; }
.palette-btn.mark-red-state { background: #e0645a; color: #fff; border-color: transparent; }
.palette-btn.mark-gray-state { background: #9aa39c; color: #fff; border-color: transparent; }

.question-box {
  background: var(--secondary-bg);
  border: 1px solid var(--separator);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
}

.question-text {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.9;
  margin-bottom: 14px;
}

.question-image {
  display: block;
  max-width: 100%;
  border-radius: 10px;
  margin-bottom: 14px;
  background: #fff;
}

.question-image.hidden {
  display: none;
}

.mark-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.mark-btn {
  flex: 1;
  border: 1px solid var(--separator);
  background: var(--secondary-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  padding: 10px 4px;
  border-radius: 10px;
  cursor: pointer;
}

.mark-btn.active-red { background: #e0645a; color: #fff; border-color: transparent; }
.mark-btn.active-gray { background: #9aa39c; color: #fff; border-color: transparent; }

.finish-btn { width: 100%; margin-top: 4px; }

/* Booklet overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.overlay.hidden { display: none; }

.overlay-box {
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 16px;
  overflow-y: auto;
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 800;
  margin-bottom: 12px;
}

.overlay-body img { max-width: 100%; border-radius: 10px; }

/* Results */
.result-score-block {
  text-align: center;
}

.result-score {
  display: block;
  font-size: 34px;
  font-weight: 800;
  color: var(--accent);
  margin-top: 6px;
}

.result-stats {
  display: flex;
  justify-content: space-between;
  text-align: center;
}

.result-stats > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.result-stats span {
  font-size: 18px;
  font-weight: 800;
}

.result-stats small {
  color: var(--hint);
  font-size: 11.5px;
}

.foot {
  text-align: center;
  color: var(--hint);
  font-size: 11.5px;
  padding-top: 24px;
  opacity: 0.7;
}
