@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --color-bg: #0c0e15;
  --color-surface: #141720;
  --color-tile: #1c2030;
  --color-tile-hover: #222740;
  --color-border: #2a2f45;
  --color-primary: #6366f1;
  --color-primary-light: #818cf8;
  --color-accent: #22d3ee;
  --color-success: #34d399;
  --color-danger: #f87171;
  --color-text: #e2e8f0;
  --color-muted: #64748b;
  --color-dim: #334155;
  --font-mono: 'JetBrains Mono', monospace;
  --font-ui: 'Outfit', sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
}

button {
  font: inherit;
}

::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 2px;
}

@keyframes pop-in {
  0% {
    transform: scale(0.85);
    opacity: 0;
  }
  60% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

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

@keyframes slide-up {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes win-pulse {
  0% {
    transform: scale(0.9);
    opacity: 0;
  }
  50% {
    transform: scale(1.03);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.pop-in {
  animation: pop-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.shake {
  animation: shake 0.35s ease both;
}

.slide-up {
  animation: slide-up 0.2s ease both;
}

.win-appear {
  animation: win-pulse 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.app-shell {
  width: min(560px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.start-panel,
.game-panel {
  position: relative;
  max-width: 560px;
  margin: 0 auto;
  background: rgba(20, 23, 32, 0.92);
  border: 1px solid var(--color-border);
  border-radius: 18px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.3);
}

.start-panel {
  padding: 18px 18px 16px;
  background: rgba(17, 22, 32, 0.96);
  border-color: rgba(78, 88, 116, 0.9);
}

.game-panel {
  padding: 16px 18px 14px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--color-primary-light);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 14px;
  font-size: clamp(2.4rem, 7vw, 4rem);
  line-height: 0.96;
  letter-spacing: -0.06em;
  color: var(--color-text);
}

.start-title {
  margin: 0 0 18px;
  color: #ecf3ff;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.start-rules {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.rule-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  color: #edf2ff;
  font-size: 0.95rem;
  line-height: 1.5;
}

.rule-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.rule-mark.red {
  background: rgba(239, 68, 68, 0.92);
  color: #fff;
}

.rule-mark.amber {
  background: rgba(251, 191, 36, 0.18);
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.42);
}

.rule-mark.cyan {
  background: rgba(34, 211, 238, 0.18);
  color: #67e8f9;
  border-color: rgba(34, 211, 238, 0.38);
}

.rule-mark.blue {
  background: rgba(96, 165, 250, 0.18);
  color: #bfdbfe;
  border-color: rgba(96, 165, 250, 0.38);
}

.info-banner {
  padding: 14px 14px 10px;
  margin-bottom: 18px;
  border: 1px solid rgba(122, 144, 255, 0.5);
  border-radius: 12px;
  background: rgba(33, 42, 64, 0.9);
}

.info-banner h3 {
  margin: 0 0 10px;
  color: #dfeaff;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 800;
}

.info-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: #dfeaff;
  line-height: 1.5;
  margin-bottom: 10px;
  font-size: 0.94rem;
}

.info-bullet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.6);
  color: #fca5a5;
  font-size: 0.72rem;
  font-weight: 700;
  margin-top: 1px;
}

.difficulty-tray {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.difficulty-pill {
  flex: 1;
  padding: 10px 8px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 0.76rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.04em;
  color: #edf2ff;
}

.difficulty-pill span {
  font-weight: 800;
}

.difficulty-pill.easy {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.45);
  color: #6ee7b7;
}

.difficulty-pill.medium {
  background: rgba(251, 191, 36, 0.12);
  border-color: rgba(251, 191, 36, 0.45);
  color: #fcd34d;
}

.difficulty-pill.hard {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

.start-button {
  width: 100%;
  margin-top: 18px;
}

.primary-button,
.secondary-button,
.operation-button,
.number-tile {
  border: 1px solid transparent;
  border-radius: 12px;
  transition: transform 0.18s ease, border-color 0.18s ease, opacity 0.18s ease, box-shadow 0.18s ease;
}

.primary-button,
.secondary-button {
  min-height: 34px;
  padding: 0 14px;
  font-family: var(--font-ui);
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  font-size: 0.85rem;
}

.primary-button {
  background: rgba(99, 102, 241, 0.18);
  border-color: rgba(99, 102, 241, 0.7);
  color: var(--color-primary-light);
  box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.12);
}

.secondary-button {
  background: rgba(20, 23, 32, 0.9);
  border-color: var(--color-border);
  color: var(--color-muted);
}

.primary-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled),
.operation-button:hover:not(:disabled),
.number-tile:hover:not(:disabled) {
  transform: translateY(-2px);
}

.secondary-button:disabled,
.operation-button:disabled,
.number-tile:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  box-shadow: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: nowrap;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: rgba(20, 23, 32, 0.9);
  color: var(--color-text);
  font-family: var(--font-ui);
  font-weight: 700;
  white-space: nowrap;
  font-size: 0.82rem;
}

