*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: repeating-linear-gradient(
    45deg,
    #dbe6f7 0 6px,
    #d5e1f4 6px 12px
  );
  color: #334155;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.site-header {
  border-bottom: 6px solid #7f92b7;
  background: #d6e0f1;
}

.header-inner {
  padding: 1.25rem 1.25rem 1.5rem;
}

.site-title {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: 0.02em;
}

.site-tagline {
  margin: 0.4rem 0 0;
  color: #64748b;
  font-size: 0.95rem;
}

.site-main {
  flex: 1;
  padding: 1.5rem 1.25rem 2rem;
}

.hidden {
  display: none !important;
}

.dashboard {
  display: grid;
  grid-template-columns: 1fr 0.9fr;
  gap: 1rem;
  max-width: 820px;
  margin: 0 auto;
  padding: 1rem;
  border: 8px solid #6f84ad;
  background: #d6e0f1;
  color: #334155;
}

.dashboard-left,
.dashboard-right {
  border: 6px solid #7386b0;
  background: #c8d5ea;
  padding: 0.8rem;
}

.dash-play {
  width: 100%;
  border: 4px solid #7386b0;
  background: #dce7f7;
  color: #0f172a;
  font-size: 1.6rem;
  letter-spacing: 0.03em;
  font-weight: 800;
  text-transform: uppercase;
  padding: 0.85rem 0.5rem;
  cursor: pointer;
  transition: transform 0.06s ease, filter 0.12s ease;
}

.dash-play:hover {
  filter: brightness(1.03);
  transform: translateY(-1px);
}

.dash-level {
  margin-top: 0.7rem;
  border: 4px solid #7386b0;
  background: #dce7f7;
  padding: 0.55rem 0.7rem;
  font-size: 1.5rem;
  font-weight: 700;
}

.dash-highscores {
  margin-top: 0.7rem;
  border: 4px solid #7386b0;
  background: #dce7f7;
  padding: 0.5rem;
}

.dash-highscores h3 {
  margin: 0 0 0.45rem;
  text-align: center;
  font-size: 1rem;
  text-transform: uppercase;
}

.dash-highscores ol {
  margin: 0;
  padding-left: 1.4rem;
}

.dash-highscores li {
  padding: 0.22rem 0;
  font-size: 1rem;
}

.dash-stats {
  border: 4px solid #7386b0;
  background: #dce7f7;
  display: grid;
  gap: 0;
}

.dash-stats div {
  padding: 0.7rem;
  font-size: 1.45rem;
  font-weight: 700;
  border-bottom: 3px solid #9fb0cf;
}

.dash-stats div:last-child {
  border-bottom: 0;
}

.dash-logo {
  margin-top: 1rem;
  border: 4px solid #7386b0;
  background: linear-gradient(180deg, #f59e0b, #facc15 55%, #f8fafc);
  color: #1e3a8a;
  font-weight: 900;
  font-size: 2rem;
  letter-spacing: 0.02em;
  text-align: center;
  line-height: 1.08;
  padding: 1.1rem 0.7rem;
}

.games-list {
  display: block;
  max-width: 900px;
  margin: 0 auto;
  border: 8px solid #6f84ad;
  padding: 1rem;
  background: #d6e0f1;
}

.gameplay-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 160px;
  align-items: start;
  gap: 1rem;
}

.side-panel {
  border: 6px solid #7386b0;
  background: #c8d5ea;
  padding: 0.8rem;
}

.left-panel {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.play-stats {
  border: 3px solid #7386b0;
  background: #dce7f7;
}

.play-stats div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0.65rem;
  border-bottom: 2px solid #9fb0cf;
  font-weight: 700;
  font-size: 1rem;
}

.play-stats div:last-child {
  border-bottom: 0;
}

.center-board {
  justify-self: center;
}

.right-panel {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.next-title {
  margin: 0;
  text-transform: uppercase;
  color: #445782;
}

.next-wrapper {
  border: 3px solid #7386b0;
  background: #dce7f7;
  padding: 0.45rem;
}

#nextCanvas {
  width: 100%;
  height: auto;
  border: 3px solid #1e293b;
  background: #b9c8df;
}

.section-title {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  text-transform: uppercase;
  color: #445782;
}

.game-buttons {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.game-button {
  width: 100%;
  border-radius: 0;
  border: 3px solid #7386b0;
  padding: 0.55rem 0.75rem;
  background: #dce7f7;
  color: #334155;
  text-align: left;
  font: inherit;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.06s ease;
}

.game-button:hover:not(:disabled) {
  border-color: #5d739e;
  background: #e5ecf9;
  transform: translateY(-1px);
}

.game-button.active {
  border-color: #4f6a9a;
  box-shadow: inset 0 0 0 2px #b7c8e8;
}

.game-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.help-card {
  border-radius: 0;
  padding: 0.9rem 0.9rem 0.8rem;
  background: #dce7f7;
  border: 3px solid #7386b0;
}

.help-card h3 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
}

.help-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.9rem;
  color: #475569;
}

.help-list li + li {
  margin-top: 0.15rem;
}

