@import url('https://fonts.googleapis.com/css2?family=M+PLUS+Rounded+1c:wght@400;700;900&display=swap');

:root {
  --bg-dark: #1a1a2e;
  --bg-darker: #0f0f1a;
  --bg-card: #252545;
  --neon-green: #39ff14;
  --neon-blue: #00d4ff;
  --neon-purple: #b84dff;
  --neon-orange: #ff6b35;
  --neon-pink: #ff2d95;
  --neon-yellow: #ffe600;
  --text-white: #f0f0f0;
  --text-gray: #8888aa;
  --border-radius: 6px;
  --touch-min: 60px;
}

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

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-white);
  min-height: 100dvh;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 20px;
  width: 100%;
}

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

@keyframes glow {
  0%, 100% {
    text-shadow:
      0 0 10px currentColor,
      0 0 20px currentColor,
      0 0 40px currentColor;
  }
  50% {
    text-shadow:
      0 0 20px currentColor,
      0 0 40px currentColor,
      0 0 80px currentColor;
  }
}

@keyframes blockDrop {
  0% {
    transform: translateY(-120px) scale(1.1);
    opacity: 0;
  }
  60% {
    transform: translateY(10px) scale(0.95);
    opacity: 1;
  }
  80% {
    transform: translateY(-5px) scale(1.02);
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes celebrate {
  0% {
    transform: scale(0.5) rotate(-10deg);
    opacity: 0;
  }
  50% {
    transform: scale(1.15) rotate(3deg);
  }
  70% {
    transform: scale(0.95) rotate(-2deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-12px);
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

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

@keyframes confettiFall {
  0% {
    transform: translateY(-10vh) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(110vh) rotate(720deg);
    opacity: 0;
  }
}

@keyframes starTwinkle {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

@keyframes correctFlash {
  0% { opacity: 0; }
  30% { opacity: 0.3; }
  100% { opacity: 0; }
}

#screen-title {
  background: radial-gradient(ellipse at center, #2a2a4e 0%, var(--bg-dark) 70%);
  gap: 20px;
  text-align: center;
}

.title-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.title-logo {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.title-logo-2 {
  margin-top: -4px;
}

.title-block {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  font-size: 2rem;
  font-weight: 900;
  border-radius: var(--border-radius);
  border-bottom: 5px solid;
  animation: float 3s ease-in-out infinite;
}

.title-block-1 { background: var(--neon-green); color: var(--bg-darker); border-bottom-color: #2bcc10; animation-delay: 0s; }
.title-block-2 { background: var(--neon-blue); color: var(--bg-darker); border-bottom-color: #009fcc; animation-delay: 0.1s; }
.title-block-3 { background: var(--neon-purple); color: #fff; border-bottom-color: #8a3acc; animation-delay: 0.2s; }
.title-block-4 { background: var(--neon-orange); color: var(--bg-darker); border-bottom-color: #cc5020; animation-delay: 0.3s; }
.title-block-5 { background: var(--neon-pink); color: #fff; border-bottom-color: #cc2277; animation-delay: 0.4s; }
.title-block-6 { background: var(--neon-yellow); color: var(--bg-darker); border-bottom-color: #ccb800; animation-delay: 0.5s; }
.title-block-7 { background: var(--neon-green); color: var(--bg-darker); border-bottom-color: #2bcc10; animation-delay: 0.6s; }
.title-block-8 { background: var(--neon-blue); color: var(--bg-darker); border-bottom-color: #009fcc; animation-delay: 0.7s; }

.title-sub {
  font-size: 1.1rem;
  color: var(--neon-blue);
  font-weight: 700;
  margin: 8px 0 16px;
}

.btn-large {
  font-size: 1.8rem;
  padding: 20px 60px;
  min-width: 240px;
}

.screen-title-text {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--neon-blue);
  text-shadow: 0 0 10px rgba(0, 212, 255, 0.4);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-min);
  min-width: 200px;
  padding: 16px 40px;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--bg-darker);
  background: var(--neon-green);
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-bottom: 6px solid #2bcc10;
  border-radius: var(--border-radius);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow:
    0 0 15px rgba(57, 255, 20, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  transition: transform 0.1s, box-shadow 0.1s, border-bottom-width 0.1s;
}

.btn-primary:active {
  transform: translateY(4px);
  border-bottom-width: 2px;
  box-shadow:
    0 0 8px rgba(57, 255, 20, 0.3);
}

.btn-primary:disabled {
  background: var(--text-gray);
  border-color: #555;
  border-bottom-color: #444;
  box-shadow: none;
  color: #666;
  cursor: not-allowed;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-min);
  padding: 14px 30px;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-white);
  background: var(--bg-card);
  border: 3px solid var(--neon-blue);
  border-bottom: 5px solid #009fcc;
  border-radius: var(--border-radius);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(0, 212, 255, 0.2);
  transition: transform 0.1s, box-shadow 0.1s, border-bottom-width 0.1s;
}

.btn-secondary:active {
  transform: translateY(3px);
  border-bottom-width: 2px;
  box-shadow: 0 0 5px rgba(0, 212, 255, 0.15);
}

.btn-answer {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  flex: 1;
  padding: 12px 8px;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--text-white);
  background: var(--bg-card);
  border: 3px solid var(--neon-purple);
  border-bottom: 6px solid #8a3acc;
  border-radius: var(--border-radius);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(184, 77, 255, 0.2);
  transition: transform 0.1s, box-shadow 0.1s, border-bottom-width 0.1s, background 0.15s;
}

.btn-answer:active {
  transform: translateY(4px);
  border-bottom-width: 2px;
  box-shadow: 0 0 5px rgba(184, 77, 255, 0.15);
}

.btn-answer.correct {
  background: var(--neon-green);
  color: var(--bg-darker);
  border-color: #2bcc10;
  border-bottom-color: #1fa00d;
  box-shadow: 0 0 25px rgba(57, 255, 20, 0.5);
}

.btn-answer.incorrect {
  background: #ff3333;
  border-color: #cc2222;
  border-bottom-color: #aa1111;
  animation: shake 0.4s ease-in-out;
  box-shadow: 0 0 20px rgba(255, 51, 51, 0.4);
}

.btn-answer:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.answer-grid {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 600px;
  padding: 0 10px;
}

.screen-select {
  gap: 20px;
  padding-top: 40px;
}

.screen-select .select-title {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--neon-blue);
  text-shadow: 0 0 10px rgba(0, 212, 255, 0.4);
}

.building-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  width: 100%;
  max-width: 500px;
  padding: 10px;
}

.building-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px 12px;
  background: var(--bg-card);
  border: 3px solid var(--neon-blue);
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  min-height: 140px;
  position: relative;
  overflow: hidden;
}

.building-card:active {
  transform: scale(0.96);
}

.building-card .card-icon {
  font-size: 3rem;
}

.building-card .card-label {
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
}

.building-card .card-status {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-gray);
}

.building-card.locked {
  border-color: #444;
  opacity: 0.5;
  cursor: not-allowed;
}

.building-card.locked::after {
  content: '🔒';
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 1.4rem;
}

.building-card.in-progress {
  border-color: var(--neon-orange);
  box-shadow: 0 0 15px rgba(255, 107, 53, 0.3);
}

.building-card.in-progress::after {
  content: '🔨';
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 1.4rem;
  animation: float 2s ease-in-out infinite;
}

.building-card.completed {
  border-color: var(--neon-green);
  box-shadow: 0 0 15px rgba(57, 255, 20, 0.2);
}

.building-card.completed::after {
  content: '⭐';
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 1.4rem;
  animation: starTwinkle 2s ease-in-out infinite;
}

#screen-game {
  justify-content: flex-start;
  padding: 10px;
  gap: 0;
  position: relative;
}

.game-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 600px;
  flex: 1;
  gap: 10px;
}

.game-top {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-bottom {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  flex: 1;
  justify-content: center;
}

.building-info {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
}

.building-info span {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--neon-blue);
}

.feedback {
  text-align: center;
  padding: 12px 24px;
  border-radius: var(--border-radius);
  font-size: 1.3rem;
  font-weight: 900;
  animation: celebrate 0.5s ease-out;
}

.feedback-correct {
  color: var(--neon-green);
  text-shadow: 0 0 15px rgba(57, 255, 20, 0.5);
}

.feedback-incorrect {
  color: var(--neon-orange);
  text-shadow: 0 0 15px rgba(255, 107, 53, 0.5);
}

#btn-back-select {
  top: 16px;
  left: 16px;
}

.building-area {
  width: 100%;
  max-width: 600px;
  height: 35vh;
  min-height: 200px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background:
    linear-gradient(to top, #1f1f3a 0%, transparent 30%),
    var(--bg-darker);
  border: 2px solid #333;
  border-radius: var(--border-radius);
  overflow: hidden;
  position: relative;
}

.building-area svg {
  width: 100%;
  height: 100%;
}

.progress-bar {
  width: 100%;
  max-width: 600px;
  height: 28px;
  background: var(--bg-darker);
  border: 2px solid #444;
  border-radius: 14px;
  overflow: hidden;
  position: relative;
  margin: 8px 0;
}

.progress-bar .progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--neon-green), var(--neon-blue));
  border-radius: 12px;
  transition: width 0.5s ease-out;
  position: relative;
}

