/* ============================================================
   ERA: THE COBOL ROOM — "COBOL RPG MODE"
   Scoped under .cobol, component prefix cbl-. Green-phosphor
   frame matching the site's CRT language: panels with soft
   glow and --cobol-font (IBM 3270 stack, base.css).
   ============================================================ */

.cobol{
  position: fixed; inset: 0; z-index: 8900;
  display: none;
  background: #010704;
  color: #2ee465;
  font-family: var(--cobol-font);
  -webkit-font-smoothing: none;
  text-rendering: geometricPrecision;
}
.cobol.open{ display: flex; flex-direction: column; }

.cobol .cbl-spacer{ flex: 1; }

/* ---- chrome bars ---- */
.cbl-topbar, .cbl-fbar{
  display: flex; gap: 26px; align-items: center;
  padding: 10px 16px;
  margin: 10px 12px;
  border: 1px solid #1d7a38;
  border-radius: 4px;
  font-size: 14px; letter-spacing: 1px;
  text-shadow: 0 0 6px rgba(46,228,101,.55);
  box-shadow: 0 0 12px rgba(46,228,101,.12), inset 0 0 18px rgba(46,228,101,.05);
  flex: 0 0 auto;
  white-space: nowrap;
}
.cbl-topbar b{ color: #b8ffcf; font-weight: 400; }
.cbl-fbar span[data-cbl-fkey]{ cursor: pointer; }
.cbl-fbar span[data-cbl-fkey]:hover{ color: #b8ffcf; }
.cbl-kist-toggle{ cursor:pointer; color:#b8ffcf; }
.cbl-kist-toggle b{ font-weight:400; color:#2ee465; }
.cbl-kist-toggle:hover{ color:#fff; }
.cbl-kist-toggle.switched{ animation:cblDesignFlash .52s steps(2,end); }
@keyframes cblDesignFlash{
  50%{ color:#fff; text-shadow:0 0 12px #b8ffcf; }
}
.cbl-fbar .cbl-dim{ opacity: .45; }
.cbl-fbar .cbl-mode{ color: #b8ffcf; }

/* ---- main layout ---- */
.cbl-main{
  flex: 1; display: flex; gap: 12px;
  padding: 0 12px; min-height: 0;
}
.cbl-left{
  flex: 0 0 340px; display: flex; flex-direction: column; gap: 10px; min-height: 0;
  overflow: hidden;   /* never let a panel (e.g. the docked map) spill past the F-bar */
}
.cbl-right{
  flex: 1; display: flex; flex-direction: column; gap: 10px; min-height: 0;
  /* last resort on windows too short to fit chrome + a full viewport:
     scroll the column instead of clipping the game away to nothing */
  overflow-y: auto;
}

.cbl-panel{
  border: 1px solid #1d7a38; border-radius: 4px;
  background: rgba(2, 18, 8, .72);
  box-shadow: 0 0 12px rgba(46,228,101,.10), inset 0 0 20px rgba(46,228,101,.04);
  padding: 12px 14px;
  font-size: 14px;
}
.cbl-panel-title{ color: #b8ffcf; margin-bottom: 8px; letter-spacing: 1px; }

/* ---- source + compile ---- */
.cbl-source{ flex: 1; overflow: auto; min-height: 0; }
.cbl-source pre, .cbl-compile pre{
  margin: 0; font-family: inherit; font-size: 13px; line-height: 1.75;
  letter-spacing: .5px; white-space: pre; color: #2ee465;
  text-shadow: 0 0 5px rgba(46,228,101,.45);
}
.cbl-source .cbl-kw{ color: #35d8d8; font-style: normal; }
.cbl-source .cbl-pic{ color: #d86bd8; font-style: normal; }
.cbl-source .cbl-err{
  color:#ff5448; font-style:normal;
  text-shadow:0 0 7px rgba(255,69,58,.78);
}
.cbl-source .cbl-ok{
  color:#b8ffcf; font-style:normal;
  text-shadow:0 0 7px rgba(46,228,101,.68);
}
.cbl-source.infected{
  border-color:#a92d28;
  box-shadow:inset 0 0 28px rgba(180,24,20,.07), 0 0 10px rgba(255,69,58,.10);
}
.cbl-source.healed{
  border-color:#1d7a38;
  box-shadow:inset 0 0 24px rgba(46,228,101,.04);
}
.cbl-source.flash{ animation: cblFlash 1.1s ease; }
.cbl-save-code{
  display:block;
  width:max-content;
  margin:10px 0 12px;
  padding:7px 14px 8px 20px;
  border:2px double #b8ffcf;
  color:#b8ffcf;
  background:#010703;
  font:bold clamp(24px,3vw,38px)/1 "Courier New",monospace;
  letter-spacing:.34em;
  text-shadow:0 0 10px rgba(46,228,101,.9);
  box-shadow:inset 0 0 14px rgba(46,228,101,.08),0 0 12px rgba(46,228,101,.12);
}
@keyframes cblFlash{
  0%, 100%{ box-shadow: 0 0 12px rgba(46,228,101,.10); }
  30%{ box-shadow: 0 0 26px rgba(184,255,207,.65); border-color: #b8ffcf; }
}
.cbl-compile{ flex: 0 0 auto; }

/* ---- docked live minimap (first-person hallways/rooms) ---- */
.cbl-dockmap{ flex: 0 0 auto; }
.cbl-dockmap[hidden]{ display: none; }
.cbl-dockmap-canvas{
  display: block; width: 100%; height: clamp(140px, 30vh, 220px);
  background: #02160a; image-rendering: pixelated;
  border: 1px solid #1d7a38; border-radius: 3px; cursor: pointer;
  box-shadow: inset 0 0 22px rgba(46,228,101,.06);
}
.cbl-dockmap-canvas:hover{ border-color: #2ee465; }
.cbl-dockmap-hint{
  color: #2b6e3e; font-size: 11px; letter-spacing: 1px;
  margin-top: 6px; text-align: center;
}

/* ---- viewport ---- */
.cbl-location{ flex: 0 0 auto; letter-spacing: 1px; color: #b8ffcf; }
.cbl-viewport{
  /* the game screen is the priority child: it grows to fill spare
     space, but a hard min-height floor stops any resize from ever
     squeezing it to zero (the "main screen hidden" bug). */
  flex: 1 1 auto; position: relative;
  min-height: clamp(160px, 34vh, 340px);
  border: none; border-radius: 0;
  background: #010301; overflow: hidden;
}
.cbl-canvas{ position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
.cbl-checkpoint-status{
  position:absolute; z-index:4; top:12px; right:12px;
  padding:7px 10px; border:1px solid #d69a38; border-radius:2px;
  background:rgba(17,10,1,.86); color:#ffd36a;
  font:11px/1.2 var(--cobol-font); letter-spacing:1px;
  text-shadow:0 0 6px rgba(255,190,63,.65);
  box-shadow:0 0 12px rgba(207,139,37,.18), inset 0 0 12px rgba(207,139,37,.08);
  pointer-events:none;
}
.cbl-checkpoint-status[hidden]{ display:none; }
.cbl-checkpoint-status.unlocked{
  border-color:#2ee465; background:rgba(1,18,7,.88); color:#b8ffcf;
  text-shadow:0 0 7px rgba(46,228,101,.7);
  box-shadow:0 0 14px rgba(46,228,101,.2), inset 0 0 12px rgba(46,228,101,.08);
}

/* The checkpoint's diegetic terminal puzzle: a chunky, worn CRT interface
   inspired by early post-apocalyptic computer RPGs without leaving the
   green/amber visual language of this COBOL chapter. */
.cbl-terminal-game{
  position:absolute; inset:0; z-index:12;
  display:flex; align-items:center; justify-content:center;
  padding:clamp(10px,3vw,34px);
  background:rgba(0,4,2,.72);
  backdrop-filter:blur(2px);
}
.cbl-terminal-game[hidden]{ display:none; }
.cbl-terminal-bezel{
  position:relative; width:min(760px,96%); max-height:96%;
  padding:clamp(12px,2vw,24px);
  border:8px ridge #26352b; border-radius:18px;
  background:linear-gradient(145deg,#303b31,#101710 52%,#273127);
  box-shadow:0 20px 45px rgba(0,0,0,.75), inset 0 0 0 2px #071008,
             0 0 28px rgba(46,228,101,.16);
}
.cbl-terminal-bezel::after{
  content:''; position:absolute; inset:clamp(43px,6vw,66px) clamp(12px,2vw,24px) clamp(37px,5vw,52px);
  z-index:3; pointer-events:none; border-radius:10px;
  background:repeating-linear-gradient(to bottom,rgba(255,255,255,.025) 0 1px,transparent 1px 4px);
  mix-blend-mode:screen;
}
.cbl-terminal-label,.cbl-terminal-hardware{
  display:flex; justify-content:space-between; gap:14px;
  color:#7e9681; font-size:10px; letter-spacing:1.2px;
  text-shadow:0 1px #000;
}
.cbl-terminal-label{ padding:0 4px 9px; }
.cbl-terminal-hardware{ padding:10px 5px 0; color:#68776a; }
.cbl-terminal-hardware span:first-child{ color:#79d488; }
.cbl-terminal-screen{
  position:relative; min-height:min(390px,58vh); max-height:66vh;
  overflow-y:auto; padding:clamp(18px,3vw,34px);
  border:3px solid #080d09; border-radius:11px;
  background:radial-gradient(ellipse at center,#0c2512 0,#031007 62%,#010602 100%);
  color:#a9f0b5; font:clamp(12px,1.45vw,16px)/1.55 var(--cobol-font);
  letter-spacing:.8px; text-shadow:0 0 7px rgba(75,255,112,.68);
  box-shadow:inset 0 0 38px #000, inset 0 0 12px rgba(46,228,101,.18);
}
.cbl-term-boot{ white-space:pre-line; color:#83d994; }
.cbl-term-cursor{ animation:cblTermBlink .7s steps(1,end) infinite; }
@keyframes cblTermBlink{ 50%{ opacity:0; } }
.cbl-term-progress{ color:#d6a94b; margin-bottom:16px; letter-spacing:1.5px; }
.cbl-term-question{ color:#d7ffd9; font-size:1.08em; margin-bottom:18px; }
.cbl-term-answers{ display:grid; gap:7px; }
.cbl-term-answer,.cbl-term-actions button{
  width:100%; padding:9px 11px; border:1px solid transparent;
  background:transparent; color:#8ed99b; text-align:left;
  font:inherit; letter-spacing:.6px; cursor:pointer;
}
.cbl-term-answer span{ display:inline-block; min-width:30px; color:#d6a94b; }
.cbl-term-answer:hover,.cbl-term-answer.selected,.cbl-term-actions button:hover{
  border-color:#55cc6c; background:rgba(67,201,91,.13); color:#e4ffe8;
  box-shadow:inset 0 0 14px rgba(46,228,101,.08);
}
.cbl-term-answer.selected::before,.cbl-term-actions button::before{ color:#d6a94b; }
.cbl-term-help{ margin-top:18px; color:#4d8759; font-size:.76em; letter-spacing:1px; }
.cbl-term-result{ margin:12px 0 22px; padding:10px; border:1px solid;
  font-size:1.15em; text-align:center; letter-spacing:1.4px; }
.cbl-term-result.ok{ color:#c5ffce; border-color:#2ee465; background:rgba(46,228,101,.11); }
.cbl-term-result.bad{ color:#ffd36a; border-color:#c18c35; background:rgba(193,140,53,.11); }
.cbl-term-copy{ margin:18px 0; }
.cbl-term-actions{ display:grid; gap:7px; margin-top:20px; }
.cbl-term-granted{
  margin:10px 0 22px; color:#d7ffda; font-size:clamp(22px,4vw,38px);
  letter-spacing:3px; text-align:center; text-shadow:0 0 15px #2ee465;
  animation:cblAccessPulse 1.25s steps(2,end) infinite;
}
@keyframes cblAccessPulse{ 50%{ opacity:.72; } }
.cbl-term-receipt{
  margin:18px 0; padding:12px; border:1px dashed #4a9f59;
  white-space:pre-line; color:#b8ffcf;
}
.cbl-racer-canvas{
  position: absolute !important; inset: 0 !important;
  /* the cabinet is a green-phosphor tube: monochrome the neon engine */
  filter: sepia(1) hue-rotate(65deg) saturate(2.4) brightness(.92) contrast(1.15);
}

/* ---- F2 system-map overlay ---- */
.cbl-map-overlay{
  position: absolute; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: rgba(1, 6, 3, .82); backdrop-filter: blur(2px);
  cursor: pointer; animation: cblMapIn .18s ease;
}
.cbl-map-overlay[hidden]{ display: none; }
@keyframes cblMapIn{ from{ opacity: 0; } to{ opacity: 1; } }
.cbl-map-frame{
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  max-width: 74%; max-height: 88%;
}
.cbl-map-title{
  color: #b8ffcf; letter-spacing: 2px; font-size: 13px;
  text-shadow: 0 0 8px rgba(46,228,101,.5);
}
.cbl-map-img, .cbl-map-canvas{
  max-width: 100%; max-height: 76vh; object-fit: contain;
  image-rendering: pixelated;
  border: 1px solid #1d7a38; border-radius: 4px;
  box-shadow: 0 0 26px rgba(46,228,101,.28), inset 0 0 40px rgba(46,228,101,.06);
}
.cbl-map-canvas{ width: min(560px, 70vw); height: auto; background: #02160a; }
.cbl-map-hint{ color: #2b6e3e; font-size: 11px; letter-spacing: 1px; }

/* ---- chat bar (always available: ask KIST anything) ---- */
.cbl-chatbar{
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border: 1px solid #1d7a38; border-radius: 4px;
  background: #010a04;
  box-shadow: 0 0 10px rgba(46,228,101,.12), inset 0 0 20px rgba(46,228,101,.05);
}
.cbl-chat-caret{ color: #2ee465; font-weight: 700; text-shadow: 0 0 6px rgba(46,228,101,.6); }
.cbl-chat-input{
  flex: 1; min-width: 0; background: transparent; border: none; outline: none;
  color: #b8ffcf; font-family: inherit; font-size: 14px; letter-spacing: .5px;
  text-shadow: 0 0 5px rgba(46,228,101,.45);
}
.cbl-chat-input::placeholder{ color: #2b6e3e; letter-spacing: 1px; }
.cbl-chat-hint{ flex: 0 0 auto; color: #2b6e3e; font-size: 11px; letter-spacing: 1px; }
.cbl-chatbar.busy .cbl-chat-hint{ color: #2ee465; }

/* ---- dialogue ---- */
.cbl-dialog{
  /* One stable dialogue frame: copy length can only scroll inside it and can
     never reflow or rescale the game viewport above. */
  --cbl-dialog-height: clamp(160px, 25vh, 204px);
  flex: 0 0 var(--cbl-dialog-height); display: flex; flex-direction: column; gap: 10px;
  height: var(--cbl-dialog-height); min-height: var(--cbl-dialog-height);
  max-height: var(--cbl-dialog-height); overflow: hidden;
}
.cbl-dialog-top{ flex: 1 1 auto; min-height: 0; display: flex; gap: 14px; align-items: stretch; }
.cbl-dialog[hidden]{ display: none; }
/* The checkpoint hides dialogue while its guide walks. Keep the invisible
   fixed-height slot in the layout so the canvas and its perspective frame do
   not jump larger for the walk and smaller again at the next station. */
.cobol.cbl-checkpoint-scene .cbl-dialog[hidden]{
  display: flex; visibility: hidden; pointer-events: none;
}
.cbl-portrait{ flex: 0 0 auto; }
.cbl-portrait canvas{ image-rendering: pixelated; display: block; }
.cbl-dialog-body{ flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.cbl-dialog-name{ color: #b8ffcf; letter-spacing: 1px; margin-bottom: 6px; }
.cbl-dialog-text{
  flex: 1 1 auto; min-height: 0;
  font-size: 14px; line-height: 1.55; letter-spacing: .4px;
  text-shadow: 0 0 5px rgba(46,228,101,.45);
  max-height: none; overflow-y: auto; padding-right: 6px;
}
.cbl-dialog-text b{ color: #b8ffcf; font-weight: 400; }
.cbl-dialog-text i{ color: #35d8d8; font-style: normal; }
.cbl-dialog-text .cbl-data{
  display: block; margin: 4px 0 10px; font-family: inherit; font-size: 13px;
  line-height: 1.7; white-space: pre; color: #b8ffcf;
}
.cbl-dialog-menu{
  flex: 0 0 220px; display: flex; flex-direction: column; gap: 4px;
  justify-content: flex-start;
}
.cbl-opt{
  padding: 5px 10px; cursor: pointer; letter-spacing: 1px; font-size: 13px;
  border-radius: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cbl-opt::before{ content: '  '; white-space: pre; }
.cbl-opt.sel{
  background: rgba(46,228,101,.22); color: #eafff1;
  text-shadow: 0 0 8px rgba(184,255,207,.8);
}
.cbl-opt.sel::before{ content: '> '; }

/* ============================================================
   RESPONSIVE — keep the game viewport visible & playable at every
   width/height down to the mobile breakpoint. Chrome shrinks first
   (source column → bar padding → topbar), the viewport never does.
   ============================================================ */

/* Fluid source column so mid-width windows don't starve the game. */
@media (max-width: 1200px){
  .cbl-left{ flex-basis: clamp(240px, 27vw, 340px); }
}

/* Short windows: shrink the chrome bars & location, keep the game. */
@media (max-height: 720px){
  .cbl-topbar, .cbl-fbar{ margin: 6px 12px; padding: 7px 14px; font-size: 12px; }
  .cbl-location{ padding: 8px 12px; }
  .cbl-viewport{ min-height: clamp(140px, 30vh, 260px); }
}
@media (max-height: 560px){
  .cbl-topbar{ display: none; }            /* drop least-important chrome first */
  .cbl-fbar{ margin: 5px 10px; padding: 5px 10px; font-size: 10px; }
  .cbl-viewport{ min-height: 128px; }
}

/* Tablet: drop the source column, keep the game + dialog two-up. */
@media (max-width: 900px){
  .cbl-left{ display: none; }
  .cbl-topbar{ gap: 12px; font-size: 11px; }
  .cbl-main{ padding: 0 8px; }
  .cbl-fbar{
    gap: 8px 12px; font-size: 10px;
    flex-wrap: wrap; white-space: normal; justify-content: center;
  }
  .cbl-fbar .cbl-spacer{ display: none; }  /* let the F-keys wrap centered */
}

/* Mobile breakpoint: single column, dialogue stacks under the game. */
@media (max-width: 640px){
  .cbl-topbar{ gap: 8px; font-size: 10px; padding: 6px 10px; margin: 6px 8px; }
  .cbl-right{ gap: 8px; }
  .cbl-location{ font-size: 12px; letter-spacing: .5px; padding: 7px 10px; }
  .cbl-dialog{ max-height: 52vh; }
  .cbl-dialog-top{ flex-direction: column; align-items: stretch; }
  .cbl-portrait{ align-self: center; }
  .cbl-dialog-menu{ flex: 0 0 auto; }      /* menu goes full-width under the text */
  .cbl-chat-hint{ display: none; }
}

/* view-switch flash (aerial ↔ first person) */
.cbl-viewport.cbl-fpflash::before{
  content: ''; position: absolute; inset: 0; z-index: 5; pointer-events: none;
  background: #b8ffcf; opacity: 0;
  animation: cblFpFlash .48s ease;
}
@keyframes cblFpFlash{
  0%{ opacity: 0; } 25%{ opacity: .85; } 100%{ opacity: 0; }
}

/* scroll entrance: zoom into the room and appear — no slide */
.cobol.zoom-enter{
  animation: cblZoomIn .8s cubic-bezier(.2,.75,.25,1);
}
@keyframes cblZoomIn{
  0%{ transform: scale(.08); opacity: 0; filter: brightness(2.4); }
  45%{ opacity: 1; }
  100%{ transform: scale(1); opacity: 1; filter: brightness(1); }
}
