/* ==========================================================================
   W.O.P.R. (WAR OPERATION PLAN RESPONSE) - WWW.DAVIDEPARISI.COM
   1983 WarGames IMSAI 8080 / NORAD CRT Terminal Aesthetic
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=VT323&display=swap');

:root {
  /* Tema predefinito: NORAD / Electrohome Cyan-White Phosphor (Fedele al film WarGames 1983) */
  --bg-crt: #03080d;
  --bg-panel: rgba(5, 16, 26, 0.92);
  --fg-primary: #a6f4ff;
  --fg-bright: #e6fcff;
  --fg-dim: #4692a3;
  --glow-primary: rgba(0, 212, 255, 0.65);
  --glow-strong: rgba(166, 244, 255, 0.9);
  --accent-warn: #ffcc00;
  --accent-danger: #ff3b30;
  --border-line: #27788c;
  --font-term: 'VT323', 'Share Tech Mono', 'Courier New', monospace;
  --font-ui: 'Share Tech Mono', 'Courier New', monospace;
}

/* Tema Fosforo Verde P1 */
body.theme-green {
  --bg-crt: #030b04;
  --bg-panel: rgba(4, 18, 6, 0.92);
  --fg-primary: #5cff72;
  --fg-bright: #d4ffda;
  --fg-dim: #2b8a38;
  --glow-primary: rgba(50, 255, 80, 0.6);
  --glow-strong: rgba(150, 255, 170, 0.9);
  --border-line: #1f7a2c;
}

/* Tema Fosforo Ambra P3 */
body.theme-amber {
  --bg-crt: #0c0702;
  --bg-panel: rgba(20, 11, 3, 0.92);
  --fg-primary: #ffb642;
  --fg-bright: #ffe6bd;
  --fg-dim: #8c5d15;
  --glow-primary: rgba(255, 166, 0, 0.6);
  --glow-strong: rgba(255, 210, 120, 0.9);
  --border-line: #8f5b0d;
}

/* Allarme DEFCON 1 / Guerra Termonucleare */
body.defcon-alert {
  animation: crt-red-pulse 0.8s infinite alternate;
}

@keyframes crt-red-pulse {
  0% { box-shadow: inset 0 0 60px rgba(255, 30, 30, 0.15); }
  100% { box-shadow: inset 0 0 120px rgba(255, 40, 40, 0.45); }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: #000;
  color: var(--fg-primary);
  font-family: var(--font-term);
  overflow: hidden;
  user-select: text;
  -webkit-font-smoothing: none;
}

/* Cornice Monitor CRT */
.crt-frame {
  position: relative;
  width: 100vw;
  height: 100vh;
  background: radial-gradient(ellipse at center, var(--bg-crt) 0%, #010306 100%);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px 26px 14px 26px;
  overflow: hidden;
  box-shadow: inset 0 0 90px rgba(0, 0, 0, 0.85);
}

/* Effetto Scanlines e Curvatura Fosfori */
.crt-frame::before {
  content: " ";
  display: block;
  position: absolute;
  inset: 0;
  background: linear-gradient(
    rgba(18, 16, 16, 0) 50%,
    rgba(0, 0, 0, 0.38) 50%
  ), linear-gradient(
    90deg,
    rgba(255, 0, 0, 0.03),
    rgba(0, 255, 0, 0.01),
    rgba(0, 180, 255, 0.03)
  );
  background-size: 100% 3px, 6px 100%;
  z-index: 50;
  pointer-events: none;
}

.crt-frame::after {
  content: " ";
  display: block;
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, transparent 62%, rgba(0, 0, 0, 0.65) 100%);
  z-index: 51;
  pointer-events: none;
}

/* Barra Superiore NORAD / DEFCON (visibile in modalità ridotta al login, completa dopo JOSHUA) */
.norad-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-line);
  padding-bottom: 8px;
  margin-bottom: 10px;
  font-family: var(--font-ui);
  font-size: 0.92rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  text-shadow: 0 0 8px var(--glow-primary);
  z-index: 10;
  transition: opacity 0.4s ease;
}

