/* ==========================================================================
   Breach Protocol — game styles
   Shared colours, buttons, panels etc. come from assets/css/theme.css.
   ========================================================================== */

:root {
  --cell: clamp(44px, 12vw, 64px);
}

/* ---------- Header ---------- */

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--yellow-dim);
  padding-bottom: 14px;
}
.eyebrow .badge { margin-left: 8px; vertical-align: middle; }

.timer {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 4px 14px;
  min-width: 260px;
}
.timer-label { font-size: 0.75rem; color: var(--yellow); opacity: 0.8; }
.timer-value {
  justify-self: end;
  font-size: 1.6rem;
  color: var(--yellow);
  border: 1px solid var(--yellow-dim);
  padding: 2px 10px;
  text-shadow: 0 0 8px var(--yellow-dim);
  font-variant-numeric: tabular-nums;
}
.timer-bar { grid-column: 1 / -1; height: 4px; background: var(--yellow-faint); }
.timer-fill { height: 100%; width: 100%; background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }
.timer.idle .timer-value { opacity: 0.6; }
.timer.low .timer-value,
.timer.low .timer-label { color: var(--red); border-color: var(--red-dim); text-shadow: 0 0 8px var(--red); }
.timer.low .timer-fill { background: var(--red); box-shadow: 0 0 8px var(--red); }
.timer.low .timer-value { animation: blink 0.5s infinite steps(2); }

/* ---------- Controls ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  margin: 16px 0 20px;
}
.difficulty, .controls-right { display: flex; flex-wrap: wrap; gap: 8px; }

.notice {
  margin: -8px 0 16px;
  padding: 8px 12px;
  border-left: 3px solid var(--yellow);
  background: var(--yellow-faint);
  font-size: 0.85rem;
}
.notice[hidden] { display: none; }
.notice button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--cyan);
  text-decoration: underline;
  cursor: pointer;
  font-size: inherit;
}

/* ---------- Board layout ---------- */

.board {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 20px;
  align-items: start;
}
.side { display: grid; gap: 20px; min-width: 0; }

/* ---------- Code matrix ---------- */

.matrix-wrap { padding: 18px; display: flex; justify-content: center; }

.matrix {
  display: grid;
  grid-template-columns: repeat(var(--n, 5), var(--cell));
  grid-auto-rows: var(--cell);
  min-height: calc(var(--cell) * 5);
}

.matrix-loading {
  grid-column: 1 / -1;
  align-self: center;
  justify-self: center;
  color: var(--cyan);
  animation: blink 0.8s infinite steps(2);
  font-size: 0.9rem;
}

.cell {
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: calc(var(--cell) * 0.36);
  letter-spacing: 0.05em;
  cursor: default;
  position: relative;
  transition: color 0.1s, text-shadow 0.1s;
}
.cell:focus { outline: none; }

/* the row/column you are allowed to pick from */
.cell.active-line { background: var(--cyan-faint); }
.cell.active-line:not(.used) { color: #fff; }

/* the line the NEXT pick will be on (while hovering) */
.cell.preview-line { background: var(--yellow-faint); }
.cell.preview-line.active-line { background: var(--cyan-faint); }

.cell.selectable { cursor: pointer; }

.cell.hovered { color: var(--cyan); text-shadow: 0 0 8px var(--cyan), 0 0 18px var(--cyan-dim); }
.cell.hovered::after {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid var(--cyan);
  box-shadow: 0 0 10px var(--cyan-dim), inset 0 0 10px var(--cyan-dim);
}

.cell.used { color: var(--muted); opacity: 0.55; font-size: calc(var(--cell) * 0.28); }

.matrix.locked .cell { opacity: 0.6; }

.hint {
  /* don't let the hint text decide the panel width (stops layout jumping) */
  width: 0;
  min-width: 100%;
  margin: 0;
  padding: 0 18px 16px;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}
.hint strong { color: var(--cyan); font-weight: normal; }

/* ---------- Buffer ---------- */

.buffer { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px; }
.slot {
  width: 46px; height: 46px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--yellow-dim);
  color: var(--yellow);
  font-size: 1.05rem;
}
.slot.filled { border-style: solid; text-shadow: 0 0 6px var(--yellow-dim); }
.slot.preview {
  border: 1px solid var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 10px var(--cyan-dim);
  animation: blink 0.8s infinite steps(2);
}

