* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
}

button,
.btn,
.icon-btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 16px;
}

.header {
  text-align: center;
}

.header__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header__brand {
  margin: 0;
  font-size: 1.4rem;
}

.header__user {
  text-align: right;
  font-size: 0.9rem;
  color: #cbd5f5;
}

.header__name {
  font-weight: 600;
  color: #e2e8f0;
}

.header__points {
  color: #94a3b8;
}

.subtitle {
  margin: 4px 0 0;
  color: #94a3b8;
}

main {
  flex: 1;
}

.section {
  display: none;
  flex-direction: column;
  gap: 16px;
}

.section--active {
  display: flex;
}

.section-title {
  font-size: 1.1rem;
  margin: 0 0 8px;
  text-align: left;
  color: #e2e8f0;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.game-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: #1e293b;
  border: 1px solid #334155;
  color: #e2e8f0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.icon-btn .icon-svg {
  width: 18px;
  height: 18px;
  display: block;
  margin: 0 auto;
}

.app[data-section="game"] .footer {
  display: none;
}

.app[data-section="select"] .footer {
  display: none;
}

.card {
  background: #1e293b;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.3);
}

.card--result {
  text-align: center;
  font-weight: 600;
}

.game-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 12px 0;
}

.game-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.controls-row {
  display: flex;
  gap: 8px;
}

.controls-row .btn,
.controls-row .btn--ghost {
  flex: 1;
}

.game-canvas {
  width: 100%;
  border-radius: 16px;
  background: #0b1220;
  border: 1px solid #1e293b;
  touch-action: none;
}

.status {
  font-size: 0.95rem;
  color: #94a3b8;
}

.legend {
  margin: 6px 0 4px;
  padding: 8px 10px;
  background: #111827;
  border-radius: 12px;
  font-size: 0.9rem;
  color: #cbd5f5;
}

.legend summary {
  cursor: pointer;
  font-weight: 600;
  color: #e2e8f0;
  list-style: none;
}

.legend summary::-webkit-details-marker {
  display: none;
}

.legend[open] summary {
  margin-bottom: 6px;
}

.legend ul {
  margin: 0;
  padding-left: 18px;
}

.btn {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  background: #38bdf8;
  color: #0f172a;
  font-weight: 600;
  cursor: pointer;
}

.btn--ghost {
  background: transparent;
  color: #e2e8f0;
  border: 1px solid #334155;
}

.link-btn {
  background: none;
  border: none;
  color: #38bdf8;
  font-weight: 600;
  cursor: pointer;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.game-card {
  background: #334155;
  border: none;
  color: #e2e8f0;
  padding: 16px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
}

.progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress__bar {
  height: 10px;
  background: #1e293b;
  border-radius: 999px;
  overflow: hidden;
}

.progress__fill {
  height: 100%;
  background: #22c55e;
  width: 0%;
  transition: width 0.3s ease;
}

.progress__meta {
  font-size: 0.9rem;
  color: #94a3b8;
}

.leaderboard {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.leaderboard li {
  display: flex;
  justify-content: space-between;
  background: #0f172a;
  padding: 8px 12px;
  border-radius: 10px;
}

.footer {
  display: flex;
  justify-content: center;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.is-open {
  display: flex;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.92);
}

.modal__content {
  position: relative;
  z-index: 1;
  background: #111827;
  border-radius: 16px;
  padding: 20px;
  width: min(90%, 320px);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.45);
  text-align: center;
}

#countdown-value {
  font-size: 3rem;
  color: #e2e8f0;
}

.modal__content h3 {
  margin-top: 0;
}

.modal__content p {
  color: #cbd5f5;
}

.start-legend {
  margin: 10px 0;
  padding: 10px 12px;
  background: #111827;
  border-radius: 12px;
  color: #cbd5f5;
  font-size: 0.9rem;
  text-align: left;
}

#result-modal .controls-row + .controls-row {
  margin-top: 10px;
}

@media (max-width: 420px) {
  .grid {
    grid-template-columns: 1fr;
  }
}
