/* ============================================================
   طرفية الشبح — ghostshell
   CRT hacker terminal · black / phosphor green
   ============================================================ */

:root{
  --green:#00FF41;
  --green-mid:#00B32D;
  --green-dark:#0B3B0B;
  --text:#C8FFD0;
  --amber:#FFB000;
  --red:#FF3B3B;
  --panel:rgba(0,20,0,.55);
  --line:rgba(0,255,65,.28);
  --line-dim:rgba(0,255,65,.14);
  --mono:'Share Tech Mono','IBM Plex Mono',ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  --ar:'Noto Kufi Arabic','Cairo','Segoe UI',Tahoma,Arial,sans-serif;
}

*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}

html,body{
  height:100%;
  margin:0;
  padding:0;
  background:#000;
  color:var(--text);
  font-family:var(--ar);
  font-size:13px;
  line-height:1.55;
  overflow:hidden;
  overscroll-behavior:none;
}

body{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}

button{font-family:var(--ar)}
h1,h2,h3,p{margin:0}

.hidden{display:none !important}

/* ---------- rain canvas ---------- */
#rain{
  position:fixed;
  inset:0;
  width:100%;
  height:100%;
  display:block;
  z-index:0;
  background:#000;
}

/* ---------- decoration layers ---------- */
.dot-grid{
  position:fixed;
  inset:0;
  z-index:1;
  pointer-events:none;
  background-image:radial-gradient(rgba(0,255,65,.13) 1px, transparent 1px);
  background-size:24px 24px;
  opacity:.45;
}

.crt-scanlines{
  position:fixed;
  inset:0;
  z-index:60;
  pointer-events:none;
  background:repeating-linear-gradient(
    180deg,
    rgba(0,0,0,.42) 0px,
    rgba(0,0,0,.42) 1px,
    rgba(0,0,0,0) 1px,
    rgba(0,0,0,0) 2px
  );
  opacity:.85;
}

.crt-vignette{
  position:fixed;
  inset:0;
  z-index:61;
  pointer-events:none;
  background:radial-gradient(ellipse at center, rgba(0,0,0,0) 48%, rgba(0,0,0,.72) 100%);
}

.crt-flicker{
  position:fixed;
  inset-inline:0;
  top:0;
  height:3px;
  z-index:62;
  pointer-events:none;
  background:rgba(0,255,65,.22);
  opacity:0;
}
.crt-flicker.run{animation:sweep .55s linear}
@keyframes sweep{
  0%{opacity:.9;transform:translateY(0)}
  100%{opacity:0;transform:translateY(100vh)}
}

.flash{
  position:fixed;
  inset:0;
  z-index:63;
  pointer-events:none;
  background:rgba(0,255,65,.16);
  opacity:0;
}
.flash.on{animation:flashOut .5s ease-out}
@keyframes flashOut{from{opacity:1}to{opacity:0}}

.screen-frame{
  position:fixed;
  inset:0;
  z-index:64;
  pointer-events:none;
  border:2px solid rgba(0,255,65,.5);
}
.screen-frame::before,
.screen-frame::after{
  content:"";
  position:absolute;
  width:26px;
  height:26px;
  border:2px solid var(--green);
}
.screen-frame::before{top:0;inset-inline-start:0;border-inline-end:0;border-bottom:0}
.screen-frame::after{bottom:0;inset-inline-end:0;border-inline-start:0;border-top:0}

/* ---------- boot ---------- */
.boot{
  position:fixed;
  inset:0;
  z-index:90;
  background:rgba(0,0,0,.86);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:20px 18px;
  overflow:auto;
  transition:opacity .6s ease;
}
.boot.fade-out{opacity:0;pointer-events:none}

.boot-inner{
  width:min(660px,100%);
  font-family:'Share Tech Mono','Noto Kufi Arabic',monospace;
  font-size:12.5px;
  line-height:1.95;
}
.boot-head{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  align-items:baseline;
  justify-content:space-between;
  border-bottom:1px dashed var(--line);
  padding-bottom:8px;
  margin-bottom:12px;
}
.boot-title{
  font-family:var(--ar);
  font-weight:700;
  font-size:15px;
  color:var(--green);
  text-shadow:0 0 6px rgba(0,255,65,.45);
}
.boot-sub{font-size:11px;color:var(--green-mid)}

