/* Fonts are loaded from index.html — Chakra Petch + JetBrains Mono, both with
   a Vietnamese subset. Orbitron was dropped: it has no Vietnamese glyphs, so
   every accented character fell back to a different face. */

body,
html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background-color: #050505;
  /* Chakra Petch keeps the squared-off techno look and, unlike Orbitron,
     ships a full Vietnamese subset so diacritics render in the same face. */
  font-family: "Chakra Petch", "JetBrains Mono", monospace;
  color: #20c20e;
  overflow: hidden;
  user-select: none;
}

/* Scrollbars: thin and on-theme, so the panels stay readable when they
   overflow (edit mode, short viewports) instead of showing an OS grey bar. */
.panel,
.control-bar {
  scrollbar-width: thin;
  scrollbar-color: rgba(32, 194, 14, 0.45) transparent;
}

.panel::-webkit-scrollbar,
.control-bar::-webkit-scrollbar {
  width: 8px;
}

.panel::-webkit-scrollbar-track,
.control-bar::-webkit-scrollbar-track {
  background: transparent;
}

.panel::-webkit-scrollbar-thumb,
.control-bar::-webkit-scrollbar-thumb {
  background: rgba(32, 194, 14, 0.35);
  border-radius: 4px;
}

.panel::-webkit-scrollbar-thumb:hover,
.control-bar::-webkit-scrollbar-thumb:hover {
  background: rgba(32, 194, 14, 0.6);
}

/* Matrix background */
#matrix {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  opacity: 0.35;
}

/* Hex dump background */
.hex-bg {
  position: absolute;
  right: 0;
  top: 0;
  width: 30%;
  height: 100%;
  overflow: hidden;
  opacity: 0.2;
  font-size: 0.8rem;
  color: #1a6d36;
  word-wrap: break-word;
  z-index: 0;
  text-align: right;
  padding-right: 15px;
  font-family: "JetBrains Mono", monospace;
}

/* CRT scanline effect */
.crt-effect {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%),
    linear-gradient(
      90deg,
      rgba(255, 0, 0, 0.06),
      rgba(0, 255, 0, 0.02),
      rgba(0, 0, 255, 0.06)
    );
  background-size:
    100% 4px,
    6px 100%;
  z-index: 10;
  pointer-events: none;
  box-shadow: inset 0 0 120px rgba(0, 0, 0, 0.95);
}

/* HUD telemetry panel */
.hud {
  position: absolute;
  top: 25px;
  left: 25px;
  z-index: 5;
  /* Telemetry readout — monospace sells the terminal feel. */
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9rem;
  color: #20c20e;
  text-shadow: 0 0 5px #20c20e;
  line-height: 1.6;
  opacity: 0.9;
  display: flex;
  flex-direction: column;
  gap: 5px;
  border-left: 2px solid #20c20e;
  padding-left: 10px;
}

.hud span {
  color: #fff;
}

.blink-red {
  color: #ff3333 !important;
  text-shadow: 0 0 10px red !important;
  animation: blinkWarning 1s infinite;
  font-weight: bold;
}

@keyframes blinkWarning {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

/* Stage: occupies the top 70% of the viewport, panel centred inside it */
.stage {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  padding: 0 20px;
  box-sizing: border-box;
}

/* Main panel */
.panel {
  position: relative;
  width: 100%;
  max-width: 620px;
  max-height: 100%;
  overflow-y: auto;
  /* Reserve the scrollbar track so content never shifts when it appears. */
  scrollbar-gutter: stable;
  background: rgba(0, 15, 10, 0.8);
  border: 1px solid #1a6d36;
  box-shadow:
    0 0 40px rgba(32, 194, 14, 0.15),
    inset 0 0 25px #000;
  backdrop-filter: blur(12px);
  border-radius: 6px;
  padding: 35px 30px 30px;
  box-sizing: border-box;
}

/* Scanner bar */
.scan-bar {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 5px;
  background: rgba(32, 194, 14, 0.4);
  box-shadow: 0 0 15px #20c20e;
  animation: scanner 3s infinite linear;
  z-index: 100;
  pointer-events: none;
}

@keyframes scanner {
  0% {
    top: 0%;
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    top: 100%;
    opacity: 0;
  }
}

/* Control bar: bottom 30% — content editing + result selection */
.control-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 30vh;
  z-index: 6;
  box-sizing: border-box;
  padding: 14px 24px 18px;
  overflow-y: auto;
  /* Edit mode adds a row and mobile is tighter, so the scrollbar toggles on
     and off — reserving its track keeps the layout from jumping sideways. */
  scrollbar-gutter: stable;
  background: rgba(0, 12, 8, 0.72);
  border-top: 1px solid #1a6d36;
  backdrop-filter: blur(10px);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.7);
}

