/* ============================================================
   KARAR.EXE — stylesheet
   The game itself renders on <canvas>. This file styles the
   "monitor" around it + the readable DOM layers (content panels,
   TL;DR, terminal, touch controls).
   ============================================================ */

:root {
  --ink: #26203b;
  --bg0: #17131f;
  --bg1: #2b2440;
  --paper: #f3ead9;
  --gold: #e8b04b;
  --amber: #ffcf86;
  --cyan: #6fe3d1;
  --coral: #f2762e;
  --pix: "PS2P", "Courier New", ui-monospace, Menlo, Consolas, monospace;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: radial-gradient(120% 140% at 50% 30%, #332a4e 0%, #221b33 55%, #14101d 100%);
  font-family: var(--pix);
  -webkit-font-smoothing: none;
  color: var(--paper);
}

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#frame {
  position: relative;
  box-shadow: 0 0 0 3px #0d0a14, 0 0 60px rgba(0,0,0,.55), 0 0 120px rgba(242,118,46,.07);
  background: #000;
}

#screen {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #17131f;
  outline: none;
}

/* CRT dressing ------------------------------------------------ */
#scanlines {
  position: absolute; inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(10,6,16,.10) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
}
#scanlines.off { display: none; }

#vignette {
  position: absolute; inset: 0;
  pointer-events: none;
  background: radial-gradient(105% 105% at 50% 48%, transparent 62%, rgba(13,8,22,.38) 100%);
}

/* boot layer -------------------------------------------------- */
#boot {
  position: absolute; inset: 0;
  background: var(--bg0);
  color: var(--amber);
  font-family: var(--pix);
  font-size: clamp(8px, 1.6vmin, 12px);
  line-height: 2.1;
  padding: 4% 5%;
  white-space: pre-wrap;
  overflow: hidden;
  z-index: 5;
}
#boot .ok { color: var(--cyan); }
#boot .dim { color: #8d7f9e; }
#boot .cursor::after {
  content: "▮";
  animation: blink 0.9s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  #boot .cursor::after { animation: none; }
}

/* readable panel layers --------------------------------------- */
.panel-layer {
  position: fixed; inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3vmin;
  background: rgba(15, 10, 25, .74);
}
.panel-layer[hidden] { display: none; }

