:root {
  color-scheme: dark;
  --bg: #071015;
  --panel: #101a1f;
  --panel-2: #142126;
  --ink: #eef7f4;
  --muted: #8ea5a1;
  --line: rgba(157, 188, 182, 0.2);
  --electric: #1faeff;
  --cyan: #42e8d4;
  --cyan-deep: #0ba39a;
  --green: #65f16f;
  --amber: #f4bf4c;
  --red: #ff5d57;
  --blue: #64a7ff;
  --shadow: rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  letter-spacing: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(66, 232, 212, 0.04) 1px, transparent 1px),
    linear-gradient(0deg, rgba(244, 191, 76, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 20% 0%, rgba(100, 167, 255, 0.12), transparent 34rem),
    var(--bg);
  background-size: 42px 42px, 42px 42px, auto, auto;
}

button {
  font: inherit;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: rgba(7, 16, 21, 0.88);
  backdrop-filter: blur(14px);
}

.brand-stack {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.lab-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.35rem 0.55rem 0.35rem 0.35rem;
  border: 1px solid rgba(66, 232, 212, 0.22);
  border-radius: 8px;
  text-decoration: none;
  background: rgba(16, 26, 31, 0.62);
}

.lab-brand img {
  width: 2.3rem;
  height: 2.3rem;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 0 16px rgba(31, 174, 255, 0.36);
}

.lab-brand span {
  display: grid;
  gap: 0.08rem;
}

.lab-brand strong {
  color: var(--ink);
  font-size: 0.94rem;
  line-height: 1;
}

.lab-brand small {
  color: var(--electric);
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  text-shadow: 0 0 10px rgba(31, 174, 255, 0.44);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 800;
  font-size: 1.15rem;
}

.brand-mark {
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid rgba(66, 232, 212, 0.5);
  border-radius: 8px;
  position: relative;
  background: linear-gradient(135deg, rgba(66, 232, 212, 0.16), rgba(244, 191, 76, 0.12));
  box-shadow: 0 0 22px rgba(66, 232, 212, 0.2);
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  background: var(--cyan);
  box-shadow: 0 0 12px rgba(66, 232, 212, 0.82);
}

.brand-mark::before {
  width: 1.2rem;
  height: 0.2rem;
  left: 0.5rem;
  top: 1rem;
}

.brand-mark::after {
  width: 0.2rem;
  height: 1.2rem;
  left: 1.1rem;
  top: 0.5rem;
}

.top-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.top-stats span,
.home-chip {
  min-width: 5.5rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: rgba(16, 26, 31, 0.72);
}

.home-chip {
  color: var(--cyan);
  text-decoration: none;
}

.game-shell {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 2rem);
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(240px, 320px);
  gap: 1rem;
  align-items: stretch;
  flex: 1;
}

.stage {
  min-width: 0;
  min-height: 360px;
  position: relative;
  display: grid;
  place-items: center;
  border: 1px solid rgba(66, 232, 212, 0.22);
  border-radius: 8px;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(14, 32, 36, 0.92), rgba(9, 18, 22, 0.96)),
    #091216;
  box-shadow: 0 24px 60px var(--shadow);
}

#gameCanvas {
  width: min(100%, 760px);
  aspect-ratio: 1;
  display: block;
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
}

#gameCanvas:focus-visible {
  box-shadow: inset 0 0 0 3px rgba(244, 191, 76, 0.8);
}

.message-layer {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(7, 16, 21, 0.74);
  backdrop-filter: blur(6px);
}

.message-layer.is-visible {
  display: flex;
}

.message-content {
  width: min(360px, 100%);
  padding: 1.25rem;
  border: 1px solid rgba(66, 232, 212, 0.35);
  border-radius: 8px;
  background: rgba(12, 25, 30, 0.92);
  box-shadow: 0 20px 54px var(--shadow);
  text-align: center;
}

.message-content h1 {
  margin: 0 0 0.5rem;
  font-size: 2rem;
  line-height: 1.1;
}

.message-content p {
  min-height: 1.5rem;
  margin: 0 0 1rem;
  color: var(--muted);
}

.action-button,
.ghost-button {
  min-height: 2.75rem;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #061011;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: min(14rem, 100%);
  padding: 0.7rem 1rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--cyan), var(--amber));
  box-shadow: 0 0 28px rgba(66, 232, 212, 0.26);
}

.action-mark {
  width: 0;
  height: 0;
  border-top: 0.42rem solid transparent;
  border-bottom: 0.42rem solid transparent;
  border-left: 0.68rem solid #061011;
}

.action-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.action-button:active,
.ghost-button:active {
  transform: translateY(0);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 26, 31, 0.86);
  box-shadow: 0 24px 60px var(--shadow);
}

.readout {
  display: grid;
  gap: 0.5rem;
}

.difficulty-panel {
  display: grid;
  gap: 0.65rem;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
  padding: 0.35rem;
  border: 1px solid rgba(238, 247, 244, 0.12);
  border-radius: 8px;
  background: rgba(5, 10, 12, 0.72);
}

.segmented-control button {
  min-height: 2.35rem;
  padding: 0.35rem 0.45rem;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  background: transparent;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.segmented-control button:hover {
  color: var(--ink);
  border-color: rgba(66, 232, 212, 0.26);
}

.segmented-control button.is-active {
  color: #061011;
  font-weight: 800;
  background: linear-gradient(135deg, var(--cyan), var(--amber));
  box-shadow: 0 0 18px rgba(66, 232, 212, 0.18);
}

.readout-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
}

.meter {
  height: 0.8rem;
  border: 1px solid rgba(238, 247, 244, 0.12);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(5, 10, 12, 0.82);
}

.meter span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--cyan), var(--amber));
  transition: width 160ms ease;
}

.meter.heat span {
  width: 0%;
  background: linear-gradient(90deg, var(--blue), var(--amber), var(--red));
}

.run-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.run-grid div {
  min-height: 5rem;
  display: grid;
  align-content: center;
  gap: 0.3rem;
  padding: 0.75rem;
  border: 1px solid rgba(238, 247, 244, 0.1);
  border-radius: 8px;
  background: var(--panel-2);
}

.label {
  color: var(--muted);
  font-size: 0.84rem;
}

.run-grid strong {
  font-size: 1.35rem;
}

.level-list {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  margin-top: auto;
}

.level-list span {
  height: 0.6rem;
  border-radius: 999px;
  background: rgba(142, 165, 161, 0.25);
}

.level-list span.is-active {
  background: var(--cyan);
  box-shadow: 0 0 14px rgba(66, 232, 212, 0.62);
}

.level-list span.is-complete {
  background: var(--green);
}

.panel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.ghost-button {
  padding: 0.6rem 0.75rem;
  color: var(--ink);
  background: rgba(7, 16, 21, 0.78);
  border-color: rgba(238, 247, 244, 0.16);
}

.ghost-button:disabled {
  color: rgba(238, 247, 244, 0.38);
  cursor: not-allowed;
  transform: none;
}

.footer {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.footer a {
  color: var(--cyan);
  text-decoration: none;
}

@media (max-width: 860px) {
  .game-shell {
    grid-template-columns: 1fr;
  }

  .stage {
    min-height: auto;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand-stack {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-stats {
    width: 100%;
    justify-content: stretch;
  }

  .top-stats span {
    flex: 1 1 8rem;
  }

  .game-shell {
    padding: 0.75rem;
  }
}