.control-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px dashed #1a6d36;
}

.control-label {
  font-size: 0.72rem;
  letter-spacing: 2px;
  color: #1a8c2d;
  text-transform: uppercase;
}

/* Title + placeholder editors — only visible in edit mode */
.title-edit-row {
  display: none;
  gap: 12px;
  margin-bottom: 12px;
}

body.edit-mode .title-edit-row {
  display: flex;
}

.field {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-label {
  flex-shrink: 0;
  font-size: 0.7rem;
  letter-spacing: 1px;
  color: #1a8c2d;
}

.title-input {
  flex-grow: 1;
  min-width: 0;
  background: #020a05;
  border: 1px dashed #20c20e;
  border-radius: 3px;
  color: #fff;
  font-family: inherit;
  font-size: 0.9rem;
  letter-spacing: 1px;
  padding: 9px 12px;
  outline: none;
}

.title-input:focus {
  box-shadow: 0 0 15px rgba(32, 194, 14, 0.4);
}

/* Panel title */
.panel-title {
  font-size: 1.6rem;
  text-align: center;
  letter-spacing: 3px;
  margin: 0 0 25px;
  text-transform: uppercase;
  text-shadow:
    0 0 10px #20c20e,
    0 0 20px #20c20e;
  border-bottom: 2px solid #1a6d36;
  padding-bottom: 15px;
  font-weight: bold;
  outline: none;
}

/* Edit mode toggle */
.edit-toggle {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid #1a6d36;
  color: #1a8c2d;
  font-family: inherit;
  font-size: 0.7rem;
  letter-spacing: 1px;
  padding: 4px 10px;
  border-radius: 3px;
  cursor: pointer;
  transition: 0.25s;
  z-index: 20;
}

.edit-toggle:hover,
.edit-toggle.active {
  color: #000;
  background: #20c20e;
  box-shadow: 0 0 15px rgba(32, 194, 14, 0.6);
}

/* Code input */
.input-row {
  margin-bottom: 18px;
}

.code-input {
  width: 100%;
  box-sizing: border-box;
  background: #020a05;
  border: 1px solid #20c20e;
  border-radius: 3px;
  color: #fff;
  font-family: inherit;
  font-size: 1.05rem;
  letter-spacing: 1px;
  padding: 14px 16px;
  outline: none;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
  transition: 0.25s;
}

.code-input::placeholder {
  color: #1a6d36;
  letter-spacing: 1px;
}

.code-input:focus {
  box-shadow:
    0 0 20px rgba(32, 194, 14, 0.45),
    inset 0 0 20px rgba(0, 0, 0, 0.8);
}

.btn-check {
  width: 100%;
  display: block;
  margin-bottom: 22px;
}

/* Result lines list — laid out in columns to fit the short control bar */
.results-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 8px;
}

.result-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid #123f21;
  border-radius: 3px;
  font-size: 0.88rem;
  line-height: 1.4;
  color: #1a8c2d;
  cursor: pointer;
  transition: 0.2s;
}

.result-line:hover {
  border-color: #1a6d36;
  color: #20c20e;
}

/* Selected line is the value the popup returns */
.result-line.selected {
  border-color: #20c20e;
  background: rgba(32, 194, 14, 0.1);
  color: #fff;
  text-shadow: 0 0 10px #2cfb14;
  box-shadow: 0 0 15px rgba(32, 194, 14, 0.25);
}

