/* ============================================================
   BLUEPRINT // SIEGE PROTOCOL
   Prussian-blue drafting sheet. White-cyan linework.
   Red is reserved for defects and danger.
   ============================================================ */

:root {
  --paper: #0e3055;
  --paper-deep: #0a2440;
  --sheet: #11375f;
  --ink: #dff0ff;
  --line: #bcd9f2;
  --faint: rgba(188, 217, 242, 0.16);
  --hair: rgba(188, 217, 242, 0.32);
  --red: #ff6a55;
  --red-deep: #ff5743;
  --amber: #ffc35c;
  --cyan: #7fd4ff;
  --green: #62dd9a;
  --mono: "Share Tech Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --hand: "Architects Daughter", "Comic Sans MS", cursive;
  --stencil: "Saira Stencil One", "Arial Black", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  background:
    radial-gradient(120% 90% at 50% 8%, rgba(127, 212, 255, 0.05), transparent 55%),
    radial-gradient(140% 120% at 50% 50%, var(--paper) 0%, var(--paper-deep) 78%, #081d35 100%);
  color: var(--ink);
  font-family: var(--mono);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* Fine drafting grid across the whole page, behind everything. */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg,  rgba(188,217,242,0.045) 0 1px, transparent 1px 24px),
    repeating-linear-gradient(90deg, rgba(188,217,242,0.045) 0 1px, transparent 1px 24px);
  z-index: 0;
}

/* Paper grain. */
#grain {
  position: fixed; inset: -50%;
  pointer-events: none;
  z-index: 60;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 1.6s steps(4) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-1.2%, 0.8%); }
  50% { transform: translate(0.9%, -0.6%); }
  75% { transform: translate(-0.5%, -1%); }
  100% { transform: translate(0, 0); }
}

#app {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 10px 16px 12px;
  gap: 8px;
}

.hidden { display: none !important; }

/* ============================== TOP BAR ============================== */

#topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 14px;
  border: 1px solid var(--hair);
  background: rgba(10, 36, 64, 0.55);
  flex: 0 0 auto;
}

.tb-title h1 {
  font-family: var(--stencil);
  font-weight: 400;
  font-size: 21px;
  letter-spacing: 0.06em;
  color: var(--ink);
  line-height: 1;
  white-space: nowrap;
}
.tb-title h1 span {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--cyan);
  vertical-align: 4px;
}
.doc-meta {
  font-size: 9.5px;
  letter-spacing: 0.18em;
  color: var(--line);
  opacity: 0.55;
  margin-top: 3px;
  white-space: nowrap;
}

