.page-glitch {
  position: fixed;
  z-index: 45;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, transparent 0 3px, rgb(217 255 67 / 11%) 3px 4px),
    linear-gradient(90deg, rgb(240 45 23 / 12%), transparent 38%, rgb(69 167 255 / 10%));
  mix-blend-mode: difference;
}

.algorithm-section {
  position: relative;
  display: grid;
  grid-template-columns: minmax(18rem, .68fr) minmax(32rem, 1.32fr);
  min-height: 52rem;
  overflow: hidden;
  border-top: var(--border);
  color: var(--paper);
  background: #060706;
  isolation: isolate;
}

.chaos-shader { position: absolute; z-index: -1; inset: 0; width: 100%; height: 100%; opacity: .72; }

.algorithm-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(3rem, 6vw, 6rem) clamp(1rem, 4vw, 4rem);
  border-right: 2px solid rgb(240 239 234 / 75%);
  background: rgb(6 7 6 / 56%);
  backdrop-filter: blur(4px);
}
.algorithm-copy .section-number { color: var(--acid); }
.algorithm-copy h2 { color: var(--paper); text-shadow: .08em .05em 0 var(--red), -.05em -.03em 0 #45a7ff; }
.algorithm-copy > p:last-of-type { max-width: 30rem; margin: 2rem 0; font-size: 1.05rem; line-height: 1.5; }
.game-legend { display: grid; gap: .6rem; font: 700 .62rem "Courier New", monospace; text-transform: uppercase; }
.game-legend span { display: flex; align-items: center; gap: .6rem; }
.game-legend i { width: .8rem; height: .8rem; border: 1px solid var(--paper); }
.human-dot { background: var(--paper); }
.machine-dot { background: var(--red); }

.game-terminal {
  align-self: center;
  margin: clamp(1rem, 4vw, 4rem);
  border: 2px solid var(--paper);
  background: rgb(7 8 7 / 88%);
  box-shadow: 1rem 1rem 0 var(--red), -1rem -1rem 0 rgb(69 167 255 / 28%);
  backdrop-filter: blur(10px);
}
.terminal-head,
.terminal-foot { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 1rem; padding: .75rem; font: 700 .62rem "Courier New", monospace; text-transform: uppercase; }
.terminal-head { border-bottom: 2px solid var(--paper); color: var(--acid); }
.terminal-head strong { color: var(--paper); animation: status-pulse 800ms steps(2) infinite; }
.terminal-head span:last-child { justify-self: end; }

.game-board { display: grid; grid-template-columns: repeat(3, 1fr); aspect-ratio: 1.45; }
.game-cell {
  position: relative;
  border: 0;
  border-right: 2px solid var(--paper);
  border-bottom: 2px solid var(--paper);
  color: var(--paper);
  background: transparent;
  cursor: crosshair;
  font: 900 clamp(3rem, 7vw, 7rem)/1 Arial, sans-serif;
  text-transform: uppercase;
}
.game-cell:nth-child(3n) { border-right: 0; }
.game-cell:nth-last-child(-n + 3) { border-bottom: 0; }
.game-cell:hover:not(:disabled),
.game-cell:focus-visible:not(:disabled) { color: var(--ink); background: var(--acid); outline: 0; }
.game-cell[data-owner="O"] { color: var(--red); text-shadow: .08em .05em 0 var(--acid); }
.game-cell[data-owner="X"] { text-shadow: .08em .05em 0 #45a7ff; }
.game-cell.is-corrupted { animation: cell-corrupt 320ms steps(3) 2; }
.game-cell.is-winning { color: var(--ink); background: var(--red); }

.terminal-foot { grid-template-columns: 1fr auto; border-top: 2px solid var(--paper); }
.terminal-foot p { margin: 0; color: #aaa9a1; }
.terminal-foot button { padding: .7rem .85rem; border: 1px solid var(--acid); color: var(--acid); background: transparent; cursor: pointer; font: inherit; text-transform: uppercase; }
.terminal-foot button:hover { color: var(--ink); background: var(--acid); }

@keyframes status-pulse { 50% { opacity: .4; } }
@keyframes cell-corrupt { 0% { transform: translate(0); filter: none; } 33% { transform: translate(-.4rem, .15rem); filter: invert(1); } 66% { transform: translate(.3rem, -.15rem); filter: hue-rotate(120deg); } }

.contact-section {
  display: grid;
  grid-template-columns: minmax(18rem, .62fr) minmax(35rem, 1.38fr);
  border-top: var(--border);
  background: var(--paper);
}
.contact-heading { padding: clamp(3rem, 6vw, 6rem) clamp(1rem, 4vw, 4rem); border-right: var(--border); }
.contact-heading .section-number { color: var(--red); }
.contact-heading h2 { font-size: clamp(4rem, 8vw, 8rem); }
.contact-heading > p:last-child { max-width: 28rem; margin: 2rem 0 0; font-size: 1.05rem; line-height: 1.5; }

.hostile-form { min-width: 0; padding: clamp(1rem, 3vw, 2.5rem); background: var(--acid); }
.form-fields { display: grid; grid-template-columns: 1fr 1fr; border-top: var(--border); border-left: var(--border); }
.hostile-field { display: grid; gap: .55rem; min-width: 0; padding: .8rem; border-right: var(--border); border-bottom: var(--border); cursor: pointer; }
.hostile-field.message-field { grid-column: 1 / -1; }
.hostile-field > span { font: 700 .6rem "Courier New", monospace; text-transform: uppercase; }
.hostile-field input,
.hostile-field textarea { width: 100%; min-width: 0; padding: .6rem 0; border: 0; border-bottom: 3px solid var(--ink); border-radius: 0; color: var(--ink); background: transparent; font: 800 1.05rem Arial, sans-serif; outline: 0; }
.hostile-field textarea { min-height: 7rem; resize: none; }
.hostile-field.is-active { color: var(--paper); background: var(--red); }
.hostile-field.is-active input,
.hostile-field.is-active textarea { color: var(--paper); border-color: var(--paper); }
.hostile-field.is-active input::placeholder,
.hostile-field.is-active textarea::placeholder { color: rgb(240 239 234 / 62%); }

.keyboard-console { margin-top: 1rem; border: var(--border); background: var(--ink); }
.keyboard-head { display: grid; grid-template-columns: auto 1fr auto; gap: 1rem; padding: .65rem; border-bottom: 1px solid #55554f; color: #8e8e86; font: 700 .58rem "Courier New", monospace; text-transform: uppercase; }
.keyboard-head strong { color: var(--acid); }
.keyboard-head small { justify-self: end; color: var(--red); font: inherit; }
.chaos-keyboard { display: grid; grid-template-columns: repeat(10, 1fr); }
.chaos-key {
  min-width: 0;
  min-height: 3.5rem;
  padding: .4rem;
  border: 0;
  border-right: 1px solid #55554f;
  border-bottom: 1px solid #55554f;
  color: var(--paper);
  background: var(--ink);
  cursor: pointer;
  font: 800 .75rem Arial, sans-serif;
  text-transform: uppercase;
}
.chaos-key:hover,
.chaos-key:focus-visible { color: var(--ink); background: var(--red); outline: 0; }
.chaos-key.is-control { color: var(--acid); }
.chaos-key.is-wide { grid-column: span 2; }

.phone-machine { margin: 1rem 0 0; padding: 0; border: var(--border); }
.phone-machine legend { margin-left: .7rem; padding: 0 .4rem; font: 700 .6rem "Courier New", monospace; text-transform: uppercase; }
.phone-number { display: block; min-height: 5rem; padding: .8rem; overflow: hidden; border-bottom: var(--border); font: 900 clamp(2rem, 5vw, 4.5rem)/1 Arial, sans-serif; letter-spacing: -.05em; text-overflow: ellipsis; white-space: nowrap; }
.digit-selector { display: grid; grid-template-columns: 1fr auto auto; }
.digit-selector label { display: grid; grid-template-columns: 1fr auto; gap: .5rem; padding: .7rem; border-right: var(--border); font: 700 .62rem "Courier New", monospace; text-transform: uppercase; }
.digit-selector label output { color: var(--red); font-size: 1rem; }
.digit-selector input { grid-column: 1 / -1; width: 100%; accent-color: var(--red); }
.digit-selector button { padding: .7rem 1rem; border: 0; border-right: var(--border); color: var(--paper); background: var(--ink); cursor: pointer; font: 700 .62rem "Courier New", monospace; text-transform: uppercase; }
.digit-selector button:last-child { border-right: 0; }
.digit-selector button:hover { color: var(--ink); background: var(--red); }

.submit-cage { position: relative; height: 10rem; margin-top: 1rem; overflow: hidden; border: var(--border); background: repeating-linear-gradient(135deg, transparent 0 12px, rgb(16 16 15 / 9%) 12px 14px); }
.submit-cage p { width: min(26rem, 62%); margin: .8rem; font: 700 .58rem/1.4 "Courier New", monospace; text-transform: uppercase; }
.submit-cage button { position: absolute; right: .8rem; bottom: .8rem; padding: 1rem 1.2rem; border: var(--border); color: var(--paper); background: var(--red); cursor: pointer; font-weight: 900; text-transform: uppercase; transform: translate(var(--submit-x, 0), var(--submit-y, 0)); transition: transform 90ms steps(2); }
.submit-cage button.is-caught { color: var(--ink); background: var(--acid); box-shadow: .35rem .35rem 0 var(--ink); }
.contact-status { display: block; margin-top: 1rem; padding: .85rem; border: var(--border); color: var(--acid); background: var(--ink); font: 700 .65rem "Courier New", monospace; text-transform: uppercase; }

@media (max-width: 64rem) {
  .algorithm-section,
  .contact-section { grid-template-columns: 1fr; }
  .algorithm-copy,
  .contact-heading { border-right: 0; border-bottom: var(--border); }
  .algorithm-copy h2 { font-size: clamp(4rem, 13vw, 8rem); }
  .game-terminal { width: min(52rem, calc(100% - 2rem)); margin: 3rem auto; }
  .contact-heading h2 { font-size: clamp(4rem, 13vw, 8rem); }
}

@media (max-width: 46rem) {
  .algorithm-section { min-height: 0; }
  .game-terminal { box-shadow: .4rem .4rem 0 var(--red), -.4rem -.4rem 0 rgb(69 167 255 / 28%); }
  .terminal-head { grid-template-columns: 1fr auto; }
  .terminal-head strong { grid-column: 1 / -1; grid-row: 2; }
  .game-board { aspect-ratio: 1; }
  .terminal-foot { grid-template-columns: 1fr; }
  .terminal-foot button { width: 100%; }
  .form-fields { grid-template-columns: 1fr; }
  .hostile-field.message-field { grid-column: auto; }
  .keyboard-head { grid-template-columns: 1fr auto; }
  .keyboard-head small { grid-column: 1 / -1; justify-self: start; }
  .chaos-keyboard { grid-template-columns: repeat(6, 1fr); }
  .digit-selector { grid-template-columns: 1fr 1fr; }
  .digit-selector label { grid-column: 1 / -1; border-right: 0; border-bottom: var(--border); }
  .submit-cage p { width: calc(100% - 1.6rem); }
}

@media (prefers-reduced-motion: reduce) {
  .terminal-head strong { animation: none; }
}