.norad-header.pre-login {
  opacity: 0.45;
  border-bottom-style: dashed;
}

.brand-node {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-dot {
  width: 10px;
  height: 10px;
  background: var(--fg-primary);
  box-shadow: 0 0 10px var(--fg-bright);
  display: inline-block;
  animation: blink-cursor 1.4s infinite;
}

/* Indicatore DEFCON 5..1 */
.defcon-strip {
  display: flex;
  align-items: center;
  gap: 6px;
}

.defcon-label {
  color: var(--fg-dim);
  margin-right: 4px;
}

.defcon-badge {
  padding: 2px 7px;
  border: 1px solid var(--border-line);
  color: var(--fg-dim);
  font-size: 0.8rem;
  transition: all 0.25s;
}

.defcon-badge.active[data-level="5"] { color: #5cff72; border-color: #5cff72; box-shadow: 0 0 8px rgba(92,255,114,0.5); }
.defcon-badge.active[data-level="4"] { color: var(--fg-bright); border-color: var(--fg-primary); box-shadow: 0 0 10px var(--glow-primary); background: rgba(0, 212, 255, 0.14); }
.defcon-badge.active[data-level="3"] { color: #ffe600; border-color: #ffe600; box-shadow: 0 0 10px rgba(255,230,0,0.6); }
.defcon-badge.active[data-level="2"] { color: #ff8800; border-color: #ff8800; box-shadow: 0 0 12px rgba(255,136,0,0.7); }
.defcon-badge.active[data-level="1"] { color: #ffffff; background: #ff1e1e; border-color: #ff5555; box-shadow: 0 0 18px #ff1e1e; animation: blink-cursor 0.4s infinite; }

/* Area Terminale Principale */
.terminal-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 8px 6px 18px 6px;
  font-family: var(--font-term);
  font-size: 1.65rem;
  line-height: 1.28;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  text-shadow: 0 0 7px var(--glow-primary), 0 0 2px var(--fg-bright);
  z-index: 10;
  scrollbar-width: thin;
  scrollbar-color: var(--border-line) transparent;
}

.terminal-viewport::-webkit-scrollbar {
  width: 6px;
}
.terminal-viewport::-webkit-scrollbar-thumb {
  background: var(--border-line);
}

.term-line {
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 4px;
}

.term-line.carrier-numbers {
  color: var(--fg-dim);
  font-size: 1.45rem;
  letter-spacing: 3px;
}

.term-line.system-alert {
  color: var(--accent-warn);
  text-shadow: 0 0 10px rgba(255, 204, 0, 0.75);
}

.term-line.danger-alert {
  color: #ff6b6b;
  text-shadow: 0 0 12px rgba(255, 59, 48, 0.9);
}

.term-line.user-echo {
  color: var(--fg-bright);
}

.term-line.hint-box {
  color: var(--fg-dim);
  border-left: 2px solid var(--border-line);
  padding-left: 10px;
  margin: 6px 0;
  font-size: 1.35rem;
}

/* Riga di Input Interattiva con Cursore Blocco */
.input-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 6px;
  font-size: 1.65rem;
  letter-spacing: 1.6px;
  text-shadow: 0 0 7px var(--glow-primary), 0 0 2px var(--fg-bright);
  position: relative;
}

.prompt-label {
  color: var(--fg-bright);
  margin-right: 10px;
  white-space: pre;
}

.cmd-display-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 1;
  min-width: 180px;
}

#cmd-mirror {
  color: var(--fg-bright);
  white-space: pre-wrap;
  word-break: break-all;
}

.block-cursor {
  display: inline-block;
  width: 12px;
  height: 1.15em;
  background-color: var(--fg-bright);
  box-shadow: 0 0 10px var(--glow-strong);
  vertical-align: text-bottom;
  margin-left: 1px;
  animation: blink-cursor 0.9s steps(2, start) infinite;
}

@keyframes blink-cursor {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* Input reale invisibile ma accessibile su desktop e mobile */
#terminal-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  background: transparent;
  border: none;
  outline: none;
  color: transparent;
  caret-color: transparent;
  font-size: 16px;
  cursor: text;
}

/* Pulsanti Rapidi Contesto (Quick Commands post-login o pre-login) */
.quick-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px dashed rgba(70, 146, 163, 0.35);
  z-index: 10;
}