.tb-chips {
  display: flex;
  gap: 10px;
  margin-left: auto;
}
.chip {
  display: flex;
  align-items: baseline;
  gap: 8px;
  border: 1px solid var(--faint);
  padding: 7px 12px;
  min-width: 108px;
  background: rgba(255, 255, 255, 0.02);
}
.chip label {
  font-size: 9px;
  letter-spacing: 0.2em;
  opacity: 0.6;
}
.chip b {
  font-weight: 400;
  font-size: 17px;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
#chip-funds b { color: var(--amber); }
#chip-wave b { color: var(--cyan); }
.chip .meter {
  width: 56px; height: 5px;
  border: 1px solid var(--hair);
  align-self: center;
}
.chip .meter i {
  display: block; height: 100%;
  width: 100%;
  background: var(--cyan);
  transition: width 0.3s, background 0.3s;
}
.chip.hurt b, .chip.hurt .meter i { color: var(--red); background: var(--red); }
.chip.pulse { animation: chipPulse 0.45s; }
@keyframes chipPulse {
  0% { background: rgba(255, 106, 85, 0.3); }
  100% { background: rgba(255, 255, 255, 0.02); }
}
.chip.gain { animation: chipGain 0.45s; }
@keyframes chipGain {
  0% { background: rgba(255, 195, 92, 0.25); }
  100% { background: rgba(255, 255, 255, 0.02); }
}

.tb-controls {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

/* ============================== BUTTONS ============================== */

.btn {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--hair);
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.12s, opacity 0.12s;
}
.btn:hover { background: rgba(255, 255, 255, 0.08); border-color: var(--line); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 1.5px dashed var(--cyan); outline-offset: 2px; }
.btn:disabled { opacity: 0.35; cursor: default; transform: none; }
.btn:disabled:hover { background: rgba(255, 255, 255, 0.03); border-color: var(--hair); }

.btn.primary { color: var(--amber); border-color: rgba(255, 195, 92, 0.55); }
.btn.primary:hover { border-color: var(--amber); background: rgba(255, 195, 92, 0.09); }
.btn.danger { color: var(--red); border-color: rgba(255, 106, 85, 0.5); }
.btn.danger:hover { border-color: var(--red); background: rgba(255, 106, 85, 0.09); }
.btn.icon { min-width: 40px; padding: 8px 10px; font-size: 13px; }
.btn.icon.active { color: var(--cyan); border-color: var(--cyan); }
.btn.big { font-size: 15px; padding: 14px 28px; }

.btn.adv {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 168px;
  padding: 6px 14px;
}
.btn.adv small {
  font-size: 9px;
  letter-spacing: 0.14em;
  opacity: 0.65;
  text-transform: none;
}

.btn.pen {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 6px 12px;
}
.btn.pen small {
  font-size: 9px;
  letter-spacing: 0.12em;
  opacity: 0.7;
  text-transform: none;
}
.btn.pen.armed {
  background: rgba(255, 87, 67, 0.16);
  border-color: var(--red);
  animation: penPulse 0.9s ease-in-out infinite;
}
@keyframes penPulse {
  50% { box-shadow: 0 0 0 3px rgba(255, 87, 67, 0.22); }
}

/* ============================== STAGE ============================== */

#stage {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

#frame {
  position: relative;
  border: 1px solid var(--hair);
  outline: 1px solid var(--faint);
  outline-offset: 5px;
  background: var(--sheet);
  box-shadow: 0 30px 80px rgba(3, 12, 24, 0.55);
}

#game {
  display: block;
  width: min(1040px, calc(100vw - 64px), calc((100vh - 235px) * 1040 / 700));
  height: auto;
  aspect-ratio: 1040 / 700;
  cursor: crosshair;
}

/* Registration crop marks. */
.corner { position: absolute; width: 14px; height: 14px; pointer-events: none; }
.c-tl { top: -22px; left: -22px; border-right: 1px solid var(--hair); border-bottom: 1px solid var(--hair); }
.c-tr { top: -22px; right: -22px; border-left: 1px solid var(--hair); border-bottom: 1px solid var(--hair); }
.c-bl { bottom: -22px; left: -22px; border-right: 1px solid var(--hair); border-top: 1px solid var(--hair); }
.c-br { bottom: -22px; right: -22px; border-left: 1px solid var(--hair); border-top: 1px solid var(--hair); }

/* Wave banner. */
#banner {
  position: absolute;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  padding: 10px 34px;
  background: rgba(10, 36, 64, 0.82);
  border-top: 2px double var(--hair);
  border-bottom: 2px double var(--hair);
  pointer-events: none;
  animation: bannerIn 2.8s cubic-bezier(0.2, 0.9, 0.2, 1) both;
  white-space: nowrap;
}
#banner b {
  display: block;
  font-family: var(--stencil);
  font-weight: 400;
  font-size: 26px;
  letter-spacing: 0.24em;
}
#banner span {
  display: block;
  font-family: var(--hand);
  font-size: 13px;
  color: var(--cyan);
  margin-top: 2px;
}
#banner.danger b { color: var(--red); }
@keyframes bannerIn {
  0% { opacity: 0; transform: translateX(-50%) translateY(-14px); }
  10%, 78% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(8px); }
}

