:root {
  color-scheme: dark;
  --bg-0: #020611;
  --bg-1: #071225;
  --bg-2: #0b1c32;
  --panel: rgba(7, 18, 37, 0.82);
  --panel-strong: rgba(8, 23, 46, 0.92);
  --line: rgba(104, 220, 255, 0.28);
  --line-strong: rgba(116, 240, 255, 0.8);
  --text: #d8f7ff;
  --muted: #7facc7;
  --accent: #68dcff;
  --accent-2: #15a7ff;
  --danger: #ff6e8f;
  --warn: #ffd66b;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(23, 147, 255, 0.22), transparent 34%),
    radial-gradient(circle at 20% 80%, rgba(104, 220, 255, 0.14), transparent 32%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1) 48%, #01040c 100%);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(104, 220, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(104, 220, 255, 0.03) 1px, transparent 1px);
  background-size: 3.5rem 3.5rem;
  mask-image: radial-gradient(circle at center, black 50%, transparent 100%);
}

.app-shell {
  position: relative;
  isolation: isolate;
  width: min(1180px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 1.4rem 0 2rem;
}

.circuit-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 0;
}

.circuit-path {
  fill: none;
  stroke: rgba(104, 220, 255, 0.18);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.circuit-path.connector {
  stroke: rgba(123, 248, 255, 0.22);
}

.circuit-pixel {
  fill: #f6feff;
  filter:
    drop-shadow(0 0 3px rgba(255, 255, 255, 0.95))
    drop-shadow(0 0 8px rgba(123, 248, 255, 0.72))
    drop-shadow(0 0 16px rgba(21, 167, 255, 0.42));
}

.masthead,
.layout {
  position: relative;
  z-index: 1;
}

.masthead {
  position: relative;
  margin-bottom: 1rem;
}

.panel-heading,
.feed-badge,
.controls-copy span,
.joystick-copy,
.title-hint,
.overlay-subtitle {
  text-transform: uppercase;
  letter-spacing: 0.22em;
}

.masthead-main {
  position: relative;
}

.masthead-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.2rem;
}

.title-hub {
  position: relative;
  z-index: 3;
}

.title-toggle {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  display: inline-flex;
  align-items: flex-end;
  gap: 0.85rem;
  color: inherit;
  cursor: pointer;
}

.title-text {
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: clamp(2.4rem, 4vw, 4.1rem);
  letter-spacing: 0.1em;
  color: #f3fdff;
  text-shadow:
    0 0 12px rgba(104, 220, 255, 0.32),
    0 0 28px rgba(21, 167, 255, 0.22);
}

.title-hint {
  padding-bottom: 0.55rem;
  color: var(--warn);
  font-size: 0.62rem;
}

.title-toggle:hover .title-text,
.title-toggle:focus-visible .title-text {
  color: #ffffff;
  text-shadow:
    0 0 16px rgba(123, 248, 255, 0.42),
    0 0 36px rgba(21, 167, 255, 0.28);
}

.title-toggle:focus-visible {
  outline: none;
}

.input-dropdown {
  position: absolute;
  top: calc(100% + 0.75rem);
  left: 0;
  width: min(22rem, calc(100vw - 2rem));
  padding: 1rem;
  border-radius: 1.2rem;
  border: 1px solid rgba(104, 220, 255, 0.24);
  background: linear-gradient(180deg, rgba(6, 19, 38, 0.98), rgba(3, 10, 21, 0.98));
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.42),
    inset 0 0 0 1px rgba(104, 220, 255, 0.08);
}

.feed-line {
  display: inline-flex;
  align-items: center;
  gap: 0.9rem;
  min-height: 3.1rem;
  padding: 0.7rem 1rem;
  border-radius: 999px;
  border: 1px solid rgba(104, 220, 255, 0.2);
  background: rgba(6, 18, 35, 0.72);
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.feed-line::-webkit-scrollbar {
  display: none;
}

.feed-badge,
.feed-item {
  font-size: 0.68rem;
}

.feed-badge {
  color: var(--muted);
}

.feed-item {
  color: #b8eaf8;
}

.feed-item strong {
  margin-left: 0.3rem;
  color: #f3fdff;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: 1rem;
  letter-spacing: 0.08em;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(230px, 280px);
  gap: 1.25rem;
  align-items: start;
}

.board-panel,
.panel {
  position: relative;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(11, 28, 50, 0.94), var(--panel));
  box-shadow:
    0 18px 60px rgba(0, 0, 0, 0.35),
    inset 0 0 0 1px rgba(104, 220, 255, 0.06);
}

.board-panel {
  overflow: hidden;
  border-radius: 1.6rem;
  padding: 0.95rem;
  min-height: 36.5rem;
}

.board-panel::before,
.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(104, 220, 255, 0.14), transparent 30%);
  pointer-events: none;
}

.board-frame {
  position: relative;
  min-height: 34rem;
  display: grid;
  place-items: center;
}