.progress-bar .progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.2) 50%,
    transparent 100%
  );
  animation: progressShine 2s ease-in-out infinite;
}

@keyframes progressShine {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.progress-bar .progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-white);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  z-index: 1;
}

.problem-section {
  width: 100%;
  max-width: 600px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 10px 0;
}

.problem-display {
  font-size: 3rem;
  font-weight: 900;
  color: var(--neon-yellow);
  text-align: center;
  padding: 20px;
  animation: glow 2.5s ease-in-out infinite;
  letter-spacing: 4px;
  line-height: 1.3;
}

.problem-display .operator {
  color: var(--neon-pink);
}

.problem-display .equals {
  color: var(--neon-blue);
}

.problem-display .question-mark {
  color: var(--neon-orange);
  animation: pulse 1s ease-in-out infinite;
  display: inline-block;
}

.score-display {
  font-size: 1rem;
  color: var(--text-gray);
  font-weight: 700;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 40px 30px;
  text-align: center;
  max-width: 90%;
  width: 360px;
}

.modal-content .modal-icon {
  font-size: 4rem;
  margin-bottom: 10px;
}

.modal-content .modal-title {
  font-size: 1.8rem;
  font-weight: 900;
  margin-bottom: 8px;
}

.modal-content .modal-message {
  font-size: 1rem;
  color: var(--text-gray);
  margin-bottom: 20px;
}

