:root {
  color-scheme: light;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: #f7f9fc;
  color: #101625;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
}

.app {
  /* widened by ~20% from 960 -> 1152 */
  max-width: 1152px;
  margin: 0 auto;
  padding: 32px 16px 64px;
}

.app__header {
  position: relative;
  text-align: center;
  margin-bottom: 32px;
}

.app__header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.app__title {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: clamp(2.2rem, 4vw, 3rem);
  font-weight: 700;
  margin: 0;
  flex: 1 1 auto;
}

.app__title-base {
  white-space: nowrap;
}

.dataset-toggle-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.dataset-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 18px;
  border: none;
  background: transparent;
  font: inherit;
  font-weight: inherit;
  color: #1f2a44;
  cursor: pointer;
  border-radius: 999px;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.dataset-toggle::after {
  content: '▾';
  font-size: 0.75em;
  color: #52607a;
  margin-left: 4px;
}

.dataset-toggle:hover,
.dataset-toggle:focus-visible,
.dataset-toggle.dataset-toggle--open {
  background: rgba(31, 86, 255, 0.08);
}

.dataset-toggle:focus-visible {
  outline: 2px solid rgba(31, 86, 255, 0.4);
  outline-offset: 2px;
}

.app__header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  flex: 0 0 auto;
}

.dataset-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  transform: none;
  background: #ffffff;
  border: 1px solid #d6deec;
  border-radius: 14px;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.18);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 260px;
  z-index: 60;
}

.dataset-menu[hidden] {
  display: none !important;
}

.dataset-menu__option {
  border: none;
  background: transparent;
  text-align: left;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
  color: #0f2342;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.dataset-menu__option:hover,
.dataset-menu__option:focus-visible {
  background: rgba(31, 86, 255, 0.1);
  outline: none;
}

.dataset-menu__option--active {
  background: rgba(31, 86, 255, 0.18);
  color: #1f2a44;
  font-weight: 600;
}

.language-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 18px;
  border-radius: 999px;
  border: none;
  background: transparent;
  font: inherit;
  font-weight: inherit;
  font-size: inherit;
  color: #1f2a44;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.language-toggle:hover,
.language-toggle:focus-visible {
  background: rgba(31, 86, 255, 0.08);
  outline: none;
}

h1 {
  font-size: clamp(2.2rem, 4vw, 3rem);
  margin: 0;
}


.scoreboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-top: 24px;
}

.scoreboard__item {
  background: white;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 12px 32px rgba(16, 22, 37, 0.08);
}

.scoreboard__label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6c7a93;
}

.scoreboard__value {
  display: block;
  margin-top: 8px;
  font-size: 1.75rem;
  font-weight: 700;
  color: #1f56ff;
}

/* make the 'Solved' stat visually green when rendered */
#stat-solved {
  color: #198754; /* bootstrap success green */
}

.app__content {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 24px;
  /* ensure both columns stretch to equal height */
  align-items: stretch;
  margin-bottom: 32px;
}

.question-card {
  position: relative;
  background: white;
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 16px 40px rgba(16, 22, 37, 0.1);
  /* fill column so sidebar and question area match height */
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
}

