:root {
  --color-player: #4a90d9;
  --color-computer: #e87c3e;
  --color-correct: #27ae60;
  --color-incorrect: #e74c3c;
  --color-ocean: #1b4f72;
  --color-bg: #f4f8fc;
  --color-surface: #ffffff;
  --color-text: #1c2735;
  --color-muted: #5f6f81;
  --color-border: #ced8e3;
}

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

html,
body {
  width: 100%;
  height: 100%;
}

body {
  min-width: 1024px;
  min-height: 768px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--color-text);
  background: linear-gradient(160deg, #eef5ff 0%, #f8fbff 55%, #f0f6ff 100%);
}

.hidden {
  display: none !important;
}

.app-shell {
  width: 100%;
  height: 100%;
}

.screen {
  width: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.3s ease-in;
}

.screen.active {
  opacity: 1;
}

#screen-start,
#screen-result {
  max-width: 980px;
  margin: 0 auto;
}

#screen-start h1,
#screen-result h2 {
  font-size: 40px;
  line-height: 1.2;
  text-align: center;
}

.panel {
  width: min(900px, 100%);
  padding: 16px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background-color: var(--color-surface);
}

.panel-title {
  margin-bottom: 8px;
  font-size: 22px;
}

.panel p + p {
  margin-top: 8px;
}

.settings-preview {
  font-size: 18px;
}

.language-switch {
  display: flex;
  gap: 10px;
}

.language-switch-global {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 1100;
  padding: 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--color-border);
  backdrop-filter: blur(2px);
}

.lang-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
  border: 2px solid #c6cfdb;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.2s ease;
}

.btn {
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease, background-color 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.btn:focus-visible,
.answer-btn:focus-visible {
  outline: 3px solid var(--color-player);
  outline-offset: 2px;
}

button:focus-visible {
  outline: 3px solid var(--color-player);
  outline-offset: 2px;
}

.btn-primary {
  color: #ffffff;
  background-color: var(--color-player);
  border-color: var(--color-player);
}

.btn-secondary {
  color: var(--color-text);
  background-color: #ffffff;
}

.lang-btn.active,
.lang-btn.is-active {
  color: #ffffff;
  background-color: var(--color-player);
  border-color: var(--color-player);
}

#screen-game {
  align-items: stretch;
  height: 100vh;
  min-height: 768px;
  max-height: 100vh;
  justify-content: stretch;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

#map-container {
  width: 100%;
  flex: 0 0 40%;
  min-height: 220px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  overflow: hidden;
}

#score-bar {
  padding: 8px 12px;
  font-size: 18px;
  background-color: rgba(255, 255, 255, 0.9);
  border-top: 1px solid var(--color-border);
}

#task-container {
  width: 100%;
  flex: 1 1 60%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background-color: var(--color-surface);
  transition: opacity 0.3s ease-in, transform 0.3s ease-in, background-color 0.5s ease-out;
}

#task-container.task-entering {
  opacity: 0;
  transform: translateY(10px);
}

#task-question {
  min-height: 56px;
  font-size: clamp(24px, 3.2vh, 30px);
  line-height: 1.2;
  text-align: center;
}

#answers-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.answer-btn {
  min-height: 52px;
  border: 2px solid #dddddd;
  border-radius: 8px;
  padding: 8px;
  background-color: #ffffff;
  color: var(--color-text);
  font-size: clamp(18px, 2.3vh, 20px);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transform: translateY(0);
  transition: background-color 0.3s, transform 0.1s, border-color 0.3s;
}

.answer-btn:hover:not(.disabled) {
  background-color: #f0f0f0;
  transform: scale(1.02);
}

.answer-btn.answer-enter {
  opacity: 0;
  transform: translateY(10px);
  animation: fadeInUp 0.3s ease-out forwards;
}

