* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --ink: #f8fffb;
  --muted: #a8bac3;
  --quiet: #78929d;
  --page: #061014;
  --console: #081217;
  --console-2: #0e2024;
  --deck: #1a2f49;
  --deck-2: #112339;
  --cell-off: #203541;
  --cell-inlay: #294653;
  --cyan: #38d7de;
  --cyan-hot: #54f0e2;
  --cyan-soft: rgba(56, 215, 222, 0.28);
  --gold: #d7b16a;
  --gold-hot: #ebd49a;
  --rose: #a95b48;
  --good: #9bcba8;
  --danger: #ff7f8f;
}

html {
  min-height: 100%;
  background: var(--page);
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(90deg, transparent 0 calc(7vw - 1px), rgba(169, 91, 72, 0.44) calc(7vw - 1px) calc(7vw + 2px), transparent calc(7vw + 2px)),
    linear-gradient(90deg, transparent 0 calc(93vw - 2px), rgba(169, 91, 72, 0.36) calc(93vw - 2px) calc(93vw + 1px), transparent calc(93vw + 1px)),
    linear-gradient(180deg, #061014 0%, #10231e 52%, #061014 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
  touch-action: manipulation;
}

button,
a {
  font: inherit;
}

a {
  color: inherit;
}

.shell {
  width: min(1160px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 34px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  margin-bottom: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  font-size: 21px;
  font-weight: 950;
  letter-spacing: 0;
  text-decoration: none;
}

.brand::before {
  width: 25px;
  height: 25px;
  border: 2px solid var(--cyan-hot);
  border-radius: 5px;
  background:
    linear-gradient(var(--cyan-hot) 0 0) 50% 0 / 2px 100% no-repeat,
    linear-gradient(var(--cyan-hot) 0 0) 0 50% / 100% 2px no-repeat,
    rgba(56, 215, 222, 0.08);
  box-shadow: 0 0 24px rgba(56, 215, 222, 0.38);
  content: "";
}

.topbar-actions,
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.icon-button,
.button,
.level-pill {
  border: 1px solid rgba(56, 215, 222, 0.44);
  border-radius: 4px;
  color: var(--ink);
  background: #08141d;
  box-shadow:
    inset 0 1px 0 rgba(84, 240, 226, 0.14),
    4px 5px 0 rgba(0, 0, 0, 0.42);
  cursor: pointer;
  text-decoration: none;
  transition: border-color 150ms ease, background-color 150ms ease, color 150ms ease, transform 150ms ease;
}

.icon-button {
  display: inline-flex;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.icon-button svg,
.button svg {
  stroke: currentColor;
  stroke-width: 2.25;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button svg {
  width: 21px;
  height: 21px;
}

.icon-button:hover,
.button:hover,
.level-pill:hover {
  transform: translateY(-1px);
  border-color: var(--gold);
  background: #10243a;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 840px) minmax(246px, 300px);
  gap: 18px;
  align-items: start;
  justify-content: center;
}

.stage {
  position: relative;
  overflow: hidden;
  border: 2px solid rgba(56, 215, 222, 0.58);
  border-radius: 24px;
  padding: clamp(18px, 3.2vw, 34px);
  background:
    linear-gradient(180deg, rgba(8, 18, 23, 0.98), rgba(4, 12, 17, 0.98)),
    var(--console);
  box-shadow:
    0 0 0 1px rgba(84, 240, 226, 0.24),
    0 0 40px rgba(56, 215, 222, 0.26),
    0 32px 90px rgba(0, 0, 0, 0.36);
}

.stage::before,
.stage::after {
  position: absolute;
  right: 8%;
  left: 8%;
  height: 4px;
  border-radius: 999px;
  background: rgba(56, 215, 222, 0.24);
  content: "";
  pointer-events: none;
}

.stage::before {
  top: 11px;
}

.stage::after {
  bottom: 11px;
}

.console-title {
  display: grid;
  grid-template-columns: minmax(0, max-content) minmax(84px, 1fr);
  gap: clamp(16px, 6vw, 150px);
  align-items: center;
  margin: 6px 0 24px;
}

.console-title p {
  margin: 0;
  color: var(--ink);
  font-size: clamp(30px, 5vw, 54px);
  font-weight: 950;
  line-height: 0.96;
  letter-spacing: 0;
}

.console-title span {
  display: block;
  margin-top: 18px;
  color: var(--muted);
  font-size: clamp(13px, 2vw, 17px);
}

.console-title i {
  display: block;
  height: 4px;
  background: linear-gradient(90deg, rgba(56, 215, 222, 0.12), rgba(56, 215, 222, 0.52));
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
  padding-top: 7px;
  border-top: 4px solid var(--cyan);
}

.status-strip > div {
  min-height: 58px;
  border: 1px solid rgba(56, 215, 222, 0.2);
  border-radius: 4px;
  padding: 9px 10px;
  background: rgba(4, 12, 17, 0.8);
}

.label {
  display: block;
  margin-bottom: 2px;
  color: var(--quiet);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-strip strong {
  color: var(--ink);
  font-size: clamp(19px, 4vw, 28px);
  line-height: 1;
}

.panel {
  border: 1px solid rgba(56, 215, 222, 0.24);
  border-radius: 4px;
  background: rgba(4, 12, 17, 0.74);
}

.board-panel {
  position: relative;
  padding: clamp(12px, 2.8vw, 22px);
}

.panel-heading {
  display: flex;
  min-height: 28px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 950;
}

.panel-heading span:first-child {
  color: var(--gold);
  text-transform: uppercase;
}

.panel-heading span:last-child {
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-shell {
  position: relative;
  width: min(100%, 640px);
  margin: 0 auto;
  padding: clamp(10px, 2.2vw, 18px);
  border: 1px solid rgba(84, 240, 226, 0.9);
  background: linear-gradient(180deg, #132b2f, #0d2024);
  box-shadow:
    0 0 0 7px rgba(56, 215, 222, 0.14),
    0 0 0 12px rgba(56, 215, 222, 0.08),
    0 0 34px rgba(56, 215, 222, 0.28);
}

.board-shell::before,
.board-shell::after {
  position: absolute;
  right: 4%;
  left: 4%;
  height: 3px;
  background: linear-gradient(90deg, transparent, rgba(84, 240, 226, 0.58), transparent);
  content: "";
  pointer-events: none;
}

.board-shell::before {
  top: 6%;
}

.board-shell::after {
  bottom: 6%;
}

canvas {
  display: block;
  width: 100%;
  border-radius: 2px;
  background: #071116;
}

#board-canvas,
#target-canvas {
  aspect-ratio: 1 / 1;
}

#board-canvas {
  cursor: pointer;
}

.hud-deck {
  display: grid;
  grid-template-columns: minmax(190px, 0.56fr) minmax(0, 1fr);
  gap: clamp(14px, 3vw, 22px);
  margin-top: 22px;
  border: 2px solid rgba(55, 103, 166, 0.74);
  border-radius: 2px;
  padding: clamp(13px, 2.5vw, 20px);
  background:
    linear-gradient(180deg, rgba(60, 100, 153, 0.34) 0 5px, transparent 5px),
    linear-gradient(180deg, var(--deck), #172d47);
  box-shadow: 6px 7px 0 rgba(0, 0, 0, 0.34);
}

.target-panel {
  border: 0;
  background: transparent;
}

.target-shell {
  width: min(100%, 240px);
  margin-top: 12px;
  padding: 8px;
  border-top: 4px solid rgba(215, 177, 106, 0.62);
  background: rgba(9, 26, 39, 0.52);
}

.hud-panel {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  border-left: 2px solid rgba(94, 137, 193, 0.62);
  padding-left: clamp(14px, 3vw, 26px);
}

.message {
  min-height: 72px;
  margin: 0;
  border-bottom: 4px solid rgba(215, 177, 106, 0.38);
  padding: 6px 0 14px;
  color: #d8e8ee;
  font-size: 15px;
  font-weight: 850;
}

.message::before {
  display: inline-block;
  width: 15px;
  height: 15px;
  margin-right: 10px;
  border-right: 3px solid var(--cyan-hot);
  border-bottom: 3px solid var(--cyan-hot);
  content: "";
  transform: translateY(2px) rotate(45deg);
}

.message.win {
  color: #c9f3d4;
  border-bottom-color: rgba(155, 203, 168, 0.72);
}

.message.fail {
  color: #ffd1d7;
  border-bottom-color: rgba(255, 127, 143, 0.78);
}

.button {
  display: inline-flex;
  flex: 1 1 0;
  min-width: 78px;
  min-height: 74px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 8px;
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.button svg {
  width: 28px;
  height: 28px;
}

.button.primary {
  border-color: rgba(84, 240, 226, 0.76);
  background: #1c4266;
}

.button:disabled {
  color: rgba(168, 186, 195, 0.48);
  border-color: rgba(120, 146, 157, 0.18);
  background: rgba(8, 20, 29, 0.56);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    3px 4px 0 rgba(0, 0, 0, 0.28);
  cursor: default;
  transform: none;
}

.side {
  display: grid;
  gap: 14px;
}

.level-card {
  border: 1px solid rgba(56, 215, 222, 0.22);
  border-radius: 4px;
  padding: 16px;
  background: rgba(8, 18, 23, 0.82);
  box-shadow: 0 20px 58px rgba(0, 0, 0, 0.28);
}

.level-card h2 {
  margin: 0 0 14px;
  color: var(--gold);
  font-size: 16px;
  line-height: 1;
  text-transform: uppercase;
}

.level-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.level-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.level-pill {
  min-height: 42px;
  padding: 0;
  font-weight: 950;
}

.level-pill[aria-current="true"] {
  border-color: var(--gold);
  color: var(--gold-hot);
  background: rgba(215, 177, 106, 0.12);
}

.level-pill.solved {
  box-shadow:
    inset 0 -4px 0 rgba(155, 203, 168, 0.78),
    4px 5px 0 rgba(0, 0, 0, 0.42);
}

@media (max-width: 920px) {
  .shell {
    width: calc(100% - 24px);
    max-width: 760px;
    padding-top: 12px;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

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

  .level-list {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .shell {
    width: calc(100% - 20px);
    max-width: 520px;
  }

  .topbar {
    margin-bottom: 12px;
  }

  .brand {
    font-size: 20px;
  }

  .icon-button {
    width: 40px;
    height: 40px;
  }

  .stage {
    border-radius: 18px;
    padding: 14px;
  }

  .console-title {
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 16px;
  }

  .console-title span {
    margin-top: 9px;
  }

  .status-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  .status-strip > div {
    min-height: 54px;
    padding: 8px 7px;
  }

  .label {
    font-size: 10px;
  }

  .status-strip strong {
    font-size: 20px;
  }

  .board-panel {
    padding: 10px;
  }

  .panel-heading {
    font-size: 12px;
  }

  .hud-deck {
    grid-template-columns: 1fr;
    gap: 15px;
  }

  .target-shell {
    width: min(220px, 100%);
    margin-right: auto;
    margin-left: auto;
  }

  .hud-panel {
    border-top: 2px solid rgba(94, 137, 193, 0.62);
    border-left: 0;
    padding-top: 14px;
    padding-left: 0;
  }

  .message {
    min-height: 60px;
    font-size: 14px;
  }

  .button {
    min-height: 64px;
  }

  .button svg {
    width: 24px;
    height: 24px;
  }

  .level-list {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (max-width: 390px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .shell {
    width: 100%;
    max-width: 100%;
    padding: 12px 10px 24px;
  }

  .topbar {
    gap: 10px;
  }

  .brand {
    font-size: 18px;
  }

  .topbar-actions {
    gap: 8px;
  }

  .controls {
    gap: 8px;
  }

  .game-layout,
  .stage,
  .panel,
  .board-shell,
  .hud-deck,
  .hud-panel,
  .side {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .button span {
    font-size: 11px;
  }
}