.boot-lines{min-height:120px}
.boot-line{
  white-space:pre-wrap;
  word-break:break-word;
  color:var(--text);
}
.boot-line.ok{color:var(--green)}
.boot-line.dim{color:var(--green-mid)}
.boot-line.warn{color:var(--amber)}

.boot-cursor{
  display:inline-block;
  width:9px;
  height:15px;
  background:var(--green);
  box-shadow:0 0 8px rgba(0,255,65,.6);
  animation:blink 1s steps(1) infinite;
  margin-top:2px;
}

.boot-skip{margin-top:18px}

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

/* ---------- app shell ---------- */
.app{
  position:relative;
  z-index:10;
  height:100%;
  padding:8px;
  opacity:0;
  transition:opacity .6s ease;
}
.app.ready{opacity:1}
.app:not(.ready){pointer-events:none}

.shell{
  height:100%;
  display:flex;
  flex-direction:column;
  gap:6px;
  min-height:0;
}

/* ---------- topbar ---------- */
.topbar{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:2px 2px 6px;
  border-bottom:1px dashed var(--line);
}
.brand{display:flex;align-items:center;gap:8px;min-width:0}
.brand-mark{
  color:var(--green);
  font-family:var(--mono);
  font-size:17px;
  line-height:1;
  animation:pulseMark 3s ease-in-out infinite;
}
@keyframes pulseMark{0%,100%{opacity:.55}50%{opacity:1}}
.brand-text{display:flex;flex-direction:column;line-height:1.25;min-width:0}
.brand-name{
  font-weight:700;
  font-size:14px;
  color:var(--green);
  text-shadow:0 0 6px rgba(0,255,65,.45);
  white-space:nowrap;
}
.brand-sub{
  font-family:var(--mono);
  font-size:10px;
  color:var(--green-mid);
  letter-spacing:0;
  white-space:nowrap;
}
.top-right{display:flex;align-items:center;gap:6px;flex:0 0 auto}
.chip{
  display:inline-flex;
  align-items:center;
  gap:5px;
  border:1px solid var(--line);
  background:rgba(0,20,0,.6);
  color:var(--text);
  font-size:10px;
  padding:3px 7px;
  font-family:var(--mono);
  white-space:nowrap;
}
.chip-dim{color:var(--green-mid)}
.dot{
  width:6px;height:6px;
  background:var(--green);
  display:inline-block;
  box-shadow:0 0 6px rgba(0,255,65,.8);
  animation:blink 2.2s steps(1) infinite;
}

/* ---------- stage ---------- */
.stage{
  flex:1 1 auto;
  min-height:0;
  display:flex;
  flex-direction:column;
  gap:8px;
  overflow-y:auto;
  overscroll-behavior:contain;
  padding-bottom:2px;
}
.stage::-webkit-scrollbar{width:6px}
.stage::-webkit-scrollbar-thumb{background:rgba(0,255,65,.3)}

/* ---------- panels ---------- */
.panel{
  border:1px solid var(--line);
  background:var(--panel);
  backdrop-filter:blur(2px);
  -webkit-backdrop-filter:blur(2px);
  display:flex;
  flex-direction:column;
  min-height:0;
  position:relative;
}
.panel-head{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  padding:7px 10px;
  border-bottom:1px dashed var(--line);
}
.panel-head h2{
  font-size:12px;
  font-weight:700;
  color:var(--green);
  text-shadow:0 0 6px rgba(0,255,65,.45);
  white-space:nowrap;
}
.panel-meta{
  font-family:var(--mono);
  font-size:10.5px;
  color:var(--green-mid);
  white-space:nowrap;
}
.live{
  display:inline-flex;
  align-items:center;
  gap:5px;
  font-family:var(--mono);
  font-size:10.5px;
  color:var(--green-mid);
  white-space:nowrap;
}