/* Field-note callouts. */
#callouts {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 320px;
  pointer-events: none;
}
.callout {
  border-left: 3px solid var(--red);
  background: rgba(10, 36, 64, 0.88);
  padding: 9px 12px;
  animation: calloutIn 0.35s cubic-bezier(0.2, 1.2, 0.3, 1) both;
}
.callout.fade { animation: calloutOut 0.4s both; }
.callout b {
  display: block;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--red);
}
.callout.info { border-left-color: var(--cyan); }
.callout.info b { color: var(--cyan); }
.callout span {
  display: block;
  font-family: var(--hand);
  font-size: 13px;
  color: var(--ink);
  margin-top: 2px;
}
@keyframes calloutIn { from { opacity: 0; transform: translateX(-18px); } to { opacity: 1; transform: none; } }
@keyframes calloutOut { to { opacity: 0; transform: translateX(-12px); } }

/* Boss integrity readout. */
#bossbar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 44%;
  text-align: center;
  pointer-events: none;
}
#bossbar label {
  display: block;
  font-size: 9px;
  letter-spacing: 0.24em;
  color: var(--red);
  margin-bottom: 4px;
  text-shadow: 0 0 8px rgba(255, 87, 67, 0.4);
}
#bossbar .bar {
  height: 7px;
  border: 1px solid rgba(255, 106, 85, 0.65);
  background: rgba(10, 36, 64, 0.75);
  padding: 1px;
}
#bossbar .bar i {
  display: block;
  height: 100%;
  width: 100%;
  background: repeating-linear-gradient(-45deg, var(--red) 0 6px, #d94a38 6px 12px);
  transition: width 0.25s;
}

/* Non-blocking pause watermark. */
#pause-stamp {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) rotate(-9deg);
  font-family: var(--stencil);
  font-size: 64px;
  letter-spacing: 0.1em;
  color: var(--cyan);
  border: 4px double var(--cyan);
  padding: 6px 30px;
  opacity: 0.32;
  pointer-events: none;
  animation: stampIn 0.3s cubic-bezier(0.2, 1.6, 0.3, 1) both;
}

/* ============================== BOTTOM BAR ============================== */

#bottombar {
  flex: 0 0 auto;
  display: flex;
  gap: 12px;
  align-items: stretch;
}

#palette {
  display: flex;
  gap: 8px;
}

.card {
  position: relative;
  width: 112px;
  border: 1px solid var(--hair);
  background: rgba(255, 255, 255, 0.02);
  padding: 8px 9px 7px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background 0.12s, border-color 0.12s, transform 0.12s, opacity 0.2s;
}
.card:hover { background: rgba(255, 255, 255, 0.06); border-color: var(--line); transform: translateY(-2px); }
.card svg {
  width: 30px; height: 30px;
  stroke: var(--ink);
  color: var(--ink);
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.card .nm { font-size: 10.5px; letter-spacing: 0.1em; }
.card .cost { font-size: 12px; color: var(--amber); }
.card kbd {
  position: absolute;
  top: 5px; right: 6px;
  font-family: var(--mono);
  font-size: 9px;
  border: 1px solid var(--faint);
  padding: 1px 4px;
  opacity: 0.6;
}
.card.selected {
  border-color: var(--cyan);
  box-shadow: inset 0 0 0 1px var(--cyan);
  background: rgba(127, 212, 255, 0.08);
}
.card.selected svg { stroke: var(--cyan); color: var(--cyan); }
.card.broke { opacity: 0.38; }
.card.broke::after {
  content: "";
  position: absolute; inset: 0;
  background: repeating-linear-gradient(-45deg, transparent 0 7px, rgba(255, 106, 85, 0.12) 7px 9px);
  pointer-events: none;
}

#context {
  flex: 1;
  border: 1px solid var(--faint);
  background: rgba(10, 36, 64, 0.45);
  padding: 9px 14px;
  display: flex;
  align-items: center;
  min-width: 0;
}
#ctx-hint .hand {
  font-family: var(--hand);
  font-size: 13.5px;
  color: var(--line);
}
#ctx-hint .keys {
  font-size: 10px;
  letter-spacing: 0.1em;
  opacity: 0.55;
  margin-top: 4px;
}