/* ---------- Daemons ---------- */

.daemons { list-style: none; margin: 0; padding: 8px 16px 16px; display: grid; gap: 10px; }

.daemon {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-left: 3px solid var(--yellow-dim);
  background: rgba(255, 255, 255, 0.015);
  transition: border-color 0.15s, background 0.15s;
}
.daemon-codes { display: flex; gap: 6px; }
.daemon-codes .code {
  width: 34px; height: 30px;
  display: grid;
  place-items: center;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.95rem;
}
.daemon-codes .code.matched { color: var(--bg); background: var(--yellow); border-color: var(--yellow); }
.daemon-codes .code.preview { color: var(--cyan); border-color: var(--cyan); box-shadow: 0 0 8px var(--cyan-dim); }

.daemon-info { display: grid; gap: 2px; min-width: 0; }
.daemon-name { color: var(--yellow); }
.daemon-tier { color: var(--muted); font-size: 0.75rem; }
.daemon-status { font-size: 0.8rem; color: var(--muted); }

.daemon.will-progress { border-color: var(--cyan-dim); }
.daemon.will-complete { border-color: var(--cyan); background: var(--cyan-faint); box-shadow: 0 0 12px var(--cyan-dim); }
.daemon.will-complete .daemon-status { color: var(--cyan); }
.daemon.will-break { border-color: var(--red-dim); }
.daemon.will-break .daemon-status { color: var(--red); }

.daemon.done { border-left-color: var(--cyan); background: var(--cyan-faint); }
.daemon.done .code { color: var(--bg); background: var(--cyan); border-color: var(--cyan); }
.daemon.done .daemon-name, .daemon.done .daemon-status { color: var(--cyan); text-shadow: 0 0 6px var(--cyan-dim); }

.daemon.failed { border-left-color: var(--red); opacity: 0.6; }
.daemon.failed .daemon-name { color: var(--red); text-decoration: line-through; }
.daemon.failed .daemon-status { color: var(--red); }

.daemon.flash { animation: daemon-flash 0.6s steps(3); }
@keyframes daemon-flash {
  0%   { transform: translateX(-4px); filter: drop-shadow(2px 0 var(--yellow)); }
  50%  { transform: translateX(3px);  filter: drop-shadow(-2px 0 var(--cyan)); }
  100% { transform: none; filter: none; }
}

/* ---------- Leaderboard ---------- */

.leaderboard { margin-top: 28px; scroll-margin-top: 16px; }
.leaderboard-body { padding: 16px; display: grid; gap: 12px; }
.lb-mine { margin: 0; font-size: 0.85rem; color: var(--muted); }
.lb-mine strong { color: var(--cyan); font-weight: normal; }
.lb-mine button {
  background: none; border: 0; padding: 0;
  color: var(--cyan); text-decoration: underline; cursor: pointer; font-size: inherit;
}

/* ---------- Glitch on success / fail ---------- */

.app.glitch-success { animation: glitch 0.5s steps(2, end); }
.app.glitch-fail { animation: glitch 0.7s steps(2, end); filter: hue-rotate(-60deg) saturate(2); }

@keyframes glitch {
  0%   { transform: none; clip-path: none; }
  15%  { transform: translate(-4px, 1px) skewX(-3deg); clip-path: inset(0 0 55% 0); }
  30%  { transform: translate(4px, -1px); clip-path: inset(40% 0 20% 0); }
  45%  { transform: translate(-2px, 2px) skewX(2deg); clip-path: inset(70% 0 0 0); }
  60%  { transform: translate(2px, 0); clip-path: inset(10% 0 30% 0); }
  80%  { transform: translate(-1px, 0); clip-path: none; }
  100% { transform: none; clip-path: none; }
}