/* ---------- nodes ---------- */
.nodes-body{
  padding:8px;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:6px;
  min-height:0;
  flex:1 1 auto;
  justify-content:center;
}
.node-wrap{
  width:100%;
  max-width:320px;
  margin-inline:auto;
  aspect-ratio:1 / 1;
}
#nodeGrid{width:100%;height:100%;display:block;overflow:visible}

.nodes-hint{
  font-size:10px;
  color:rgba(200,255,208,.5);
  text-align:center;
  padding-inline:6px;
  line-height:1.5;
}

.node{cursor:pointer;outline:none}
.node .node-inner{
  transform-box:fill-box;
  transform-origin:center;
}
.node .hex-base{
  fill:rgba(0,20,0,.55);
  stroke:rgba(0,255,65,.34);
  stroke-width:1;
  transition:stroke .18s ease, fill .18s ease;
}
.node .hex-prog{
  fill:none;
  stroke:var(--green);
  stroke-width:2;
  stroke-dasharray:228;
  stroke-dashoffset:228;
  stroke-linejoin:round;
  opacity:.95;
  transition:stroke-dashoffset .1s linear, stroke .2s ease;
}
.node .hex-id{
  fill:var(--text);
  font-family:var(--mono);
  font-size:12px;
  text-anchor:middle;
  pointer-events:none;
}
.node .hex-sub{
  fill:rgba(200,255,208,.55);
  font-family:var(--ar);
  font-size:9px;
  text-anchor:middle;
  pointer-events:none;
}

@media (hover:hover){
  .node:hover .hex-base{stroke:var(--amber);fill:rgba(255,176,0,.09)}
  .node:hover .hex-id{fill:var(--amber)}
}
.node:focus-visible .hex-base{stroke:var(--amber);stroke-width:2;fill:rgba(255,176,0,.09)}
.node:focus-visible .hex-id{fill:var(--amber)}

.node.hacking .hex-base{stroke:var(--amber);fill:rgba(255,176,0,.07)}
.node.hacking .hex-id{fill:var(--amber)}
.node.hacking .hex-sub{fill:rgba(255,176,0,.7)}

.node.hacked .hex-base{stroke:var(--green);fill:rgba(0,255,65,.16)}
.node.hacked .hex-id{fill:var(--green)}
.node.hacked .hex-sub{fill:rgba(0,255,65,.75)}
.node.hacked .hex-prog{stroke-dashoffset:0 !important}

.node.failed .hex-base{stroke:var(--red);fill:rgba(255,59,59,.14)}
.node.failed .hex-id{fill:var(--red)}
.node.failed .hex-sub{fill:rgba(255,59,59,.75)}

.node-inner.shake{animation:shake .42s ease-in-out}
@keyframes shake{
  0%,100%{transform:translateX(0)}
  20%{transform:translateX(-4px)}
  40%{transform:translateX(4px)}
  60%{transform:translateX(-3px)}
  80%{transform:translateX(2px)}
}

#nodeGrid.scanning .hex-base{animation:scanPulse .55s ease-in-out 2}
@keyframes scanPulse{
  0%,100%{stroke:rgba(0,255,65,.34)}
  50%{stroke:var(--green)}
}

