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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 1rem;
}

.container {
  max-width: 440px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.5rem;
}

header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
}

.subtitle {
  font-size: 0.85rem;
  color: #999;
  font-weight: 400;
  text-align: center;
  line-height: 1.4;
}

#mode-toggle {
  display: flex;
  background: #16213e;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid #333;
}

.mode-btn {
  padding: 0.5rem 1.2rem;
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  border-radius: 0;
  background: transparent;
  color: #888;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.mode-btn.active {
  background: #3498db;
  color: #fff;
}

.mode-btn:hover:not(.active) {
  background: #1e2f4a;
  color: #ccc;
}

.badge {
  display: inline-block;
  padding: 0.25rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.badge-easy { background: #2ecc71; color: #000; }
.badge-medium { background: #f39c12; color: #000; }
.badge-hard { background: #e74c3c; color: #fff; }
.badge-expert { background: #8e44ad; color: #fff; }

#status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid #333;
}

#min-moves-info {
  font-size: 0.85rem;
  color: #999;
}

#grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  justify-items: center;
}

.card {
  width: 100%;
  aspect-ratio: 3 / 4;
  max-width: 120px;
  background: #16213e;
  border: 2px solid #444;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  font-weight: 700;
  color: #fff;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
  user-select: none;
}

.card .suit {
  font-size: 1.1rem;
  color: #888;
  margin-top: 0.15rem;
}

.card.correct {
  background: #1b4332;
  border-color: #2ecc71;
}

.card.correct .suit {
  color: #2ecc71;
}

#reserve-section {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.reserve-label {
  font-size: 1rem;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

#reserve {
  width: 90px;
  aspect-ratio: 3 / 4;
}

#controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.group-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #888;
}

.btn-row {
  display: flex;
  gap: 0.5rem;
}

.btn-row button {
  flex: 1;
}

button {
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: #2a2a4a;
  color: #e0e0e0;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

button:hover {
  background: #3a3a6a;
}

button:active {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.col-controls .btn-row {
  justify-content: center;
}

.col-btn-pair {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
}

.col-btn-pair span {
  font-size: 0.75rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.col-btn-pair button {
  width: 100%;
  padding: 0.6rem;
}

.hidden {
  display: none !important;
}

#inperson-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#btn-show-solution {
  width: 100%;
  padding: 0.85rem;
  background: #1a2a3a;
  color: #3498db;
  font-size: 1rem;
  border: 1px solid #3498db44;
}

#btn-show-solution:hover {
  background: #223a52;
}

.solution-visible {
  background: #16213e;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 1rem;
  max-height: 400px;
  overflow-y: auto;
}

.solution-header {
  font-size: 0.9rem;
  color: #999;
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.solution-steps {
  list-style: none;
  counter-reset: step;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.solution-steps li {
  counter-increment: step;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.5rem 0.75rem;
  background: #1a1a2e;
  border-radius: 8px;
  border-left: 3px solid #3498db;
}

.solution-steps li::before {
  content: "Step " counter(step);
  font-size: 0.7rem;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.solution-steps li strong {
  font-size: 1rem;
  color: #e0e0e0;
}

.step-state {
  font-size: 0.8rem;
  color: #888;
  font-family: monospace;
}

.solution-error {
  color: #e74c3c;
  text-align: center;
  padding: 0.5rem;
}

#inperson-result {
  display: flex;
  gap: 0.5rem;
}

.btn-solved {
  flex: 1;
  background: #1b4332 !important;
  color: #2ecc71 !important;
  border: 1px solid #2ecc7144 !important;
}

.btn-solved:hover:not(:disabled) {
  background: #265e45 !important;
}

.btn-failed {
  flex: 1;
  background: #4a1111 !important;
  color: #e74c3c !important;
  border: 1px solid #e74c3c44 !important;
}

.btn-failed:hover:not(:disabled) {
  background: #5a2020 !important;
}

#message {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  padding: 1rem;
  border-radius: 10px;
}

#message.win {
  background: #1b4332;
  color: #2ecc71;
  border: 2px solid #2ecc71;
}

#message.lose {
  background: #4a1111;
  color: #e74c3c;
  border: 2px solid #e74c3c;
}

footer {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

footer button {
  flex: 1;
  font-size: 0.9rem;
}

#btn-easier {
  background: #3a2a1a;
  color: #f39c12;
}

#btn-easier:hover {
  background: #4a3a2a;
}

#btn-harder {
  background: #1a2a3a;
  color: #3498db;
}

#btn-harder:hover {
  background: #2a3a4a;
}

#btn-new {
  background: #2a4a2a;
  color: #2ecc71;
}

#btn-new:hover {
  background: #3a5a3a;
}

@media (max-width: 480px) {
  .container {
    padding: 1rem;
  }

  header h1 {
    font-size: 1.6rem;
  }

  .card {
    font-size: 1.8rem;
    border-radius: 10px;
  }
}
