@font-face {
  font-family: '3270';
  src: url('font/3270SemiCondensed-Regular.ttf');
  font-weight: normal;
  font-style: normal;
}

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

:root {
  --green: #33ff33;
  --green-text: #29cc29;
  --green-dim: #1a8c1a;
  --green-glow: #33ff3388;
  --bg: #06160688;
  --scanline-opacity: 0.22;
}

html, body {
  height: 100%;
  background: #000;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: '3270', 'Courier New', monospace;
  font-size: 17px;
  color: var(--green);
  overflow: hidden;
  background: #111 url('bg.png') center/cover no-repeat;
}

.img-overlay {
  background-color: #000000ef;
  position: absolute;
  inset: 0;
}

.crt-screen {
  position: relative;
  width: 90vw;
  height: 90vh;
  background: var(--bg);
  border-radius: 12px;
  overflow: hidden;
  filter: brightness(1.1) contrast(1.1);
  box-shadow:
    0 0 0 2px #111,
    0 0 0 4px #222,
    0 0 60px 10px #33ff3304,
    0 0 120px 30px #33ff3304;
  animation: flicker 10s infinite;
}

.crt-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0, 0, 0, var(--scanline-opacity)) 2px,
    rgba(0, 0, 0, var(--scanline-opacity)) 4px
  );
}

.crt-screen::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 9;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0, 0, 0, 0.5) 100%);
}

.crt-content {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 24px 28px;
}

.glow {
  text-shadow:
    0 0 4px var(--green),
    0 0 12px var(--green-glow),
    0 0 24px var(--green-glow);
}

.tab-input {
  display: none;
}

.tab-nav {
  display: flex;
  flex-wrap: wrap;
  flex-shrink: 0;
  border-bottom: 1px solid var(--green-dim);
  margin-bottom: 20px;
}

.tab-label {
  padding: 6px 20px;
  cursor: pointer;
  color: var(--green-dim);
  font-size: 16px;
  letter-spacing: 0.05em;
  border: 1px solid transparent;
  border-bottom: none;
  position: relative;
  bottom: -1px;
  transition: color 0.75s;
  user-select: none;
}

.tab-label:hover {
  color: var(--green);
}

#tab-upload:checked ~ .tab-nav .tab-label[for="tab-upload"],
#tab-map:checked ~ .tab-nav .tab-label[for="tab-map"],
#tab-credits:checked ~ .tab-nav .tab-label[for="tab-credits"] {
  color: var(--green);
  border-color: var(--green-dim);
  background: var(--bg);
  text-shadow: 0 0 4px var(--green), 0 0 10px var(--green-glow);
}

.tab-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tab-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  line-height: 1.7;
  scrollbar-width: thin;
  scrollbar-color: var(--green-dim) transparent;
  padding-right: 8px;
}

#tab-upload:checked ~ .tab-content #panel-upload,
#tab-credits:checked ~ .tab-content #panel-credits {
  display: block;
}

.panel-title {
  font-size: 20px;
  letter-spacing: 0.1em;
  margin-bottom: 16px;
}

h2 {
  font-size: 18px;
  font-weight: normal;
  margin-bottom: 4px;
}

p {
  color: var(--green-text);
}

small {
  color: var(--green-dim);
}

.info-box {
  flex: 1 1 300px;
  background: #00000040;
  border: 1px solid var(--green-dim);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
}

.box-title {
  font-size: 18px;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}

button {
  font-family: '3270', 'Courier New', monospace;
  font-size: 16px;
  background: #00000080;
  color: var(--green);
  border: 1px solid var(--green-dim);
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
}

button:focus-visible {
  outline: 1px solid var(--green);
}

button {
  padding: 4px 16px;
  margin-left: 8px;
}

button:hover:not(:disabled) {
  border-color: var(--green);
  text-shadow: 0 0 4px var(--green), 0 0 10px var(--green-glow);
}

button:disabled {
  color: var(--green-dim);
  cursor: default;
}

progress {
  width: 100%;
  height: 14px;
  appearance: none;
  border: 1px solid var(--green-dim);
  border-radius: 4px;
  background: #00000080;
  overflow: hidden;
}

progress::-webkit-progress-bar {
  background: transparent;
}

progress::-webkit-progress-value {
  background: var(--green);
  box-shadow: 0 0 8px var(--green-glow);
}

progress::-moz-progress-bar {
  background: var(--green);
}

code {
  font-family: inherit;
  color: var(--green);
}

.hide-item {
  display: none;
}

.tab-input:disabled ~ .tab-nav .tab-label[for="tab-map"] {
  opacity: 0.4;
  cursor: default;
}

#tab-map:checked ~ .tab-content #panel-map {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.upload-box {
  margin-top: 16px;
}

.upload-box button.first {
  margin-left: 0;
}

.upload-box progress {
  display: block;
  margin-top: 12px;
}

.upload-box progress.hide-item {
  display: none;
}

#upload-message {
  margin-top: 8px;
}

#upload-message:empty {
  display: none;
}

