:root {
  --bg: #0f1117;
  --panel: #1a1d29;
  --panel-2: #232735;
  --accent: #e0455f;
  --accent-2: #4f8cff;
  --good: #2ecc71;
  --bad: #e74c3c;
  --text: #f2f3f7;
  --text-dim: #9aa0b4;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(circle at top, #1c2030, var(--bg) 60%);
  color: var(--text);
  display: flex;
  justify-content: center;
  padding: 32px 16px;
}

.app {
  width: 100%;
  max-width: 480px;
}

.app-header {
  text-align: center;
  margin-bottom: 24px;
}

.app-header h1 {
  margin: 0 0 4px;
  font-size: 1.6rem;
}

.subtitle {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.screen {
  display: none;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.screen.active {
  display: block;
}

.intro {
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 20px;
}

.length-picker {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  font-size: 0.95rem;
}

.length-picker select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #333952;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.95rem;
}

.primary-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.2s ease;
}

.primary-btn:hover { opacity: 0.92; }
.primary-btn:active { transform: scale(0.98); }

.quiz-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.progress-bar {
  height: 6px;
  background: var(--panel-2);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 20px;
}

#progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.3s ease;
}

.photo-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--panel-2);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 20px;
}

.photo-loading {
  color: var(--text-dim);
  font-size: 0.9rem;
}

#photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
}

.hidden {
  display: none !important;
}

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.option-btn {
  padding: 14px 10px;
  border-radius: 10px;
  border: 1px solid #333952;
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--accent-2);
}

.option-btn:active:not(:disabled) {
  transform: scale(0.98);
}

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

.option-btn.correct {
  background: rgba(46, 204, 113, 0.18);
  border-color: var(--good);
  color: #6bffa3;
}

.option-btn.incorrect {
  background: rgba(231, 76, 60, 0.18);
  border-color: var(--bad);
  color: #ff9285;
}

.feedback {
  text-align: center;
  font-weight: 600;
  margin-bottom: 16px;
}

.feedback.correct-text { color: var(--good); }
.feedback.incorrect-text { color: var(--bad); }

.final-score {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  margin: 8px 0;
}

.final-message {
  text-align: center;
  color: var(--text-dim);
  margin-bottom: 20px;
}

.review-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
  max-height: 260px;
  overflow-y: auto;
}

.review-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--panel-2);
  border-radius: 8px;
  font-size: 0.9rem;
}

.review-item .mark {
  font-weight: 700;
}

.review-item.right .mark { color: var(--good); }
.review-item.wrong .mark { color: var(--bad); }

/* Landscape: give short, wide viewports (phones rotated, small laptops)
   a layout that doesn't force the buttons below the fold. */
@media (orientation: landscape) {
  body {
    align-items: flex-start;
    padding: 16px;
  }

  .app {
    max-width: 760px;
  }

  .app-header {
    margin-bottom: 12px;
  }

  .app-header h1 {
    font-size: 1.25rem;
  }

  .subtitle {
    font-size: 0.8rem;
  }

  .screen {
    padding: 16px 20px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
  }
}

@media (orientation: landscape) and (min-width: 480px) {
  #screen-quiz.screen.active {
    display: grid;
    grid-template-columns: 38% 1fr;
    grid-template-rows: auto auto 1fr auto auto;
    column-gap: 20px;
    row-gap: 8px;
    grid-template-areas:
      "top     top"
      "bar     bar"
      "photo   options"
      "photo   feedback"
      "photo   next";
    align-items: start;
  }

  #screen-quiz .quiz-top {
    grid-area: top;
    margin-bottom: 0;
  }

  #screen-quiz .progress-bar {
    grid-area: bar;
    margin-bottom: 0;
  }

  #screen-quiz .photo-wrap {
    grid-area: photo;
    aspect-ratio: auto;
    height: 100%;
    margin-bottom: 0;
  }

  #screen-quiz .options {
    grid-area: options;
    align-content: start;
    margin-bottom: 0;
  }

  #screen-quiz .feedback {
    grid-area: feedback;
    margin-bottom: 0;
  }

  #screen-quiz #next-btn.primary-btn {
    grid-area: next;
  }
}