.board-shell {
  position: relative;
  width: min(44vw, 14rem);
  aspect-ratio: 1 / 2;
  border-radius: 1rem;
  transform-origin: center;
  transition: transform 560ms cubic-bezier(0.2, 0.85, 0.2, 1);
  overflow: visible;
  background:
    linear-gradient(180deg, rgba(8, 23, 46, 0.94), rgba(5, 12, 24, 0.96)),
    radial-gradient(circle at top, rgba(104, 220, 255, 0.2), transparent 38%);
}

.board-rotor {
  position: absolute;
  inset: -0.4rem;
  border-radius: 1.3rem;
  border: 1px solid rgba(104, 220, 255, 0.44);
  box-shadow:
    0 0 0 1px rgba(104, 220, 255, 0.12),
    0 0 24px rgba(21, 167, 255, 0.2);
}

.board-rotor::before,
.board-rotor::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.board-rotor::before {
  left: 12%;
  right: 12%;
  bottom: 0.65rem;
  height: 0.28rem;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, rgba(123, 248, 255, 0.96), transparent);
  box-shadow:
    0 0 10px rgba(123, 248, 255, 0.72),
    0 0 20px rgba(21, 167, 255, 0.32);
}

.board-rotor::after {
  inset: 0.55rem;
  border-radius: 0.95rem;
  border: 1px solid rgba(104, 220, 255, 0.14);
  background:
    linear-gradient(120deg, transparent 0 35%, rgba(123, 248, 255, 0.16) 45%, transparent 58%),
    linear-gradient(300deg, transparent 0 30%, rgba(255, 214, 107, 0.12) 44%, transparent 60%);
  animation: circuitSweep 2.8s linear infinite;
}

.board-grid,
.preview-grid {
  display: grid;
  gap: 1.5px;
}

.board-grid {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(20, 1fr);
  padding: 0.28rem;
  border-radius: 1rem;
  overflow: hidden;
  border: 1px solid rgba(104, 220, 255, 0.18);
  box-shadow: inset 0 0 0 1px rgba(104, 220, 255, 0.06);
}

.preview-grid {
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  width: min(100%, 7.15rem);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  padding: 0.28rem;
  border-radius: 0.85rem;
  background: linear-gradient(180deg, rgba(4, 11, 22, 0.9), rgba(10, 23, 40, 0.96));
  border: 1px solid rgba(104, 220, 255, 0.24);
}

.cell {
  position: relative;
  border-radius: 0.18rem;
  border: 1px solid rgba(104, 220, 255, 0.06);
  background:
    linear-gradient(180deg, rgba(6, 12, 22, 0.82), rgba(3, 8, 18, 0.92));
  overflow: hidden;
}

.cell.filled {
  border-color: currentColor;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.14),
    0 0 8px currentColor,
    0 0 16px rgba(255, 255, 255, 0.06);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.34), transparent 38%),
    repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.18) 0 6px, rgba(255, 255, 255, 0) 6px 12px),
    linear-gradient(180deg, var(--block-top), var(--block-bottom));
  animation: blockPulse 1.9s ease-in-out infinite;
}

.cell.filled::after {
  content: "";
  position: absolute;
  inset: -30% -120%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.36), transparent);
  transform: translateX(-45%) skewX(-24deg);
  animation: lightSweep 2.5s linear infinite;
  mix-blend-mode: screen;
}

.cell.active {
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.24),
    0 0 12px currentColor,
    0 0 22px currentColor;
  animation: blockSurge 1s ease-in-out infinite;
}

.block-i {
  color: #7bf8ff;
  --block-top: #7ef4ff;
  --block-bottom: #0880ff;
}

.block-o {
  color: #ffe56f;
  --block-top: #ffe977;
  --block-bottom: #ff9a14;
}

.block-t {
  color: #d08fff;
  --block-top: #da97ff;
  --block-bottom: #6b39ff;
}

.block-s {
  color: #65ffb7;
  --block-top: #79ffc2;
  --block-bottom: #00b971;
}

.block-z {
  color: #ff7489;
  --block-top: #ff8da1;
  --block-bottom: #ff3157;
}

.block-j {
  color: #7cafff;
  --block-top: #8bb9ff;
  --block-bottom: #1c49ff;
}

.block-l {
  color: #ffb177;
  --block-top: #ffc98a;
  --block-bottom: #ff6d1f;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.45rem;
  padding: 1.5rem;
  text-align: center;
  background: rgba(1, 6, 16, 0.78);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  backdrop-filter: blur(7px);
}

.overlay::before {
  content: "";
  position: absolute;
  width: min(72%, 17rem);
  min-height: 9.75rem;
  border-radius: 1.25rem;
  border: 1px solid rgba(104, 220, 255, 0.34);
  background:
    linear-gradient(180deg, rgba(5, 16, 31, 0.96), rgba(3, 9, 18, 0.96)),
    radial-gradient(circle at top, rgba(123, 248, 255, 0.12), transparent 58%);
  box-shadow:
    0 18px 48px rgba(0, 0, 0, 0.45),
    inset 0 0 0 1px rgba(104, 220, 255, 0.1);
}

