:root {
  --primary: #4cae4f;
  --danger: #e25555;
  --success: #2fa764;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body,
.screen {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

body::-webkit-scrollbar,
.screen::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.screen {
  display: none;
  min-height: 100vh;
}

.screen.active {
  display: block;
}

.hidden {
  display: none !important;
}

.loader {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 4px solid rgba(76, 174, 79, 0.18);
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

.muted {
  color: #94a3b8;
  font-size: 14px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.primary-btn,
.secondary-btn {
  flex: 1;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  border: none;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
}

.secondary-btn {
  background: rgba(76, 174, 79, 0.12);
  color: var(--primary);
}

.progress {
  height: 8px;
  width: 100%;
  border-radius: 999px;
  background: rgba(76, 174, 79, 0.2);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #54bc58 0%, #35a95f 100%);
  transition: width 0.2s ease;
}

.choice {
  border: 2px solid transparent;
  background: #fff;
  color: inherit;
}

.choice-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border-radius: 16px;
  box-shadow: 0 8px 16px rgba(76, 174, 79, 0.08);
}

.choice-pill {
  padding: 12px 0;
  border-radius: 999px;
  font-weight: 700;
  background: rgba(76, 174, 79, 0.1);
}

.choice-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 8px 16px rgba(76, 174, 79, 0.08);
}

.choice.selected,
.choice:hover {
  border-color: var(--primary);
  background: rgba(76, 174, 79, 0.08);
}

body.dark .choice,
body.dark .choice-row,
body.dark .choice-card {
  background: rgba(30, 41, 59, 0.7);
  color: #e2e8f0;
}

body.dark .choice-pill {
  background: rgba(76, 174, 79, 0.18);
}

.segmented {
  display: flex;
  gap: 6px;
  background: rgba(76, 174, 79, 0.12);
  padding: 6px;
  border-radius: 999px;
}

.segmented-btn {
  flex: 1;
  border-radius: 999px;
  padding: 10px 12px;
  font-weight: 700;
  background: transparent;
}

.segmented-btn.selected {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.theme-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border-radius: 12px;
}

.toggle-track {
  width: 44px;
  height: 24px;
  background: #e2e8f0;
  border-radius: 999px;
  position: relative;
  transition: background 0.2s ease;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #fff;
  transition: transform 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

#soundToggle:checked + .toggle-track {
  background: var(--primary);
}

#soundToggle:checked + .toggle-track::after {
  transform: translateX(20px);
}

.feedback-area {
  min-height: 32px;
  font-weight: 700;
  font-size: 22px;
  color: var(--primary);
  text-align: center;
}

.feedback-area.correct {
  color: var(--success);
}

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

.feedback-area.muted {
  color: #94a3b8;
  font-weight: 600;
  font-size: 14px;
}

#keyboard button {
  height: 64px;
  border-radius: 999px;
  border: none;
  font-size: 24px;
  font-weight: 700;
  background: #f6f7f6;
  color: #1f2937;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

body.dark #keyboard button {
  background: #27272a;
  color: #f8fafc;
}

#keyboard button:active {
  transform: scale(0.96);
}

#keyboard .key-back {
  background: rgba(239, 68, 68, 0.12);
  color: #dc2626;
}

#keyboard .key-submit {
  background: var(--primary);
  color: #fff;
  font-size: 28px;
  box-shadow: 0 10px 20px rgba(76, 174, 79, 0.25);
}

#trainingScreen #questionText {
  font-size: clamp(42px, 10vw, 80px);
}

#trainingScreen #answerDisplayText {
  font-size: clamp(32px, 8vw, 64px);
}

@media (max-height: 720px) {
  #trainingScreen main {
    padding-top: 16px;
    padding-bottom: 16px;
    gap: 14px;
  }

  #trainingScreen #questionCard {
    max-width: 320px;
  }

  #trainingScreen .keyboard-panel {
    padding: 16px;
  }

  #trainingScreen #keyboard button {
    height: 52px;
    font-size: 20px;
  }

  #trainingScreen #keyboard .key-submit {
    font-size: 24px;
  }
}

#trainingScreen .training-shell {
  min-height: 100dvh;
}

#trainingScreen .training-main {
  min-height: 0;
}

#trainingScreen #questionCard {
  width: min(92vw, 360px);
  aspect-ratio: 1 / 1;
}

@media (max-width: 430px) {
  #trainingScreen header {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  #trainingScreen .training-main {
    justify-content: flex-start;
    padding-top: 10px;
    padding-bottom: 8px;
    gap: 10px;
  }

  #trainingScreen #questionCard {
    width: min(76vw, 240px);
    height: clamp(160px, 24vh, 210px);
    aspect-ratio: auto;
  }

  #trainingScreen #questionText {
    font-size: 58px;
  }

  #trainingScreen #answerDisplayText {
    font-size: 42px;
  }

  #trainingScreen .keyboard-panel {
    padding: 10px;
  }

  #keyboard {
    gap: 6px;
  }

  #keyboard button {
    height: 40px;
    font-size: 18px;
  }

  #keyboard .key-submit {
    font-size: 20px;
  }
}

