/* ===================================================================
   Computability & Complexity — Interactive Lecture Tools
   Animation-first visual design for all 7 modules (lectures 7-21)
   Dr. Arash Kermani · CUD · BCS 402
   =================================================================== */

:root {
  --bg: #fbfaf7;
  --paper: #ffffff;
  --ink: #1a1a1a;
  --muted: #4a4a4a;
  --dim: #888;
  --rule: #e6e3dc;
  --rule-strong: #cfcabd;

  --accent: #2a6f5f;
  --accent-soft: #d6ebe4;
  --accent-strong: #1c4a3f;

  --warn: #b95825;
  --warn-soft: #f4dfcf;

  --info: #2f60a8;
  --info-soft: #d6e3f4;

  --gold: #b58b00;
  --gold-soft: #f3e9c4;

  --grid: #efece4;
  --code-bg: #f3f1ea;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 940px; margin: 0 auto; padding: 0 24px; }

header.hero {
  padding: 40px 24px 24px;
  text-align: center;
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(180deg, #fffefb 0%, var(--bg) 100%);
}
header.hero .eyebrow {
  font-family: var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 10px;
}
header.hero h1 {
  font-family: var(--serif);
  font-size: 36px;
  font-weight: 700;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
header.hero .sub {
  font-size: 17px;
  color: var(--muted);
  margin: 0 0 8px;
}
header.hero .tag {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
}

nav.tabs {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 4px; padding: 16px 16px 0;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}
nav.tabs button, nav.tabs a {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  text-decoration: none;
  transition: color .15s, border-color .15s;
}
nav.tabs button:hover, nav.tabs a:hover { color: var(--accent); }
nav.tabs button.active, nav.tabs a.active {
  color: var(--accent-strong);
  border-bottom-color: var(--accent);
}

section { padding: 30px 0 26px; }
section + section { border-top: 1px solid var(--rule); }

h2 { font-size: 22px; font-weight: 700; margin: 0 0 14px; letter-spacing: -0.005em; }
h3 { font-size: 17px; font-weight: 700; margin: 18px 0 8px; }
h4 {
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 14px 0 6px;
}

p { margin: 0 0 12px; }
a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-soft); }
a:hover { border-bottom-color: var(--accent); }
ul, ol { padding-left: 20px; }
li { margin: 4px 0; }

code, kbd, samp { font-family: var(--mono); font-size: 0.92em; background: var(--code-bg); padding: 1px 5px; border-radius: 3px; }
pre {
  font-family: var(--mono); font-size: 13.5px; line-height: 1.5;
  background: var(--code-bg); padding: 12px 14px; border-radius: 6px;
  overflow-x: auto; border: 1px solid var(--rule);
}
pre code { background: transparent; padding: 0; }

.math { font-family: "STIX Two Math", "Latin Modern Math", "Cambria Math", var(--serif); font-style: italic; }
.math-block {
  display: block; text-align: center; margin: 12px auto;
  font-family: "STIX Two Math", "Latin Modern Math", "Cambria Math", var(--serif);
  font-size: 18px;
}

.callout {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 10px 16px;
  margin: 14px 0;
}
.callout h5 {
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 6px;
  font-weight: 600;
}
.callout.warn { border-left-color: var(--warn); }
.callout.info { border-left-color: var(--info); }
.callout.gold { border-left-color: var(--gold); background: #fffdf3; }

.key-idea {
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 10px 16px;
  margin: 14px 0;
  font-size: 15.5px;
}
.key-idea strong { color: var(--accent-strong); }

.cols-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 720px) { .cols-2 { grid-template-columns: 1fr; } }

.widget {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 18px;
  margin: 18px 0;
  box-shadow: 0 1px 0 rgba(0,0,0,.02);
}
.widget-title {
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.widget-title .pill {
  background: var(--accent-soft);
  color: var(--accent-strong);
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 10px;
  letter-spacing: 0.1em;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 10px 0;
}
.controls label {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.controls input[type="range"] { width: 130px; }
.controls input[type="text"], .controls input[type="number"], .controls select, .controls textarea {
  font-family: var(--mono);
  font-size: 13px;
  padding: 5px 8px;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  background: white;
  color: var(--ink);
}

button.btn, .controls button {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  background: var(--accent);
  color: white;
  border: 0;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: background .15s, transform .08s;
}
button.btn:hover, .controls button:hover { background: var(--accent-strong); }
button.btn:active { transform: scale(0.97); }
button.btn.ghost, .controls button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--rule-strong);
}
button.btn.ghost:hover, .controls button.ghost:hover { background: var(--accent-soft); }
button.btn:disabled { background: var(--rule-strong); cursor: not-allowed; }

button.play-btn {
  background: var(--gold);
  color: white;
  padding: 8px 18px;
  font-weight: 600;
}
button.play-btn:hover { background: #8a6800; }

.status {
  display: flex;
  gap: 16px;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
  flex-wrap: wrap;
}
.status .stat { display: flex; gap: 6px; align-items: baseline; }
.status .stat b { font-family: var(--mono); font-size: 13px; color: var(--ink); }

table.data {
  border-collapse: collapse;
  margin: 14px 0;
  font-family: var(--sans);
  font-size: 13px;
  width: 100%;
}
table.data th, table.data td {
  border: 1px solid var(--rule);
  padding: 6px 9px;
  text-align: left;
  vertical-align: top;
  transition: background .3s, color .3s;
}
table.data th { background: var(--code-bg); font-weight: 600; }

svg { display: block; max-width: 100%; height: auto; }

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin: 20px 0;
}
.module-card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 16px 18px;
  text-decoration: none;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.module-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,.06);
  border-color: var(--accent);
}
.module-card .num {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.module-card .ttl { font-size: 18px; font-weight: 700; line-height: 1.25; }
.module-card .desc { font-size: 14px; color: var(--muted); }
.module-card .meta {
  font-family: var(--sans);
  font-size: 11px;
  color: var(--dim);
  margin-top: auto;
  padding-top: 6px;
  border-top: 1px solid var(--rule);
}

.exercise {
  background: #fffdf3;
  border: 1px solid var(--gold-soft);
  border-left: 3px solid var(--gold);
  border-radius: 6px;
  padding: 12px 16px;
  margin: 14px 0;
}
.exercise .ex-num {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 600;
}
.exercise details { margin-top: 8px; }
.exercise summary {
  cursor: pointer;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
  user-select: none;
}
.exercise .hint, .exercise .solution {
  margin-top: 6px;
  font-size: 15px;
  color: var(--muted);
  padding-left: 8px;
  border-left: 2px solid var(--rule);
}

footer.foot {
  border-top: 1px solid var(--rule);
  padding: 24px;
  text-align: center;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--dim);
  margin-top: 32px;
}

