:root {
  --bg: #11151d;
  --bg2: #161c27;
  --panel: #1b2330;
  --panel2: #212b3b;
  --line: #2c3850;
  --text: #d6deec;
  --muted: #8794ab;
  --accent: #5b9dff;
  --good: #46c98b;
  --warn: #e8b54a;
  --bad: #e2585f;
  --susp: #d8654f;
  --resolve: #4aa6e8;
  --shadow: 0 6px 22px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  background: radial-gradient(120% 120% at 50% 0%, #1a2230 0%, var(--bg) 60%);
  color: var(--text);
}

#app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 0.6rem;
  padding: 0.7rem;
}

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  padding: 0.55rem 0.9rem;
}
.brand { display: flex; align-items: center; gap: 0.7rem; }
.logo { font-size: 1.7rem; transform: rotate(8deg); }
.brand-text h1 { margin: 0; font-size: 1.2rem; letter-spacing: .3px; }
.brand-text p { margin: 0; font-size: 0.74rem; color: var(--muted); }
.stats { display: flex; gap: 0.6rem; }
.stat {
  background: var(--panel2); border: 1px solid var(--line);
  border-radius: 0.6rem; padding: 0.3rem 0.7rem; text-align: center; min-width: 4.2rem;
}
.stat-label { display: block; font-size: 0.62rem; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.stat-val { display: block; font-size: 1.05rem; font-weight: 700; }

/* ---------- board ---------- */
#board {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr 1.1fr;
  gap: 0.6rem;
  min-height: 0;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  padding: 0.7rem 0.8rem;
  min-height: 0;
  display: flex; flex-direction: column;
}
.panel h2 {
  margin: 0 0 0.55rem;
  font-size: 0.92rem; letter-spacing: .4px;
  display: flex; align-items: center; gap: 0.4rem;
}

