* { box-sizing: border-box; }

:root {
  --ink: #1a1a1a;
  --paper: #ffffff;
  --ground: #f8f9fa;
  --field: #030303;
  --line: #d0d0d0;
  --red: #b30000;
}

html { color-scheme: light; }

body {
  margin: 0;
  padding: 16px;
  background-color: var(--ground);
  color: var(--ink);
  font-family: "Times New Roman", Times, serif;
  line-height: 1.4;
  font-size: 17px;
  overflow-x: hidden;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 4px 24px rgba(0,0,0,0.04);
  padding: 32px;
  width: 100%;
}

h1, h2, h3, h4 { margin-top: 0; font-weight: normal; color: #000; }

h1 {
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid #000;
  padding-bottom: 12px;
  margin-bottom: 24px;
  text-align: center;
}

h3 {
  font-size: 1.2rem;
  font-style: italic;
  border-bottom: 1px dotted #ccc;
  padding-bottom: 4px;
}

a { color: inherit; text-underline-offset: 2px; }

.abstract {
  font-size: 1.05rem;
  margin-bottom: 32px;
  text-align: justify;
}

.abstract p { margin: 0 0 16px; }

blockquote {
  margin: 24px 0;
  padding: 16px 24px;
  border-left: 3px solid var(--ink);
  background: #f4f4f485;
  font-style: italic;
  font-size: 1.05rem;
}

blockquote p { margin: 0 !important; }
blockquote a { color: var(--ink); text-decoration: none; border-bottom: 1px dotted var(--ink); }
blockquote a:hover { border-bottom-style: solid; }

.concept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 24px;
  margin-bottom: 40px;
}

.concept-panel { padding: 0 8px; }
.concept-panel p { font-size: 0.95rem; color: #333; }

.math-block {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin-top: 12px;
  padding: 7px 3px;
  font-size: 1.02rem;
  white-space: nowrap;
}

.theory-essay {
  margin: 6px 0 44px;
}

.theory-lede,
.analysis-intro {
  max-width: 820px;
  margin: 0 auto 28px;
  font-size: 1.04rem;
  text-align: justify;
}

.theory-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 28px 34px;
}

.theory-note {
  min-width: 0;
  border-top: 1px solid #d7d7d7;
  padding-top: 12px;
}

.theory-note h3 { margin-bottom: 10px; }
.theory-note p { margin: 0 0 12px; font-size: 0.96rem; text-align: justify; }

.equation {
  margin: 14px 0;
  padding: 10px 8px;
  border-top: 1px dotted #bbb;
  border-bottom: 1px dotted #bbb;
  text-align: center;
  font-size: 1.04rem;
  overflow-x: auto;
  white-space: nowrap;
}

.citation { font-size: 0.68em; line-height: 0; vertical-align: super; }
.citation a { text-decoration: none; border-bottom: 1px solid #777; }

.instrument-note {
  margin-top: 34px;
  padding-top: 16px;
  border-top: 1px solid #000;
}

.instrument-note > p { font-size: 0.95rem; max-width: 850px; }

.table-scroll { width: 100%; overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th,
td {
  border: 1px solid #d2d2d2;
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

th { background: #f4f4f4; font-weight: normal; font-style: italic; color: #000; }
td:first-child { width: 18%; white-space: nowrap; }

.bibliography {
  margin-top: 30px;
  padding-top: 16px;
  border-top: 1px dotted #aaa;
}

.bibliography ol {
  margin: 0;
  padding-left: 28px;
  font-size: 0.88rem;
}

.bibliography li {
  margin-bottom: 8px;
  padding-left: 4px;
  scroll-margin-top: 18px;
}

.bibliography a { text-decoration-thickness: 1px; }

#arena-wrapper {
  position: relative;
  border: 1px solid #000;
  background: var(--field);
  margin-bottom: 32px;
  display: flex;
  flex-direction: column;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
  width: 100%;
}

#arena-wrapper:fullscreen,
#arena-wrapper:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  border: none;
  margin: 0;
  padding: 0;
}

#arena-wrapper:fullscreen #canvas-container,
#arena-wrapper:-webkit-full-screen #canvas-container { min-height: 0; }

#canvas-container {
  position: relative;
  flex-grow: 1;
  width: 100%;
  min-height: 500px;
  overflow: hidden;
  background: #030303;
}

canvas { display: block; width: 100%; height: 100%; }

#simulacrumOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: rgba(255,255,255,0);
  background: rgba(0,0,0,0);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  pointer-events: none;
  transition: color 1.5s ease, background 1.5s ease;
}

#simulacrumOverlay span { font-size: clamp(1.3rem, 3.4vw, 2rem); }
#simulacrumOverlay small { margin-top: 8px; font-size: 0.7rem; letter-spacing: 0.12em; }
#simulacrumOverlay.visible { color: rgba(255,255,255,0.8); background: rgba(0,0,0,0.18); }