.question-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.question-card__badge {
  display: inline-block;
  background: linear-gradient(135deg, #ff8a5b, #ff3d68);
  color: white;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 6px 14px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ensure the badge stays compact and doesn't stretch in flex layout */
.question-card__badge {
  display: inline-block;
  width: auto;
  max-width: max-content;
  white-space: nowrap;
}

.mobile-browser-toggle {
  display: none;
}

.question-card__body {
  margin-top: 16px;
  padding: 12px 0;
}

.question-card__text {
  font-size: 1.2rem;
  line-height: 1.6;
  margin: 0;
}

.answer-form {
  margin-top: 24px;
  display: grid;
  gap: 12px;
}

.answer-form__label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.answer-form__label {
  font-weight: 600;
  color: #3a4b6a;
}

.answer-form__input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.answer-form__input {
  padding: 10px 12px;
  font-size: 1rem;
  border-radius: 10px;
  border: 2px solid #d6deec;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  flex: 1 1 180px;
  width: 100%;
  min-width: 0;
}

.answer-form__input:focus {
  border-color: #1f56ff;
  box-shadow: 0 0 0 3px rgba(31, 86, 255, 0.15);
}

.calculator__toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 10px;
}

.calculator__toggle-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.answer-form__calculator {
  margin-top: 8px;
}

.calculator {
  border: 1px solid #d6deec;
  border-radius: 12px;
  background: #f7f9ff;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.calculator[hidden] {
  display: none !important;
}

.calculator__label {
  font-weight: 600;
  color: #3a4b6a;
}

.calculator__textarea {
  width: 100%;
  min-height: 96px;
  resize: vertical;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #c5d1eb;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.4;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.calculator__textarea:focus {
  border-color: #1f56ff;
  box-shadow: 0 0 0 3px rgba(31, 86, 255, 0.15);
  outline: none;
}

.calculator__controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.calculator__button {
  flex: 0 0 auto;
  min-width: 120px;
}

.calculator__feedback {
  min-height: 20px;
  font-size: 0.9rem;
  color: #374366;
}

.calculator__feedback--success {
  color: #1a7f35;
}

.calculator__feedback--error {
  color: #b31b1b;
}

.answer-form__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.answer-form__actions-right {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
}

.answer-form__options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  grid-auto-flow: row dense;
}

.answer-form__options--provided {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice {
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid #d6deec;
  background: #eef3ff;
  color: #0f2342;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  text-align: center;
}

.choice--selected {
  background: linear-gradient(135deg,#dfe9ff,#eef6ff);
  border-color: #1f56ff;
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(31,86,255,0.12);
}

.button--ghost#hint-button {
  padding: 10px 14px;
}

.choice:hover,
.choice:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(14, 35, 66, 0.12);
  outline: none;
}

.choice--wide {
  grid-column: span 2;
}

.button--icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.button__icon {
  font-size: 1.1rem;
  line-height: 1;
}

.button {
  padding: 12px 20px;
  border-radius: 12px;
  border: none;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.button--primary {
  background: linear-gradient(135deg, #1f56ff, #5f8cff);
  color: white;
  box-shadow: 0 14px 30px rgba(31, 86, 255, 0.25);
}

.button--ghost {
  background: white;
  border: 2px solid #d6deec;
  color: #1f2a44;
  box-shadow: none;
}

.button--ghost:hover:not(:disabled),
.button--ghost:focus-visible:not(:disabled) {
  background: #eef3ff;
  box-shadow: 0 10px 20px rgba(14, 35, 66, 0.1);
}

.button--primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 20px 36px rgba(31, 86, 255, 0.26);
}

.button:hover:not(:disabled),
.button:focus-visible:not(:disabled) {
  transform: translateY(-1px);
}

.feedback {
  min-height: 32px;
  margin-top: 8px;
  font-weight: 600;
}

.feedback--success {
  color: #198754;
}

.feedback--error {
  color: #d0312d;
}

.feedback--hint {
  color: #6a5bff;
}

.browser {
  background: white;
  border-radius: 24px;
  padding: 20px;
  box-shadow: 0 16px 40px rgba(16, 22, 37, 0.08);
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 620px;
}

/* ensure browser column also fills height to match question card */
.browser {
  flex: 1 1 auto;
}

.browser__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.browser__header h2 {
  margin: 0;
}

.browser__pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-left: auto;
}

.browser__close {
  display: none;
  border: none;
  background: transparent;
  color: #6c7a93;
  font-size: 1.75rem;
  line-height: 1;
  padding: 4px;
  cursor: pointer;
}

.mobile-browser-scrim {
  position: fixed;
  inset: 0;
  background: rgba(16, 22, 37, 0.35);
  z-index: 800;
  display: none;
}

.browser__page-indicator {
  font-weight: 600;
  color: #3a4b6a;
}

.browser__list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 12px;
  overflow-y: auto;
  padding-right: 4px;
}

.browser__empty {
  color: #6c7a93;
  font-size: 0.95rem;
}

.browser__item {
  margin: 0;
}

