/* Colours used across the app */
:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #5b6475;
  --primary: #1f5fd1;
  --primary-dark: #174aa6;
  --border: #d6dbe6;
  --danger: #d12f2f;
  --success: #1d7a3a;
}

/* Width includes padding and border, so nothing grows past the screen */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans Malayalam', sans-serif;
  font-size: 18px;
  line-height: 1.5;
  /* Long Malayalam words wrap instead of being cut off */
  overflow-wrap: anywhere;
}

/* One centred column: full width on a phone, narrow on a laptop */
.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px;
  min-height: 100vh;
}

/* Hidden screens stay hidden */
[hidden] {
  display: none !important;
}

/* Message bar at the top: no internet, or another problem */
.notice {
  margin: 0 0 16px;
  padding: 12px 16px;
  border: 2px solid var(--danger);
  border-radius: 12px;
  background: var(--card);
  color: var(--danger);
  font-size: 16px;
  font-weight: 600;
}

/* ---------- Start screen ---------- */

#start-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100vh - 48px);
  text-align: center;
}

.app-name {
  margin: 0 0 12px;
  font-size: 32px;
  line-height: 1.3;
  color: var(--primary);
}

.tagline {
  margin: 0 0 32px;
  color: var(--muted);
}

/* Login area: items stack in one column */
#logged-in-box {
  display: flex;
  flex-direction: column;
}

.login-error {
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 16px;
}

/* Player name and Log out button, side by side */
.user-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 0 0 20px;
  text-align: left;
}

.user-name {
  font-weight: 600;
}

.logout-button {
  flex-shrink: 0;
  min-height: 48px;
  padding: 6px 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  cursor: pointer;
}

/* Daily streak on the start screen */
.streak {
  margin: 0 0 20px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--card);
  border: 2px solid var(--border);
  font-weight: 600;
}

/* Topic choice on the start screen */
.topic-label {
  margin: 0 0 8px;
  font-weight: 600;
  text-align: left;
}

.topic-select {
  width: 100%;
  min-height: 52px;
  margin: 0 0 20px;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 18px;
  line-height: 1.5;
}

.main-button {
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-family: inherit;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.5;
  cursor: pointer;
}

/* Start button text a little bigger than other main buttons */
#start-button {
  font-size: 22px;
}

.main-button:active {
  background: var(--primary-dark);
}

/* Smaller white buttons: leaderboard, weak topics, back */
.more-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.second-button {
  width: 100%;
  min-height: 52px;
  padding: 10px 16px;
  border: 2px solid var(--primary);
  border-radius: 12px;
  background: var(--card);
  color: var(--primary);
  font-family: inherit;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.5;
  cursor: pointer;
}

/* ---------- Leaderboard and weak topics screens ---------- */

.list-title {
  margin: 8px 0 16px;
  font-size: 24px;
  line-height: 1.4;
  color: var(--primary);
}

.list-message {
  margin: 0 0 16px;
  color: var(--muted);
}

.list-message:empty {
  display: none;
}

.score-list {
  margin: 0 0 24px;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* One row: name or topic on the left, score on the right */
.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
}

.row-name {
  min-width: 0;
}

.row-value {
  flex-shrink: 0;
  font-weight: 700;
}

/* ---------- Question screen ---------- */

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

.progress-text {
  font-weight: 600;
}

.timer {
  min-width: 48px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--card);
  border: 2px solid var(--primary);
  color: var(--primary);
  font-weight: 700;
  text-align: center;
}

/* Timer turns red in the last 5 seconds */
.timer.low {
  border-color: var(--danger);
  color: var(--danger);
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--primary);
  transition: width 0.3s;
}

.question-topic {
  margin: 20px 0 4px;
  font-size: 15px;
  color: var(--muted);
}

.question-text {
  margin: 0 0 20px;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.5;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Big option buttons that grow taller for long answers */
.option-button {
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 18px;
  line-height: 1.5;
  text-align: left;
  cursor: pointer;
}

.option-button:active {
  border-color: var(--primary);
}

.option-button:disabled {
  cursor: default;
}

/* ---------- Result screen ---------- */

#result-screen {
  text-align: center;
}

.score-label {
  margin: 8px 0 0;
  color: var(--muted);
}

.score {
  margin: 0 0 24px;
  font-size: 44px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--primary);
}

/* Challenge a friend: the score to beat, and the result */
.challenge-card {
  margin: 0 0 20px;
  padding: 12px 16px;
  border: 2px solid var(--primary);
  border-radius: 12px;
  background: var(--card);
  font-weight: 600;
  text-align: center;
}

.topic-box {
  display: flex;
  flex-direction: column;
}

.challenge-button {
  margin-bottom: 12px;
}

.challenge-message {
  margin: 0 0 8px;
  color: var(--success);
  font-size: 16px;
  font-weight: 600;
}

/* The link itself, so it can be copied by hand if needed */
.challenge-link {
  width: 100%;
  min-height: 48px;
  margin: 0 0 24px;
  padding: 8px 12px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-family: monospace;
  font-size: 14px;
}

/* Shown only if the round could not be saved */
.save-error {
  margin: 0 0 24px;
  color: var(--danger);
  font-size: 16px;
}

.mistakes-title {
  margin: 0 0 12px;
  font-size: 20px;
  text-align: left;
}

.mistakes {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
  text-align: left;
}

/* One card for each wrong or missed question */
.mistake-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
}

.mistake-question {
  margin: 0 0 8px;
  font-weight: 600;
}

.mistake-line {
  margin: 0 0 4px;
  font-size: 16px;
}

.wrong-answer {
  color: var(--danger);
}

.right-answer {
  color: var(--success);
}

.mistake-explanation {
  margin: 8px 0 0;
  font-size: 16px;
  color: var(--muted);
}

/* Shown when every answer is right */
.all-correct {
  margin: 0;
  font-weight: 600;
  color: var(--success);
  text-align: center;
}
