:root {
  color-scheme: dark;
  --bg: #07090d;
  --panel: rgba(14, 19, 27, 0.88);
  --panel-solid: #111822;
  --line: rgba(255, 255, 255, 0.14);
  --text: #f3f7fb;
  --muted: #98a8b8;
  --green: #37e6a0;
  --cyan: #5fc9f3;
  --amber: #f6c85f;
  --red: #ff5c7a;
  --floor: #202c37;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  overflow: hidden;
}

button,
input,
a {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  min-height: 520px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) auto minmax(220px, 1fr);
  align-items: center;
  gap: 18px;
  padding: 12px 18px;
  background: rgba(8, 12, 18, 0.96);
  border-bottom: 1px solid var(--line);
}

.brand,
.status-strip,
.nav-actions,
.button-row {
  display: flex;
  align-items: center;
}

.brand {
  gap: 10px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark {
  width: 20px;
  height: 20px;
  display: inline-block;
  background:
    linear-gradient(135deg, transparent 0 28%, var(--green) 29% 51%, transparent 52%),
    linear-gradient(45deg, var(--cyan), var(--amber));
  border: 1px solid rgba(255, 255, 255, 0.28);
  transform: rotate(45deg);
}

.status-strip {
  justify-content: center;
  gap: 10px;
  min-width: 0;
}

.status-strip span {
  min-width: 72px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
}

.nav-actions {
  justify-content: flex-end;
  gap: 10px;
}

.stage {
  position: relative;
  overflow: hidden;
  min-height: 0;
  background:
    radial-gradient(circle at 20% 15%, rgba(55, 230, 160, 0.12), transparent 24%),
    radial-gradient(circle at 74% 28%, rgba(246, 200, 95, 0.10), transparent 22%),
    linear-gradient(180deg, #080c12 0%, #111620 58%, #0b0d11 100%);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.metrics-panel {
  position: absolute;
  left: 16px;
  bottom: 16px;
  display: grid;
  grid-template-columns: repeat(4, minmax(116px, 1fr));
  gap: 10px;
  width: min(650px, calc(100% - 32px));
  pointer-events: none;
}

.metrics-panel div {
  min-height: 64px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
}

.metrics-panel span,
.launch-panel label span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.metrics-panel strong {
  display: block;
  margin-top: 5px;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.launch-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 5, 8, 0.58);
  backdrop-filter: blur(4px);
}

.launch-panel,
.finish-panel {
  width: min(620px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 22, 31, 0.94);
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.48);
}

.launch-panel {
  padding: 24px;
}

.launch-panel h1 {
  margin: 0 0 18px;
  font-size: clamp(30px, 5vw, 52px);
  line-height: 1;
  letter-spacing: 0;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.launch-panel label {
  display: grid;
  gap: 7px;
}

.launch-panel .field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field-label-row output {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.course-picker {
  grid-column: 1 / -1;
  display: grid;
  gap: 7px;
}

.course-picker > span {
  color: var(--muted);
  font-size: 12px;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-height: 42px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0a1018;
}

.segmented-control label {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  cursor: pointer;
}

.segmented-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segmented-control label span {
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--muted);
  text-align: center;
}

.segmented-control input:checked + span {
  color: #06120e;
  background: var(--green);
  font-weight: 800;
}

.segmented-control input:focus-visible + span {
  outline: 2px solid var(--cyan);
  outline-offset: -2px;
}

.launch-panel input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #0a1018;
  color: var(--text);
  outline: none;
}

.launch-panel input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(95, 201, 243, 0.14);
}

.launch-panel input[type="range"] {
  padding: 0;
  accent-color: var(--green);
}

.button-row {
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.primary-button,
.link-button,
.icon-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 13px;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.primary-button {
  border-color: rgba(55, 230, 160, 0.7);
  background: linear-gradient(180deg, #39d79a, #1aa774);
  color: #06100c;
  font-weight: 800;
}

.link-button,
.icon-button {
  background: rgba(255, 255, 255, 0.06);
}

.icon-button.danger {
  border-color: rgba(255, 92, 122, 0.45);
  color: #ffd3dc;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

.form-error {
  min-height: 20px;
  margin: 12px 0 0;
  color: #ffb1bf;
}

.finish-panel {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: min(440px, calc(100% - 32px));
  padding: 16px;
}

.finish-panel strong,
.finish-panel span {
  display: block;
}

.finish-panel span {
  margin-top: 5px;
  color: var(--muted);
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .status-strip,
  .nav-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .metrics-panel,
  .field-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metrics-panel {
    bottom: 10px;
    left: 10px;
    width: calc(100% - 20px);
  }

  .metrics-panel div {
    min-height: 56px;
  }

  .metrics-panel strong {
    font-size: 19px;
  }
}

.converter-shell {
  min-height: 100vh;
}

.converter-main {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 14px;
  min-height: 0;
  padding: 14px;
  background:
    linear-gradient(180deg, #080c12 0%, #101721 58%, #080a0e 100%);
}

.converter-panel,
.replay-stage {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
}

.converter-panel {
  display: grid;
  align-content: start;
  gap: 16px;
  min-width: 0;
  padding: 16px;
  overflow: auto;
}

.converter-panel > * {
  min-width: 0;
}

.converter-panel label {
  display: grid;
  gap: 7px;
}

.fixed-field {
  display: grid;
  gap: 7px;
}

.fixed-field strong {
  min-height: 42px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  padding: 0 10px;
  color: var(--text);
  background: #0a0f15;
  font-size: 14px;
}

.converter-panel input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #0a1018;
  color: var(--text);
}

.converter-panel label span,
.subtle-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.compact-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.log-list {
  display: grid;
  gap: 7px;
  margin-top: 8px;
}

.log-list button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.log-list button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-list small {
  color: var(--muted);
}

.replay-stage {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#replayCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

@media (max-width: 920px) {
  .converter-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(360px, 1fr);
  }
}
