@import url("https://fonts.googleapis.com/css2?family=Inter:wght@500;600;700&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap");

:root {
  --bg-950: #090b0f;
  --bg-900: #11141b;
  --bg-800: #1e2430;
  --text-100: #eef2f9;
  --text-300: #c9d1df;
  --text-500: #a9b2c3;
  --gold-500: #c8a24a;
  --gold-400: #d8b767;
  --gold-300: #e5cc8f;
  --surface: rgba(17, 20, 27, 0.93);
  --surface-alt: rgba(30, 36, 48, 0.9);
  --border: rgba(229, 204, 143, 0.22);
  --shadow-lg: 0 16px 32px rgba(0, 0, 0, 0.4);
  --app-bg: radial-gradient(circle at 16% 10%, #2b364d 0%, #1d2433 38%, #0b0e15 100%);
  --panel-text-strong: #fff5df;
  --rail-tick: #f1dc9d;
}

body[data-theme="light"] {
  --bg-950: #e9f4fb;
  --bg-900: #fff4dd;
  --bg-800: #ffffff;
  --text-100: #123140;
  --text-300: #4b6570;
  --text-500: #4b6570;
  --gold-500: #0f7e9b;
  --gold-400: #0b5f77;
  --gold-300: #d67b19;
  --surface: rgba(255, 255, 255, 0.96);
  --surface-alt: rgba(247, 252, 255, 0.98);
  --border: #c8dbe3;
  --shadow-lg: 0 12px 24px rgba(12, 54, 68, 0.12);
  --app-bg:
    radial-gradient(1200px 700px at 8% 2%, rgba(19, 143, 176, 0.18), transparent 62%),
    radial-gradient(900px 600px at 92% 98%, rgba(220, 132, 32, 0.18), transparent 66%),
    linear-gradient(165deg, #e9f4fb, #fff4dd);
  --panel-text-strong: #123140;
  --rail-tick: #123140;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Inter", "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--text-100);
  background: var(--app-bg);
  line-height: 1.45;
  overflow-x: hidden;
}

.bg-grid {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(229, 204, 143, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(229, 204, 143, 0.07) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at center, black 42%, transparent 95%);
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: "Inter", "IBM Plex Sans", "Segoe UI", sans-serif;
}

.shell {
  width: min(1480px, calc(100% - 2rem));
  margin-inline: auto;
}

.hero {
  margin-top: 1.2rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.2rem 1.4rem;
  padding-right: 12.5rem;
  background: linear-gradient(130deg, rgba(20, 25, 36, 0.95), rgba(11, 13, 19, 0.95));
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 12px;
  background: var(--gold-500);
  border-radius: 14px 0 0 14px;
}

body[data-theme="light"] .hero {
  background: linear-gradient(160deg, #ffffff, #f7fbfd);
  border-color: #c8dbe3;
}

.kicker {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gold-400);
  font-weight: 700;
}

.hero h1 {
  font-size: clamp(1.8rem, 2.4vw, 3rem);
  margin-top: 0.35rem;
  color: var(--panel-text-strong);
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.subtitle {
  margin: 0.38rem 0 0;
  color: var(--text-300);
  max-width: 75ch;
}

.hero-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.hero-top > :first-child {
  flex: 1 1 auto;
  min-width: 0;
  padding-left: 0.4rem;
}

.display-toggle {
  min-width: 156px;
  position: absolute;
  top: 1rem;
  right: 1rem;
  padding-inline: 1rem;
  z-index: 2;
}

.app-layout {
  margin-top: 1rem;
  margin-bottom: 2rem;
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

.panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 1rem;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
}

.full {
  grid-column: span 12;
}

.wide {
  grid-column: span 8;
}

.narrow {
  grid-column: span 4;
}

.inquiry-grid {
  margin-top: 0.8rem;
  display: grid;
  gap: 0.7rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.inquiry-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  background: var(--surface-alt);
}

.inquiry-card h3 {
  font-size: 1.05rem;
  margin-bottom: 0.34rem;
}

.inquiry-card p {
  color: var(--text-300);
  margin: 0;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  font-size: 0.92rem;
  color: var(--text-300);
}

.control-note {
  font-size: 0.82rem;
  line-height: 1.35;
  color: var(--text-500);
}

input,
select,
button,
output {
  font: inherit;
}

input,
select,
output {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
  color: var(--text-100);
  padding: 0.54rem 0.62rem;
}

button {
  border: 1px solid var(--gold-500);
  border-radius: 10px;
  background: linear-gradient(135deg, var(--gold-500), var(--gold-400));
  color: #2b1d06;
  font-weight: 700;
  padding: 0.58rem 0.82rem;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.06);
}

button.ghost {
  background: rgba(200, 162, 74, 0.12);
  color: var(--text-100);
}

body[data-theme="light"] button {
  background: linear-gradient(160deg, #0d839f, #0b5f77);
  color: #ffffff;
  border-color: #0a5d74;
}

body[data-theme="light"] button.ghost {
  background: #f6fbfd;
  color: var(--text-100);
  border-color: #9dbac5;
}

body[data-theme="light"] .display-toggle {
  background: #eef6fa;
  color: var(--text-100);
  border-color: #b8d1db;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
output:focus-visible {
  outline: 2px solid var(--gold-400);
  outline-offset: 2px;
}

.controls-grid {
  margin-top: 0.6rem;
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
}

.control-span-2 {
  grid-column: span 2;
}

.range-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem;
}

.range-row output {
  min-width: 3.8ch;
  text-align: right;
  color: var(--gold-300);
  border: none;
  background: transparent;
  padding: 0;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.button-row {
  margin-top: 0.7rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.button-row button {
  flex: 1 1 0;
  min-width: 0;
}

.compact-toggle {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 0.45rem;
  min-height: 38px;
  padding: 0.2rem 0;
}

.compact-toggle input {
  width: 1rem;
  height: 1rem;
  margin: 0;
}

.sim-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.7rem;
}

.sim-toolbar .hint {
  margin: 0;
  flex: 1 1 280px;
}

.scenario-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.45rem;
  width: min(100%, 920px);
}

.scenario-row button {
  width: 100%;
}

.sim-canvas {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: radial-gradient(circle at 12% 12%, rgba(223, 190, 115, 0.14), transparent 34%),
    linear-gradient(180deg, #0d1118 0%, #090b0f 100%);
}

body[data-theme="light"] .sim-canvas {
  background: linear-gradient(180deg, #f8fcff, #f2f8fb);
  border-color: #b8d1db;
}

.sim-canvas + h3 {
  margin: 0.6rem 0 0.3rem;
  color: var(--gold-300);
  font-size: 1.05rem;
}

.metric-grid {
  margin-top: 0.7rem;
  display: grid;
  gap: 0.55rem;
}

.metric-card {
  border: 1px solid var(--border);
  border-left: 5px solid var(--gold-500);
  background: var(--surface-alt);
  border-radius: 10px;
  padding: 0.62rem 0.7rem;
}

.metric-card h3 {
  font-size: 1rem;
  margin-bottom: 0.35rem;
}

.metric-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6rem;
  color: var(--text-300);
}

.metric-line span {
  color: var(--text-100);
  font-weight: 700;
}

.metric-ok {
  color: #5cbf79;
}

.metric-bad {
  color: #ff5f7a;
}

.metric-warn {
  color: var(--gold-300);
}

.check-grid {
  margin-top: 0.55rem;
  display: grid;
  gap: 0.55rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.hint {
  margin: 0.6rem 0 0;
  color: var(--text-300);
  font-size: 0.92rem;
}

.hint.success {
  color: #99f0b2;
  font-weight: 700;
}

.hint.error {
  color: #ffb7c4;
  font-weight: 700;
}

#probeReadout {
  margin-top: 0.45rem;
  white-space: pre-line;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
  padding: 0.65rem 0.75rem;
}

#scoreLine {
  color: var(--gold-300);
  font-weight: 700;
}

.hidden-details {
  display: none;
}

body.hide-details .metric-grid,
body.hide-details #probeReadout {
  display: none;
}

#gameModeHint,
#newChallengeBtn,
#scoreLine {
  display: none;
}

body.test-mode .compact-toggle {
  order: 1;
}

body.test-mode #gameModeHint,
body.test-mode #newChallengeBtn,
body.test-mode #scoreLine {
  display: flex;
}