.quick-btn {
  background: rgba(0, 180, 216, 0.07);
  border: 1px solid var(--border-line);
  color: var(--fg-primary);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  padding: 4px 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.18s ease;
  text-shadow: 0 0 5px var(--glow-primary);
}

.quick-btn:hover, .quick-btn:focus {
  background: var(--fg-primary);
  color: #02080d;
  box-shadow: 0 0 14px var(--glow-primary);
  text-shadow: none;
}

.quick-btn.danger-btn {
  border-color: #a83232;
  color: #ff8585;
}
.quick-btn.danger-btn:hover {
  background: #ff3b30;
  color: #fff;
  box-shadow: 0 0 16px rgba(255, 59, 48, 0.8);
}

/* Barra Inferiore Hardware IMSAI 8080 / Controlli CRT */
.crt-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  border-top: 1px solid var(--border-line);
  padding-top: 8px;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--fg-dim);
  letter-spacing: 1px;
  z-index: 10;
}

.pgp-footer-link {
  color: var(--fg-dim);
  text-decoration: none;
  border: 1px solid var(--border-line);
  padding: 2px 10px;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  transition: all 0.18s;
}

.pgp-footer-link:hover, .pgp-footer-link:focus {
  color: var(--fg-bright);
  border-color: var(--fg-primary);
  box-shadow: 0 0 10px var(--glow-primary);
}

.ctrl-chip {
  background: transparent;
  border: 1px solid var(--border-line);
  color: var(--fg-dim);
  font-family: var(--font-ui);
  font-size: 0.76rem;
  padding: 2px 8px;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.15s;
}

.ctrl-chip:hover, .ctrl-chip.active {
  color: var(--fg-bright);
  border-color: var(--fg-primary);
  box-shadow: 0 0 8px var(--glow-primary);
}

/* ==========================================================================
   MODALI VETTORIALI NORAD (TIC-TAC-TOE, SCACCHI, ADMIN)
   ========================================================================== */

.norad-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(1, 6, 11, 0.86);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 16px;
}

.norad-modal-backdrop.open {
  display: flex;
}