#map-layout {
  display: flex;
  flex: 1;
  gap: 12px;
  min-height: 0;
}

#map-panel {
  flex: 0 0 220px;
  margin-bottom: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--green-dim) transparent;
}

#map-panel h2 {
  font-size: 18px;
  overflow-wrap: anywhere;
}

#map-panel h4 {
  margin-top: 12px;
  font-weight: normal;
}

#map-panel button {
  margin-left: 0;
  padding: 4px 10px;
  font-size: 15px;
}

#map-panel button.selected {
  background: #33ff3322;
  border-color: var(--green);
}

#map-floors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

#map-zoom, #map-goto, #map-rotation {
  display: flex;
  align-items: center;
  gap: 6px;
}

#map-goto button {
  flex: 1;
}

#map-toggles {
  display: flex;
  gap: 6px;
}

#map-toggles button {
  flex: 1;
  padding: 4px 2px;
  font-size: 13px;
}

#map-toggles .swatch {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 4px;
}

#map-toggles .swatch.missed {
  background: #ffe600;
}

#map-toggles .swatch.spawned {
  background: #b45cff;
}

#map-items.hide-missed .map-item:not(.highlighted),
#map-items.hide-spawned .map-spawned-item:not(.highlighted) {
  display: none;
}

.map-item.highlighted, .map-spawned-item.highlighted {
  z-index: 1;
  outline: 2px solid #fff;
  animation: map-item-highlight 1s ease-in-out infinite;
}

@keyframes map-item-highlight {
  50% { outline-color: transparent; box-shadow: 0 0 10px 4px #ffffffaa; }
}

#map-panel button:disabled {
  opacity: 0.4;
  cursor: default;
}

#map-rotation-level {
  min-width: 40px;
  text-align: center;
}

#map-zoom-level {
  min-width: 48px;
  text-align: center;
}

#map-download, #map-upload {
  width: 100%;
  margin-top: 8px;
}

#map-download {
  margin-top: 20px;
}

#map-view {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

#map-view.dragging {
  cursor: grabbing;
}

#map-stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

#map-image {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  user-select: none;
}

.map-item, .map-spawned-item, .map-entrance, .map-door, .map-code {
  position: absolute;
  transform: translate(-50%, -50%) rotate(calc(var(--map-rotation, 0deg) * -1)) scale(var(--item-scale, 1));
  cursor: help;
}

.map-item {
  width: 8px;
  height: 8px;
  background: #ffe600;
}

.map-item, .map-spawned-item {
  cursor: pointer;
}

.map-spawned-item {
  width: 8px;
  height: 8px;
  background: #b45cff;
}

.map-entrance {
  width: 18px;
  height: 18px;
  -webkit-mask: var(--door-icon) center/contain no-repeat;
  mask: var(--door-icon) center/contain no-repeat;
  --door-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M3 0h10v15h2v1H1v-1h2zM10 7v2h1.5V7z'/%3E%3C/svg%3E");
}

.map-entrance.main {
  background: #4ade80;
}

.map-entrance.fire {
  background: #ff5c5c;
}

.map-door {
  width: 7px;
  height: 7px;
  background: #9aa59a;
  border: 1px solid #000;
}

.map-door.locked {
  background: #ff9f1a;
}

.map-door.unlocked {
  background: #4ac0ff;
}

.map-code {
  padding: 0 2px;
  font-size: 8px;
  line-height: 10px;
  white-space: nowrap;
  border-radius: 2px;
  color: #000;
}

.map-code.hazard {
  background: #ff5c5c;
}

.map-code.big-door {
  background: #4ac0ff;
}

.map-floor-link {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 1px;
  transform: translate(-50%, -50%) rotate(calc(var(--map-rotation, 0deg) * -1)) scale(var(--item-scale, 1));
}

.map-floor-link button {
  width: 14px;
  height: 11px;
  margin: 0;
  padding: 0;
  font-size: 8px;
  line-height: 1;
  background: #00000070;
  border: 1px solid #33ff3333;
  border-radius: 2px;
  color: #33ff3388;
  cursor: pointer;
}

.map-floor-link button:hover {
  background: #000000c0;
  border-color: var(--green);
  color: var(--green);
}

#map-tooltip {
  position: absolute;
  z-index: 1;
  padding: 6px 10px;
  background: #020a02f0;
  border: 2px solid var(--green-dim);
  border-radius: 6px;
  font-size: 15px;
  line-height: 1.4;
  white-space: nowrap;
  pointer-events: none;
}

.cursor-bar {
  flex-shrink: 0;
  padding-top: 12px;
  border-top: 1px solid var(--green-dim);
  margin-top: 12px;
}

.cursor::after {
  content: '█';
  animation: blink 1s steps(1) infinite;
}

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

@keyframes flicker {
  0%, 100% { opacity: 1; }
  59%, 61% { opacity: 1; }
  60% { opacity: 0.93; }
  64%, 66% { opacity: 1; }
  65% { opacity: 0.93; }
}

@media (max-width: 600px) {
  .crt-screen {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
  }

  .crt-content {
    padding: 16px;
  }
}