/* ---------- Result overlay ---------- */

.result {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 6, 10, 0.75);
  backdrop-filter: blur(2px);
}
.result[hidden] { display: none; }

.result-card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--yellow-dim);
  padding: 24px;
  text-align: center;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.7);
}

.result-title {
  margin: 0 0 6px;
  font-weight: normal;
  font-size: clamp(1.5rem, 6vw, 2.1rem);
  letter-spacing: 0.12em;
}
.result.ok .result-title      { color: var(--cyan);   text-shadow: 0 0 12px var(--cyan-dim); }
.result.partial .result-title { color: var(--yellow); text-shadow: 0 0 12px var(--yellow-dim); }
.result.fail .result-title    { color: var(--red);    text-shadow: 0 0 12px var(--red-dim); }

.result-reason { margin: 0 0 16px; color: var(--muted); }

.result-score { display: grid; gap: 2px; margin-bottom: 18px; }
.score-label { font-size: 0.7rem; color: var(--muted); letter-spacing: 0.2em; }
.score-total {
  font-size: 2.6rem;
  color: var(--yellow);
  text-shadow: 0 0 14px var(--yellow-dim);
  font-variant-numeric: tabular-nums;
}
.score-breakdown { font-size: 0.8rem; color: var(--muted); }
.score-breakdown b { color: var(--text); font-weight: normal; }

.result-list { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 6px; text-align: left; }
.result-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-left: 3px solid;
  background: rgba(255, 255, 255, 0.02);
}
.result-list li.done   { border-color: var(--cyan); color: var(--cyan); }
.result-list li.failed { border-color: var(--red);  color: var(--red); }

.result-post { margin: 0 0 18px; font-size: 0.85rem; color: var(--muted); min-height: 1.2em; }
.result-post.ok { color: var(--cyan); }
.result-post.error { color: var(--red); }
.result-post.pending { color: var(--yellow); animation: blink 0.8s infinite steps(2); }
.result-post button {
  background: none; border: 0; padding: 0;
  color: var(--cyan); text-decoration: underline; cursor: pointer; font-size: inherit;
}

/* ---------- Responsive ---------- */

@media (max-width: 820px) {
  .board { grid-template-columns: 1fr; }
  .timer { min-width: 0; width: 100%; }
}
@media (max-width: 480px) {
  .daemon { grid-template-columns: 1fr auto; }
  .daemon-codes { grid-column: 1 / -1; }
  .slot { width: 40px; height: 40px; }
  .matrix-wrap { padding: 12px 4px; }
}

/* ==========================================================================
   OVERCLOCKED
   ========================================================================== */