.norad-window {
  width: 100%;
  max-width: 920px;
  max-height: 92vh;
  background: var(--bg-panel);
  border: 2px solid var(--fg-primary);
  box-shadow: 0 0 30px var(--glow-primary), inset 0 0 25px rgba(0, 212, 255, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.window-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(0, 180, 216, 0.14);
  border-bottom: 1px solid var(--fg-primary);
  font-family: var(--font-ui);
  font-size: 1rem;
  letter-spacing: 1.5px;
  color: var(--fg-bright);
  text-shadow: 0 0 8px var(--glow-primary);
}

.window-close {
  background: transparent;
  border: 1px solid var(--fg-primary);
  color: var(--fg-bright);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  padding: 3px 10px;
  cursor: pointer;
}

.window-close:hover {
  background: var(--fg-primary);
  color: #000;
}

.window-body {
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ==========================================================================
   MODULO 1: TIC-TAC-TOE (TRIS VETTORIALE W.O.P.R.)
   ========================================================================== */

.ttt-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  align-items: center;
}

.ttt-board-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ttt-grid {
  display: grid;
  grid-template-columns: repeat(3, 110px);
  grid-template-rows: repeat(3, 110px);
  gap: 0;
  position: relative;
}

.ttt-cell {
  border: 2px solid var(--fg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
  font-size: 4.2rem;
  color: var(--fg-bright);
  text-shadow: 0 0 16px var(--glow-strong);
  cursor: pointer;
  background: transparent;
  transition: background 0.15s;
}

/* Rimuovi bordi esterni come nella griglia vettoriale NORAD */
.ttt-cell:nth-child(1), .ttt-cell:nth-child(2), .ttt-cell:nth-child(3) { border-top: none; }
.ttt-cell:nth-child(7), .ttt-cell:nth-child(8), .ttt-cell:nth-child(9) { border-bottom: none; }
.ttt-cell:nth-child(1), .ttt-cell:nth-child(4), .ttt-cell:nth-child(7) { border-left: none; }
.ttt-cell:nth-child(3), .ttt-cell:nth-child(6), .ttt-cell:nth-child(9) { border-right: none; }

.ttt-cell:hover:not(.taken) {
  background: rgba(166, 244, 255, 0.08);
}

.ttt-cell.win-cell {
  background: rgba(166, 244, 255, 0.24);
  color: #fff;
}

.ttt-sidebar {
  border: 1px solid var(--border-line);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-family: var(--font-ui);
}

.ttt-launch-code {
  border: 1px solid var(--border-line);
  padding: 8px;
  text-align: center;
  background: rgba(0, 0, 0, 0.5);
  font-size: 1.15rem;
  letter-spacing: 4px;
  color: var(--accent-warn);
  text-shadow: 0 0 8px rgba(255, 204, 0, 0.7);
}

/* ==========================================================================
   MODULO 2: SCACCHI (W.O.P.R. STRATEGIC CHESS)
   ========================================================================== */

.chess-layout {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 22px;
  align-items: start;
}

.chess-board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 56px);
  grid-template-rows: repeat(8, 56px);
  border: 2px solid var(--fg-primary);
  box-shadow: 0 0 20px var(--glow-primary);
}

.chess-sq {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.35rem;
  cursor: pointer;
  position: relative;
  user-select: none;
  transition: all 0.12s;
}

.chess-sq.light {
  background: rgba(166, 244, 255, 0.13);
}

.chess-sq.dark {
  background: rgba(3, 12, 20, 0.9);
}

.chess-sq.selected {
  background: rgba(255, 230, 0, 0.32) !important;
  box-shadow: inset 0 0 10px #ffe600;
}

.chess-sq.valid-move::after {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--fg-bright);
  box-shadow: 0 0 8px var(--glow-strong);
  position: absolute;
}

.chess-sq.valid-capture {
  box-shadow: inset 0 0 0 2px #ff4d4d;
  background: rgba(255, 59, 48, 0.22) !important;
}

.chess-sq.last-move {
  border: 1px dashed var(--fg-primary);
}

.chess-piece.white-piece {
  color: var(--fg-bright);
  text-shadow: 0 0 10px var(--glow-strong);
}

.chess-piece.black-piece {
  color: #ff9e64;
  text-shadow: 0 0 10px rgba(255, 130, 50, 0.8);
}

.chess-panel {
  border: 1px solid var(--border-line);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-family: var(--font-ui);
  min-width: 260px;
}

.chess-log {
  height: 150px;
  overflow-y: auto;
  border: 1px solid var(--border-line);
  padding: 8px;
  font-size: 0.88rem;
  background: rgba(0, 0, 0, 0.45);
  line-height: 1.4;
}

.chess-cmd-input {
  display: flex;
  gap: 8px;
}

.norad-input, .norad-select, .norad-textarea {
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid var(--fg-primary);
  color: var(--fg-bright);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  padding: 6px 10px;
  outline: none;
  width: 100%;
}

.norad-input:focus, .norad-textarea:focus {
  box-shadow: 0 0 10px var(--glow-primary);
}

/* ==========================================================================
   MODULO 3: PANNELLO ADMIN MARIADB
   ========================================================================== */

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.admin-shell {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
}

.admin-tabs-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 1px solid var(--border-line);
  padding-bottom: 8px;
}

.admin-tabs-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.admin-tab-btn {
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--border-line);
  color: var(--fg-primary);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  padding: 6px 12px;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.admin-tab-btn:hover {
  border-color: var(--fg-primary);
  background: rgba(0, 180, 216, 0.14);
}

