*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at top, #1a1a2e 0%, #0f0f1a 60%, #050508 100%);
  color: #f0f0f5;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  position: relative;
}

.settings-btn {
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
}

@media (min-width: 640px) {
  .settings-btn {
    position: absolute;
    right: 0;
  }
}

header h1 {
  margin: 0;
  font-size: 2.5rem;
  letter-spacing: 0.05em;
}

.subtitle {
  margin: 0.5rem 0 0;
  color: #a0a0b8;
}

.main-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 2rem;
  align-items: start;
}

.game-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.stats {
  display: flex;
  gap: 2rem;
}

.stat {
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.85rem;
  color: #a0a0b8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-value {
  display: block;
  font-size: 2rem;
  font-weight: 700;
}

.stat-value.stat-bump {
  animation: stat-bump 0.35s ease-out;
}

.difficulty-picker {
  text-align: center;
}

.difficulty-picker.locked {
  opacity: 0.55;
  pointer-events: none;
}

.difficulty-label {
  display: block;
  font-size: 0.85rem;
  color: #a0a0b8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.6rem;
}

.difficulty-options {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.difficulty-option {
  cursor: pointer;
}

.difficulty-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.difficulty-option span {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.9rem;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.difficulty-option input:checked + span {
  background: linear-gradient(135deg, #6c63ff, #4a42d4);
  border-color: transparent;
  color: #fff;
}

.difficulty-option input:focus-visible + span {
  outline: 2px solid #6c63ff;
  outline-offset: 2px;
}

.difficulty-option:hover span {
  transform: translateY(-1px);
}

.simon-board {
  position: relative;
  width: min(var(--board-size, 480px), 92vw);
  height: min(var(--board-size, 480px), 92vw);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #3d3d3d 0%, #252525 45%, #121212 100%);
  box-shadow:
    0 0 0 12px #2b2b2b,
    0 0 0 14px #1a1a1a,
    0 22px 50px rgba(0, 0, 0, 0.7),
    inset 0 -10px 24px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  transition: width 0.2s ease, height 0.2s ease, box-shadow 0.3s ease;
}

.simon-board.player-turn {
  animation: board-ready 1.2s ease-in-out infinite;
}

.simon-board.board-shake {
  animation: board-shake 0.45s ease-in-out;
}

.pad {
  position: absolute;
  width: 50%;
  height: 50%;
  border: none;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.08s ease;
  -webkit-tap-highlight-color: transparent;
  transform-origin: center;
  outline: 4px solid #0c0c0c;
}

.pad:disabled {
  cursor: default;
}

.pad-green {
  top: 0;
  right: 0;
  border-top-right-radius: 100%;
  background: radial-gradient(circle at 62% 38%, #4fd06a 0%, #2ecc71 35%, #1fa855 70%, #168a44 100%);
  box-shadow:
    inset 3px 3px 10px rgba(255, 255, 255, 0.35),
    inset -6px -8px 14px rgba(0, 0, 0, 0.45),
    3px 6px 12px rgba(0, 0, 0, 0.35);
}

.pad-red {
  top: 0;
  left: 0;
  border-top-left-radius: 100%;
  background: radial-gradient(circle at 38% 38%, #e83540 0%, #c42026 35%, #a01820 70%, #7a1018 100%);
  box-shadow:
    inset 3px 3px 10px rgba(255, 255, 255, 0.3),
    inset -6px -8px 14px rgba(0, 0, 0, 0.45),
    3px 6px 12px rgba(0, 0, 0, 0.35);
}

.pad-yellow {
  bottom: 0;
  right: 0;
  border-bottom-right-radius: 100%;
  background: radial-gradient(circle at 62% 62%, #ffe566 0%, #f0c800 35%, #d4ad00 70%, #b89200 100%);
  box-shadow:
    inset 3px 3px 10px rgba(255, 255, 255, 0.4),
    inset -6px -8px 14px rgba(0, 0, 0, 0.4),
    3px 6px 12px rgba(0, 0, 0, 0.35);
}

.pad-blue {
  bottom: 0;
  left: 0;
  border-bottom-left-radius: 100%;
  background: radial-gradient(circle at 38% 62%, #4a9eff 0%, #1565c0 35%, #0d47a1 70%, #083570 100%);
  box-shadow:
    inset 3px 3px 10px rgba(255, 255, 255, 0.3),
    inset -6px -8px 14px rgba(0, 0, 0, 0.45),
    3px 6px 12px rgba(0, 0, 0, 0.35);
}

.pad-green.lit {
  background: radial-gradient(circle at 62% 38%, #8cffaa 0%, #4fd06a 45%, #2ecc71 100%);
  box-shadow:
    inset 0 0 22px rgba(255, 255, 255, 0.55),
    inset 2px 2px 8px rgba(0, 0, 0, 0.25),
    0 0 28px rgba(46, 204, 113, 0.75),
    0 0 50px rgba(46, 204, 113, 0.35);
  filter: brightness(1.15);
}

.pad-red.lit {
  background: radial-gradient(circle at 38% 38%, #ff6b72 0%, #e83540 45%, #c42026 100%);
  box-shadow:
    inset 0 0 22px rgba(255, 255, 255, 0.45),
    inset 2px 2px 8px rgba(0, 0, 0, 0.25),
    0 0 28px rgba(196, 32, 38, 0.75),
    0 0 50px rgba(196, 32, 38, 0.35);
  filter: brightness(1.15);
}

.pad-yellow.lit {
  background: radial-gradient(circle at 62% 62%, #fff599 0%, #ffe566 45%, #f0c800 100%);
  box-shadow:
    inset 0 0 22px rgba(255, 255, 255, 0.55),
    inset 2px 2px 8px rgba(0, 0, 0, 0.2),
    0 0 28px rgba(240, 200, 0, 0.75),
    0 0 50px rgba(240, 200, 0, 0.35);
  filter: brightness(1.15);
}

.pad-blue.lit {
  background: radial-gradient(circle at 38% 62%, #7ec0ff 0%, #4a9eff 45%, #1565c0 100%);
  box-shadow:
    inset 0 0 22px rgba(255, 255, 255, 0.45),
    inset 2px 2px 8px rgba(0, 0, 0, 0.25),
    0 0 28px rgba(21, 101, 192, 0.75),
    0 0 50px rgba(21, 101, 192, 0.35);
  filter: brightness(1.15);
}

.pad.pad-press {
  transform: scale(0.965);
  box-shadow:
    inset 0 0 16px rgba(0, 0, 0, 0.35),
    inset 4px 4px 10px rgba(0, 0, 0, 0.4);
}

.board-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 38%;
  height: 38%;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #555 0%, #3a3a3a 35%, #222 70%, #111 100%);
  box-shadow:
    0 0 0 5px #333,
    0 0 0 7px #222,
    0 8px 20px rgba(0, 0, 0, 0.75),
    inset 0 4px 8px rgba(255, 255, 255, 0.1),
    inset 0 -8px 16px rgba(0, 0, 0, 0.65);
  pointer-events: none;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-center span {
  font-size: clamp(0.85rem, 3.5vw, 1.35rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #888;
  text-transform: uppercase;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.controls {
  display: flex;
  gap: 1rem;
}

.btn {
  padding: 0.75rem 1.75rem;
  border: none;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, #6c63ff, #4a42d4);
  color: #fff;
}

.btn-secondary {
  background: #333;
  color: #f0f0f5;
}

.status {
  margin: 0;
  color: #a0a0b8;
  min-height: 1.5rem;
  text-align: center;
}

.status.status-animate {
  animation: status-pop 0.35s ease-out;
}

.scoreboard-section {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 1.25rem;
}

.scoreboard-section h2 {
  margin: 0 0 1rem;
  font-size: 1.25rem;
}

.scoreboard-message {
  color: #a0a0b8;
  text-align: center;
  padding: 1rem 0;
}

#scoreboard {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

#scoreboard th,
#scoreboard td {
  padding: 0.5rem 0.4rem;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#scoreboard th {
  color: #a0a0b8;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#scoreboard td:first-child {
  color: #a0a0b8;
  width: 2rem;
}

.page-centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal[hidden] {
  display: none;
}

.panel {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 2rem;
  width: min(420px, 100%);
  text-align: center;
}

.panel h1 {
  margin: 0 0 0.5rem;
  font-size: 2rem;
}

.panel-score {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.panel-meta {
  margin: 0 0 1.5rem;
  color: #a0a0b8;
  font-size: 0.95rem;
}

.panel-desc {
  margin: 0 0 1.5rem;
  color: #a0a0b8;
  font-size: 0.95rem;
}

.panel label {
  display: block;
  text-align: left;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  color: #a0a0b8;
}

.panel input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: #0f0f1a;
  color: #f0f0f5;
  font-size: 1rem;
  margin-bottom: 1rem;
}

.panel-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.panel-actions a.btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.error {
  color: #ff6b6b;
  font-size: 0.85rem;
  margin-top: 0.75rem;
}

.success {
  color: #6bff9f;
  font-size: 0.9rem;
  margin-top: 0.75rem;
}

.success a {
  color: #6c63ff;
}

.settings-panel {
  text-align: left;
}

.settings-panel h2 {
  margin: 0 0 1.25rem;
  text-align: center;
}

.settings-field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
  color: #a0a0b8;
}

.settings-value {
  color: #f0f0f5;
  font-weight: 600;
}

#board-size-slider {
  width: 100%;
  margin-bottom: 1.5rem;
  accent-color: #6c63ff;
}

.settings-panel .panel-actions {
  justify-content: center;
}

@keyframes pad-flash {
  0% { filter: brightness(1); transform: scale(1); }
  25% { filter: brightness(1.5); transform: scale(1.02); }
  100% { filter: brightness(1.15); transform: scale(1); }
}

@keyframes board-ready {
  0%, 100% {
    box-shadow:
      0 0 0 10px #1a1a1a,
      0 0 0 12px #333,
      0 18px 40px rgba(0, 0, 0, 0.65),
      inset 0 -8px 20px rgba(0, 0, 0, 0.5);
  }
  50% {
    box-shadow:
      0 0 0 10px #1a1a1a,
      0 0 0 12px #444,
      0 18px 45px rgba(108, 99, 255, 0.2),
      inset 0 -8px 20px rgba(0, 0, 0, 0.5);
  }
}

@keyframes board-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

@keyframes stat-bump {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); color: #6c63ff; }
  100% { transform: scale(1); }
}

@keyframes status-pop {
  0% { opacity: 0.4; transform: translateY(6px); }
  100% { opacity: 1; transform: translateY(0); }
}

@media (max-width: 768px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .scoreboard-section {
    order: 2;
  }
}
