:root {
  --bg: #060c12;
  --panel-bg: #0c1a22;
  --panel-border: #1f4d3f;
  --ink: #8fd694;
  --ink-dim: #4c7a5a;
  --amber: #ffb84d;
  --red: #ff5c5c;
  --grid-line: #123027;
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at center, #0a1a14 0%, #050a08 100%);
  color: var(--ink);
  font-family: 'Press Start 2P', monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-x: hidden;
}

.crt {
  position: relative;
  max-width: 1100px;
  width: 100%;
  background: linear-gradient(180deg, var(--panel-bg), #050a08);
  padding: 20px;
  box-shadow:
    inset 0 0 0 3px var(--panel-border),
    inset 0 0 0 6px #04100a,
    0 10px 0 0 rgba(0, 0, 0, 0.45),
    0 10px 24px rgba(0, 0, 0, 0.5);
}

.titlebar {
  text-align: center;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 3px solid var(--panel-border);
}

.back-link {
  display: block;
  margin-bottom: 10px;
  font-size: 9px;
  letter-spacing: 1px;
  color: var(--ink-dim);
  text-decoration: none;
}
.back-link:hover, .back-link:focus-visible {
  color: var(--amber);
}

.back-arrow {
  display: inline-block;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-right: 6px solid currentColor;
  vertical-align: middle;
  margin-bottom: 1px;
}

.titlebar h1 {
  font-size: 24px;
  letter-spacing: 2px;
  color: var(--amber);
  text-shadow: 0 0 6px rgba(255, 184, 77, 0.6), 0 0 18px rgba(255, 184, 77, 0.25);
  margin: 0;
}

.layout {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: nowrap;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 0 0 clamp(92px, 30vw, 190px);
  width: auto;
  min-width: 0;
}

.panel-block {
  background: linear-gradient(180deg, var(--panel-bg), #081319);
  border: 2px solid var(--panel-border);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.6), 0 0 0 1px #04100a;
  padding: 10px;
}

.panel-block h2 {
  font-size: 9px;
  margin: 0 0 10px;
  color: var(--ink-dim);
  letter-spacing: 1px;
  border-bottom: 1px dashed var(--panel-border);
  padding-bottom: 6px;
}

.board-wrap {
  position: relative;
  min-width: 0;
  padding: 10px;
  background: #030807;
  border: 3px solid var(--panel-border);
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.85), 0 0 24px rgba(20, 100, 70, 0.15);
}

.board-stage {
  position: relative;
}

.board {
  --cell: 28px;
  position: relative;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  background-color: #030807;
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  touch-action: none;
}

.cell {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  box-sizing: border-box;
  overflow: hidden;
}

.cell .frag {
  display: none;
  position: absolute;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  transform-origin: 50% 50%;
}

.cell.ghost {
  border: 2px dashed;
  opacity: 0.45;
}

.oil-price {
  font-size: 22px;
  color: var(--amber);
  text-shadow: 0 0 8px rgba(255, 184, 77, 0.5);
  text-align: center;
}

.oil-unit {
  text-align: center;
  font-size: 8px;
  color: var(--ink-dim);
  margin-top: 6px;
}

.next-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.preview-box {
  min-height: 76px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #04100a;
  border: 1px solid var(--panel-border);
  padding: 8px;
}

.preview-box.small {
  min-height: 60px;
}

.preview-box img {
  width: 56px;
  height: 56px;
  image-rendering: pixelated;
}

.preview-box.small img {
  width: 44px;
  height: 44px;
}

.preview-label {
  font-size: 7px;
  color: var(--ink-dim);
  text-align: center;
  letter-spacing: 0.5px;
}

.controls {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 8px;
}

.controls li {
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.controls span {
  color: var(--amber);
}

.shock-banner {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translate(-50%, -100%);
  background: var(--red);
  color: #1a0000;
  font-size: 12px;
  padding: 8px 14px;
  letter-spacing: 1px;
  box-shadow: 0 0 16px rgba(255, 92, 92, 0.7);
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 5;
  white-space: nowrap;
}

.shock-banner.show {
  opacity: 1;
  transform: translate(-50%, -130%);
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(3, 8, 7, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 10;
}

.overlay.show {
  display: flex;
}

.overlay-inner h2 {
  color: var(--red);
  font-size: 16px;
  text-shadow: 0 0 10px rgba(255, 92, 92, 0.6);
  margin: 0 0 14px;
}

.overlay-inner p {
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink);
  margin: 6px 0;
}

.overlay-cta {
  color: var(--amber);
}

.scanlines {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.15) 0px,
    rgba(0, 0, 0, 0.15) 1px,
    transparent 2px,
    transparent 3px
  );
  mix-blend-mode: multiply;
  z-index: 100;
}

.mobile-controls {
  display: none;
}

@media (pointer: coarse) {
  .desktop-controls {
    display: none;
  }
  .mobile-controls {
    display: flex;
  }
}

@media (max-width: 480px) {
  .panel-block {
    padding: 6px;
  }
  .panel-block h2 {
    font-size: 7px;
    margin-bottom: 6px;
    padding-bottom: 4px;
  }
  .oil-price {
    font-size: 14px;
  }
  .oil-unit {
    font-size: 6px;
  }
  .controls {
    font-size: 6px;
    gap: 5px;
  }
  .preview-box img {
    width: 36px;
    height: 36px;
  }
  .preview-box.small img {
    width: 30px;
    height: 30px;
  }
  .preview-label {
    font-size: 6px;
  }
}

/* On tablets (esp. landscape) width is plentiful but height is tight: the
   side panel's own size (not the board) is what stops the frame fitting the
   viewport, so shrink it directly rather than relying on cell-size fitting. */
@media (max-height: 700px) {
  .panel {
    gap: 8px;
  }
  .panel-block {
    padding: 6px;
  }
  .panel-block h2 {
    margin-bottom: 6px;
    padding-bottom: 4px;
  }
  .next-list {
    gap: 6px;
  }
  .preview-box.small {
    min-height: 44px;
    padding: 5px;
  }
  .preview-box.small img {
    width: 30px;
    height: 30px;
  }
  .controls {
    gap: 4px;
  }
}