.modal-content.correct-modal {
  border: 3px solid var(--neon-green);
  box-shadow: 0 0 40px rgba(57, 255, 20, 0.3);
}

.modal-content.correct-modal .modal-title {
  color: var(--neon-green);
}

.modal-content.incorrect-modal {
  border: 3px solid var(--neon-orange);
  box-shadow: 0 0 40px rgba(255, 107, 53, 0.3);
}

.modal-content.incorrect-modal .modal-title {
  color: var(--neon-orange);
}

.block-animation {
  animation: blockDrop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.correct-flash {
  position: fixed;
  inset: 0;
  background: var(--neon-green);
  z-index: 90;
  pointer-events: none;
  animation: correctFlash 0.5s ease-out forwards;
}

#screen-complete {
  gap: 20px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.complete-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.complete-title {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--neon-green);
  animation: glow 2s ease-in-out infinite;
}

.complete-name {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--neon-blue);
}

.complete-message {
  font-size: 1.1rem;
  color: var(--neon-yellow);
  font-weight: 700;
}

.building-area-large {
  max-width: 300px;
  height: 250px;
  animation: float 3s ease-in-out infinite;
}

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

.effects-layer .confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  top: -20px;
  animation: confettiFall linear forwards;
}

.effects-layer .confetti:nth-child(odd) {
  border-radius: 50%;
}

.stars-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.stars-container .star {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--text-white);
  border-radius: 50%;
  animation: starTwinkle 3s ease-in-out infinite;
}

#screen-settings {
  gap: 20px;
  padding-top: 40px;
}

.settings-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 400px;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 16px 20px;
  background: var(--bg-card);
  border-radius: var(--border-radius);
}

.setting-label {
  font-size: 1.2rem;
  font-weight: 700;
}