.overlay.visible {
  opacity: 1;
}

.overlay[data-mode="levelup"] {
  background: rgba(3, 11, 24, 0.52);
}

.overlay[data-mode="gameover"] {
  background: rgba(13, 4, 10, 0.78);
}

.overlay-title {
  position: relative;
  z-index: 1;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: clamp(2.3rem, 6vw, 4.5rem);
  letter-spacing: 0.16em;
  color: #f1fdff;
  text-shadow: 0 0 18px rgba(104, 220, 255, 0.45);
}

.overlay-detail {
  position: relative;
  z-index: 1;
  color: var(--warn);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.82rem;
}

.overlay-subtitle {
  position: relative;
  z-index: 1;
  font-size: 0.68rem;
  color: var(--muted);
}

.sidebar {
  display: grid;
  gap: 0.85rem;
}

.panel {
  border-radius: 1.35rem;
  padding: 0.95rem;
}

.panel-heading {
  margin-bottom: 0.85rem;
  color: var(--muted);
  font-size: 0.7rem;
}

.joystick {
  width: min(100%, 190px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 0.7rem;
  align-items: center;
}

.joystick-btn,
.action-btn {
  border: 1px solid rgba(104, 220, 255, 0.28);
  background: linear-gradient(180deg, rgba(11, 35, 65, 0.95), rgba(5, 15, 30, 0.95));
  color: #ecfbff;
  cursor: pointer;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.joystick-btn {
  width: 100%;
  height: 100%;
  border-radius: 1rem;
  font-size: 1.2rem;
}

.joystick-btn.up {
  grid-column: 2;
  grid-row: 1;
}

.joystick-btn.right {
  grid-column: 3;
  grid-row: 2;
}

.joystick-btn.down {
  grid-column: 2;
  grid-row: 3;
}

.joystick-btn.left {
  grid-column: 1;
  grid-row: 2;
}

.joystick-btn.active {
  border-color: rgba(255, 214, 107, 0.68);
  box-shadow: 0 0 18px rgba(255, 214, 107, 0.22);
}

.joystick-core {
  grid-column: 2;
  grid-row: 2;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 40%, rgba(104, 220, 255, 0.4), rgba(7, 18, 37, 0.96)),
    linear-gradient(180deg, rgba(12, 36, 68, 0.95), rgba(4, 12, 23, 0.95));
  border: 1px solid rgba(104, 220, 255, 0.42);
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  letter-spacing: 0.12em;
  font-size: 0.92rem;
}

.joystick-copy {
  margin: 0.8rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.6;
}

.button-row {
  display: grid;
  gap: 0.65rem;
}

.action-btn {
  border-radius: 0.95rem;
  padding: 0.85rem 1rem;
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.action-btn.danger {
  border-color: rgba(255, 110, 143, 0.36);
  color: #ffd1db;
}

.controls-copy {
  margin-top: 0.85rem;
  display: grid;
  gap: 0.45rem;
}

.controls-copy p {
  margin: 0;
  padding: 0.55rem 0.75rem;
  border-radius: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: rgba(4, 12, 24, 0.74);
  border: 1px solid rgba(104, 220, 255, 0.08);
}

.controls-copy span {
  font-size: 0.66rem;
  color: var(--muted);
}

.controls-copy strong {
  font-size: 0.82rem;
  letter-spacing: 0.08em;
}

.joystick-btn:hover,
.joystick-btn:focus-visible,
.action-btn:hover,
.action-btn:focus-visible {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  box-shadow: 0 0 18px rgba(21, 167, 255, 0.16);
  outline: none;
}

.joystick-btn:disabled {
  cursor: default;
  opacity: 0.8;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .board-panel {
    min-height: 33rem;
  }

  .sidebar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100vw - 1rem, 100%);
    padding-top: 1rem;
  }

  .masthead {
    margin-bottom: 0.75rem;
  }

  .masthead-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .board-panel {
    min-height: 30rem;
    padding: 0.8rem;
  }

  .board-shell {
    width: min(62vw, 13rem);
  }

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

  .feed-line {
    width: 100%;
  }

  .input-dropdown {
    position: static;
    width: 100%;
    margin-top: 0.75rem;
  }
}

@keyframes blockPulse {
  0%,
  100% {
    filter: saturate(1) brightness(1);
  }
  50% {
    filter: saturate(1.12) brightness(1.08);
  }
}

@keyframes blockSurge {
  0%,
  100% {
    filter: saturate(1) brightness(1);
  }
  50% {
    filter: saturate(1.2) brightness(1.18);
  }
}

@keyframes lightSweep {
  from {
    transform: translateX(-75%) skewX(-24deg);
  }
  to {
    transform: translateX(85%) skewX(-24deg);
  }
}

@keyframes circuitSweep {
  from {
    background-position: 0 0, 0 0;
  }
  to {
    background-position: 1.8rem 0, -1.8rem 0;
  }
}