.tape {
  display: flex;
  gap: 0;
  font-family: var(--mono);
  font-size: 15px;
  margin: 10px 0;
  overflow-x: auto;
  padding: 4px 0;
}
.tape .cell {
  width: 32px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--rule-strong);
  border-right: 0;
  background: var(--paper);
  transition: background .25s ease, color .25s ease, border-color .25s ease, transform .25s ease;
}
.tape .cell:last-child { border-right: 1px solid var(--rule-strong); }
.tape .cell.head {
  background: var(--accent-soft);
  border-color: var(--accent);
  font-weight: 700;
  transform: translateY(-2px);
}
.tape .cell.blank { color: var(--dim); }
.tape .cell.write { animation: pulseWrite 0.5s ease; }

@keyframes pulseWrite {
  0%   { background: var(--gold-soft); }
  100% { background: var(--accent-soft); }
}

.state-display {
  display: inline-block;
  font-family: var(--mono);
  font-size: 14px;
  background: var(--info-soft);
  color: var(--info);
  padding: 3px 9px;
  border-radius: 4px;
  border: 1px solid var(--info);
  font-weight: 600;
  transition: background .3s, color .3s;
}

.toggle-group {
  display: inline-flex;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  overflow: hidden;
}
.toggle-group button {
  background: var(--paper);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13px;
  padding: 6px 12px;
  border: 0;
  cursor: pointer;
  border-right: 1px solid var(--rule);
}
.toggle-group button:last-child { border-right: 0; }
.toggle-group button.active {
  background: var(--accent);
  color: white;
}