#ctx-tower { width: 100%; }
.tw-head { display: flex; align-items: baseline; gap: 10px; }
.tw-head b { font-size: 14px; letter-spacing: 0.12em; color: var(--cyan); }
.tw-head span { font-size: 10px; opacity: 0.55; letter-spacing: 0.14em; }
#tw-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--line);
  font-size: 13px;
  cursor: pointer;
  opacity: 0.6;
}
#tw-close:hover { opacity: 1; color: var(--red); }
#tw-stats {
  display: flex;
  gap: 18px;
  font-size: 11.5px;
  margin: 6px 0 8px;
  letter-spacing: 0.06em;
  flex-wrap: wrap;
}
#tw-stats .st label { opacity: 0.55; font-size: 9px; letter-spacing: 0.16em; display: block; }
#tw-stats .st b { font-weight: 400; color: var(--ink); }
#tw-stats .st b em { font-style: normal; color: var(--green); font-size: 10px; }
.tw-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tw-actions .btn { padding: 6px 12px; font-size: 11px; }

/* ============================== TOOLTIP ============================== */

#tooltip {
  position: fixed;
  z-index: 80;
  width: 270px;
  background: rgba(8, 27, 49, 0.96);
  border: 1px solid var(--hair);
  padding: 11px 13px;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 12px));
}
#tooltip::after {
  content: "";
  position: absolute;
  left: 50%; bottom: -5px;
  width: 8px; height: 8px;
  border-right: 1px solid var(--hair);
  border-bottom: 1px solid var(--hair);
  background: rgba(8, 27, 49, 0.96);
  transform: translateX(-50%) rotate(45deg);
}
#tooltip h4 { font-size: 12px; letter-spacing: 0.14em; color: var(--cyan); font-weight: 400; }
#tooltip h4 small { color: var(--amber); float: right; }
#tooltip p { font-size: 11px; line-height: 1.45; color: var(--line); margin-top: 5px; }
#tooltip .spec {
  display: flex; gap: 14px;
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px dashed var(--faint);
  font-size: 10.5px;
}
#tooltip .spec b { color: var(--ink); font-weight: 400; display: block; }
#tooltip .spec label { font-size: 8.5px; opacity: 0.55; letter-spacing: 0.14em; }
#tooltip .note { font-family: var(--hand); color: var(--amber); font-size: 12px; margin-top: 6px; }

/* ============================== OVERLAYS ============================== */

.overlay {
  position: fixed; inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 22, 40, 0.78);
  backdrop-filter: blur(3px);
}

.sheet {
  position: relative;
  width: min(640px, 92vw);
  max-height: 92vh;
  overflow: auto;
  background: var(--sheet);
  border: 1.5px solid var(--line);
  outline: 1px solid var(--faint);
  outline-offset: 6px;
  padding: 34px 44px 30px;
  text-align: center;
  box-shadow: 0 40px 120px rgba(2, 10, 20, 0.7);
  background-image:
    repeating-linear-gradient(0deg,  rgba(188,217,242,0.05) 0 1px, transparent 1px 24px),
    repeating-linear-gradient(90deg, rgba(188,217,242,0.05) 0 1px, transparent 1px 24px);
}

