:root {
  color-scheme: dark;
  --bg: #101820;
  --panel: #17232d;
  --panel-2: #22303b;
  --ink: #f5f3e8;
  --muted: #afbcc2;
  --cyan: #51d6d0;
  --coral: #ff6f59;
  --amber: #ffd166;
  --blue: #5f8cff;
  --line: rgba(255, 255, 255, 0.15);
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body {
  min-height: 100svh;
  background:
    linear-gradient(118deg, rgba(81, 214, 208, 0.14), transparent 35%),
    linear-gradient(304deg, rgba(255, 111, 89, 0.14), transparent 34%),
    linear-gradient(180deg, #101820, #0e1217);
}

button,
a {
  font: inherit;
}

.pr-bar {
  padding: 7px 12px;
  background: #0b1015;
  color: #d7d4c6;
  font-size: 12px;
  text-align: center;
  border-bottom: 1px solid var(--line);
}

.app {
  width: min(100%, 920px);
  min-height: calc(100svh - 31px);
  margin: 0 auto;
  padding: 18px clamp(12px, 3vw, 28px) 22px;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  gap: 14px;
}

.topline,
.scoreboard,
.stage,
.controls,
.support-strip,
.result {
  border: 1px solid var(--line);
  background: rgba(16, 24, 32, 0.86);
  box-shadow: var(--shadow);
}

.topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-radius: 8px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--amber);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1;
}

.hub-link,
.support-strip a {
  color: var(--ink);
  text-decoration: none;
}

.hub-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  font-weight: 800;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border-radius: 8px;
}

.scoreboard div {
  min-width: 0;
  padding: 10px;
  background: var(--panel);
}

.scoreboard span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.scoreboard strong {
  display: block;
  margin-top: 3px;
  font-size: 22px;
  line-height: 1;
}

.stage {
  min-height: 0;
  border-radius: 8px;
  padding: clamp(12px, 3vw, 20px);
  display: grid;
  grid-template-columns: minmax(190px, 0.72fr) minmax(280px, 1.28fr);
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 16px;
  align-items: stretch;
}

.target-panel,
.board-wrap {
  min-width: 0;
}

.target-panel {
  display: grid;
  align-content: center;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel-label {
  color: var(--amber);
  font-size: 12px;
  font-weight: 900;
}

.target-panel strong {
  min-height: 40px;
  font-size: 30px;
  line-height: 1;
}

.target-panel p {
  min-height: 48px;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.charges {
  color: var(--coral);
  font-size: 22px;
  letter-spacing: 4px;
}

.board-wrap {
  display: grid;
  align-items: center;
}

.puzzle-grid {
  width: min(100%, 460px);
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.cell {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #15212b;
  color: var(--ink);
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  font-weight: 900;
}

button.cell {
  cursor: pointer;
}

button.cell:enabled:hover,
button.cell:enabled:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

button.cell:disabled {
  cursor: default;
  color: #7f8a90;
}

.empty {
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    #13202a;
  background-size: 18px 18px;
}

.mirror {
  background: #243642;
}

.mirror span {
  display: grid;
  place-items: center;
  width: 76%;
  aspect-ratio: 1;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--cyan), var(--blue));
  color: #081017;
  font-size: clamp(26px, 8vw, 54px);
  line-height: 1;
}

.start,
.goal {
  color: #101820;
  text-align: center;
  font-size: clamp(10px, 2.4vw, 15px);
}

.start {
  background: var(--amber);
}

.goal {
  background: var(--coral);
}

.beam-cell::after {
  content: "";
  position: absolute;
  inset: 38%;
  border-radius: 999px;
  background: var(--amber);
  box-shadow: 0 0 18px 7px rgba(255, 209, 102, 0.62);
}

.feedback,
.viewport-state {
  grid-column: 1 / -1;
  min-height: 24px;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.viewport-state {
  min-height: 18px;
  font-size: 12px;
  color: #87949b;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
}

button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

button.primary {
  background: var(--cyan);
  border-color: rgba(81, 214, 208, 0.92);
  color: #071214;
}

button:disabled {
  cursor: default;
  color: #7f8a90;
  background: #1a252e;
}

.support-strip {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
}

.support-strip a {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-weight: 800;
}

.result {
  position: fixed;
  left: 50%;
  top: 50%;
  width: min(420px, calc(100vw - 24px));
  transform: translate(-50%, -50%);
  z-index: 10;
  padding: 22px;
  border-radius: 8px;
  text-align: center;
}

.result[hidden] {
  display: none;
}

.result-label {
  margin: 0;
  color: var(--amber);
  font-size: 12px;
  font-weight: 900;
}

.result strong {
  display: block;
  margin: 8px 0;
  font-size: 46px;
}

.result p {
  color: var(--muted);
}

.result button {
  width: 100%;
  margin-top: 8px;
}

@media (max-width: 720px) {
  .app {
    padding-top: 12px;
  }

  h1 {
    font-size: 27px;
  }

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

  .puzzle-grid {
    width: min(100%, 380px);
  }
}

@media (max-width: 480px) {
  .topline {
    padding: 12px;
  }

  h1 {
    font-size: 24px;
  }

  .scoreboard strong {
    font-size: 19px;
  }

  .stage {
    gap: 12px;
  }

  .puzzle-grid {
    gap: 5px;
  }

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

  .support-strip {
    flex-direction: column;
  }

  .support-strip a {
    justify-content: center;
  }
}
