/* Core War widget. The arena is always dark (it is a "screen"), independent of the site theme. */
.cw {
  --bg: #0b0f17; --panel: #111827; --line: rgba(148, 163, 184, .18); --ink: #e2e8f0; --muted: #8b98ad; --accent: #1e9fd0;
  container-type: inline-size;
  width: min(72rem, calc(100vw - 2rem)); /* app.js shifts it to the viewport centre */
  margin: 1.5rem 0; padding: clamp(.6rem, 2cqi, 1.1rem);
  background: radial-gradient(120% 80% at 50% 0%, #131c2e 0%, var(--bg) 60%);
  color: var(--ink); border: 1px solid var(--line); border-radius: 1rem;
  box-shadow: 0 20px 60px -30px rgba(0, 0, 0, .7);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.cw * { box-sizing: border-box; }
.cw code, .cw .cw-listing, .cw .cw-cycle, .cw output, .cw .cw-tip, .cw textarea { font-family: "JetBrains Mono Variable", ui-monospace, monospace; }
.cw h4 { margin: 0 0 .5rem; font-size: .95rem; font-weight: 600; display: flex; align-items: center; gap: .45rem; }
.cw h4 small { color: var(--muted); font-weight: 400; margin-left: auto; }
.cw-chip { display: inline-block; width: .8rem; height: .8rem; border-radius: .2rem; background: var(--c); flex: none; }

.cw-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .6rem; margin-bottom: .6rem; }
.cw button, .cw select, .cw textarea {
  font: inherit; color: var(--ink); background: #1b2436; border: 1px solid var(--line); border-radius: .5rem;
}
.cw button { padding: .38rem .8rem; cursor: pointer; transition: background .15s, border-color .15s; }
.cw button:hover:not(:disabled) { background: #24314a; border-color: rgba(148, 163, 184, .4); }
.cw button:disabled { opacity: .5; cursor: progress; }
.cw button:focus-visible, .cw select:focus-visible, .cw input:focus-visible, .cw textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cw .cw-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; min-width: 5.2rem; }
.cw .cw-primary:hover:not(:disabled) { background: #2bb1e3; }
.cw select { padding: .38rem .5rem; cursor: pointer; }
.cw-pick { display: inline-flex; align-items: center; gap: .4rem; padding: .15rem .2rem .15rem .55rem; border-radius: .6rem; background: color-mix(in srgb, var(--c) 14%, transparent); border: 1px solid color-mix(in srgb, var(--c) 45%, transparent); }
.cw-pick select { border: 0; background: transparent; font-weight: 600; }
.cw-pick option { background: var(--panel); }
.cw-swap { padding: .3rem .55rem !important; }
.cw-score { margin-left: auto; font: 600 1.25rem/1 "JetBrains Mono Variable", ui-monospace, monospace; }
.cw-score small { font: 400 .8rem system-ui, sans-serif; color: var(--muted); }
.cw-speed, .cw-toggle { display: inline-flex; align-items: center; gap: .4rem; color: var(--muted); cursor: pointer; }
.cw-speed input { width: clamp(6rem, 16cqi, 10rem); accent-color: var(--accent); }
.cw-speed output { min-width: 6.5em; color: var(--ink); font-size: .8rem; }
.cw-toggle input { accent-color: var(--accent); width: 1rem; height: 1rem; }

.cw-status { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .8rem; margin-bottom: .6rem; }
.cw-progress { flex: 1 1 10rem; height: 6px; background: #1b2436; border-radius: 99px; overflow: hidden; }
.cw-progress div { height: 100%; width: 0; background: linear-gradient(90deg, #f2556b, #1e9fd0); border-radius: 99px; }
.cw-cycle { font-size: .78rem; color: var(--muted); }

.cw-main { display: grid; gap: .8rem; grid-template-columns: 1fr; }
@container (min-width: 860px) { .cw-with-code .cw-main { grid-template-columns: minmax(0, 1fr) 22rem; } }
.cw-arena { position: relative; min-width: 0; }
.cw-core { display: block; width: 100%; height: auto; border-radius: .5rem; background: #161c28; image-rendering: pixelated; touch-action: manipulation; cursor: crosshair; }
.cw-banner {
  position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%);
  padding: .7rem 1.4rem; border-radius: .8rem; font-size: clamp(1rem, 3.5cqi, 1.6rem); font-weight: 700; white-space: nowrap;
  background: rgba(11, 15, 23, .82); border: 2px solid var(--c); color: var(--ink);
  backdrop-filter: blur(6px); box-shadow: 0 0 40px -6px var(--c); pointer-events: none;
  animation: cw-pop .35s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes cw-pop { from { transform: translate(-50%, -50%) scale(.6); opacity: 0; } }
.cw-tip {
  position: absolute; z-index: 2; max-width: 18rem; padding: .45rem .6rem; border-radius: .45rem; pointer-events: none;
  background: rgba(15, 23, 42, .95); border: 1px solid var(--line); font-size: .75rem; line-height: 1.5; color: var(--ink);
}
.cw-tip code { color: #fff; }

.cw-code { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); align-content: start; }
@container (min-width: 860px) { .cw-with-code .cw-code { grid-template-columns: 1fr; } }
.cw-code section { background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--c); border-radius: .6rem; padding: .6rem .7rem; }
.cw-listing { list-style: none; margin: 0; padding: 0; font-size: .78rem; }
.cw-listing li { display: flex; gap: .7rem; padding: .08rem .35rem; border-left: 3px solid var(--o); border-radius: .2rem; white-space: nowrap; overflow: hidden; }
.cw-listing li span { color: var(--muted); }
.cw-listing li.pc span::after { content: " ●"; color: #fff; }
.cw-listing li.now { background: color-mix(in srgb, var(--c) 28%, transparent); color: #fff; }
.cw-listing li.hit { outline: 1px dashed var(--c); }
.cw-say { margin: .5rem 0 0; min-height: 2.9em; font-size: .82rem; color: var(--ink); }
.cw-say b { color: var(--c); }
.cw-hint { margin: 0; font-size: .78rem; color: var(--muted); }

.cw-legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; margin: .6rem 0; font-size: .75rem; color: var(--muted); }
.cw-legend span { display: inline-flex; align-items: center; gap: .35rem; }
.cw-legend .sw { width: .8rem; height: .8rem; border-radius: .15rem; background: linear-gradient(90deg, #a54e5b 50%, #3a7c99 50%); }
.cw-legend .sw.dat { background: linear-gradient(90deg, #52282f 50%, #1e3f4e 50%); }
.cw-legend .sw.proc { background: #161c28; box-shadow: inset 0 0 0 .22rem #161c28, inset 0 0 0 1rem #fff; }
.cw-legend .sw.exec { background: #fff; }
.cw-legend .sw.fresh { background: linear-gradient(90deg, #52282f, #ff8092); }

.cw-pop { position: relative; margin: .4rem 0 .8rem; }
.cw-pop figcaption { font-size: .78rem; color: var(--muted); margin-bottom: .3rem; }
.cw-pop canvas { display: block; width: 100%; height: 130px; }

.cw details { margin-top: .6rem; border-top: 1px solid var(--line); padding-top: .6rem; }
.cw summary { cursor: pointer; font-weight: 600; padding: .2rem 0; }
.cw summary::marker { color: var(--accent); }
.cw-editors { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); margin: .7rem 0; }
.cw textarea { width: 100%; padding: .6rem; font-size: .8rem; line-height: 1.5; background: #0d131f; resize: vertical; tab-size: 8; }
.cw-msg { margin: .3rem 0 0; font-size: .78rem; color: #4ade80; }
.cw-msg.err { color: #fb7185; }
.cw-tour .cw-bar { margin-top: .6rem; }
.cw-tour label { color: var(--muted); display: inline-flex; gap: .4rem; align-items: center; }
.cw-tprog { max-width: 16rem; }
.cw-tout h4 { margin-top: 1rem; }
.cw-rank { list-style: none; margin: 0; padding: 0; display: grid; gap: .25rem; }
.cw-rank li { display: grid; grid-template-columns: minmax(7rem, 11rem) 1fr 3rem; gap: .6rem; align-items: center; font-size: .82rem; }
.cw-rank b { text-align: right; font-family: "JetBrains Mono Variable", ui-monospace, monospace; }
.cw-rbar { height: .7rem; background: #1b2436; border-radius: 4px; overflow: hidden; }
.cw-rbar i { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.cw-matrix { overflow-x: auto; }
.cw-matrix table { border-collapse: separate; border-spacing: 2px; font-size: .75rem; margin: 0; }
.cw-matrix th { font-weight: 500; color: var(--muted); padding: .2rem .4rem; text-align: left; white-space: nowrap; }
.cw-matrix td {
  min-width: 3.6rem; padding: .3rem .35rem; text-align: center; border-radius: 4px; color: var(--ink); font-weight: 600;
  background: color-mix(in srgb, var(--accent) calc(var(--a) * 85%), #1b2436);
}
.cw-matrix td small { display: block; font-weight: 400; font-size: .65rem; opacity: .75; }
.cw-matrix td.self { background: transparent; color: var(--muted); }

@media (prefers-reduced-motion: reduce) { .cw-banner { animation: none; } }
