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

:root {
  --bg: #1a1a2e;
  --bg-light: #16213e;
  --bg-card: #0f3460;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --text: #eaeaea;
  --text-dim: #a0a0b0;
  --correct: #2ecc71;
  --incorrect: #e74c3c;
  --border-radius: 12px;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

@font-face {
  font-family: 'Ponomar';
  src: url('Ponomar-Regular.woff') format('woff');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  height: 100%;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.screen {
  display: none;
  height: 100%;
  overflow-y: auto;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* MENU */
.menu-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px;
}

.logo {
  font-size: 3.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #ff9a56);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.subtitle {
  color: var(--text-dim);
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.ticker-wrap {
  overflow: hidden;
  width: 100%;
  margin-bottom: 32px;
}

#btn-start {
  margin-bottom: 8px;
}

.lang-select {
  background: var(--bg-light);
  color: var(--text);
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.95rem;
  cursor: pointer;
  width: 100%;
  max-width: 320px;
}

.ticker {
  display: inline-block;
  white-space: nowrap;
  color: var(--text-dim);
  font-size: 1.05rem;
  font-family: monospace;
  animation: ticker-scroll 40s linear infinite;
  padding-left: 100%;
}

@keyframes ticker-scroll {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

/* BUTTONS */
.btn {
  display: block;
  width: 100%;
  padding: 14px 24px;
  border: none;
  border-radius: var(--border-radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.1s;
  text-align: center;
}

.btn:active {
  transform: scale(0.97);
  opacity: 0.9;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
}

.btn-large {
  padding: 18px 32px;
  font-size: 1.2rem;
  max-width: 320px;
  margin: 0 auto;
}

/* SETUP */
.setup-container {
  padding: 24px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
  padding-bottom: 100px;
}

.setup-container h2 {
  margin-bottom: 20px;
}

.setup-section {
  margin-bottom: 28px;
}

.setup-section h3 {
  color: var(--text-dim);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.system-group {
  margin-bottom: 28px;
}

.system-group h3 {
  color: var(--text-dim);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.option-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.option-btn {
  padding: 14px 12px;
  background: var(--bg-light);
  border: 2px solid transparent;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.option-btn.selected {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.15);
}

.option-btn:active {
  transform: scale(0.97);
}

#btn-play {
  margin-top: 16px;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

#btn-options-back {
  margin-top: 12px;
}

#btn-setup-back, #btn-config-back {
  margin-top: 12px;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

/* GAME */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: var(--bg-light);
  flex-shrink: 0;
  position: relative;
}

.score-display {
  font-size: 1.2rem;
  font-weight: 700;
}

#score-system {
  margin-left: 8px;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.timer-area {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  visibility: hidden;
}

.timer-area.visible {
  visibility: visible;
}

.timer-label {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.timer-display {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 60px;
  text-align: right;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-stop {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.btn-stop:active {
  background: var(--accent);
  color: white;
}

.timer-display.urgent {
  color: var(--incorrect);
  animation: pulse 0.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.game-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 20px;
  overflow-y: auto;
}

.number-display {
  font-size: 2.8rem;
  font-weight: 800;
  text-align: center;
  padding: 32px 20px;
  margin: 16px 0;
  background: var(--bg-card);
  border-radius: var(--border-radius);
  width: 100%;
  max-width: 400px;
  word-break: break-all;
  line-height: 1.3;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.number-display.small-text {
  font-size: 1.6rem;
}

.slavonic-font {
  font-family: 'Ponomar', serif;
}

.number-display.slavonic-font {
  font-size: 3.2rem;
}

.answer-feedback {
  min-height: 40px;
  font-size: 1.1rem;
  font-weight: 600;
  text-align: center;
  margin: 8px 0;
  transition: opacity 0.2s;
}

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

.answer-feedback.incorrect {
  color: var(--incorrect);
}

/* CHOICES */
.choice-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 400px;
  margin-top: 16px;
}

.choice-btn {
  padding: 18px 20px;
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: var(--border-radius);
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.choice-btn:active {
  transform: scale(0.98);
}

.choice-btn.correct-choice {
  border-color: var(--correct);
  background: rgba(46, 204, 113, 0.15);
}

.choice-btn.incorrect-choice {
  border-color: var(--incorrect);
  background: rgba(231, 76, 60, 0.15);
}

.choice-btn:disabled {
  opacity: 0.7;
  cursor: default;
}

/* NUMPAD */
.numpad-area {
  width: 100%;
  max-width: 360px;
  margin-top: 16px;
}

.numpad-input {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  padding: 16px;
  background: var(--bg-card);
  border-radius: 8px;
  min-height: 60px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 2px;
  overflow: hidden;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.numpad-key {
  padding: 18px;
  background: var(--bg-light);
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 1.4rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.1s;
}

.numpad-key:active {
  background: var(--bg-card);
}

.numpad-action {
  background: var(--bg-card);
  color: var(--text-dim);
}

#btn-submit-answer {
  max-width: 320px;
  margin: 0 auto;
}

.hidden {
  display: none !important;
}

#btn-next {
  margin-top: 16px;
  max-width: 320px;
}

/* RESULTS */
.results-container {
  padding: 24px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
  padding-bottom: 100px;
  position: relative;
}

.results-container h2 {
  margin-bottom: 16px;
}

.results-summary {
  font-size: 1.2rem;
  margin-bottom: 24px;
  padding: 20px;
  background: var(--bg-card);
  border-radius: var(--border-radius);
  text-align: center;
}

.results-summary .big-number {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--accent);
}

.results-congrats {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--correct);
  margin-bottom: 16px;
  min-height: 48px;
}

.results-mistakes-label {
  color: var(--text-dim);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-light);
  border-radius: 8px;
  border-left: 4px solid var(--incorrect);
}

.result-system {
  font-size: 1.4rem;
  font-weight: 700;
  flex-shrink: 0;
  min-width: 80px;
  word-break: break-all;
}

.result-arrow {
  color: var(--text-dim);
  flex-shrink: 0;
}

.result-decimal {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--correct);
}

.no-mistakes {
  text-align: center;
  color: var(--correct);
  font-size: 1.2rem;
  padding: 32px;
}

#btn-play-again {
  max-width: 320px;
  margin: 0 auto 12px;
}

#btn-results-menu {
  max-width: 320px;
  margin: 0 auto;
}

.setup-message {
  display: none;
  background: var(--accent);
  color: white;
  padding: 14px 20px;
  border-radius: var(--border-radius);
  font-weight: 600;
  text-align: center;
  margin-bottom: 16px;
  animation: fadeIn 0.2s;
}

.setup-message.visible {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.confetti-burst {
  position: absolute;
  pointer-events: none;
}

.confetti-particle {
  position: absolute;
  font-size: 1.4rem;
  animation: confetti-fly 0.8s ease-out forwards;
}

@keyframes confetti-fly {
  0% {
    transform: translate(0, 0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate(var(--dx), var(--dy)) rotate(var(--rot));
    opacity: 0;
  }
}