.panel {
  background: var(--bg1);
  color: var(--paper);
  width: min(660px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  padding: 26px 26px 22px;
  box-shadow:
    0 0 0 3px var(--ink),
    0 0 0 6px var(--gold),
    0 0 0 9px var(--ink),
    0 18px 60px rgba(0,0,0,.5);
  font-size: 11px;
  line-height: 2.0;
  scrollbar-width: thin;
  scrollbar-color: var(--gold) var(--ink);
}
.panel::-webkit-scrollbar { width: 10px; }
.panel::-webkit-scrollbar-track { background: var(--ink); }
.panel::-webkit-scrollbar-thumb { background: var(--gold); border: 2px solid var(--ink); }

.panel h1 {
  color: var(--gold);
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.panel h2 {
  color: var(--coral);
  font-size: 11px;
  margin: 18px 0 6px;
  text-transform: uppercase;
}
.panel .kicker {
  color: var(--cyan);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 12px;
}
.panel p  { margin: 8px 0; }
.panel ul { list-style: none; margin: 6px 0; }
.panel li { margin: 7px 0; padding-left: 16px; position: relative; }
.panel li::before { content: "▸"; position: absolute; left: 0; color: var(--gold); }
.panel a { color: var(--cyan); text-decoration: none; border-bottom: 1px dotted var(--cyan); }
.panel a:hover { color: #aef7ea; }
.panel .dim { color: #b3a6c4; font-size: 10px; }
.panel .tag {
  display: inline-block;
  background: var(--ink);
  color: var(--amber);
  font-size: 9px;
  padding: 4px 7px;
  margin: 2px 4px 2px 0;
  box-shadow: 0 0 0 2px #4a3f68;
}
.panel .stat {
  display: inline-block;
  margin: 6px 14px 6px 0;
}
.panel .stat b { color: var(--gold); font-size: 14px; display: block; }
.panel .stat span { color: #b3a6c4; font-size: 9px; }
.panel hr { border: none; border-top: 2px dashed #4a3f68; margin: 14px 0; }

.btn {
  display: inline-block;
  font-family: var(--pix);
  font-size: 10px;
  color: var(--ink);
  background: var(--gold);
  border: none;
  cursor: pointer;
  padding: 10px 14px;
  margin: 10px 10px 2px 0;
  box-shadow: 0 3px 0 #8a6420, 0 0 0 2px var(--ink);
  text-decoration: none;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #8a6420, 0 0 0 2px var(--ink); }
.btn.alt { background: var(--cyan); box-shadow: 0 3px 0 #3d8a7e, 0 0 0 2px var(--ink); }
.btn.ghost { background: var(--bg1); color: var(--paper); box-shadow: 0 3px 0 #141021, 0 0 0 2px #6a5f8c; }

/* anchor-buttons must not inherit the panel link styling */
.panel .btn { color: var(--ink); border-bottom: none; }
.panel .btn:hover { color: var(--ink); }
.panel .btn.ghost, .panel .btn.ghost:hover { color: var(--paper); }

.panel .close-hint {
  margin-top: 16px;
  color: #8d7f9e;
  font-size: 9px;
  text-align: center;
}

/* always-reachable close (essential on touch, where the backdrop
   sliver around the panel is nearly impossible to tap) */
.panel-close {
  position: sticky;
  top: 4px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  margin: -8px -8px 2px auto;   /* left:auto right-aligns; negatives tuck it into the corner */
  padding: 0;
  font-family: var(--pix);
  font-size: 14px;
  color: var(--paper);
  background: var(--ink);
  border: none;
  box-shadow: inset 0 0 0 2px var(--gold);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.panel-close:hover { color: var(--gold); }
.panel-close:active { background: var(--gold); color: var(--ink); }

/* corner buttons (TL;DR + mute) -------------------------------- */
#corner-ui {
  position: fixed;
  top: 10px; right: 12px;
  z-index: 26;
  display: flex;
  gap: 8px;
}
#corner-ui button {
  font-family: var(--pix);
  font-size: 9px;
  color: var(--paper);
  background: rgba(38, 32, 59, .88);
  border: none;
  padding: 7px 9px;
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--ink), inset 0 0 0 1px #4a3f68;
}
#corner-ui button:hover { color: var(--gold); box-shadow: 0 0 0 2px var(--ink), inset 0 0 0 1px var(--gold); }
#tldr-btn { color: var(--gold) !important; }
#mute-btn.muted { color: #6a5f8c !important; text-decoration: line-through; }

/* terminal ----------------------------------------------------- */
#terminal {
  position: fixed;
  left: 0; right: 0; top: 0;
  height: min(62vh, 420px);
  background: rgba(18, 13, 26, .97);
  border-bottom: 3px solid var(--gold);
  z-index: 40;
  font-family: var(--pix);
  font-size: 11px;
  line-height: 1.9;
  color: var(--amber);
  transform: translateY(-102%);
  transition: transform .18s ease-out;
  display: flex;
  flex-direction: column;
  padding: 14px 16px 10px;
}
#terminal.open { transform: translateY(0); }
#terminal[hidden] { display: none; }
#term-log { flex: 1; overflow-y: auto; white-space: pre-wrap; }
#term-log .in { color: var(--paper); }
#term-log .ok { color: var(--cyan); }
#term-log .err { color: #ff8a8a; }
#term-row { display: flex; gap: 8px; margin-top: 8px; }
#term-row .ps1 { color: var(--cyan); }
#term-in {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--amber);
  font-family: var(--pix);
  font-size: 11px;
}

/* touch controls ----------------------------------------------- */
#touch {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 14px calc(14px + env(safe-area-inset-bottom));
  pointer-events: none;
}
#touch[hidden] { display: none; }

/* d-pad: ▲ on top, ◀ ▼ ▶ below */
.t-pad {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 8px;
  justify-items: center;
  align-items: center;
  pointer-events: none;
}
#t-up    { grid-area: 1 / 2; }
#t-left  { grid-area: 2 / 1; }
#t-down  { grid-area: 2 / 2; }
#t-right { grid-area: 2 / 3; }

/* action cluster: small ☰ above a staggered B + A pair */
.t-acts {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}
.t-ab {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
}
#t-b { margin-bottom: 18px; }   /* gamepad diagonal: B floats up-left of A */

.t-btn {
  pointer-events: auto;
  flex-shrink: 0;
  width: 58px; height: 58px;
  border-radius: 50%;
  border: 2px solid rgba(243, 234, 217, .35);
  background: rgba(243, 234, 217, .10);
  color: var(--paper);
  font-family: var(--pix);
  font-size: 16px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.t-btn:active, .t-btn.held { background: rgba(232, 176, 75, .45); border-color: var(--gold); }
.t-btn.t-small { width: 44px; height: 44px; font-size: 12px; }

/* portrait phones: the engine extends the picture vertically and the frame
   sits a little high — the controls grow to proper thumb size below it */
@media (pointer: coarse) and (orientation: portrait) {
  #stage { padding-bottom: 16vh; }
  #touch { padding: 0 12px calc(18px + env(safe-area-inset-bottom)); }
  .t-btn { width: min(16.5vw, 72px); height: min(16.5vw, 72px); font-size: min(5vw, 21px); }
  .t-btn.t-small { width: min(12vw, 50px); height: min(12vw, 50px); font-size: 14px; }
  #t-a { width: min(20vw, 88px); height: min(20vw, 88px); }
  .t-pad { gap: min(2vw, 9px); }
  .t-ab { gap: min(2.6vw, 12px); }
  #t-b { margin-bottom: min(6vw, 26px); }
}

/* noscript ------------------------------------------------------ */
.noscript {
  position: fixed; inset: 0; z-index: 99;
  background: var(--bg0);
  color: var(--paper);
  padding: 10vh 8vw;
  font-family: var(--pix);
  line-height: 2.2;
}
.noscript h1 { color: var(--gold); margin-bottom: 12px; }
.noscript a { color: var(--cyan); }