/* ---------- hack progress ---------- */
.hp{
  flex:0 0 auto;
  border-top:1px dashed var(--line);
  padding:7px 10px 9px;
}
.hp-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  font-family:var(--mono);
  font-size:10.5px;
  color:var(--green-mid);
  margin-bottom:6px;
}
.hp-head span:first-child{
  font-family:var(--ar);
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.hp-track{
  height:8px;
  border:1px solid var(--line);
  background:rgba(0,0,0,.7);
  overflow:hidden;
}
.hp-fill{
  height:100%;
  width:0%;
  background:var(--green);
  box-shadow:0 0 8px rgba(0,255,65,.55);
  transition:width .08s linear, background .2s ease;
}
.hp-fill.fail{background:var(--red);box-shadow:0 0 8px rgba(255,59,59,.5)}

/* ---------- hud ---------- */
.stats{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:6px;
  padding:8px;
  border-bottom:1px dashed var(--line);
  flex:0 0 auto;
}
.stat{
  border:1px solid var(--line-dim);
  background:rgba(0,0,0,.4);
  padding:6px 8px;
  display:flex;
  flex-direction:column;
  gap:1px;
  min-width:0;
}
.stat .k{
  font-size:9.5px;
  color:rgba(200,255,208,.65);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.stat .v{
  font-family:var(--mono);
  font-size:14px;
  color:var(--green);
  line-height:1.2;
  white-space:nowrap;
}

.ctls{
  padding:8px;
  display:flex;
  flex-direction:column;
  gap:8px;
  flex:0 0 auto;
}
.ctl-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
}
.ctl-block{display:flex;flex-direction:column;gap:5px}
.ctl-label{
  font-size:11px;
  color:rgba(200,255,208,.78);
  white-space:nowrap;
}

/* ---------- buttons ---------- */
.btn{
  appearance:none;
  border:1px solid rgba(0,255,65,.45);
  background:rgba(0,20,0,.62);
  color:var(--green);
  font-size:11.5px;
  padding:6px 10px;
  min-height:34px;
  border-radius:0;
  cursor:pointer;
  user-select:none;
  -webkit-user-select:none;
  transition:background .16s ease, color .16s ease, border-color .16s ease;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  line-height:1.2;
}
.btn-toggle{min-width:74px}
.btn:hover{background:rgba(0,255,65,.16);color:#EAFFF0}
.btn:active{background:rgba(0,255,65,.3);color:#001300}
.btn:focus-visible{outline:2px solid var(--amber);outline-offset:2px}
.btn[aria-pressed="false"]{color:var(--green-mid);border-color:rgba(0,255,65,.22)}
.btn:disabled{opacity:.45;cursor:not-allowed}
.btn:disabled:hover{background:rgba(0,20,0,.62);color:var(--green-mid)}

.seg{
  display:flex;
  border:1px solid rgba(0,255,65,.4);
  background:rgba(0,0,0,.45);
}
.seg button{
  flex:1 1 0;
  appearance:none;
  background:transparent;
  border:0;
  border-inline-start:1px solid rgba(0,255,65,.22);
  color:var(--green-mid);
  font-size:11px;
  padding:7px 4px;
  min-height:34px;
  cursor:pointer;
  user-select:none;
  -webkit-user-select:none;
  transition:background .16s ease,color .16s ease;
}
.seg button:first-child{border-inline-start:0}
.seg button[aria-pressed="true"]{background:rgba(0,255,65,.2);color:var(--green)}
.seg button:focus-visible{outline:2px solid var(--amber);outline-offset:-2px}

.mini-btn{
  appearance:none;
  background:transparent;
  border:1px solid var(--line);
  color:var(--green-mid);
  font-size:10px;
  padding:3px 8px;
  min-height:24px;
  cursor:pointer;
  border-radius:0;
  user-select:none;
  -webkit-user-select:none;
}
.mini-btn:hover{background:rgba(0,255,65,.14);color:var(--green)}
.mini-btn:focus-visible{outline:2px solid var(--amber);outline-offset:2px}

/* ---------- terminal ---------- */
.terminal{
  flex:0 0 auto;
  display:flex;
  flex-direction:column;
  min-height:0;
  max-height:clamp(140px, 34vh, 290px);
  border:1px solid var(--line);
  background:rgba(0,10,0,.75);
  backdrop-filter:blur(2px);
  -webkit-backdrop-filter:blur(2px);
}
.term-head{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  padding:5px 10px;
  border-bottom:1px dashed var(--line);
}
.term-head h2{
  font-size:11px;
  color:var(--green);
  text-shadow:0 0 6px rgba(0,255,65,.45);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.term-sub{
  font-family:var(--mono);
  font-size:10px;
  color:var(--green-mid);
  text-shadow:none;
}

.log{
  flex:1 1 auto;
  min-height:0;
  overflow-y:auto;
  overscroll-behavior:contain;
  padding:7px 10px 9px;
  font-family:'Share Tech Mono','Noto Kufi Arabic',monospace;
  font-size:12px;
  line-height:1.75;
  scrollbar-width:thin;
  scrollbar-color:rgba(0,255,65,.35) transparent;
}
.log::-webkit-scrollbar{width:6px}
.log::-webkit-scrollbar-track{background:transparent}
.log::-webkit-scrollbar-thumb{background:rgba(0,255,65,.32)}

.ln{
  unicode-bidi:plaintext;
  white-space:pre-wrap;
  word-break:break-word;
  color:var(--text);
}
.ln-sys{color:var(--green-mid)}
.ln-cmd{color:#EAFFF0}
.ln-ok{color:var(--green)}
.ln-err{color:var(--red)}
.ln-warn{color:var(--amber)}
.ln-dim{color:rgba(200,255,208,.55)}
.ln-out{color:var(--text)}

.term-input-row{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  gap:7px;
  padding:6px 10px;
  border-top:1px dashed var(--line);
  min-height:46px;
  background:rgba(0,0,0,.35);
}
.prompt{
  font-family:var(--mono);
  font-size:14px;
  color:var(--green);
  flex:0 0 auto;
  line-height:1;
}
.term-field{
  position:relative;
  flex:1 1 auto;
  min-width:0;
  height:30px;
  display:flex;
  align-items:center;
  direction:rtl;
  overflow:hidden;
}
.term-mirror{
  font-family:'Share Tech Mono','Noto Kufi Arabic',monospace;
  font-size:13px;
  color:#EAFFF0;
  white-space:pre;
  overflow:hidden;
  max-width:100%;
}
.caret{
  display:inline-block;
  flex:0 0 auto;
  width:8px;
  height:15px;
  margin-inline-start:2px;
  background:var(--green);
  box-shadow:0 0 7px rgba(0,255,65,.65);
  animation:blink 1s steps(1) infinite;
}
.term-hint{
  position:absolute;
  inset-inline-start:0;
  top:50%;
  transform:translateY(-50%);
  font-size:11.5px;
  color:rgba(200,255,208,.38);
  pointer-events:none;
  white-space:nowrap;
}
#termInput{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  border:0;
  outline:0;
  padding:0;
  background:transparent;
  color:transparent;
  caret-color:transparent;
  font-family:'Share Tech Mono','Noto Kufi Arabic',monospace;
  font-size:16px;
  z-index:2;
}
#termInput::selection{background:rgba(0,255,65,.3)}

/* ---------- status bar ---------- */
.statusbar{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  padding:3px 4px 1px;
  border-top:1px dashed var(--line-dim);
  font-family:var(--mono);
  font-size:9.5px;
  color:rgba(200,255,208,.55);
}
.statusbar-end{color:rgba(0,179,45,.8);white-space:nowrap}

/* ---------- desktop ---------- */
@media (min-width:900px){
  .app{padding:10px}
  .shell{gap:10px}
  .stage{
    display:grid;
    grid-template-columns:minmax(0,1fr) 322px;
    grid-template-rows:minmax(0,1fr);
    overflow:hidden;
    gap:10px;
  }
  .nodes-panel{min-height:0}
  .hud-panel{min-height:0;overflow-y:auto}
  .node-wrap{max-width:min(360px, 46vh)}
  .terminal{max-height:clamp(160px, 30vh, 300px)}
  .brand-name{font-size:15px}
  .log{font-size:12.5px}
}

/* ---------- short screens ---------- */
@media (max-height:720px){
  .node-wrap{max-width:236px}
  .nodes-hint{display:none}
  .boot-inner{font-size:11.5px;line-height:1.8}
}
@media (max-height:560px){
  .node-wrap{max-width:190px}
  .terminal{max-height:42vh}
  .brand-sub{display:none}
}

@media (max-width:430px){
  .chip-dim{display:none}
  .brand-name{font-size:13px}
  .stat .v{font-size:13px}
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce){
  .caret,.dot,.brand-mark,.boot-cursor{animation:none}
  .caret{opacity:1}
  .crt-flicker.run{animation:none}
  .node-inner.shake{animation:none}
  #nodeGrid.scanning .hex-base{animation:none}
  .app{transition:none}
  .boot{transition:none}
  .flash.on{animation:none}
}