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

body {
  font-family: 'Arial', sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  color: #333;
}

.container {
  background: white;
  border-radius: 15px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  padding: 30px;
  max-width: 1300px;
  width: 100%;
}

h1 {
  text-align: center;
  color: #4a5568;
  margin-bottom: 30px;
  font-size: 2.5em;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.main-content {
  display: flex;
  gap: 30px;
  flex-wrap: wrap;
  justify-content: center;
}

.polybius-section {
  flex: 1;
  min-width: 450px;
  max-width: 500px;
}

.work-section {
  flex: 1;
  min-width: 400px;
}

.polybius-grid {
  display: grid;
  grid-template-columns: 40px repeat(6, 55px);
  grid-template-rows: 40px repeat(6, 55px);
  gap: 2px;
  margin: 20px 0;
  justify-content: center;
  background: #f7fafc;
  padding: 15px;
  border-radius: 10px;
}

.grid-header {
  background: #4299e1;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  border-radius: 4px;
  font-size: 16px;
}

.grid-cell {
  background: #e6fffa;
  border: 2px solid #4299e1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  border-radius: 4px;
  position: relative;
}

.grid-cell:hover {
  background: #bee3f8;
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.grid-cell.highlighted {
  background: #fbb6ce;
  animation: pulse 1.5s ease-in-out;
  transform: scale(1.1);
  box-shadow: 0 8px 16px rgba(251, 182, 206, 0.5);
}

.grid-cell.encoding {
  background: #f6ad55;
  animation: encode 2s ease-in-out;
  transform: scale(1.15);
  box-shadow: 0 8px 20px rgba(246, 173, 85, 0.6);
}

.grid-cell.decoding {
  background: #68d391;
  animation: decode 2s ease-in-out;
  transform: scale(1.15);
  box-shadow: 0 8px 20px rgba(104, 211, 145, 0.6);
}

.grid-cell .coordinates {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #f6ad55;
  color: white;
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 50%;
  font-weight: bold;
  opacity: 0;
  transition: all 0.3s ease;
  transform: scale(0);
}

.grid-cell .letter-highlight {
  position: absolute;
  top: -8px;
  left: -8px;
  background: #68d391;
  color: white;
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 50%;
  font-weight: bold;
  opacity: 0;
  transition: all 0.3s ease;
  transform: scale(0);
}

.grid-cell:hover .coordinates,
.grid-cell.highlighted .coordinates,
.grid-cell.encoding .coordinates {
  opacity: 1;
  transform: scale(1);
}

.grid-cell:hover .letter-highlight,
.grid-cell.highlighted .letter-highlight,
.grid-cell.decoding .letter-highlight {
  opacity: 1;
  transform: scale(1);
}

@keyframes pulse {
  0%, 100% { 
      transform: scale(1.1); 
      background: #fbb6ce;
  }
  50% { 
      transform: scale(1.2); 
      background: #f093fb;
  }
}

@keyframes encode {
  0% { 
      transform: scale(1.1); 
      background: #f6ad55;
  }
  25% { 
      transform: scale(1.3) rotate(5deg); 
      background: #ff6b6b;
  }
  50% { 
      transform: scale(1.25) rotate(-5deg); 
      background: #4ecdc4;
  }
  75% { 
      transform: scale(1.2) rotate(2deg); 
      background: #45b7d1;
  }
  100% { 
      transform: scale(1.15); 
      background: #96ceb4;
  }
}

@keyframes decode {
  0% { 
      transform: scale(1.1); 
      background: #68d391;
  }
  25% { 
      transform: scale(1.3) rotate(-5deg); 
      background: #4fd1c7;
  }
  50% { 
      transform: scale(1.25) rotate(5deg); 
      background: #63b3ed;
  }
  75% { 
      transform: scale(1.2) rotate(-2deg); 
      background: #9f7aea;
  }
  100% { 
      transform: scale(1.15); 
      background: #f6ad55;
  }
}

.mode-switcher {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 20px 0;
}

.mode-btn {
  padding: 12px 24px;
  border: 2px solid #4299e1;
  border-radius: 8px;
  background: white;
  color: #4299e1;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 16px;
  font-weight: bold;
}

.mode-btn.active {
  background: #4299e1;
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(66, 153, 225, 0.4);
}

.mode-btn:hover {
  background: #3182ce;
  color: white;
  transform: translateY(-2px);
}

.work-area {
  background: #f7fafc;
  padding: 20px;
  border-radius: 10px;
  margin: 15px 0;
}

.hidden {
  display: none;
}

.input-group {
  margin-bottom: 20px;
}

.input-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: bold;
  color: #4a5568;
}

.input-field {
  width: 100%;
  padding: 12px;
  border: 2px solid #4299e1;
  border-radius: 8px;
  font-size: 18px;
  font-family: 'Courier New', monospace;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.output-field {
  background: #edf2f7;
  min-height: 80px;
  padding: 15px;
  border: 2px solid #a0aec0;
  border-radius: 8px;
  font-family: 'Courier New', monospace;
  font-size: 20px;
  letter-spacing: 3px;
  word-break: break-all;
  display: flex;
  align-items: center;
  position: relative;
  overflow: hidden;
}

.output-character {
  display: inline-block;
  opacity: 0;
  transform: translateY(-20px);
  animation: fadeInDown 0.5s ease-out forwards;
  margin-right: 2px;
}

.output-character.decrypt {
  animation: fadeInUp 0.5s ease-out forwards;
  color: #2d3748;
}

@keyframes fadeInDown {
  to {
      opacity: 1;
      transform: translateY(0);
  }
}

@keyframes fadeInUp {
  from {
      opacity: 0;
      transform: translateY(20px);
  }
  to {
      opacity: 1;
      transform: translateY(0);
  }
}

.typing-cursor {
  display: inline-block;
  background: #4299e1;
  width: 3px;
  height: 24px;
  animation: blink 1s infinite;
  margin-left: 5px;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

.button-group {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin: 20px 0;
}

button {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: bold;
}

.btn-primary {
  background: #4299e1;
  color: white;
}

.btn-primary:hover {
  background: #3182ce;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(66, 153, 225, 0.4);
}

.btn-primary:disabled {
  background: #a0aec0;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: #a0aec0;
  color: white;
}

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

.btn-magic {
  background: linear-gradient(45deg, #667eea, #764ba2);
  color: white;
  position: relative;
  overflow: hidden;
}

.btn-magic:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
}

.btn-magic::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  transition: left 0.5s;
}

.btn-magic:hover::before {
  left: 100%;
}

.tutorial-step {
  background: #f0fff4;
  border: 2px solid #68d391;
  padding: 20px;
  border-radius: 8px;
  margin: 15px 0;
}

.animation-status {
  text-align: center;
  padding: 10px;
  border-radius: 6px;
  margin: 10px 0;
  font-weight: bold;
  background: #bee3f8;
  color: #2b6cb0;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.animation-status.show {
  opacity: 1;
}

.animation-status.decrypt-mode {
  background: #c6f6d5;
  color: #2f855a;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  margin: 10px 0;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4299e1, #667eea);
  width: 0%;
  transition: width 0.3s ease;
  border-radius: 3px;
}

.progress-fill.decrypt-mode {
  background: linear-gradient(90deg, #68d391, #48bb78);
}

.alphabet-info {
  background: #edf2f7;
  padding: 15px;
  border-radius: 8px;
  margin: 15px 0;
  font-size: 14px;
  text-align: center;
}

.alphabet-display {
  font-family: 'Courier New', monospace;
  letter-spacing: 2px;
  color: #4a5568;
  font-weight: bold;
  margin-top: 8px;
}

.message {
  text-align: center;
  padding: 15px;
  border-radius: 8px;
  margin: 15px 0;
  font-weight: bold;
}

.success {
  background: #c6f6d5;
  color: #2f855a;
}

.error {
  background: #fed7d7;
  color: #c53030;
}

.hint {
  background: #bee3f8;
  color: #2b6cb0;
}

@media (max-width: 768px) {
  .main-content {
      flex-direction: column;
  }
  
  .polybius-grid {
      grid-template-columns: 30px repeat(6, 40px);
      grid-template-rows: 30px repeat(6, 40px);
  }

  .grid-cell {
      font-size: 12px;
  }

  .grid-header {
      font-size: 12px;
  }

  .input-field, .output-field {
      font-size: 16px;
  }

  .button-group {
      flex-wrap: wrap;
  }

  .mode-switcher {
      flex-wrap: wrap;
  }

  .polybius-section {
      min-width: 300px;
  }
}