:root {
  --primary: #0d9488;
  --primary-light: #14b8a6;
  --primary-dark: #0f766e;
  --primary-glow: rgba(13, 148, 136, 0.3);
  --bg-gradient-start: #0f172a;
  --bg-gradient-end: #1e293b;
  --card-bg: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.15);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.2);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, var(--bg-gradient-start) 0%, #134e4a 50%, var(--bg-gradient-end) 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
  padding-top: 80px;
  line-height: 1.6;
  color: var(--text-primary);
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(13, 148, 136, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(20, 184, 166, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(13, 148, 136, 0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.game-container {
  position: relative;
  z-index: 1;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(20px);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xl), 0 0 0 1px rgba(255, 255, 255, 0.1);
  max-width: 900px;
  width: 100%;
  padding: 32px;
  animation: containerIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes containerIn {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.header {
  text-align: center;
  margin-bottom: 24px;
}

.title {
  font-size: 2.4rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 50%, #2dd4bf 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 6px;
  letter-spacing: -0.5px;
}

.subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.info-bar {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin-bottom: 20px;
  padding: 14px 24px;
  background: linear-gradient(135deg, rgba(13, 148, 136, 0.06) 0%, rgba(20, 184, 166, 0.04) 100%);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(13, 148, 136, 0.1);
}

.info-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.info-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.info-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  min-width: 52px;
}

.level-selector {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.level-nav-btn {
  padding: 8px 18px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  border: none;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  transition: var(--transition);
  box-shadow: 0 2px 8px var(--primary-glow);
}

.level-nav-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--primary-glow);
}

.level-nav-btn:active {
  transform: translateY(0);
}

.level-thumbnails {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 400px;
}

.level-thumb {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-xs);
  border: 2px solid var(--border-color);
  background: white;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  overflow: hidden;
}

.level-thumb:hover {
  border-color: var(--primary);
  transform: scale(1.1);
}

.level-thumb.active {
  border-color: var(--primary);
  background: linear-gradient(135deg, rgba(13, 148, 136, 0.1) 0%, rgba(20, 184, 166, 0.08) 100%);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.level-thumb.completed {
  position: relative;
}

.level-thumb.completed::after {
  content: '✓';
  position: absolute;
  bottom: 1px;
  right: 2px;
  font-size: 10px;
  color: var(--primary);
  font-weight: 900;
}

.game-area {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.target-area {
  position: relative;
  background: linear-gradient(145deg, #f8fafc 0%, #f1f5f9 100%);
  border: 2px dashed rgba(13, 148, 136, 0.25);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  overflow: hidden;
}

.target-area svg {
  width: 100%;
  height: 100%;
  max-width: 260px;
  max-height: 260px;
}

.target-label {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 600;
  background: rgba(255, 255, 255, 0.9);
  padding: 3px 12px;
  border-radius: 20px;
}

.play-area {
  position: relative;
  background: linear-gradient(145deg, #fefefe 0%, #f8fafc 100%);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  min-height: 320px;
  perspective: 1200px;
  overflow: hidden;
  touch-action: none;
}

.tangram-piece {
  position: absolute;
  cursor: grab;
  transition: box-shadow 0.2s ease, filter 0.2s ease;
  transform-style: preserve-3d;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.tangram-piece:hover {
  z-index: 100 !important;
}

.tangram-piece.dragging {
  cursor: grabbing;
  z-index: 1000 !important;
  filter: brightness(1.08);
}

.tangram-piece.selected {
  z-index: 999 !important;
  filter: drop-shadow(0 0 12px var(--primary-glow));
}

.tangram-piece.snapped {
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tangram-piece[data-piece="large-tri-1"],
.tangram-piece[data-piece="large-tri-2"] {
  width: 0;
  height: 0;
  border-left: 70px solid transparent;
  border-right: 70px solid transparent;
  border-bottom: 140px solid #ef4444;
  filter: drop-shadow(3px 5px 8px rgba(239, 68, 68, 0.35));
  transform-origin: center center;
}

.tangram-piece[data-piece="large-tri-1"] {
  border-bottom-color: #ef4444;
}

.tangram-piece[data-piece="large-tri-2"] {
  border-bottom-color: #f97316;
}

.tangram-piece[data-piece="medium-tri"] {
  width: 0;
  height: 0;
  border-left: 55px solid transparent;
  border-right: 55px solid transparent;
  border-bottom: 110px solid #eab308;
  filter: drop-shadow(3px 5px 8px rgba(234, 179, 8, 0.35));
  transform-origin: center center;
}

.tangram-piece[data-piece="small-tri-1"],
.tangram-piece[data-piece="small-tri-2"] {
  width: 0;
  height: 0;
  border-left: 40px solid transparent;
  border-right: 40px solid transparent;
  border-bottom: 80px solid #22c55e;
  filter: drop-shadow(2px 4px 6px rgba(34, 197, 94, 0.35));
  transform-origin: center center;
}

.tangram-piece[data-piece="small-tri-2"] {
  border-bottom-color: #06b6d4;
}

.tangram-piece[data-piece="square"] {
  width: 70px;
  height: 70px;
  background: #8b5cf6;
  filter: drop-shadow(3px 5px 8px rgba(139, 92, 246, 0.35));
  transform-origin: center center;
}

.tangram-piece[data-piece="parallelogram"] {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 50px 50px 20px;
  border-color: transparent transparent #ec4899 transparent;
  filter: drop-shadow(3px 5px 8px rgba(236, 72, 153, 0.35));
  transform-origin: center center;
}

.tangram-piece.flipped-h {
  transform: scaleX(-1);
}

.tangram-piece .piece-inner {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.control-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 22px;
  background: white;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text-primary);
  transition: var(--transition);
}

.control-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md), 0 0 0 3px var(--primary-glow);
}

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

.control-btn .btn-icon {
  font-size: 1.1rem;
}

.control-btn .btn-text {
  font-weight: 700;
}

.instructions {
  background: linear-gradient(135deg, rgba(13, 148, 136, 0.04) 0%, rgba(20, 184, 166, 0.02) 100%);
  border: 1px solid rgba(13, 148, 136, 0.1);
  border-radius: var(--radius-sm);
  padding: 18px 24px;
}

.instructions h3 {
  font-size: 1rem;
  font-weight: 800;
  color: var(--primary-dark);
  margin-bottom: 10px;
}

.instructions ul {
  list-style: none;
  padding: 0;
}

.instructions li {
  font-size: 0.87rem;
  color: var(--text-secondary);
  padding: 4px 0;
  padding-left: 18px;
  position: relative;
}

.instructions li::before {
  content: '▸';
  position: absolute;
  left: 0;
  color: var(--primary);
  font-weight: 700;
}

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(8px);
  z-index: 100000;
  align-items: center;
  justify-content: center;
  animation: modalFadeIn 0.3s ease;
}

.modal.show {
  display: flex;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: white;
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  box-shadow: var(--shadow-xl);
  animation: modalSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 420px;
  width: 90%;
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.victory-icon {
  font-size: 4rem;
  margin-bottom: 12px;
  animation: bounceIn 0.6s ease;
}

@keyframes bounceIn {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

.victory-content h2 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 20px;
}

.victory-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 24px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
}

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

.modal-btn {
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.92rem;
  transition: var(--transition);
}

.modal-btn.primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.modal-btn.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--primary-glow);
}

.modal-btn.secondary {
  background: #f1f5f9;
  color: var(--text-primary);
  border: 2px solid var(--border-color);
}

.modal-btn.secondary:hover {
  background: #e2e8f0;
  transform: translateY(-2px);
}

.hint-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.hint-overlay.show {
  opacity: 0.25;
}

@keyframes pieceRotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(45deg); }
}