body.test-mode #collisionMode,
body.test-mode #restitution,
body.test-mode #mass1,
body.test-mode #mass2,
body.test-mode #velocity1,
body.test-mode #velocity2,
body.test-mode #friction {
  opacity: 0.66;
}

body.test-mode #mass1,
body.test-mode #mass2,
body.test-mode #velocity1,
body.test-mode #velocity2,
body.test-mode #restitution,
body.test-mode #friction {
  pointer-events: none;
}

body.test-mode #mass1Value,
body.test-mode #mass2Value,
body.test-mode #velocity1Value,
body.test-mode #velocity2Value,
body.test-mode #restitutionValue,
body.test-mode #frictionValue {
  opacity: 0.66;
}

body[data-theme="light"] .metric-card {
  background: linear-gradient(170deg, #f7fcff, #f1f9fd);
  border-color: #b8d1db;
}

body[data-theme="light"] input,
body[data-theme="light"] select,
body[data-theme="light"] output {
  background: #f9fdff;
  color: var(--text-100);
  border-color: #a9c4cf;
}

body[data-theme="light"] .bg-grid {
  background-image: linear-gradient(rgba(15, 126, 155, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(214, 123, 25, 0.06) 1px, transparent 1px);
}

@media (max-width: 1180px) {
  .inquiry-grid,
  .wide,
  .narrow {
    grid-column: span 12;
  }

  .scenario-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .hero-top {
    flex-direction: column;
  }

  .hero {
    padding-right: 1.4rem;
  }

  .display-toggle {
    position: static;
    min-width: 0;
    width: auto;
    max-width: 220px;
  }
}

@media (max-width: 780px) {
  .shell {
    width: min(1480px, calc(100% - 1rem));
  }

  .inquiry-grid {
    grid-template-columns: 1fr;
  }

  .controls-grid,
  .check-grid {
    grid-template-columns: 1fr;
  }

  .control-span-2 {
    grid-column: span 1;
  }

  .range-row {
    grid-template-columns: 1fr 3rem;
  }

  .scenario-row {
    grid-template-columns: 1fr;
  }

  .display-toggle {
    max-width: none;
  }

  .hero {
    padding: 1rem 1rem 1.1rem;
  }

  .hero h1 {
    font-size: clamp(1.7rem, 10vw, 2.8rem);
  }
}