/* Square tick box acting as the selection radio */
.result-line .marker {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: 1px solid #20c20e;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  line-height: 1;
  color: transparent;
  transition: 0.2s;
}

.result-line.selected .marker {
  background: #20c20e;
  color: #000;
  box-shadow: 0 0 12px rgba(32, 194, 14, 0.7);
}

.result-line .text {
  flex-grow: 1;
  word-break: break-word;
  outline: none;
}

/* Inline text editing affordance, only while edit mode is on */
.result-line .text[contenteditable="true"] {
  background: rgba(32, 194, 14, 0.08);
  border: 1px dashed #20c20e;
  border-radius: 3px;
  padding: 2px 6px;
  cursor: text;
}

.result-line .text[contenteditable="true"]:focus {
  background: rgba(32, 194, 14, 0.16);
  box-shadow: 0 0 12px rgba(32, 194, 14, 0.4);
}

/* Status pill: safe / danger — click toggles, drives the popup theme */
.status-pill {
  flex-shrink: 0;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.6rem;
  letter-spacing: 1px;
  line-height: 1;
  padding: 5px 9px;
  cursor: pointer;
  transition: 0.2s;
  white-space: nowrap;
}

.result-line.status-safe .status-pill {
  background: rgba(32, 194, 14, 0.15);
  border: 1px solid #20c20e;
  color: #20c20e;
}

.result-line.status-safe .status-pill:hover {
  background: #20c20e;
  color: #000;
}

.result-line.status-danger .status-pill {
  background: rgba(255, 51, 51, 0.15);
  border: 1px solid #ff3333;
  color: #ff5555;
}

.result-line.status-danger .status-pill:hover {
  background: #ff3333;
  color: #000;
}

/* Danger lines read red across the whole row */
.result-line.status-danger {
  border-color: #4a1414;
  color: #c25c5c;
}

.result-line.status-danger:hover {
  border-color: #ff3333;
  color: #ff5555;
}

.result-line.status-danger .marker {
  border-color: #ff3333;
}

.result-line.status-danger.selected {
  border-color: #ff3333;
  background: rgba(255, 51, 51, 0.12);
  color: #fff;
  text-shadow: 0 0 10px #ff5555;
  box-shadow: 0 0 15px rgba(255, 51, 51, 0.3);
}

.result-line.status-danger.selected .marker {
  background: #ff3333;
  color: #000;
  box-shadow: 0 0 12px rgba(255, 51, 51, 0.7);
}

.result-line.status-danger .text[contenteditable="true"] {
  background: rgba(255, 51, 51, 0.08);
  border-color: #ff3333;
}

.result-line .del {
  display: none;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid #ff3333;
  color: #ff3333;
  border-radius: 3px;
  font-family: inherit;
  font-size: 0.72rem;
  line-height: 1;
  padding: 4px 7px;
  cursor: pointer;
}

.result-line .del:hover {
  background: #ff3333;
  color: #000;
}

/* Edit-mode-only controls */
.edit-actions {
  display: none;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

body.edit-mode .edit-actions {
  display: flex;
}

body.edit-mode .result-line .del {
  display: block;
}

.btn-mini {
  background: rgba(32, 194, 14, 0.1);
  border: 1px solid #20c20e;
  color: #20c20e;
  font-family: inherit;
  font-size: 0.8rem;
  letter-spacing: 1px;
  padding: 8px 14px;
  border-radius: 3px;
  cursor: pointer;
  transition: 0.25s;
}

.btn-mini:hover {
  background: #20c20e;
  color: #000;
}

.btn-danger {
  border-color: #ff3333;
  color: #ff3333;
  background: rgba(255, 51, 51, 0.08);
}

.btn-danger:hover {
  background: #ff3333;
  color: #000;
}

/* Result popup */
.popup-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 5, 2, 0.82);
  backdrop-filter: blur(5px);
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}

.popup-backdrop.open {
  display: flex;
}