.game-area {
  border-radius: 0;
  padding: 1rem;
  background: #c8d5ea;
  border: 6px solid #7386b0;
  box-shadow: none;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.game-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.scoreboard {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.75rem;
  border-radius: 0;
  background: #dce7f7;
  border: 3px solid #7386b0;
  font-size: 0.9rem;
}

.scoreboard span:last-child {
  font-weight: 600;
  color: #2f4e84;
}

.game-wrapper {
  position: relative;
  display: inline-block;
}

.game-toast {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  background: rgba(220, 231, 247, 0.95);
  border: 3px solid #7386b0;
  color: #334155;
  font-weight: 800;
  letter-spacing: 0.02em;
  padding: 0.35rem 0.8rem;
  z-index: 4;
  pointer-events: none;
  text-transform: uppercase;
}

canvas {
  display: block;
  border-radius: 0;
  background: #b9c8df;
  border: 4px solid #1e293b;
}

.mobile-controls {
  position: static;
  display: none;
  gap: 0.5rem;
  z-index: 5;
  touch-action: none;
  margin-top: 0.7rem;
  justify-content: center;
  align-items: center;
}

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

.mctrl {
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  border: 3px solid #7386b0;
  background: #dce7f7;
  color: #334155;
  font: inherit;
  font-weight: 800;
  padding: 0.5rem 0.6rem;
  min-width: 3.7rem;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
}

.mctrl-secondary {
  background: #c7d6f4;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
  background: rgba(100, 116, 139, 0.35);
}

.overlay-card {
  padding: 1rem 1.25rem;
  border-radius: 0;
  background: #dce7f7;
  border: 3px solid #7386b0;
  text-align: center;
  max-width: 260px;
}

.overlay-card h3 {
  margin: 0 0 0.4rem;
}

.overlay-card p {
  margin: 0 0 0.8rem;
  font-size: 0.9rem;
  color: #475569;
}

.primary-button {
  border-radius: 0;
  border: 3px solid #7386b0;
  padding: 0.45rem 1.2rem;
  font: inherit;
  cursor: pointer;
  background: #dce7f7;
  color: #334155;
  font-weight: 600;
  transition: transform 0.06s ease, box-shadow 0.1s ease, filter 0.1s ease;
  box-shadow: none;
}

.primary-button:hover {
  filter: brightness(1.03);
  transform: translateY(-1px);
  box-shadow: none;
}

.primary-button:active {
  transform: translateY(0);
  box-shadow: none;
}

.game-notes {
  margin-top: 1rem;
  padding-top: 0.6rem;
  border-top: 1px dashed rgba(55, 65, 81, 1);
  font-size: 0.9rem;
  color: #d1d5db;
}

.game-notes h3 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
}

.game-notes ul {
  margin: 0;
  padding-left: 1rem;
}

.game-notes li + li {
  margin-top: 0.15rem;
}

.site-footer {
  border-top: 6px solid #7f92b7;
  padding: 0.9rem 1.25rem 1.4rem;
  font-size: 0.85rem;
  color: #64748b;
  background: #d6e0f1;
}

.footer-inner {
  text-align: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 41, 59, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}

.modal-card {
  width: min(420px, 100%);
  border: 6px solid #7386b0;
  background: #dce7f7;
  padding: 1rem;
  box-shadow: 0 12px 28px rgba(51, 65, 85, 0.28);
}

.modal-card h3 {
  margin: 0 0 0.5rem;
  color: #334155;
  text-transform: uppercase;
}

.modal-score {
  margin: 0 0 0.8rem;
  font-weight: 700;
}

.name-form {
  display: grid;
  gap: 0.55rem;
}

.name-form label {
  font-size: 0.9rem;
  font-weight: 700;
  color: #475569;
}

.name-form input {
  border: 3px solid #7386b0;
  background: #f8fbff;
  color: #1e293b;
  padding: 0.5rem 0.6rem;
  font: inherit;
}

.name-error {
  margin: 0;
  color: #b91c1c;
  font-size: 0.85rem;
  font-weight: 700;
}

@media (max-width: 840px) {
  .dashboard {
    grid-template-columns: minmax(0, 1fr);
  }

  .gameplay-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .center-board {
    justify-self: start;
  }
}

@media (max-width: 520px) {
  .header-inner,
  .site-main {
    padding-inline: 0.85rem;
  }

  /* Remove extra framed containers so gameplay is bigger */
  .games-list {
    border: 0;
    padding: 0;
    background: transparent;
    max-width: none;
  }

  .game-area {
    border: 0;
    padding: 0;
    background: transparent;
  }

  .dashboard {
    grid-template-columns: minmax(0, 1fr);
    max-width: 420px;
    padding: 0.8rem;
  }

  .dashboard-left,
  .dashboard-right {
    max-width: 100%;
  }

  .game-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .game-wrapper {
    width: 100%;
  }

  canvas {
    width: 100%;
    height: auto;
  }

  .mobile-controls {
    display: flex;
    flex-direction: column;
  }

  .game-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  /* Mobile: gameplay on top, hide Next preview */
  .gameplay-layout {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
    width: 100%;
  }

  .center-board {
    order: 1;
    justify-self: auto;
    width: 100%;
    max-width: none;
    display: flex;
    justify-content: center;
  }

  .left-panel {
    order: 2;
    width: 100%;
    max-width: none;
  }

  .right-panel {
    display: none;
  }

  /* Make canvas smaller so buttons remain visible */
  #gameCanvas {
    max-width: 240px;
  }

  .mobile-controls {
    margin-top: 0.4rem;
  }

  .mctrl {
    min-width: 3.1rem;
    padding: 0.45rem 0.5rem;
    font-size: 0.95rem;
  }
}