.btn-toggle {
  min-height: 50px;
  min-width: 80px;
  padding: 10px 20px;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 1.1rem;
  font-weight: 900;
  border: 3px solid;
  border-radius: var(--border-radius);
  cursor: pointer;
}

.toggle-on {
  background: var(--neon-green);
  color: var(--bg-darker);
  border-color: #2bcc10;
}

.toggle-off {
  background: var(--bg-darker);
  color: var(--text-gray);
  border-color: #444;
}

.btn-danger {
  min-height: 50px;
  padding: 10px 24px;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  background: #ff3333;
  color: #fff;
  border: 3px solid #cc2222;
  border-bottom: 5px solid #aa1111;
  border-radius: var(--border-radius);
  cursor: pointer;
}

.btn-danger:active {
  transform: translateY(3px);
  border-bottom-width: 2px;
}

.setting-divider {
  border: none;
  border-top: 1px solid #333;
  width: 100%;
}

.setting-hint {
  font-size: 0.85rem;
  color: var(--text-gray);
  margin-top: -12px;
}

.setting-item-danger {
  border: 2px solid #ff3333;
}

.modal-text {
  font-size: 1.3rem;
  font-weight: 900;
  margin-bottom: 20px;
}

.modal-buttons {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal-overlay:not([hidden]) {
  opacity: 1;
  pointer-events: auto;
}

.progress-text {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-gray);
}

.building-card-icon {
  font-size: 3rem;
}

.building-card-name {
  font-size: 1rem;
  font-weight: 700;
}

.building-card-status {
  font-size: 0.85rem;
  color: var(--text-gray);
}

.settings-group {
  width: 100%;
  max-width: 500px;
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 20px;
  margin-bottom: 12px;
}

.settings-group .settings-label {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-gray);
  margin-bottom: 12px;
}

.settings-group .settings-options {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.settings-group .settings-option {
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  padding: 12px 20px;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-white);
  background: var(--bg-darker);
  border: 2px solid #444;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.settings-group .settings-option.selected {
  border-color: var(--neon-purple);
  box-shadow: 0 0 12px rgba(184, 77, 255, 0.3);
  color: var(--neon-purple);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 50px;
  background: var(--bg-card);
  border: 2px solid #444;
  border-radius: var(--border-radius);
  color: var(--text-white);
  font-size: 1.4rem;
  cursor: pointer;
  position: fixed;
  z-index: 50;
}

.btn-icon:active {
  transform: scale(0.92);
}

.btn-settings {
  top: 16px;
  right: 16px;
}

.combo-display {
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--neon-orange);
  text-shadow: 0 0 10px rgba(255, 107, 53, 0.4);
}

.combo-display.combo-active {
  animation: pulse 0.5s ease-in-out;
}

.streak-fire {
  display: inline-block;
  animation: float 1s ease-in-out infinite;
}

@media (max-width: 600px) {
  .problem-display {
    font-size: 2.4rem;
  }

  .btn-answer {
    font-size: 1.5rem;
    min-height: 56px;
  }

  .answer-grid {
    gap: 8px;
  }

  .building-area {
    height: 30vh;
    min-height: 160px;
  }

  .screen-title .app-logo {
    font-size: 2.4rem;
  }

  .building-grid {
    gap: 12px;
  }

  .building-card {
    min-height: 120px;
    padding: 16px 10px;
  }
}

@media (min-width: 601px) and (max-width: 1024px) {
  .building-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .screen-game {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
  }

  .building-area {
    width: 50%;
    height: 70vh;
  }

  .problem-section {
    width: 50%;
    padding: 10px;
  }

  .game-header {
    width: 100%;
    max-width: none;
  }

  .progress-bar {
    max-width: none;
  }
}

@media (orientation: landscape) {
  .screen {
    min-height: 100dvh;
  }

  .building-area {
    height: 40vh;
  }
}

@media (hover: hover) {
  .btn-primary:hover {
    box-shadow:
      0 0 25px rgba(57, 255, 20, 0.5),
      inset 0 1px 0 rgba(255, 255, 255, 0.3);
  }

  .btn-answer:hover {
    background: #303060;
    box-shadow: 0 0 18px rgba(184, 77, 255, 0.3);
  }

  .building-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  }

  .building-card.locked:hover {
    transform: none;
    box-shadow: none;
  }
}