.admin-tab-btn.active {
  background: rgba(0, 180, 216, 0.24);
  border-color: var(--fg-bright);
  color: var(--fg-bright);
  box-shadow: 0 0 8px var(--glow-primary);
  font-weight: bold;
}

.admin-tab-panel {
  display: none;
}

.admin-tab-panel.active {
  display: block;
}

.admin-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.admin-since-badge {
  color: var(--fg-dim);
  font-size: 0.8rem;
  border: 1px dashed var(--border-line);
  padding: 3px 8px;
  background: rgba(0, 0, 0, 0.35);
}

.admin-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.admin-info-card {
  border: 1px solid var(--border-line);
  background: rgba(0, 180, 216, 0.06);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.admin-info-label {
  color: var(--fg-dim);
  font-size: 0.74rem;
  letter-spacing: 0.04em;
}

.admin-info-value {
  color: var(--fg-bright);
  font-size: 1.15rem;
  font-weight: bold;
}

.admin-info-sub {
  color: var(--fg-primary);
  font-size: 0.75rem;
  opacity: 0.85;
}

.admin-table-full {
  max-height: 360px;
}

.session-list-full {
  max-height: 480px;
}

.admin-box {
  border: 1px solid var(--border-line);
  padding: 12px;
  font-family: var(--font-ui);
  font-size: 0.85rem;
}

.admin-table-wrap {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border-line);
  margin-top: 8px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.admin-table th, .admin-table td {
  border-bottom: 1px solid rgba(70, 146, 163, 0.3);
  padding: 6px;
  text-align: left;
  vertical-align: top;
}

.admin-stats-bar {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  border: 1px solid var(--border-line);
  padding: 8px 12px;
  background: rgba(0, 180, 216, 0.06);
  font-family: var(--font-ui);
  font-size: 0.82rem;
}

.admin-stat-item {
  padding-right: 12px;
  border-right: 1px dashed var(--border-line);
}
.admin-stat-item:last-child {
  border-right: none;
}

.session-list-wrap {
  max-height: 410px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
  padding-right: 4px;
}

.session-card {
  border: 1px solid var(--border-line);
  background: rgba(0, 0, 0, 0.45);
}

.session-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 7px 10px;
  background: rgba(0, 180, 216, 0.12);
  cursor: pointer;
  font-size: 0.82rem;
  border-bottom: 1px solid transparent;
}

.session-card.expanded .session-card-header {
  border-bottom-color: var(--border-line);
}

.session-card-body {
  display: none;
  padding: 8px 10px;
  flex-direction: column;
  gap: 8px;
}

.session-card.expanded .session-card-body {
  display: flex;
}

.chat-turn {
  border-left: 2px solid var(--fg-primary);
  padding: 5px 8px;
  background: rgba(5, 22, 34, 0.65);
  font-size: 0.8rem;
}

.chat-turn-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--fg-dim);
  font-size: 0.74rem;
  margin-bottom: 3px;
}

.chat-turn-user {
  color: var(--fg-bright);
  margin-bottom: 3px;
}

.chat-turn-wopr {
  color: var(--fg-primary);
  white-space: pre-wrap;
  opacity: 0.9;
}

/* Responsive Mobile / Tablet */
@media (max-width: 780px) {
  .crt-frame {
    padding: 10px 12px;
  }
  .terminal-viewport, .input-row {
    font-size: 1.3rem;
  }
  .ttt-layout, .chess-layout, .admin-grid {
    grid-template-columns: 1fr;
  }
  .chess-board {
    grid-template-columns: repeat(8, 40px);
    grid-template-rows: repeat(8, 40px);
  }
  .chess-sq {
    width: 40px;
    height: 40px;
    font-size: 1.75rem;
  }
  .ttt-grid {
    grid-template-columns: repeat(3, 88px);
    grid-template-rows: repeat(3, 88px);
  }
}

/* Accessibilita' / Contenuto semantico per screen reader e motori di ricerca */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