.difficulty-chip {
  background: rgba(251, 191, 36, 0.08);
  border-color: rgba(251, 191, 36, 0.2);
  color: #fbbf24;
}

.chip-label {
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.82;
  display: none;
}

.game-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  justify-content: flex-end;
  margin-left: auto;
}

.game-actions .primary-button,
.game-actions .secondary-button {
  white-space: nowrap;
}

.feedback {
  min-height: 24px;
  margin: 8px 0 14px;
  display: flex;
  align-items: center;
  padding: 0;
  font-size: 0.95rem;
  color: var(--color-muted);
  background: transparent;
  font-family: var(--font-ui);
}

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

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

.feedback.info {
  color: var(--color-muted);
}

.target-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 152px;
  margin: 10px auto 18px;
  padding: 14px 16px 12px;
  border-radius: 18px;
  background: rgba(26, 29, 46, 0.9);
  border: 1px solid rgba(99, 102, 241, 0.22);
}

.target-copy {
  margin-bottom: 8px;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-muted);
  font-family: var(--font-ui);
}

.target-display {
  font-family: var(--font-mono);
  font-size: clamp(3rem, 9vw, 5rem);
  font-weight: 700;
  line-height: 1;
  color: var(--color-primary-light);
  letter-spacing: -0.05em;
  text-shadow: 0 0 18px rgba(99, 102, 241, 0.22);
}

.board {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

.board-section {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.board-section h2 {
  margin: 0 0 10px;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-muted);
  font-weight: 700;
  text-align: center;
}

.numbers-container,
.operations-container {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  width: 100%;
}

.number-tile {
  position: relative;
  min-width: 64px;
  min-height: 64px;
  padding: 0 12px;
  background: var(--color-tile);
  border-color: var(--color-border);
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.number-tile.generated-result {
  border-color: #fbbf24;
  background: rgba(52, 38, 20, 0.96);
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.6), 0 0 10px rgba(251, 191, 36, 0.22);
}

.number-tile.generated-result::after {
  content: "";
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fbbf24;
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.8), 0 0 0 2px rgba(251, 191, 36, 0.25);
}

.number-tile.selected {
  background: rgba(45, 49, 88, 0.95);
  border-color: var(--color-primary);
  color: var(--color-primary-light);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}

.operation-button {
  min-width: 56px;
  min-height: 56px;
  padding: 0 16px;
  background: var(--color-tile);
  border-color: var(--color-border);
  color: #94a3b8;
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 700;
}

.operation-button.selected {
  background: var(--color-primary);
  border-color: var(--color-primary-light);
  color: white;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}

.history-section {
  margin-top: 4px;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.history-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(20, 23, 32, 0.9);
  border: 1px solid rgba(42, 47, 69, 0.9);
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
}

.history-list li.empty {
  justify-content: flex-start;
  color: var(--color-muted);
  background: transparent;
  border-style: dashed;
}

.success-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 14, 21, 0.85);
  backdrop-filter: blur(4px);
  padding: 18px;
  border-radius: 18px;
}

.success-overlay.hidden {
  display: none;
}

.success-card {
  width: min(100%, 420px);
  background: rgba(20, 23, 32, 0.98);
  border: 1px solid rgba(52, 211, 153, 0.3);
  border-radius: 18px;
  padding: 22px 18px 18px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.3);
}

.success-eyebrow {
  color: var(--color-success);
}

.success-card h2 {
  margin-bottom: 8px;
  font-size: clamp(1.8rem, 5vw, 2.3rem);
}

.success-summary {
  color: var(--color-muted);
}

.solution-chain {
  margin: 18px 0 22px;
  padding-left: 18px;
  color: var(--color-text);
  line-height: 1.9;
  font-family: var(--font-mono);
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 18px, 720px);
    padding-top: 18px;
  }

  .start-panel,
  .game-panel {
    max-width: 100%;
    border-radius: 18px;
  }

  .game-panel {
    padding: 14px 12px 12px;
  }

  .status-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .game-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .primary-button,
  .secondary-button {
    flex: 1 1 0;
    min-width: 0;
  }

  .number-tile {
    min-width: 58px;
    min-height: 58px;
    font-size: 1.1rem;
  }

  .operation-button {
    min-width: 48px;
    min-height: 48px;
  }
}