.answer-btn.answer-enter:nth-child(1) { animation-delay: 0.05s; }
.answer-btn.answer-enter:nth-child(2) { animation-delay: 0.1s; }
.answer-btn.answer-enter:nth-child(3) { animation-delay: 0.15s; }
.answer-btn.answer-enter:nth-child(4) { animation-delay: 0.2s; }
.answer-btn.answer-enter:nth-child(5) { animation-delay: 0.25s; }
.answer-btn.answer-enter:nth-child(6) { animation-delay: 0.3s; }

.answer-btn:active:not(.disabled) {
  transform: scale(0.95) !important;
}

.answer-btn.disabled {
  cursor: default;
  opacity: 0.8;
}

.answer-correct,
.answer-btn.is-correct {
  background-color: #27ae60 !important;
  color: #ffffff;
  border-color: #1e8449;
}

.answer-incorrect,
.answer-btn.is-incorrect {
  background-color: #e74c3c !important;
  color: #ffffff;
  border-color: #c0392b;
}

@keyframes fadeInUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#timer-wrapper {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#timer-bar {
  width: 100%;
  height: 6px;
  background: #e0e0e0;
  border-radius: 4px;
  overflow: hidden;
  margin: 4px 0;
}

#timer-bar-fill {
  width: 0;
  height: 100%;
  border-radius: 4px;
  transition: width 1s linear;
}

.timer-green {
  background-color: #27ae60;
}

.timer-yellow {
  background-color: #f39c12;
}

.timer-red {
  background-color: #e74c3c;
}

#timer-text {
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}

.timer-pulse {
  animation: pulse 0.5s ease-in-out infinite alternate;
}

@keyframes pulse {
  from {
    opacity: 1;
  }

  to {
    opacity: 0.3;
  }
}

.fraction {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 4px;
  position: relative;
}

.fraction-num {
  padding: 0 6px 2px;
  border-bottom: 2px solid currentColor;
  line-height: 1.2;
  text-align: center;
}

.fraction-den {
  padding: 2px 6px 0;
  line-height: 1.2;
  text-align: center;
}

.fraction-negative {
  margin-left: 14px;
}

.fraction-sign {
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
}

.mixed-number {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.mixed-whole {
  font-size: inherit;
  vertical-align: middle;
}

.decimal-number,
.integer-number {
  display: inline;
  white-space: nowrap;
}

.task-line {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.task-prefix {
  font-weight: 600;
}

.math-expression {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  vertical-align: middle;
}

.math-expression .fraction {
  margin: 0 2px;
}

.expr-op,
.expr-text,
.expr-paren {
  display: inline-flex;
  align-items: center;
  line-height: 1;
}

.expr-op {
  font-weight: 700;
}

.expr-paren {
  font-weight: 600;
}

.expr-paren-strong {
  font-size: 1.35em;
}

.fraction-size-large .fraction-num,
.fraction-size-large .fraction-den {
  font-size: 24px;
}

.fraction-size-large .fraction-num {
  border-bottom-width: 3px;
}

.fraction-size-large .fraction-sign {
  left: -14px;
  font-size: 24px;
}

.fraction-size-medium .fraction-num,
.fraction-size-medium .fraction-den {
  font-size: 18px;
}

.fraction-size-medium .fraction-num {
  border-bottom-width: 2px;
}

.fraction-size-medium .fraction-sign {
  left: -12px;
  font-size: 18px;
}

.fraction-size-small .fraction-num,
.fraction-size-small .fraction-den {
  font-size: 16px;
}

.fraction-size-small .fraction-num {
  border-bottom-width: 2px;
}

.fraction-size-small .fraction-sign {
  left: -10px;
  font-size: 16px;
}

.decimal-number.math-size-large,
.integer-number.math-size-large,
.mixed-number.math-size-large,
.math-expression.math-size-large,
.math-size-large .expr-op,
.math-size-large .expr-text,
.math-size-large .expr-paren {
  font-size: 24px;
}

.decimal-number.math-size-medium,
.integer-number.math-size-medium,
.mixed-number.math-size-medium,
.math-expression.math-size-medium,
.math-size-medium .expr-op,
.math-size-medium .expr-text,
.math-size-medium .expr-paren {
  font-size: 18px;
}

.decimal-number.math-size-small,
.integer-number.math-size-small,
.mixed-number.math-size-small,
.math-expression.math-size-small,
.math-size-small .expr-op,
.math-size-small .expr-text,
.math-size-small .expr-paren {
  font-size: 16px;
}

.task-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 16px;
  color: var(--color-muted);
}

#feedback {
  margin-top: 0;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 16px;
  max-height: 96px;
  overflow-y: auto;
  background: #edf4ff;
}