@media (max-height: 740px), (max-width: 420px) {
  #trainingScreen .training-main {
    padding-top: 14px;
    padding-bottom: 14px;
    gap: 14px;
  }

  #trainingScreen #questionCard {
    width: min(78vw, 250px);
    height: clamp(165px, 24vh, 220px);
    aspect-ratio: auto;
  }

  #trainingScreen #questionText {
    font-size: 64px;
  }

  #trainingScreen #answerDisplayText {
    font-size: 48px;
  }

  #trainingScreen .keyboard-panel {
    padding: 16px;
  }

  #keyboard button {
    height: 52px;
    font-size: 22px;
  }

  #keyboard .key-submit {
    font-size: 24px;
  }
}

@media (max-height: 640px) {
  #trainingScreen #questionCard {
    width: min(72vw, 230px);
    height: clamp(150px, 22vh, 200px);
    aspect-ratio: auto;
  }

  #trainingScreen #questionText {
    font-size: 56px;
  }

  #trainingScreen #answerDisplayText {
    font-size: 42px;
  }

  #keyboard button {
    height: 38px;
    font-size: 17px;
  }
}

@media (max-height: 600px) {
  #trainingScreen header {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  #trainingScreen .training-main {
    padding-top: 12px;
    padding-bottom: 12px;
    gap: 10px;
  }

  #trainingScreen #questionCard {
    width: min(70vw, 220px);
    height: clamp(140px, 20vh, 190px);
    aspect-ratio: auto;
  }

  #trainingScreen #questionText {
    font-size: 50px;
  }

  #trainingScreen #answerDisplayText {
    font-size: 38px;
  }

  #trainingScreen .keyboard-panel {
    padding: 12px;
  }

  #keyboard {
    gap: 8px;
  }

  #keyboard button {
    height: 34px;
    font-size: 15px;
  }

  #keyboard .key-submit {
    font-size: 18px;
  }
}

@media (max-height: 520px) {
  #trainingScreen header {
    padding-top: 6px;
    padding-bottom: 6px;
  }

  #trainingScreen .training-main {
    flex: 0 0 auto;
  }

  #trainingScreen #questionCard {
    width: min(64vw, 190px);
    height: clamp(130px, 18vh, 170px);
    aspect-ratio: auto;
  }

  #trainingScreen #questionText {
    font-size: 44px;
  }

  #trainingScreen #answerDisplayText {
    font-size: 34px;
  }

  #keyboard button {
    height: 32px;
    font-size: 14px;
  }

  #keyboard .key-submit {
    font-size: 16px;
  }

  #keyboard {
    gap: 6px;
  }
}

@media (max-width: 430px), (max-height: 820px) {
  #trainingScreen header {
    padding-top: clamp(6px, 1.2vh, 10px);
    padding-bottom: clamp(6px, 1.2vh, 10px);
  }

  #trainingScreen .training-main {
    justify-content: flex-start;
    padding-top: clamp(8px, 1.6vh, 14px);
    padding-bottom: clamp(6px, 1.2vh, 12px);
    gap: clamp(8px, 1.6vh, 12px);
  }

  #trainingScreen #questionCard {
    width: min(78vw, 260px);
    height: clamp(150px, 24vh, 230px);
    aspect-ratio: auto;
  }

  #trainingScreen #questionText {
    font-size: clamp(40px, 8vh, 62px);
  }

  #trainingScreen #answerDisplayText {
    font-size: clamp(30px, 6vh, 48px);
  }

  #trainingScreen .keyboard-panel {
    padding: clamp(8px, 1.6vh, 12px);
  }

  #keyboard {
    gap: clamp(6px, 1.2vh, 8px);
  }

  #keyboard button {
    height: clamp(32px, 6vh, 46px);
    font-size: clamp(15px, 3.2vh, 20px);
  }

  #keyboard .key-submit {
    font-size: clamp(16px, 3.4vh, 22px);
  }
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 40;
}

.modal-card {
  background: #fff;
  border-radius: 18px;
  padding: 20px;
  width: min(360px, 100%);
  text-align: center;
  box-shadow: 0 24px 50px rgba(15, 23, 42, 0.25);
}

body.dark .modal-card {
  background: #1f2937;
  color: #e2e8f0;
}

.modal-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.12);
  color: #dc2626;
  display: grid;
  place-items: center;
}

.modal .actions {
  display: flex;
  gap: 8px;
}

.modal button {
  flex: 1;
  border-radius: 999px;
  padding: 10px 12px;
  border: none;
  font-weight: 700;
}

.modal .secondary {
  background: #f1f5f9;
  color: #475569;
}

.modal .danger {
  background: #dc2626;
  color: #fff;
}

.reward-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

#resultScreen {
  position: relative;
}

#resultScreen > *:not(.reward-canvas) {
  position: relative;
  z-index: 2;
}

.checkin-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.checkin-weekday {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: rgba(76, 174, 79, 0.6);
  padding: 6px 0;
}

.checkin-cell {
  height: 40px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 600;
  color: #334155;
  background: transparent;
}

body.dark .checkin-cell {
  color: #cbd5f5;
}

.checkin-cell.done {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 8px 16px rgba(76, 174, 79, 0.2);
}

.checkin-cell.today {
  border: 2px solid var(--primary);
}

.checkin-cell.future {
  color: #cbd5f5;
}

.checkin-cell.empty {
  background: transparent;
}

.pulse-correct {
  animation: pulseGlow 0.5s ease;
}

.shake-error {
  animation: shake 0.35s ease;
}

@keyframes pulseGlow {
  0% { box-shadow: 0 0 0 0 rgba(76, 174, 79, 0.4); }
  100% { box-shadow: 0 0 0 12px rgba(76, 174, 79, 0); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
