/* Circuit - mobile-web, portrait, touch-only static bundle. */

:root {
  --bg: #0b1015;
  --panel: #111923;
  --panel-strong: #172230;
  --cell: #1d2a37;
  --wall: #070b0f;
  --wire: #ffd166;
  --wire-hot: #fff1a8;
  --cyan: #5eead4;
  --green: #7bd88f;
  --red: #ff6b6b;
  --blue: #70a6ff;
  --text: #f6f2e8;
  --muted: #9facb8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  appearance: none;
  border: 0;
  border-radius: 8px;
  min-height: 48px;
  padding: 0 14px;
  color: var(--text);
  background: var(--panel-strong);
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  touch-action: manipulation;
  transition: transform 0.06s ease, filter 0.12s ease, background 0.12s ease;
}

button:active {
  transform: scale(0.96);
  filter: brightness(1.14);
}

button:disabled {
  opacity: 0.42;
}

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  min-width: 0;
  padding:
    max(12px, var(--safe-top))
    max(12px, var(--safe-right))
    max(12px, var(--safe-bottom))
    max(12px, var(--safe-left));
  background:
    linear-gradient(90deg, rgba(94, 234, 212, 0.09) 1px, transparent 1px),
    linear-gradient(180deg, rgba(112, 166, 255, 0.07) 1px, transparent 1px),
    linear-gradient(180deg, #101720 0%, #0d141b 54%, #0b1015 100%);
  background-size: 28px 28px, 28px 28px, auto;
}

.topbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 0 0 auto;
  padding-bottom: 8px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  position: relative;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  background: var(--wire);
}

.brand-mark::before {
  left: 7px;
  top: 17px;
  width: 22px;
  height: 3px;
  border-radius: 2px;
}

.brand-mark::after {
  left: 17px;
  top: 8px;
  width: 3px;
  height: 20px;
  border-radius: 2px;
}

.brand h1 {
  margin: 0;
  color: var(--wire);
  font-size: 26px;
  line-height: 1;
  letter-spacing: 0;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.1;
}

#hud {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stat {
  min-width: 0;
  min-height: 48px;
  padding: 7px 5px 6px;
  border-radius: 8px;
  background: rgba(17, 25, 35, 0.86);
  text-align: center;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.07);
}

.label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.stat span:last-child {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
}

#stage {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 209, 102, 0.08), transparent 42%),
    linear-gradient(180deg, rgba(23, 34, 48, 0.86), rgba(11, 16, 21, 0.84));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.07);
}

.board-band {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px 0 8px;
}

#board-shell {
  --cols: 5;
  --rows: 5;
  --gap: 4px;
  position: relative;
  width: min(100%, calc(var(--cols) * 58px + (var(--cols) - 1) * var(--gap)));
  max-height: 100%;
}

#board {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(44px, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(44px, 1fr));
  gap: var(--gap);
  width: 100%;
  touch-action: none;
}

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

.wire-path {
  fill: none;
  stroke: var(--wire);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 7px rgba(255, 209, 102, 0.42));
}

.cell {
  position: relative;
  min-width: 0;
  min-height: 44px;
  aspect-ratio: 1;
  border-radius: 8px;
  background: var(--cell);
  color: var(--text);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.07),
    inset 0 -7px 12px rgba(0, 0, 0, 0.12);
}

.cell.open::after {
  content: "";
  position: absolute;
  inset: 42% 20%;
  border-radius: 999px;
  background: rgba(94, 234, 212, 0.26);
}

.cell.wall {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0)),
    var(--wall);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.cell.wired {
  background: #293322;
  box-shadow:
    inset 0 0 0 2px rgba(255, 209, 102, 0.74),
    0 0 14px rgba(255, 209, 102, 0.2);
}

.cell.wired::after {
  inset: 34%;
  background: var(--wire-hot);
  box-shadow: 0 0 9px rgba(255, 241, 168, 0.72);
}

.cell.node {
  background: #14343c;
  box-shadow:
    inset 0 0 0 2px rgba(94, 234, 212, 0.88),
    0 0 14px rgba(94, 234, 212, 0.18);
}

.cell.node.wired {
  background: #3a3218;
  box-shadow:
    inset 0 0 0 2px rgba(255, 209, 102, 0.92),
    0 0 16px rgba(255, 209, 102, 0.26);
}

.cell.invalid {
  background: #3b171b;
  box-shadow:
    inset 0 0 0 2px rgba(255, 107, 107, 0.92),
    0 0 16px rgba(255, 107, 107, 0.32);
}

.cell.hint {
  box-shadow:
    inset 0 0 0 2px rgba(112, 166, 255, 0.95),
    0 0 15px rgba(112, 166, 255, 0.36);
}

.cell.solved {
  background: #183624;
  box-shadow:
    inset 0 0 0 2px rgba(123, 216, 143, 0.86),
    0 0 12px rgba(123, 216, 143, 0.2);
}

.node-label {
  position: absolute;
  z-index: 2;
  inset: 50% auto auto 50%;
  display: grid;
  place-items: center;
  min-width: 27px;
  height: 27px;
  padding: 0 7px;
  border-radius: 999px;
  transform: translate(-50%, -50%);
  background: var(--cyan);
  color: #071015;
  font-size: 16px;
  font-weight: 950;
  line-height: 1;
}

.cell.wired .node-label {
  background: var(--wire);
}

#message {
  flex: 0 0 auto;
  min-height: 42px;
  margin: 0;
  padding: 0 12px 10px;
  color: #d6dee7;
  font-size: 15px;
  line-height: 1.35;
  text-align: center;
}

#message.warn {
  color: var(--red);
  font-weight: 800;
}

#message.good {
  color: var(--green);
  font-weight: 800;
}

#controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  flex: 0 0 auto;
  gap: 8px;
  padding-top: 10px;
}

#new-run-btn {
  background: var(--wire);
  color: #191006;
}

#daily-btn {
  background: var(--cyan);
  color: #061312;
}

#hint-btn {
  background: var(--blue);
  color: #061023;
}

.panel {
  position: absolute;
  z-index: 5;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px;
  border-radius: 8px;
  background: rgba(10, 15, 20, 0.94);
  text-align: center;
  box-shadow:
    0 14px 36px rgba(0, 0, 0, 0.34),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.panel[hidden] {
  display: none;
}

.panel-kicker {
  margin: 0;
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.panel h2 {
  margin: 0;
  color: var(--wire);
  font-size: 24px;
  line-height: 1.05;
  letter-spacing: 0;
}

.panel p {
  margin: 0;
  color: #d8e0e8;
  font-size: 15px;
  line-height: 1.3;
}

.cta {
  width: min(100%, 224px);
  min-height: 52px;
  margin-top: 4px;
  background: var(--green);
  color: #06140a;
  font-size: 18px;
}

@media (max-height: 700px) {
  .topbar {
    gap: 6px;
    padding-bottom: 6px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
    flex-basis: 32px;
  }

  .brand h1 {
    font-size: 23px;
  }

  .stat {
    min-height: 44px;
    padding-top: 6px;
  }

  .stat span:last-child {
    font-size: 18px;
  }

  #message {
    min-height: 34px;
    padding-bottom: 6px;
    font-size: 14px;
  }

  button {
    min-height: 44px;
  }
}