#feedback.feedback-with-continue {
  flex: 1 1 auto;
  min-height: 108px;
  max-height: none;
}

#feedback-message {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
}

#feedback p + p {
  margin-top: 6px;
}

#feedback-explanation {
  font-size: 16px;
  line-height: 1.35;
}

#btn-continue-task {
  align-self: flex-end;
  min-width: 164px;
  min-height: 44px;
  margin-top: 6px;
  padding: 10px 20px;
}

@media (max-height: 820px) {
  #screen-game {
    gap: 8px;
    padding: 8px 10px 10px;
  }

  #map-container {
    flex-basis: 38%;
    min-height: 200px;
  }

  #score-bar {
    padding: 6px 10px;
    font-size: 16px;
  }

  #task-container {
    gap: 8px;
    padding: 8px 10px;
  }

  #task-question {
    min-height: 48px;
  }

  .answer-btn {
    min-height: 48px;
  }

  #timer-bar {
    margin: 2px 0;
  }

  #feedback {
    padding: 6px 8px;
    max-height: 84px;
  }

  #feedback.feedback-with-continue {
    min-height: 92px;
    max-height: none;
  }

  #btn-continue-task {
    min-width: 148px;
    margin-top: 4px;
    padding: 8px 16px;
  }
}

.feedback-correct {
  background: #d5f5e3;
  color: #1e8449;
}

.feedback-incorrect {
  background: #fadbd8;
  color: #c0392b;
}

.flash-correct {
  animation: flashGreen 0.5s ease-out;
}

@keyframes flashGreen {
  0% {
    background-color: rgba(39, 174, 96, 0.3);
  }
  100% {
    background-color: transparent;
  }
}

.explanation {
  margin-top: 8px;
  font-size: 16px;
  color: #555555;
}

#screen-result {
  position: relative;
}

#screen-result.result-win {
  background: linear-gradient(180deg, rgba(64, 184, 109, 0.24) 0%, rgba(255, 255, 255, 0.92) 58%);
}

#screen-result.result-lost {
  background: linear-gradient(180deg, rgba(155, 163, 175, 0.3) 0%, rgba(255, 255, 255, 0.92) 58%);
}

#result-title {
  font-size: 44px;
  text-shadow: 0 4px 12px rgba(20, 38, 58, 0.2);
}

.result-subtitle {
  font-size: 20px;
  color: var(--color-muted);
  text-align: center;
}

#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 1000;
}

#stats-panel {
  width: min(960px, 100%);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  background: transparent;
  border: 0;
  padding: 0;
}

#stats-panel p {
  margin: 0;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid #d9e1ea;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  font-size: 18px;
  box-shadow: 0 8px 24px rgba(20, 38, 58, 0.08);
}

#stats-panel p::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 10px;
  flex: 0 0 10px;
}

#stats-panel p:nth-child(1)::before { background: #4a90d9; }
#stats-panel p:nth-child(2)::before { background: #27ae60; }
#stats-panel p:nth-child(3)::before { background: #e74c3c; }
#stats-panel p:nth-child(4)::before { background: #f39c12; }
#stats-panel p:nth-child(5)::before { background: #8857d5; }

#stats-panel p span {
  margin-right: auto;
}

.result-actions {
  display: flex;
  gap: 12px;
}
