:root {
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: #f7f8fa;
  background: radial-gradient(circle at top, #0e1c2f, #050b16 60%);
  min-height: 100%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 1rem;
  background: var(--theme-gradient);
  transition: background 0.6s ease;
  overflow-x: hidden;
  --theme-gradient: radial-gradient(circle at top, #0e1c2f, #050b16 60%);
  --theme-image: none;
  --theme-image-opacity: 0;
}

h1,
h2,
h3 {
  margin: 0;
}

main.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(260px, 1fr);
  gap: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

.playfield {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 1.5rem;
  position: relative;
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow: hidden;
  isolation: isolate;
}

.playfield::before,
.playfield::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 0;
}

.playfield::before {
  background: var(--theme-gradient);
  opacity: 0.4;
}

.playfield::after {
  background-image: var(--theme-image);
  background-size: cover;
  background-position: center;
  opacity: var(--theme-image-opacity, 0);
  mix-blend-mode: screen;
}

.playfield-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
}

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

.top-bar-actions {
  display: flex;
  gap: 0.5rem;
}

.tagline {
  color: #b5c8ff;
  margin-top: 0.35rem;
}

#start-btn {
  background: #ff4d97;
  border: none;
  border-radius: 999px;
  padding: 0.75rem 1.5rem;
  color: white;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease;
}

#start-btn:hover {
  transform: translateY(-2px);
}

#restart-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #f7f8fa;
  border-radius: 999px;
  padding: 0.65rem 1.25rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

#restart-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

canvas#playfield {
  width: min(320px, 100%);
  height: min(70vh, 640px);
  aspect-ratio: 1 / 2;
  display: block;
  background: rgba(2, 9, 18, 0.9);
  border-radius: 8px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  touch-action: none;
  position: relative;
  z-index: 1;
}

.side-info {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.power-status {
  margin: 0;
  font-size: 0.85rem;
  color: #fde68a;
  min-height: 1.2rem;
}

.hud {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin: 0;
  text-align: center;
  flex-wrap: wrap;
  width: 100%;
}

.hud-wrapper {
  width: 100%;
}

.hud-wrapper:empty {
  display: none;
}

.hud div {
  background: rgba(255, 255, 255, 0.05);
  padding: 0.5rem 1rem;
  border-radius: 10px;
  min-width: 90px;
}

.hud span {
  display: block;
  font-size: 0.8rem;
  color: #c1d7ff;
}

.hud strong {
  font-size: 1.6rem;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.preview-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  width: 100%;
  margin-bottom: 0.5rem;
}

.playfield-grid > .preview-row {
  margin-bottom: 0;
}

.mini-panel {
  background: rgba(2, 9, 18, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 0.75rem;
  text-align: center;
}

.mini-panel h3 {
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.mini-panel canvas {
  width: 100%;
  height: auto;
  max-width: 120px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  transition: box-shadow 0.2s ease;
}

.mini-panel canvas.power-ready {
  box-shadow: 0 0 15px rgba(252, 211, 77, 0.8);
}

.panel {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 1rem 1.25rem;
}

.scoreboard ol {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 0.35rem;
}

.scoreboard h3 {
  margin-bottom: 0.5rem;
  font-size: 1rem;
  color: #fef3c7;
}

.scoreboard-grids {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}

.scoreboard li {
  display: grid;
  grid-template-columns: 1.5rem 1fr auto;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.rank-note {
  margin-top: 0.5rem;
  color: #fef3c7;
}

.scoreboard li:last-child {
  border-bottom: none;
}

.scoreboard .rank {
  opacity: 0.75;
}

.scoreboard .points {
  font-weight: 700;
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.level-tag {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  font-weight: 600;
}

.instructions ul {
  padding-left: 1rem;
  line-height: 1.7;
}


.stats-panel {
  display: none;
}

.stats-panel.active {
  display: block;
}

.stats-panel .hud {
  justify-content: space-between;
  gap: 1rem;
}

.mobile-controls {
  display: none;
}

.mobile-controls button {
  font-size: 1.35rem;
  padding: 0.75rem;
  border-radius: 10px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  backdrop-filter: blur(4px);
}

.mobile-controls button[data-action="hold"] {
  font-size: 1rem;
  font-weight: 700;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal {
  border: none;
  border-radius: 16px;
  padding: 1.5rem;
  max-width: 320px;
  width: 90vw;
}

.modal form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.modal input {
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
}

.modal .rank-note {
  background: rgba(255, 255, 255, 0.2);
  color: #0f172a;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  font-weight: 600;
}

#final-stats {
  margin: 0;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  font-weight: 600;
  text-align: center;
  display: none;
}

#session-chart {
  width: 100%;
  height: auto;
  background: rgba(15, 23, 42, 0.08);
  border-radius: 10px;
  border: 1px solid rgba(15, 23, 42, 0.15);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.modal-actions button {
  border: none;
  border-radius: 10px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
}

.modal-actions button[type="submit"] {
  background: #0a7cff;
  color: white;
}

#share-score {
  background: #22c55e;
  color: #04220f;
}

.small {
  font-size: 0.85rem;
  opacity: 0.75;
}

@media (max-width: 960px) {
  main.app-shell {
    grid-template-columns: 1fr;
  }

  canvas#playfield {
    max-width: 320px;
    margin: 0 auto;
  }

  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .panel {
    flex: 1 1 45%;
  }
}

@media (max-width: 640px) {
  body {
    padding: 0.5rem;
  }

  .playfield {
    padding: 1rem;
  }

  .playfield-grid {
    align-items: center;
  }

  .hud {
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .sidebar {
    flex-direction: column;
  }

  .mobile-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
    gap: 0.5rem;
    width: 100%;
    max-width: 420px;
    align-self: center;
    margin-top: auto;
    margin-left: auto;
    margin-right: auto;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    position: sticky;
    bottom: 1rem;
    background: linear-gradient(180deg, rgba(5, 12, 25, 0), rgba(5, 12, 25, 0.85));
    backdrop-filter: blur(8px);
  }
}

@media (min-width: 961px) {
  .playfield-grid {
    flex-direction: row;
    align-items: flex-start;
  }

  .playfield-grid > canvas {
    flex: 1 1 auto;
    max-width: 440px;
  }

  .side-info {
    flex: 0 0 220px;
  }

  .stats-panel.active {
    display: block;
  }

  .stats-panel .hud {
    justify-content: space-around;
  }
}
#restart-btn.hidden,
.mobile-controls.hidden {
  display: none;
}
.brand-badge {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 999;
  background: rgba(4, 10, 25, 0.65);
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
  letter-spacing: 0.03em;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.brand-badge a {
  color: #fef3c7;
  text-decoration: none;
  font-weight: 600;
}