.explain-panel {
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 12px 16px;
  margin-top: 10px;
  font-size: 14.5px;
  /* Reserve enough vertical space for the longest narrations so the page below
     does not jump as the explainer content changes between animation steps. */
  min-height: 260px;
  /* If a narration is ever longer than that, scroll inside the panel rather
     than push everything else down the page. */
  max-height: 720px;
  overflow-y: auto;
  transition: background .3s;
}
@media (max-width: 720px) {
  .explain-panel { min-height: 320px; max-height: 460px; }
}
.explain-panel .step-num {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-strong);
  font-weight: 600;
  margin-bottom: 4px;
}

/* ===== ANIMATION UTILITIES ===== */

/* Smooth SVG transitions for everything */
.svg-anim circle, .svg-anim line, .svg-anim rect, .svg-anim text, .svg-anim path, .svg-anim polygon, .svg-anim ellipse {
  transition: cx .35s ease, cy .35s ease, x .35s ease, y .35s ease,
              x1 .35s ease, y1 .35s ease, x2 .35s ease, y2 .35s ease,
              r .25s ease, fill .35s ease, stroke .35s ease, stroke-width .25s ease,
              opacity .35s ease, transform .35s ease;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 0.4s ease forwards; }

@keyframes slideInLeft { from { opacity: 0; transform: translateX(-12px); } to { opacity: 1; transform: translateX(0); } }
.slide-in-left { animation: slideInLeft 0.35s ease forwards; }

@keyframes slideInRight { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: translateX(0); } }
.slide-in-right { animation: slideInRight 0.35s ease forwards; }

@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.pulse { animation: pulse 1.2s ease infinite; }

@keyframes flash {
  0%   { background: var(--gold-soft); }
  50%  { background: var(--gold); color: white; }
  100% { background: var(--accent-soft); }
}
.flash { animation: flash 0.6s ease; }

@keyframes dashFlow { to { stroke-dashoffset: -40; } }
.dash-flow {
  stroke-dasharray: 6 4;
  animation: dashFlow 1.2s linear infinite;
}

@keyframes glow {
  0%,100% { filter: drop-shadow(0 0 0 transparent); }
  50%     { filter: drop-shadow(0 0 8px var(--accent)); }
}
.glow { animation: glow 1.6s ease infinite; }

@keyframes accept-flash {
  0%,100% { background: var(--accent-soft); }
  50%     { background: var(--accent); color: white; }
}
.accept-flash { animation: accept-flash 0.6s ease 3; }

@keyframes reject-flash {
  0%,100% { background: var(--warn-soft); }
  50%     { background: var(--warn); color: white; }
}
.reject-flash { animation: reject-flash 0.6s ease 3; }

@keyframes bounce-dot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1; }
}
.running-dots span {
  display: inline-block;
  width: 6px; height: 6px;
  margin: 0 1px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce-dot 1.2s infinite ease;
}
.running-dots span:nth-child(2) { animation-delay: .15s; }
.running-dots span:nth-child(3) { animation-delay: .3s; }

.speed-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--muted);
}

/* Animated highlight wave */
@keyframes wave {
  0%   { background-position: -200px 0; }
  100% { background-position: 200px 0; }
}
.wave-bg {
  background: linear-gradient(90deg, var(--accent-soft) 0%, var(--gold-soft) 50%, var(--accent-soft) 100%);
  background-size: 400px 100%;
  animation: wave 2.5s linear infinite;
}

@media (max-width: 600px) {
  header.hero h1 { font-size: 26px; }
  header.hero .sub { font-size: 15px; }
  h2 { font-size: 19px; }
  .wrap { padding: 0 14px; }
}