.mode-switch { display: flex; gap: 8px; }
.overclock-btn { border-color: rgba(255, 77, 94, 0.45); color: #ff8a95; }
.overclock-btn.active { background: var(--red); color: var(--bg); border-color: var(--red); box-shadow: 0 0 14px var(--red-dim); }
.mode-title { color: var(--red); font-size: 0.55em; letter-spacing: 0.3em; vertical-align: middle; text-shadow: 0 0 10px var(--red-dim); }
.app.overclocked .title { text-shadow: 0 0 8px var(--yellow-dim), 2px 0 0 rgba(255, 77, 94, 0.35); }

/* ---------- Deck panel ---------- */
.deck-panel { --panel-border: rgba(255, 77, 94, 0.45); }
.deck-panel .panel-head { background: linear-gradient(90deg, var(--yellow), #ff8a95); }
.deck-body { padding: 14px 16px 16px; display: grid; gap: 12px; }
.deck-archetype { margin: 0; font-size: 0.8rem; color: var(--cyan); }
.ram-label, .ice-label { font-size: 0.7rem; color: var(--muted); letter-spacing: 0.15em; }
.ram-label span { color: var(--yellow); }
.ram-bar { height: 6px; margin-top: 4px; background: var(--yellow-faint); }
.ram-fill { height: 100%; background: var(--cyan); box-shadow: 0 0 8px var(--cyan); transition: width 0.3s; }

.program-list { display: grid; gap: 8px; }
.program-btn {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  text-align: left;
  background: rgba(94, 246, 255, 0.04);
  border: 1px solid var(--cyan-dim);
  color: var(--text);
  padding: 8px 10px;
  font-family: inherit;
  cursor: pointer;
  transition: box-shadow 0.15s, background 0.15s;
}
.program-btn:hover:not(:disabled) { background: var(--cyan-faint); box-shadow: 0 0 10px var(--cyan-dim); }
.program-btn .pg-name { color: var(--cyan); letter-spacing: 0.08em; }
.program-btn .pg-cost { color: var(--yellow); font-size: 0.75rem; }
.program-btn .pg-desc { grid-column: 1 / -1; font-size: 0.72rem; color: var(--muted); line-height: 1.4; }
.program-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.program-btn.used { text-decoration: line-through; }
.program-btn.targeting { background: var(--cyan); box-shadow: 0 0 14px var(--cyan); }
.program-btn.targeting .pg-name, .program-btn.targeting .pg-desc, .program-btn.targeting .pg-cost { color: var(--bg); }
.muted-small { margin: 0; font-size: 0.8rem; color: var(--muted); }

.ice-list { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 4px; font-size: 0.75rem; color: var(--muted); }
.ice-list strong { color: var(--red); font-weight: normal; margin-right: 4px; }
.ice-list li.cleared { text-decoration: line-through; opacity: 0.5; }

/* ---------- ICE + quickhack effects on the matrix ---------- */
.cell.corrupted:not(.used) {
  color: var(--red);
  background: repeating-linear-gradient(135deg, rgba(255, 77, 94, 0.14) 0 4px, transparent 4px 8px);
  text-shadow: 1px 0 var(--cyan), -1px 0 var(--red);
}
.cell.firewalled:not(.used) {
  color: var(--muted);
  background: rgba(255, 77, 94, 0.07);
  box-shadow: inset 0 0 0 1px rgba(255, 77, 94, 0.35);
}
.cell.firewalled:not(.used)::before {
  content: '⛨';
  position: absolute;
  top: 2px; right: 4px;
  font-size: 0.55rem;
  color: var(--red);
}
.cell.pinged:not(.used) { color: var(--bg); background: var(--yellow); box-shadow: 0 0 12px var(--yellow); }
.matrix.rerouting .cell.selectable { box-shadow: inset 0 0 0 1px var(--cyan-dim); }

.daemon.targetable { cursor: crosshair; border-color: var(--cyan); box-shadow: 0 0 12px var(--cyan-dim); }
.daemon.pinged { border-color: var(--yellow); box-shadow: 0 0 12px var(--yellow-dim); }

.matrix.flash { animation: ice-hit 0.4s steps(2); }
@keyframes ice-hit {
  0%   { filter: drop-shadow(3px 0 var(--red)) hue-rotate(-40deg); transform: translateX(-3px); }
  50%  { filter: drop-shadow(-3px 0 var(--red)); transform: translateX(3px); }
  100% { filter: none; transform: none; }
}

.result-rewards { margin: 0 0 8px; color: var(--yellow); font-size: 0.9rem; min-height: 1.2em; text-shadow: 0 0 8px var(--yellow-dim); }
.result-rewards:empty { display: none; }

/* leaderboard: mode tabs and difficulty tabs on one line */
.leaderboard-body > .tabs { display: inline-flex; }
.leaderboard-body { grid-template-columns: auto 1fr; align-items: center; }
.leaderboard-body > :not(.tabs) { grid-column: 1 / -1; }
#lbModeTabs { margin-right: 18px; }
@media (max-width: 560px) { .leaderboard-body { grid-template-columns: 1fr; } }
