/* ===================================
   Game Screen Styles (Dark Mode)
   =================================== */

.game-page {
  background: var(--color-game-bg);
  color: var(--color-game-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.game-screen-flex {
  flex: 1;
  flex-direction: column;
}

/* Game Header */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.game-header-back {
  color: var(--color-game-text);
  font-size: var(--text-sm);
  opacity: 0.7;
  transition: opacity 0.2s;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.game-header-back:hover {
  opacity: 1;
  color: var(--color-game-text);
}

.game-header-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
}

.game-header-level {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-accent);
}

/* Game Body */
.game-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* Timer Bar */
.timer-section {
  width: 100%;
  margin-bottom: var(--space-8);
}

.timer-bar-container {
  width: 100%;
  height: 8px;
  background: var(--color-game-surface);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: var(--space-2);
}

.timer-bar {
  height: 100%;
  background: var(--color-accent);
  border-radius: var(--radius-full);
  transition: width 1s linear;
}

.timer-bar.warning {
  background: var(--color-warning);
}

.timer-bar.danger {
  background: var(--color-error);
}

.timer-text {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-align: right;
}

/* Problem Card */
.problem-card {
  background: var(--color-game-surface);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-xl);
  padding: var(--space-12) var(--space-8);
  width: 100%;
  text-align: center;
  margin-bottom: var(--space-6);
  transition: background 0.3s;
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.problem-expression {
  font-family: var(--font-display);
  font-size: clamp(3rem, 10vw, 6rem);
  font-weight: 700;
  color: var(--color-game-text);
  letter-spacing: 0.05em;
}

.problem-card.correct {
  background: rgba(22, 163, 74, 0.25);
}

.problem-card.wrong {
  background: rgba(220, 38, 38, 0.25);
}

/* Instruction Text */
.game-instruction {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  text-align: center;
  margin-bottom: var(--space-6);
  min-height: 1.5em;
}

.game-instruction.memorize {
  color: var(--color-warning);
  font-weight: 500;
}

/* Number Pad */
.number-pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-3);
  width: 100%;
  max-width: 400px;
  margin-bottom: var(--space-6);
}

.num-btn {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 600;
  padding: var(--space-4);
  background: var(--color-game-surface);
  color: var(--color-game-text);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.num-btn:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.2);
}

.num-btn:active {
  transform: scale(0.95);
  background: rgba(255,255,255,0.18);
}

.num-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.num-btn:disabled:hover {
  background: var(--color-game-surface);
  border-color: rgba(255,255,255,0.1);
}

.num-btn:disabled:active {
  transform: none;
}

/* Score Display */
.game-score {
  display: flex;
  justify-content: center;
  gap: var(--space-8);
  font-family: var(--font-display);
  font-size: var(--text-base);
  color: var(--color-text-muted);
}

.game-score span {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.score-value {
  font-weight: 600;
  color: var(--color-game-text);
}

/* Feedback Text */
.feedback-text {
  font-size: var(--text-sm);
  text-align: center;
  min-height: 1.5em;
  margin-bottom: var(--space-2);
}

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

.feedback-text.wrong-fb {
  color: var(--color-error);
}

/* ===================================
   Start Screen (within game page)
   =================================== */
.game-start-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: var(--space-8);
  text-align: center;
}

.game-start-n {
  font-family: var(--font-display);
  font-size: var(--text-hero);
  font-weight: 700;
  color: var(--color-accent);
  margin-bottom: var(--space-2);
}

.game-start-label {
  font-size: var(--text-lg);
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
}

.n-selector {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  margin-bottom: var(--space-8);
}

.n-selector-btn {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--color-game-surface);
  color: var(--color-game-text);
  border: 1px solid rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.n-selector-btn:hover {
  background: rgba(255,255,255,0.12);
}

.n-selector-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.game-start-btn {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  padding: var(--space-4) var(--space-16);
  background: var(--color-accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(45, 108, 223, 0.3);
}

.game-start-btn:hover {
  background: var(--color-accent-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(45, 108, 223, 0.4);
}

.game-start-best {
  margin-top: var(--space-6);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ===================================
   Result Screen
   =================================== */
.result-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: var(--space-8);
  text-align: center;
}

.result-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.result-n-level {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--color-accent);
  margin-bottom: var(--space-8);
}

.result-score-label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

.result-score {
  font-family: var(--font-display);
  font-size: clamp(3.5rem, 12vw, 6rem);
  font-weight: 700;
  color: var(--color-accent);
  margin-bottom: var(--space-6);
  line-height: 1;
}

.result-score-unit {
  font-size: 0.35em;
  font-weight: 400;
  color: var(--color-text-muted);
  margin-left: 0.1em;
}

.result-sub-stats {
  display: flex;
  gap: var(--space-8);
  margin-bottom: var(--space-8);
}

.result-sub-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.result-sub-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.result-sub-value {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--color-game-text);
}