/* meters */
.meter-label { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--muted); margin-bottom: 0.2rem; }
.bar { height: 0.7rem; background: #0e131c; border-radius: 1rem; overflow: hidden; border: 1px solid var(--line); }
.bar-fill { height: 100%; width: 100%; border-radius: 1rem; transition: width .25s ease; }
.bar-fill.resolve { background: linear-gradient(90deg, #2f78b8, var(--resolve)); }
.bar-fill.suspicion { background: linear-gradient(90deg, #b8463a, var(--susp)); width: 0%; }
.bar.susp { height: 0.8rem; }

/* ---------- tactics ---------- */
.resolve-wrap { margin-bottom: 0.7rem; }
.actions { display: flex; flex-direction: column; gap: 0.5rem; overflow-y: auto; min-height: 0; padding-right: 0.2rem; }
.action {
  text-align: left; cursor: pointer;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  padding: 0.5rem 0.6rem;
  color: var(--text);
  position: relative; overflow: hidden;
  transition: transform .06s, border-color .15s, background .15s;
}
.action:hover:not(.disabled) { border-color: var(--accent); background: #263247; }
.action:active:not(.disabled) { transform: scale(.98); }
.action.disabled { opacity: 0.42; cursor: not-allowed; }
.action .act-name { font-weight: 600; font-size: 0.85rem; display: flex; align-items: center; gap: 0.35rem; }
.action .act-desc { font-size: 0.68rem; color: var(--muted); margin-top: 0.12rem; }
.action .act-tags { display: flex; gap: 0.35rem; margin-top: 0.35rem; flex-wrap: wrap; }
.tag { font-size: 0.6rem; padding: 0.1rem 0.4rem; border-radius: 0.4rem; background: #0e131c; border: 1px solid var(--line); }
.tag.dmg { color: var(--good); }
.tag.cost { color: var(--resolve); }
.tag.susp { color: var(--susp); }
.act-cd {
  position: absolute; left: 0; bottom: 0; height: 3px;
  background: var(--accent); width: 0%;
}
.cd-overlay {
  position: absolute; inset: 0; background: rgba(10,14,20,.55);
  display: none; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700; color: var(--muted);
}
.action.cooling .cd-overlay { display: flex; }

/* ---------- scene ---------- */
.scene { align-items: stretch; }
.susp-wrap { margin-bottom: 0.5rem; }
.susp-hint { font-size: 0.66rem; color: var(--muted); margin-top: 0.25rem; text-align: center; }
.susp-hint strong { color: var(--susp); }

.manager-stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; gap: 0.35rem; }
.ring-wrap { position: relative; width: min(38vh, 100%); aspect-ratio: 1; max-width: 16rem; }
.ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: #0e131c; stroke-width: 7; }
.ring-fg {
  fill: none; stroke: var(--good); stroke-width: 7; stroke-linecap: round;
  stroke-dasharray: 326.7; stroke-dashoffset: 0;
  transition: stroke-dashoffset .3s ease, stroke .3s ease;
}
.manager { position: absolute; inset: 14%; display: flex; align-items: center; justify-content: center; }
.man-svg { width: 100%; height: 100%; }
.manager.hit { animation: shake .25s; }
.manager.heal { animation: pulseHeal .5s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-5px) rotate(-2deg); }
  75% { transform: translateX(5px) rotate(2deg); }
}
@keyframes pulseHeal {
  0% { filter: drop-shadow(0 0 0 rgba(70,201,139,0)); }
  50% { filter: drop-shadow(0 0 14px rgba(70,201,139,.8)); }
  100% { filter: drop-shadow(0 0 0 rgba(70,201,139,0)); }
}
.man-name { font-weight: 700; font-size: 0.95rem; }
.sec-readout { font-size: 0.8rem; }
.sec-readout #secText { font-weight: 800; font-size: 1.1rem; }
.sec-cap { color: var(--muted); font-size: 0.72rem; }
.man-quip {
  font-style: italic; color: var(--muted); font-size: 0.74rem;
  text-align: center; min-height: 1.1rem; max-width: 92%;
}

/* ---------- obstacles ---------- */
.obs-count {
  margin-left: auto; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 1rem; padding: 0.05rem 0.5rem; font-size: 0.72rem; color: var(--muted);
}
.obstacle-list { display: flex; flex-direction: column; gap: 0.5rem; overflow-y: auto; min-height: 0; padding-right: 0.2rem; }
.obs-empty { color: var(--muted); font-size: 0.76rem; font-style: italic; padding: 0.5rem 0.2rem; }
.obs-card {
  background: var(--panel2); border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  border-radius: 0.55rem; padding: 0.45rem 0.55rem;
  animation: slideIn .25s ease;
}
.obs-card.heal { border-left-color: var(--good); }
.obs-card.block { border-left-color: var(--bad); }
.obs-card.spike { border-left-color: var(--susp); }
@keyframes slideIn { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }
.obs-title { font-weight: 600; font-size: 0.8rem; display: flex; align-items: center; gap: 0.35rem; }
.obs-desc { font-size: 0.67rem; color: var(--muted); margin-top: 0.12rem; }
.obs-timer { height: 3px; background: #0e131c; border-radius: 1rem; margin-top: 0.4rem; overflow: hidden; }
.obs-timer > div { height: 100%; background: var(--warn); width: 100%; }
.obs-card.heal .obs-timer > div { background: var(--good); }
.obs-counter {
  margin-top: 0.4rem; width: 100%;
  background: #0e131c; border: 1px solid var(--line); color: var(--text);
  border-radius: 0.45rem; padding: 0.3rem; font-size: 0.72rem; cursor: pointer;
  transition: background .12s, transform .06s;
}
.obs-counter:hover:not(:disabled) { background: #283449; border-color: var(--accent); }
.obs-counter:active:not(:disabled) { transform: scale(.97); }
.obs-counter:disabled { opacity: .4; cursor: not-allowed; }
.shred-bar { height: 4px; background: #0e131c; border-radius: 1rem; margin-top: 0.3rem; overflow: hidden; }
.shred-bar > div { height: 100%; background: var(--accent); width: 0%; transition: width .1s; }

/* ---------- log ---------- */
#logbar {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 0.8rem; padding: 0.45rem 0.7rem;
  display: flex; flex-direction: column; max-height: 8.5rem;
}
.log-head { font-size: 0.66rem; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; margin-bottom: 0.25rem; }
.log { overflow-y: auto; font-size: 0.76rem; display: flex; flex-direction: column-reverse; gap: 0.18rem; }
.log-entry { line-height: 1.25; }
.log-entry.good { color: var(--good); }
.log-entry.bad { color: var(--bad); }
.log-entry.warn { color: var(--warn); }
.log-entry .ts { color: var(--muted); font-size: 0.66rem; margin-right: 0.35rem; }

/* ---------- overlay ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(8,11,16,.82);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  backdrop-filter: blur(3px);
}
.overlay.hidden { display: none; }
.overlay-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 1rem; padding: 1.6rem 1.8rem; max-width: 30rem; width: 90%;
  text-align: center; box-shadow: var(--shadow);
  animation: pop .3s ease;
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }
.overlay-emoji { font-size: 3rem; }
.overlay-card h2 { margin: 0.3rem 0 0.5rem; font-size: 1.4rem; }
.overlay-card p { color: var(--muted); font-size: 0.9rem; line-height: 1.5; }
.overlay-stats { font-size: 0.82rem; margin: 0.8rem 0; color: var(--text); }
.btn-restart {
  margin-top: 0.6rem; background: var(--accent); color: #08111f; border: none;
  border-radius: 0.6rem; padding: 0.6rem 1.4rem; font-size: 0.95rem; font-weight: 700; cursor: pointer;
  transition: filter .15s, transform .06s;
}
.btn-restart:hover { filter: brightness(1.1); }
.btn-restart:active { transform: scale(.97); }

/* ---------- floating damage ---------- */
.float {
  position: absolute; pointer-events: none; font-weight: 800; font-size: 1rem;
  animation: floatUp 0.9s ease forwards; z-index: 5;
}
.float.dmg { color: var(--good); }
.float.heal { color: var(--bad); }
@keyframes floatUp {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(-42px); opacity: 0; }
}

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  #board { grid-template-columns: 1fr; grid-auto-rows: minmax(0, auto); overflow-y: auto; }
  .scene { order: -1; }
  .ring-wrap { max-width: 12rem; }
  #app { gap: 0.45rem; padding: 0.5rem; }
  #logbar { max-height: 6rem; }
}
