/* --- Reset & base --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  font-family: 'Orbitron', system-ui, sans-serif;
  color: #fff;
  background: #4a0e4e;
  background-image:
    linear-gradient(rgba(107, 45, 107, 0.15) 1px, transparent 1px),
    linear-gradient(90deg, rgba(107, 45, 107, 0.15) 1px, transparent 1px);
  background-size: 32px 32px;
  background-position: 0 0, 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
}

/* --- Header --- */
.header {
  width: 100%;
  max-width: 720px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  margin-bottom: 1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.difficulty-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.difficulty-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.7);
}

.difficulty-btns {
  display: flex;
  gap: 0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.btn-diff {
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.85);
  background: rgba(30, 27, 75, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-diff:first-child {
  border-right: none;
  border-radius: 8px 0 0 8px;
}

.btn-diff:last-child {
  border-left: none;
  border-radius: 0 8px 8px 0;
}

.btn-diff:hover {
  background: rgba(126, 34, 206, 0.4);
  color: #fff;
}

.btn-diff.active {
  background: linear-gradient(180deg, #7c3aed 0%, #6b2d6b 100%);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
}

.logo {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  background: linear-gradient(90deg, #60a5fa, #34d399, #fbbf24, #f472b6, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.btn-play {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: #fff;
  background: linear-gradient(180deg, #7c3aed 0%, #a855f7 50%, #6b2d6b 100%);
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1.25rem;
  cursor: pointer;
  box-shadow:
    0 4px 0 #4c1d95,
    0 6px 12px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transition: transform 0.1s, box-shadow 0.1s;
}

.btn-play:hover {
  transform: translateY(-1px);
  box-shadow:
    0 5px 0 #4c1d95,
    0 8px 16px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.btn-play:active {
  transform: translateY(2px);
  box-shadow:
    0 2px 0 #4c1d95,
    0 4px 8px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

/* --- Game container --- */
.game-container {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  justify-content: center;
  align-items: flex-start;
}

/* --- Game panel (board) --- */
.game-panel {
  position: relative;
  border-radius: 12px;
  padding: 12px;
  background: linear-gradient(145deg, #1e1b4b 0%, #312e81 50%, #1e1b4b 100%);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

#gameCanvas {
  display: block;
  border-radius: 6px;
  background: #0f172a;
  max-width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* --- Overlay (start / game over) --- */
.game-overlay {
  position: absolute;
  inset: 12px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

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

.overlay-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  margin-bottom: 0.25rem;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.overlay-sub {
  font-size: 0.85rem;
  opacity: 0.85;
  letter-spacing: 0.1em;
}

/* --- Touch controls (mobile) --- */
.touch-controls {
  display: none;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  max-width: 300px;
  margin-top: 0.75rem;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 768px) {
  .touch-controls {
    display: flex;
  }
}

.touch-controls-row {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

.touch-btn {
  font-family: inherit;
  font-size: 1.5rem;
  font-weight: 600;
  color: #fff;
  background: rgba(124, 58, 237, 0.8);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  min-width: 56px;
  min-height: 52px;
  padding: 0.5rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}

.touch-btn:hover {
  background: rgba(124, 58, 237, 1);
}

.touch-btn:active {
  transform: scale(0.96);
}

.touch-btn-wide {
  flex: 1;
  min-width: 0;
  font-size: 1.25rem;
}

/* --- Side panel --- */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 160px;
  padding: 1rem;
  border-radius: 12px;
  background: rgba(30, 27, 75, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

.panel-section {
  text-align: center;
}

.panel-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 0.35rem;
}

.panel-value {
  font-size: 1.25rem;
  font-weight: 600;
  color: #fbbf24;
}

#nextCanvas {
  display: block;
  margin: 0 auto;
  border-radius: 6px;
  background: #0f172a;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.controls-list {
  list-style: none;
  text-align: left;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.9);
}

.controls-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

kbd {
  display: inline-block;
  padding: 0.15rem 0.4rem;
  font-family: inherit;
  font-size: 0.65rem;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  min-width: 1.6em;
  text-align: center;
}

/* --- Tips section --- */
.tips-section {
  width: 100%;
  max-width: 720px;
  margin-top: 2rem;
  padding: 1.5rem 1.75rem;
  border-radius: 12px;
  background: rgba(30, 27, 75, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
  box-sizing: border-box;
}

.tips-heading {
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  font-weight: 600;
  letter-spacing: 0.15em;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 1.25rem;
  text-align: center;
}

.tips-list {
  list-style: none;
  font-size: clamp(0.95rem, 2.2vw, 1.05rem);
  line-height: 1.7;
  color: rgba(255, 255, 255, 0.92);
}

.tips-list li {
  position: relative;
  padding-left: 1.5rem;
  margin-bottom: 0.85rem;
}

.tips-list li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a855f7;
}

.tips-list strong {
  color: #fbbf24;
  font-weight: 600;
}

.tips-list kbd {
  font-size: 0.85em;
  padding: 0.2rem 0.45rem;
}

/* --- Who Built This --- */
.who-built-section {
  width: 100%;
  margin-top: 3rem;
  padding: 2rem 1.5rem;
  border-radius: 0;
  background: rgba(30, 27, 75, 0.5);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
  box-sizing: border-box;
}

.who-built-heading {
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  font-weight: 700;
  color: #fff;
  margin-bottom: 1.5rem;
  letter-spacing: 0.02em;
  text-align: center;
}

.who-built-content {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  max-width: 900px;
  margin: 0 auto;
}

.who-built-text {
  flex: 1;
  min-width: 280px;
}

.who-built-intro {
  font-size: clamp(0.9rem, 2vw, 1rem);
  line-height: 1.65;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 1rem;
}

.who-built-profile {
  text-align: center;
  padding: 1.5rem;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.who-built-photo {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  margin: 0 auto 1rem;
}

.who-built-profile .profile-card-name {
  font-size: 1.2rem;
  font-weight: 600;
  color: #fff;
  margin-bottom: 0.25rem;
}

.who-built-profile .profile-card-role {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 1rem;
}

.who-built-profile .profile-card-social {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

.who-built-profile .profile-card-social a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 600;
  transition: background 0.2s, color 0.2s;
}

.who-built-profile .profile-card-social a:hover {
  background: #7c3aed;
  color: #fff;
}

@media (max-width: 520px) {
  .who-built-section {
    padding: 1.5rem 1rem;
  }

  .who-built-content {
    flex-direction: column;
  }

  .who-built-photo {
    width: 160px;
    height: 160px;
  }
}

/* --- Footer --- */
.site-footer {
  width: 100%;
  margin-top: 3rem;
  background: #1e1b4b;
  color: rgba(255, 255, 255, 0.9);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.footer-top {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 2rem;
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr;
  gap: 2rem;
}

.footer-heading {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #fff;
  margin-bottom: 1rem;
}

.footer-tagline {
  font-size: 0.85rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 1rem;
  max-width: 220px;
}

.footer-social {
  display: flex;
  gap: 0.5rem;
}

.footer-social a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
  transition: background 0.2s, color 0.2s;
}

.footer-social a:hover {
  background: #7c3aed;
  color: #fff;
}

.footer-links,
.footer-contact {
  list-style: none;
  font-size: 0.85rem;
  line-height: 1.8;
}

.footer-links a,
.footer-contact a {
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-links a:hover,
.footer-contact a:hover {
  color: #fbbf24;
}

.footer-bottom {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.footer-copy {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.7);
  margin: 0;
}

.footer-legal {
  display: flex;
  gap: 1.25rem;
}

.footer-legal a {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-legal a:hover {
  color: #fbbf24;
}

/* --- Responsive --- */
@media (max-width: 520px) {
  .game-container {
    flex-direction: column;
    align-items: center;
  }

  .side-panel {
    flex-direction: row;
    flex-wrap: wrap;
    min-width: auto;
    width: 100%;
    max-width: 300px;
    justify-content: space-around;
  }

  .panel-section.controls {
    width: 100%;
    text-align: center;
  }

  .controls-list {
    justify-content: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .tips-section {
    margin-top: 1.5rem;
    padding: 1.25rem 1.25rem;
    margin-left: 0;
    margin-right: 0;
  }

  .tips-list {
    font-size: 1rem;
    line-height: 1.75;
  }

  .tips-list li {
    margin-bottom: 1rem;
  }

  .footer-top {
    grid-template-columns: 1fr 1fr;
    padding: 1.5rem 1.25rem;
    gap: 1.5rem;
  }

  .footer-about {
    grid-column: 1 / -1;
  }

  .footer-bottom {
    flex-direction: column;
    text-align: center;
    padding: 1rem 1.25rem;
  }
}

/* Extra small screens: keep tips readable and prevent overflow */
@media (max-width: 380px) {
  body {
    padding: 0.75rem;
  }

  .tips-section {
    padding: 1rem 1rem;
  }

  .tips-heading {
    font-size: 1rem;
    letter-spacing: 0.1em;
  }

  .tips-list {
    font-size: 0.95rem;
  }
}

@media (max-width: 640px) {
  .footer-top {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .footer-about {
    grid-column: 1;
  }

  .footer-tagline {
    max-width: none;
    margin-left: auto;
    margin-right: auto;
  }

  .footer-social {
    justify-content: center;
  }
}