.result-sub-value.high {
  color: var(--color-success);
}

.result-sub-value.low {
  color: var(--color-error);
}

.result-sub-value.mid {
  color: var(--color-warning);
}

.result-best-section {
  width: 100%;
  max-width: 400px;
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: var(--space-6);
  margin-bottom: var(--space-6);
}

.result-best-title {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: var(--space-4);
}

.result-best-list {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.result-best-item {
  display: flex;
  justify-content: space-between;
  padding: var(--space-2) 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.result-best-item .rank {
  color: var(--color-text-muted);
  min-width: 2em;
}

.result-best-item .best-score {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--color-accent);
  min-width: 3.5em;
}

.result-best-item .accuracy {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--color-game-text);
}

.result-best-item .n-info {
  color: var(--color-accent);
}

.result-best-item .date {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.result-new-best {
  display: inline-block;
  background: var(--color-warning);
  color: #ffffff;
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  margin-left: var(--space-2);
}

.result-level-message {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--space-8);
}

.result-level-message.up {
  color: var(--color-success);
}

.result-level-message.down {
  color: var(--color-error);
}

.result-level-message.keep {
  color: var(--color-text-muted);
}

.result-actions {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
  justify-content: center;
}

.result-actions .btn {
  min-width: 160px;
}

/* ===================================
   Memory Grid Game
   =================================== */

.mg-start-icon {
  font-size: 4rem;
  margin-bottom: var(--space-4);
}

.mg-level-info {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

.mg-round-progress {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-align: center;
  margin-bottom: var(--space-4);
}

.mg-grid-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: var(--space-6);
  width: 100%;
}

.mg-grid {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}

.mg-cell {
  background: var(--color-game-surface);
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  box-sizing: border-box;
  padding: 0;
  min-height: 0;
  overflow: hidden;
  /* JS will set explicit width/height */
}

.mg-cell.disabled {
  cursor: default;
  pointer-events: none;
}

.mg-cell:not(.disabled):hover {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
}

.mg-cell:not(.disabled):active {
  transform: scale(0.92);
}

/* Flash pulse animation for sequential lighting */
@keyframes cell-flash-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* Lit state — shown during memorize phase (sequential flash) */
.mg-cell.lit {
  background: var(--color-accent);
  border-color: var(--color-accent);
  box-shadow: 0 0 20px rgba(45, 108, 223, 0.6), 0 0 40px rgba(45, 108, 223, 0.2);
  animation: cell-flash-pulse 0.7s ease-in-out;
}

/* Selected by user during answer phase */
.mg-cell.selected {
  background: var(--color-accent);
  border-color: var(--color-accent-light);
  box-shadow: 0 0 12px rgba(45, 108, 223, 0.4);
}

/* Feedback states */
.mg-cell.correct {
  background: var(--color-success);
  border-color: var(--color-success);
  box-shadow: 0 0 12px rgba(22, 163, 74, 0.4);
}

.mg-cell.wrong {
  background: var(--color-error);
  border-color: var(--color-error);
  box-shadow: 0 0 12px rgba(220, 38, 38, 0.4);
}

.mg-cell.missed {
  background: transparent;
  border: 2px dashed var(--color-warning);
  box-shadow: 0 0 8px rgba(217, 119, 6, 0.3);
}

/* Submit section */
.mg-submit-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.mg-submit-btn {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  padding: var(--space-3) var(--space-12);
  background: var(--color-accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(45, 108, 223, 0.3);
}

.mg-submit-btn:hover {
  background: var(--color-accent-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(45, 108, 223, 0.4);
}

.mg-submit-btn:active {
  transform: translateY(0);
}

.mg-selection-count {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ===================================
   Responsive
   =================================== */
@media (max-width: 480px) {
  .game-header {
    padding: var(--space-3) var(--space-4);
  }

  .game-body {
    padding: var(--space-4);
  }

  .number-pad {
    gap: var(--space-2);
  }

  .num-btn {
    padding: var(--space-3);
    font-size: var(--text-xl);
  }

  .problem-card {
    padding: var(--space-8) var(--space-4);
    min-height: 120px;
  }

  .n-selector {
    gap: var(--space-4);
  }

  .mg-grid {
    max-width: 280px;
    gap: 4px;
  }

  .mg-cell {
    border-radius: var(--radius-sm);
  }

  .mg-grid-wrapper {
    margin-bottom: var(--space-4);
  }
}