.sheet-firm {
  font-size: 9px;
  letter-spacing: 0.34em;
  opacity: 0.55;
  animation: rise 0.5s 0.05s both;
}
.sheet-title {
  font-family: var(--stencil);
  font-weight: 400;
  font-size: clamp(54px, 9vw, 84px);
  letter-spacing: 0.08em;
  line-height: 1.05;
  margin-top: 10px;
  color: var(--ink);
  text-shadow: 0 0 22px rgba(127, 212, 255, 0.25);
  animation: rise 0.5s 0.12s both;
}
.sheet-sub {
  font-size: 11px;
  letter-spacing: 0.3em;
  color: var(--cyan);
  margin-top: 4px;
  animation: rise 0.5s 0.2s both;
}
.sheet-hand {
  font-family: var(--hand);
  font-size: 14.5px;
  color: var(--line);
  line-height: 1.55;
  max-width: 460px;
  margin: 18px auto 0;
  animation: rise 0.5s 0.28s both;
}
.sheet-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--hair);
  margin-top: 20px;
  animation: rise 0.5s 0.36s both;
}
.sheet-grid > div {
  border: 0.5px solid var(--faint);
  padding: 8px 6px 7px;
}
.sheet-grid label {
  display: block;
  font-size: 8px;
  letter-spacing: 0.22em;
  opacity: 0.5;
}
.sheet-grid b {
  font-weight: 400;
  font-size: 11.5px;
  letter-spacing: 0.06em;
}
.sheet-grid.stats b { font-size: 15px; color: var(--amber); }
.sheet-steps {
  display: grid;
  gap: 5px;
  margin: 18px auto 0;
  max-width: 430px;
  text-align: left;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--line);
  animation: rise 0.5s 0.44s both;
}
.sheet-steps i { color: var(--amber); font-style: normal; margin-right: 6px; }
.sheet .btn.big { margin-top: 24px; animation: rise 0.5s 0.52s both; }
.sheet-best {
  margin-top: 14px;
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--cyan);
  opacity: 0.8;
  animation: rise 0.5s 0.6s both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* The verdict stamp. */
.stamp {
  display: inline-block;
  font-family: var(--stencil);
  font-size: clamp(44px, 7vw, 64px);
  letter-spacing: 0.1em;
  padding: 10px 38px;
  border: 5px double currentColor;
  border-radius: 4px;
  transform: rotate(-7deg);
  margin: 6px 0 14px;
  text-shadow: 0 0 1px currentColor;
  box-shadow: inset 0 0 24px rgba(255, 255, 255, 0.05);
  animation: stampIn 0.42s cubic-bezier(0.2, 1.7, 0.3, 1) both;
}
.stamp.red { color: var(--red-deep); }
.stamp.green { color: var(--green); }
@keyframes stampIn {
  0% { opacity: 0; transform: scale(2.6) rotate(-2deg); }
  62% { opacity: 1; transform: scale(0.94) rotate(-8deg); }
  100% { opacity: 1; transform: scale(1) rotate(-7deg); }
}
.sheet.thud { animation: thud 0.4s 0.12s; }
@keyframes thud {
  0% { transform: translateY(0); }
  35% { transform: translateY(5px) rotate(0.4deg); }
  70% { transform: translateY(-2px); }
  100% { transform: translateY(0); }
}

#ov-end h3 {
  font-size: 13px;
  letter-spacing: 0.3em;
  font-weight: 400;
  color: var(--line);
}
#end-note { margin-top: 10px; }
#ov-end .sheet-grid.stats { grid-template-columns: repeat(5, 1fr); }
.end-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 24px;
  flex-wrap: wrap;
}

.noscript {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--hand);
  font-size: 18px;
  color: var(--ink);
  background: var(--paper-deep);
  z-index: 99;
}

/* ============================== RESPONSIVE ============================== */

@media (max-width: 1180px) {
  .tb-title .doc-meta { display: none; }
  .tb-title h1 span { display: none; }
  .card { width: 92px; }
  .card .nm { font-size: 9px; }
}
@media (max-width: 940px) {
  #app { padding: 6px 8px 8px; }
  #topbar { flex-wrap: wrap; gap: 8px; padding: 6px 10px; }
  .tb-chips { margin-left: 0; }
  .chip { min-width: 84px; padding: 5px 9px; }
  #bottombar { flex-wrap: wrap; }
  #palette { flex-wrap: wrap; }
  #game { max-height: calc(100vh - 300px); }
  #ctx-hint .keys { display: none; }
}