.browser__button {
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px solid #d6deec;
  background: #f5f7ff;
  color: #0f2342;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.2s ease;
  min-height: 72px;
  display: grid;
  gap: 6px;
}

.browser__button:hover,
.browser__button:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(15, 35, 66, 0.12);
  border-color: #1f56ff;
  outline: none;
}

.browser__button--active {
  border-color: #1f56ff;
  background: linear-gradient(135deg, rgba(31, 86, 255, 0.1), rgba(95, 140, 255, 0.15));
}

.browser__button-title {
  font-size: 0.95rem;
  margin: 0;
  line-height: 1.35;
  display: -webkit-box;
  /* standard property for newer browsers */
  line-clamp: 3;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.browser__button-meta {
  font-size: 0.8rem;
  color: #52607a;
}

.history {
  margin-top: 32px;
}

.history__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.history__list {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  display: grid;
  gap: 12px;
}

.history__item {
  background: white;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 8px 24px rgba(16, 22, 37, 0.06);
  display: grid;
  gap: 8px;
}

.history__item--error {
  border-left: 4px solid #d0312d;
}

.history__item--warn {
  border-left: 4px solid #f6a72b;
}

.history__question {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.45;
}

.history__result {
  font-size: 0.85rem;
  color: #52607a;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: #52607a;
}

.switch input {
  width: 0;
  height: 0;
  opacity: 0;
  position: absolute;
}

.switch__slider {
  position: relative;
  width: 42px;
  height: 24px;
  background: #d6deec;
  border-radius: 999px;
  transition: background 0.2s ease;
}

.switch__slider::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  top: 2px;
  left: 2px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.switch input:checked + .switch__slider {
  background: #1f56ff;
}

.switch input:checked + .switch__slider::after {
  transform: translateX(18px);
}

.confetti-layer {
  pointer-events: none;
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 100;
}

.hamster-layer {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 220ms ease;
  z-index: 120;
}

.hamster-layer.show {
  opacity: 1;
}


.hamster-emoji {
  /* base size starts at 30% and grows by 10% with each correct answer */
  font-size: min(30vh, 30vw);
  /* start very small and grow to full size */
  transform: scale(0.12);
  transform-origin: center center;
  animation: hamster-grow 1200ms cubic-bezier(.2,.8,.2,1) forwards;
  filter: drop-shadow(0 10px 18px rgba(16,22,37,0.18));
}

/* size classes for consecutive correct answers (starting at 4) */
.hamster-emoji--size-1 { font-size: min(30vh, 30vw); }
.hamster-emoji--size-2 { font-size: min(40vh, 40vw); }
.hamster-emoji--size-3 { font-size: min(50vh, 50vw); }
.hamster-emoji--size-4 { font-size: min(60vh, 60vw); }
.hamster-emoji--size-5 { font-size: min(70vh, 70vw); }
.hamster-emoji--size-6 { font-size: min(80vh, 80vw); }
.hamster-emoji--size-7 { font-size: min(90vh, 90vw); }

@keyframes hamster-grow {
  0% {
    transform: translateY(24px) scale(0.12);
    opacity: 0;
  }
  45% {
    transform: translateY(-6px) scale(1.06);
    opacity: 1;
  }
  75% {
    transform: translateY(4px) scale(0.98);
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.confetti {
  position: absolute;
  opacity: 0;
  animation: confetti-fall var(--duration, 1800ms) ease-out forwards;
  will-change: transform, opacity;
  border-radius: 2px;
  mix-blend-mode: multiply;
}

.confetti[data-shape='circle'] {
  border-radius: 999px;
}

.confetti[data-shape='strip'] {
  border-radius: 6px;
}

@keyframes confetti-fall {
  0% {
    transform: translate3d(0, -40vh, 0) rotateZ(0deg);
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  60% {
    opacity: 0.95;
  }
  100% {
    transform: translate3d(var(--x, 0px), 115vh, 0) rotateZ(var(--rotation, 180deg));
    opacity: 0;
  }
}

@media (max-width: 640px) {
  .app {
    padding: 24px 12px 48px;
  }

  .app__content {
    grid-template-columns: 1fr;
  }

  .browser {
    max-height: none;
  }

  .question-card {
    padding: 20px;
  }

  .scoreboard__value {
    font-size: 1.4rem;
  }

  .answer-form__actions {
    flex-direction: column;
  }

  .answer-form__actions-right {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .answer-form__actions-right .button {
    width: 100%;
  }
}

html.is-iphone body {
  background: #f7f9fc;
}

html.is-iphone .app {
  max-width: none;
  padding: 20px 16px 96px;
}

html.is-iphone .app__header {
  text-align: left;
  margin-bottom: 24px;
}

html.is-iphone .app__header-actions {
  gap: 10px;
}

html.is-iphone .language-toggle {
  padding: 6px 14px;
  font-size: 1.4rem;
}

html.is-iphone .app__title {
  font-size: 1.8rem;
  gap: 10px;
}

html.is-iphone .dataset-menu {
  right: 0;
  left: auto;
}

@media (max-width: 768px) {
  .app__header-row {
    justify-content: space-between;
  }

  .app__header-actions {
    margin-left: 0;
  }
}

html.is-iphone h1 {
  font-size: 1.9rem;
}


html.is-iphone .scoreboard {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  overflow-x: auto;
  padding-bottom: 6px;
  scroll-snap-type: x mandatory;
}

html.is-iphone .scoreboard__item {
  min-width: 140px;
  scroll-snap-align: start;
}

html.is-iphone .app__content {
  display: block;
  margin-bottom: 24px;
}

html.is-iphone .question-card {
  padding: 22px 20px;
  border-radius: 22px;
  box-shadow: 0 16px 40px rgba(16, 22, 37, 0.15);
}

html.is-iphone .question-card__body {
  margin-top: 20px;
}

html.is-iphone .question-card__text {
  font-size: 1.08rem;
  line-height: 1.55;
}

html.is-iphone .mobile-browser-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 0.94rem;
  border-radius: 999px;
}

html.is-iphone .answer-form__input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1.05rem;
}

html.is-iphone .answer-form__input-wrapper {
  align-items: stretch;
  gap: 12px;
}

html.is-iphone .calculator__toggle {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
}

html.is-iphone .answer-form__label-row {
  gap: 10px;
}

html.is-iphone .answer-form__label {
  flex: 1;
}

html.is-iphone .button--icon {
  padding: 10px 14px;
  font-size: 0.9rem;
}

html.is-iphone .answer-form__options {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

html.is-iphone .answer-form__options.answer-form__options--provided {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

html.is-iphone .choice {
  padding: 14px 16px;
}

html.is-iphone .answer-form__actions {
  flex-direction: column;
  align-items: stretch;
}

html.is-iphone .answer-form__actions-left,
html.is-iphone .answer-form__actions-right {
  display: flex;
  gap: 10px;
}

html.is-iphone .answer-form__actions-left .button,
html.is-iphone .answer-form__actions-right .button {
  flex: 1 1 auto;
  justify-content: center;
}

html.is-iphone .history {
  margin-top: 32px;
}

html.is-iphone .history__header {
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}

html.is-iphone .history__header > div {
  width: 100%;
  justify-content: space-between;
}

html.is-iphone .browser {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -16px 40px rgba(16, 22, 37, 0.2);
  padding: 22px 20px 28px;
  max-height: 78vh;
  transform: translateY(calc(100% + 32px));
  transition: transform 0.3s ease;
  z-index: 900;
  background: #ffffff;
  pointer-events: none;
}

html.is-iphone .browser__header {
  flex-wrap: nowrap;
  align-items: center;
}

html.is-iphone .browser__pagination {
  width: 100%;
  margin-left: 0;
  justify-content: space-between;
}

html.is-iphone .browser__close {
  display: inline-flex;
  margin-left: auto;
}

html.is-iphone .browser__list {
  margin-top: 12px;
  max-height: none;
  overflow-y: auto;
}

html.is-iphone .mobile-browser-scrim {
  display: none;
}

html.is-iphone.browser-open .browser {
  transform: translateY(0);
  pointer-events: auto;
}

html.is-iphone.browser-open .mobile-browser-scrim {
  display: block;
}

html.is-iphone.browser-open body {
  overflow: hidden;
}
