:root {
  --bg: #0f1221;
  --card: #171a2d;
  --panel: #1f2440;
  --text: #f4f6ff;
  --muted: #b5bedf;
  --accent: #7d8dff;
  --accent-2: #34d3ff;
  --good: #2dd881;
  --bad: #ff6b6b;
  --border: #313b66;
  --prediction: #ea7cff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: radial-gradient(circle at top, #1c2140 0%, var(--bg) 58%);
  color: var(--text);
  min-height: 100vh;
}

.app-header {
  text-align: center;
  padding: 1.2rem 1rem 0.8rem;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(1.3rem, 2.8vw, 2rem);
  letter-spacing: 0.03em;
}

.app-header p {
  margin: 0.45rem 0 0;
  color: var(--muted);
}

.layout {
  width: min(1280px, 95%);
  margin: 0 auto 1.4rem;
  display: grid;
  grid-template-columns: 2.1fr 1fr;
  gap: 1rem;
}

.left-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.game-card,
.panel {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01));
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.28);
}

.game-card {
  padding: 0.85rem;
}

#gameCanvas,
#physicsGraphCanvas {
  width: 100%;
  height: auto;
  border-radius: 12px;
  background: linear-gradient(180deg, #1d2748 0%, #161c37 58%, #132f28 100%);
  border: 1px solid rgba(175, 190, 255, 0.2);
  display: block;
}

.physics-graph-panel {
  overflow: hidden;
}

.physics-graph-panel h2 {
  margin: 0;
  font-size: 1.05rem;
}

.physics-graph-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.65rem 1rem;
  margin-bottom: 0.65rem;
}

.physics-graph-controls {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: min(240px, 100%);
}

.physics-graph-controls label {
  font-size: 0.82rem;
  color: var(--muted);
}

.physics-graph-controls select {
  width: 100%;
}

.status-row {
  margin-top: 0.7rem;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  background-color: rgba(255, 255, 255, 0.04);
}

#message {
  margin: 0;
  font-weight: 600;
  color: var(--accent-2);
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.panel {
  padding: 0.95rem;
}

.panel h2 {
  margin: 0 0 0.65rem;
  font-size: 1.05rem;
}

.control-group {
  margin-bottom: 0.85rem;
}

.control-group label {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.control-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.control-toggle label {
  margin-bottom: 0;
}

.control-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-2);
  cursor: pointer;
}

input[type="range"],
select,
button,
.prediction-challenge-panel input[type="number"] {
  width: 100%;
}

input[type="range"] {
  accent-color: var(--accent);
}

select,
button {
  border-radius: 9px;
  border: 1px solid #4a5d9c;
  padding: 0.56rem 0.7rem;
  font-size: 0.95rem;
}

select {
  background-color: #131937;
  color: var(--text);
}

.prediction-challenge-panel input[type="number"] {
  border-radius: 9px;
  border: 1px solid rgba(138, 90, 209, 0.55);
  padding: 0.56rem 0.72rem;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, rgba(24, 16, 48, 0.95), #131937);
  color: var(--text);
}

.prediction-challenge-panel input[type="number"]::placeholder {
  color: rgba(180, 190, 230, 0.45);
}

.prediction-challenge-panel input[type="number"]:focus {
  outline: none;
  border-color: var(--prediction);
  box-shadow: 0 0 0 3px rgba(234, 124, 255, 0.18);
}

.prediction-submit-btn {
  margin-top: 0.15rem;
  background: linear-gradient(90deg, #9b4dff, var(--prediction)) !important;
  border-color: rgba(210, 150, 255, 0.55) !important;
}

.prediction-outcome {
  margin: 0.7rem 0 0;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  background: rgba(8, 10, 28, 0.45);
  border: 1px solid rgba(120, 100, 200, 0.22);
  font-size: 0.87rem;
  line-height: 1.42;
  min-height: 2.95em;
}

.prediction-outcome.muted {
  color: rgba(175, 186, 220, 0.62);
}

.prediction-outcome.excellent {
  color: var(--good);
  border-color: rgba(45, 216, 129, 0.35);
}

.prediction-outcome.good {
  color: var(--accent-2);
  border-color: rgba(52, 211, 255, 0.28);
}

.prediction-outcome.far {
  color: #ffb28a;
  border-color: rgba(255, 140, 90, 0.28);
}

.level-system-panel .compact-level {
  margin-bottom: 0.45rem;
}

.moving-target-badge {
  margin: 0;
  padding: 0.35rem 0.55rem;
  display: inline-block;
  width: fit-content;
  border-radius: 8px;
  font-size: 0.71rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 220, 120, 0.94);
  background: linear-gradient(
    145deg,
    rgba(234, 124, 255, 0.18),
    rgba(52, 211, 255, 0.12)
  );
  border: 1px solid rgba(234, 124, 255, 0.38);
}