.controls-bar {
  background: #fafafa;
  border-top: 1px solid #000;
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  color: #000;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.influence-control { flex: 1 1 260px; }
.influence-control label {
  font-size: 0.8rem;
  font-weight: bold;
  text-transform: uppercase;
  white-space: nowrap;
}
.influence-control output { font-family: Consolas, Monaco, monospace; }
.influence-control input { flex: 1; min-width: 130px; }

button {
  font-family: inherit;
  font-size: 0.78rem;
  letter-spacing: 0.5px;
  border: 1px solid #000;
  background: #fff;
  color: #000;
  padding: 8px 12px;
  cursor: pointer;
  text-transform: uppercase;
  transition: background 0.2s ease, color 0.2s ease;
}

button:hover { background: #f0f0f0; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
button.active-mode { background: #000; color: #fff; border-color: #000; }
button.active-mode:hover { background: #333; }
input[type="range"] { cursor: pointer; accent-color: #000; }

#telemetry-overlay {
  position: absolute;
  top: 16px;
  left: 16px;
  background: rgba(255, 255, 255, 0.511);
  border: 1px solid #000;
  padding: 16px;
  width: 285px;
  font-size: 0.87rem;
  box-shadow: 2px 2px 10px rgba(0,0,0,0.5);
  display: none;
  z-index: 10;
  backdrop-filter: blur(2px);
}

#telemetry-overlay.visible { display: block; }

.telemetry-header {
  font-weight: bold;
  text-transform: uppercase;
  border-bottom: 1px solid #00000068;
  padding-bottom: 6px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.overlay-close {
  border: 0;
  padding: 0 2px;
  background: transparent;
  font-size: 1.2rem;
  line-height: 1;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  border-bottom: 1px dotted #cccccc;
}

.stat-row:last-child { border-bottom: none; }
.stat-row > span:first-child { min-width: 0; }
.stat-val { font-weight: bold; font-family: Consolas, Monaco, monospace; font-size: 0.88rem; white-space: nowrap; }
.c-red { color: var(--red); }

.grid-main {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 24px;
  width: 100%;
}

.supplementary-analysis { margin-top: 42px; }

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
}

.analysis-panel { min-width: 0; }

.analysis-chart-wrap {
  height: 300px;
  width: 100%;
  position: relative;
  border: 1px solid #e0e0e0;
  padding: 8px;
  background: #fafafa;
}

.analysis-caption {
  min-height: 3.2em;
  margin: 10px 0 0;
  color: #444;
  font-size: 0.88rem;
  font-style: italic;
}

.chart-wrap {
  height: 260px;
  width: 100%;
  position: relative;
  border: 1px solid #e0e0e0;
  padding: 8px;
  background: #fafafa;
}

#narration,
#mathExplain {
  font-style: italic;
  margin-top: 12px;
  color: #444;
  font-size: 0.95rem;
}

#mathExplain { margin-top: 4px; }

.log-list {
  list-style-type: none;
  padding: 12px;
  margin: 0;
  font-family: Consolas, Monaco, monospace;
  font-size: 0.8rem;
  max-height: 260px;
  min-height: 260px;
  overflow-y: auto;
  background: #fafafa;
  border: 1px solid #e0e0e0;
}

.log-list li {
  margin-bottom: 8px;
  border-left: 2px solid #000;
  padding-left: 8px;
  color: #333;
}

.log-list li.critical { border-left-color: var(--red); color: #670000; }
.log-time { color: #777; margin-right: 6px; }

footer {
  margin-top: 36px;
  padding-top: 12px;
  border-top: 1px dotted #bbb;
  color: #555;
  font-size: 0.82rem;
  font-style: italic;
  text-align: center;
}

@media (max-width: 900px) {
  .grid-main { grid-template-columns: minmax(0, 1fr); }
  .analysis-grid { grid-template-columns: minmax(0, 1fr); }
  .container { padding: 16px; }
}

@media (max-width: 680px) {
  body { padding: 0; background: #fff; }
  .container { border: none; box-shadow: none; padding: 12px; }
  .abstract { text-align: left; }
  .concept-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .theory-grid { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .theory-lede, .analysis-intro, .theory-note p { text-align: left; }
  .concept-panel { padding: 0; }
  .math-block { justify-content: flex-start; overflow-x: auto; }
  td:first-child { white-space: normal; min-width: 120px; }
  .analysis-chart-wrap { height: 275px; }
  #canvas-container { min-height: min(66vh, 520px); }
  .controls-bar { flex-direction: column; align-items: stretch; }
  .control-group { justify-content: space-between; width: 100%; }
  .influence-control { flex-basis: auto; }
  .influence-control label { width: 100%; }
  .influence-control input { width: 100%; }
  .action-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #telemetry-overlay { width: auto; left: 10px; right: 10px; top: 10px; }
  button { min-height: 42px; padding: 10px 8px; text-align: center; }
  h1 { font-size: clamp(1.45rem, 7.5vw, 2rem); }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
  #simulacrumOverlay { transition-duration: 0.01ms; }
}