.piece-rotate-anim {
  animation: pieceRotate 0.2s ease-out;
}

@keyframes snapPulse {
  0% { box-shadow: 0 0 0 0 var(--primary-glow); }
  70% { box-shadow: 0 0 0 12px rgba(13, 148, 136, 0); }
  100% { box-shadow: 0 0 0 0 rgba(13, 148, 136, 0); }
}

.snap-pulse {
  animation: snapPulse 0.5s ease-out;
}

@media (max-width: 768px) {
  .game-area {
    grid-template-columns: 1fr;
  }

  .target-area {
    min-height: 220px;
  }

  .play-area {
    min-height: 360px;
  }

  .game-container {
    padding: 20px 16px;
  }

  .title {
    font-size: 1.8rem;
  }

  .info-bar {
    gap: 16px;
    padding: 10px 16px;
    flex-wrap: wrap;
  }

  .controls {
    gap: 8px;
  }

  .control-btn {
    padding: 9px 16px;
    font-size: 0.82rem;
  }

  .level-thumbnails {
    max-width: 280px;
  }

  .level-thumb {
    width: 30px;
    height: 30px;
    font-size: 0.85rem;
  }

  .tangram-piece[data-piece="large-tri-1"],
  .tangram-piece[data-piece="large-tri-2"] {
    border-left-width: 50px;
    border-right-width: 50px;
    border-bottom-width: 100px;
  }

  .tangram-piece[data-piece="medium-tri"] {
    border-left-width: 42px;
    border-right-width: 42px;
    border-bottom-width: 84px;
  }

  .tangram-piece[data-piece="small-tri-1"],
  .tangram-piece[data-piece="small-tri-2"] {
    border-left-width: 32px;
    border-right-width: 32px;
    border-bottom-width: 64px;
  }

  .tangram-piece[data-piece="square"] {
    width: 54px;
    height: 54px;
  }

  .tangram-piece[data-piece="parallelogram"] {
    border-width: 0 38px 38px 15px;
  }
}

@media (max-width: 480px) {
  body {
    padding: 10px;
    padding-top: 70px;
  }

  .game-container {
    padding: 16px 12px;
    border-radius: 12px;
  }

  .level-nav-btn {
    padding: 6px 12px;
    font-size: 0.76rem;
  }

  .control-btn {
    padding: 8px 12px;
    font-size: 0.78rem;
  }

  .control-btn .btn-text {
    display: none;
  }

  .control-btn .btn-icon {
    font-size: 1.2rem;
  }

  .victory-stats {
    gap: 20px;
  }
}