.popup-box {
  position: relative;
  width: 100%;
  max-width: 460px;
  background: rgba(0, 15, 10, 0.95);
  border: 1px solid #20c20e;
  border-radius: 6px;
  padding: 35px 30px 30px;
  text-align: center;
  box-sizing: border-box;
  box-shadow:
    0 0 45px rgba(32, 194, 14, 0.35),
    inset 0 0 25px rgba(0, 0, 0, 0.9);
  animation: popIn 0.35s ease-out;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.popup-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: transparent;
  border: none;
  color: #1a8c2d;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  transition: 0.2s;
}

.popup-close:hover {
  color: #fff;
  text-shadow: 0 0 12px #2cfb14;
}

.popup-icon {
  font-size: 3.2rem;
  margin-bottom: 15px;
  filter: drop-shadow(0 0 20px #20c20e);
  animation: float 2s ease-in-out infinite;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-12px);
  }
}

.popup-heading {
  font-size: 1.25rem;
  color: #fff;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-weight: bold;
  text-shadow:
    0 0 10px #20c20e,
    0 0 30px #2cfb14;
  margin-bottom: 12px;
}

.popup-code {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85rem;
  color: #1a8c2d;
  letter-spacing: 1px;
  margin-bottom: 18px;
  word-break: break-all;
  /* One line per code field. */
  white-space: pre-line;
  line-height: 1.7;
}

.popup-message {
  font-size: 1.05rem;
  line-height: 1.6;
  color: #fff;
  text-shadow: 0 0 10px #20c20e;
  background: rgba(0, 25, 12, 0.7);
  border: 1px dashed #20c20e;
  border-radius: 4px;
  padding: 16px 18px;
  margin-bottom: 25px;
}

/* Each ticked result is one row inside the message box. */
.popup-line {
  text-align: left;
  padding: 7px 0 7px 18px;
  position: relative;
}

.popup-line + .popup-line {
  border-top: 1px solid rgba(32, 194, 14, 0.25);
}

/* Bullet marker, coloured per line status so mixed results stay readable. */
.popup-line::before {
  content: "▸";
  position: absolute;
  left: 0;
  color: #20c20e;
}

.popup-line.status-danger::before {
  content: "☠";
  color: #ff5555;
}

.popup-line.status-danger {
  color: #ffb3b3;
  text-shadow: 0 0 10px #ff5555;
}

.popup-cta {
  display: inline-block;
}

/* ---- Danger theme: red popup, harsher motion ---- */
.popup-backdrop.status-danger {
  background: rgba(20, 0, 0, 0.85);
}

.popup-backdrop.status-danger .popup-box {
  border-color: #ff3333;
  background: rgba(20, 2, 2, 0.95);
  box-shadow:
    0 0 45px rgba(255, 51, 51, 0.4),
    inset 0 0 25px rgba(0, 0, 0, 0.9);
  animation: popInShake 0.5s ease-out;
}

@keyframes popInShake {
  0% {
    opacity: 0;
    transform: scale(0.9);
  }
  40% {
    opacity: 1;
    transform: scale(1.02) translateX(-8px);
  }
  55% {
    transform: scale(1) translateX(7px);
  }
  70% {
    transform: translateX(-5px);
  }
  85% {
    transform: translateX(3px);
  }
  100% {
    transform: translateX(0);
  }
}

.popup-backdrop.status-danger .popup-icon {
  filter: drop-shadow(0 0 20px #ff3333);
  animation: pulseAlert 0.9s ease-in-out infinite;
}

@keyframes pulseAlert {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
  }
}

.popup-backdrop.status-danger .popup-heading {
  color: #fff;
  text-shadow:
    0 0 10px #ff3333,
    0 0 30px #ff3333;
  animation: blinkWarning 1.1s infinite;
}

.popup-backdrop.status-danger .popup-code {
  color: #c25c5c;
}

.popup-backdrop.status-danger .popup-message {
  border-color: #ff3333;
  background: rgba(30, 4, 4, 0.75);
  text-shadow: 0 0 10px #ff5555;
}