.moving-target-badge[hidden] {
  display: none !important;
}

.level-summary {
  margin: 0.25rem 0 0;
  font-size: 0.82rem;
  line-height: 1.35;
  color: rgba(177, 188, 226, 0.78);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

button {
  cursor: pointer;
  background: linear-gradient(90deg, var(--accent), #6677ff);
  color: #fff;
  font-weight: 600;
  transition: transform 0.15s ease, filter 0.15s ease;
}

button.secondary {
  background: linear-gradient(90deg, #39416c, #2b355e);
}

button:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

.results-panel ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.results-panel li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.38rem 0;
  border-bottom: 1px dashed rgba(174, 186, 240, 0.22);
  font-size: 0.93rem;
}

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

.results-panel span {
  color: var(--muted);
}

.results-panel strong {
  font-variant-numeric: tabular-nums;
}

.explain-panel p {
  margin: 0.45rem 0;
  color: var(--muted);
  line-height: 1.42;
  font-size: 0.9rem;
}

.breakdown-panel p {
  margin: 0 0 0.5rem;
  color: var(--muted);
  line-height: 1.35;
  font-size: 0.88rem;
}

#breakdownContent {
  margin: 0;
  padding: 0.7rem;
  background: rgba(8, 12, 30, 0.55);
  border: 1px solid rgba(142, 160, 237, 0.25);
  border-radius: 10px;
  color: #dff4ff;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.hit {
  color: var(--good) !important;
}

.miss {
  color: var(--bad) !important;
}

.replay-shot-btn {
  margin-top: 0.55rem;
  width: 100%;
}

.replay-status {
  margin: 0.45rem 0 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: rgba(255, 206, 120, 0.92);
}

.challenge-generator-drawer.panel {
  padding-top: 0.65rem;
}

.challenge-summary {
  cursor: pointer;
  font-weight: 650;
  font-size: 1rem;
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.challenge-summary::-webkit-details-marker {
  display: none;
}

.challenge-summary::after {
  content: "▸";
  margin-left: auto;
  font-size: 0.72rem;
  opacity: 0.65;
}

.challenge-generator-drawer[open] .challenge-summary::after {
  content: "▾";
}

.optional-tag {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
}

.challenge-drawer-inner {
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px dashed rgba(120, 140, 210, 0.28);
}

.challenge-draft {
  margin: 0 0 0.65rem;
  font-size: 0.86rem;
  line-height: 1.42;
  min-height: 2.6em;
}

.challenge-draft.muted,
.challenge-active-banner.muted {
  color: rgba(175, 186, 220, 0.72);
}

.challenge-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.challenge-clear-btn {
  width: 100%;
}

.challenge-active-banner {
  margin: 0.55rem 0 0;
  font-size: 0.85rem;
  line-height: 1.38;
  padding: 0.5rem 0.55rem;
  border-radius: 9px;
  background: rgba(10, 14, 35, 0.45);
  border: 1px solid rgba(110, 130, 200, 0.22);
}

.challenge-active-banner.done {
  color: var(--good);
  border-color: rgba(45, 216, 129, 0.35);
}

@media (max-width: 1024px) {
  .layout {
    grid-template-columns: 1fr;
  
  }
  .bottom-info-grid {
  grid-template-columns: 1fr;
}

  /* Flatten sidebar so cards can reorder with the main column for small screens */
  main.layout > .side-panel {
    display: contents;
  }

  .left-column {
    order: 1;
  }

  .controls-panel {
    order: 2;
  }

  .level-system-panel {
    order: 3;
  }

  .prediction-challenge-panel {
    order: 4;
  }

  .results-panel {
    order: 5;
  }

  .explain-panel {
    order: 6;
  }

  .breakdown-panel {
    order: 7;
  }

  .challenge-generator-drawer {
    order: 8;
  }
}

.bottom-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.bottom-info-grid .panel {
  height: 100%;
}

.achievements-panel {
  grid-column: span 2;
}