/* Mixed results: keep safe lines green even inside the red popup. */
.popup-backdrop.status-danger .popup-line.status-safe {
  color: #c8ffc8;
  text-shadow: 0 0 10px #20c20e;
}

.popup-backdrop.status-danger .popup-line + .popup-line {
  border-top-color: rgba(255, 51, 51, 0.3);
}

.popup-backdrop.status-danger .popup-close {
  color: #c25c5c;
}

.popup-backdrop.status-danger .popup-close:hover {
  color: #fff;
  text-shadow: 0 0 12px #ff5555;
}

.popup-backdrop.status-danger .btn-hack {
  border-color: #ff3333;
  color: #ff5555;
  background: rgba(255, 51, 51, 0.1);
  box-shadow: 0 0 15px rgba(255, 51, 51, 0.3);
}

.popup-backdrop.status-danger .btn-hack:hover {
  background: #ff3333;
  color: #000;
  box-shadow:
    0 0 30px #ff3333,
    0 0 60px #ff3333;
}

/* Full-screen colour flash fired on each check */
.screen-flash {
  position: fixed;
  inset: 0;
  z-index: 290;
  pointer-events: none;
  opacity: 0;
}

.screen-flash.run.flash-safe {
  animation: flashSafe 0.7s ease-out;
}

.screen-flash.run.flash-danger {
  animation: flashDanger 1.4s ease-out;
}

@keyframes flashSafe {
  0% {
    opacity: 0;
    background: rgba(32, 194, 14, 0.55);
  }
  100% {
    opacity: 0;
    background: rgba(32, 194, 14, 0);
  }
}

@keyframes flashDanger {
  0%,
  30%,
  60% {
    opacity: 1;
    background: rgba(255, 20, 20, 0.42);
  }
  15%,
  45%,
  100% {
    opacity: 0;
    background: rgba(255, 20, 20, 0);
  }
}

.btn-hack {
  background: rgba(32, 194, 14, 0.1);
  color: #20c20e;
  border: 2px solid #20c20e;
  padding: 15px 40px;
  font-size: 1.3rem;
  font-family: inherit;
  cursor: pointer;
  text-transform: uppercase;
  text-decoration: none;
  letter-spacing: 2px;
  transition: 0.3s;
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 15px rgba(32, 194, 14, 0.3);
  border-radius: 4px;
  font-weight: bold;
}

.btn-hack:hover {
  background: #20c20e;
  color: #000;
  box-shadow:
    0 0 30px #2cfb14,
    0 0 60px #2cfb14;
  text-shadow: none;
  transform: scale(1.05);
}

/* Mobile responsive */
@media (max-width: 768px) {
  .hud,
  .hex-bg {
    display: none !important;
  }
  .stage {
    height: 62vh;
    padding: 0 10px;
  }
  .panel {
    padding: 30px 16px 22px;
  }
  .control-bar {
    height: 38vh;
    padding: 12px 14px 16px;
  }
  .control-label {
    font-size: 0.6rem;
    letter-spacing: 1px;
  }
  .results-list {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .title-edit-row {
    flex-direction: column;
    gap: 8px;
  }
  .field {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }
  .status-pill {
    font-size: 0.55rem;
    padding: 4px 7px;
  }
  .panel-title {
    font-size: 1.1rem;
    margin-bottom: 18px;
    letter-spacing: 1px;
    padding-bottom: 12px;
  }
  .code-input {
    font-size: 0.95rem;
    padding: 12px 13px;
  }
  .result-line {
    font-size: 0.85rem;
    padding: 8px 10px;
    gap: 8px;
  }
  .popup-box {
    padding: 28px 18px 22px;
  }
  .popup-icon {
    font-size: 2.4rem;
    margin-bottom: 10px;
  }
  .popup-heading {
    font-size: 1.05rem;
    letter-spacing: 1px;
  }
  .popup-message {
    font-size: 0.9rem;
    padding: 13px 14px;
    margin-bottom: 18px;
  }
  .btn-hack {
    padding: 12px 10px;
    font-size: 0.95rem;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    line-height: normal;
  }
}
