/* ── Custom properties ─────────────────────────────────── */
:root {
  --device-body:       #c8102e;
  --device-body-dark:  #9a0b22;
  --screen-bezel:      #1a1a1a;
  --screen-bg:         #0c180c;
  --screen-text:       #7cfc7c;
  --screen-text-dim:   #3a6e3a;
  --led-on:            #39ff14;
  --led-glow:          rgba(57, 255, 20, 0.55);
  --readout-bg:        #0a0a0a;
  --readout-text:      #39ff14;
  --dpad-color:        #111111;
  --dpad-text:         #666666;
  --btn-a-color:       #b8001a;
  --btn-b-color:       #145214;
  --device-shadow:     rgba(0, 0, 0, 0.75);
  --footer-text:       rgba(0, 0, 0, 0.45);
}

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

button {
  border: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Page ──────────────────────────────────────────────── */
body {
  font-family: 'Courier New', Courier, monospace;
  background: #0f0f0f;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0;
}

/* ── Device shell ──────────────────────────────────────── */
.device {
  width: 380px;
  zoom: calc(min((100vw - 1rem) / 380px, (100dvh - 1rem) / 480px));
  background: var(--device-body);
  border-radius: 18px 18px 30px 30px;
  padding: 14px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow:
    inset 0 2px 5px rgba(255, 255, 255, 0.13),
    inset 0 -4px 10px rgba(0, 0, 0, 0.35),
    0 14px 52px var(--device-shadow),
    0 2px 8px rgba(0, 0, 0, 0.5);
}

/* ── Device top ────────────────────────────────────────── */
.device-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 2px 6px;
}

/* LED */
.led {
  flex-shrink: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--led-on);
  box-shadow: 0 0 6px 3px var(--led-glow);
  animation: led-pulse 2.6s ease-in-out infinite;
}

@keyframes led-pulse {
  0%, 100% {
    opacity: 1;
    box-shadow: 0 0 6px 3px var(--led-glow);
  }
  50% {
    opacity: 0.5;
    box-shadow: 0 0 2px 1px var(--led-glow);
  }
}

/* Speaker grille — dots via background-image */
.speaker-grille {
  width: 66px;
  height: 13px;
  background-image: radial-gradient(
    circle,
    rgba(0, 0, 0, 0.45) 1.5px,
    transparent 1.5px
  );
  background-size: 7px 7px;
  border-radius: 3px;
}

/* Device label */
.device-label {
  margin-left: auto;
  font-size: 0.55rem;
  font-weight: bold;
  letter-spacing: 0.12em;
  color: rgba(0, 0, 0, 0.4);
}

/* ── Screen section ────────────────────────────────────── */
.screen {
  /* semantic wrapper — no visual styles needed */
}

.screen-bezel {
  background: var(--screen-bezel);
  border-radius: 10px;
  padding: 10px;
  box-shadow:
    inset 0 5px 14px rgba(0, 0, 0, 0.95),
    inset 0 0 0 1px rgba(0, 0, 0, 0.7);
}

.screen-viewport {
  width: 100%;
  height: 220px;
  background: var(--screen-bg);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* subtle CRT scanlines */
  background-image: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 3px,
    rgba(0, 0, 0, 0.07) 3px,
    rgba(0, 0, 0, 0.07) 4px
  );
}

/* Silhouette area — fills most of viewport height */
.silhouette-area {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.silhouette-placeholder {
  width: 72px;
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.silhouette-placeholder::before {
  content: '?';
  font-size: 3.5rem;
  font-weight: bold;
  color: var(--screen-text-dim);
  opacity: 0.6;
  text-shadow: 0 0 12px var(--screen-text-dim);
}

/* Name slot */
.enemy-name-slot {
  color: var(--screen-text);
  font-size: 1rem;
  font-weight: bold;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 0 10px 4px;
  text-shadow: 0 0 8px var(--screen-text);
}

/* Description slot */
.enemy-desc-slot {
  color: var(--screen-text-dim);
  font-size: 0.6rem;
  text-align: center;
  padding: 0 14px 10px;
  line-height: 1.5;
}

/* ── Readout strip ─────────────────────────────────────── */
.readout-strip {
  background: var(--readout-bg);
  border-radius: 5px;
  padding: 5px 12px;
  color: var(--readout-text);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-align: center;
  box-shadow:
    inset 0 2px 5px rgba(0, 0, 0, 0.7),
    inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  text-shadow: 0 0 6px var(--readout-text);
}

/* ── Controls ──────────────────────────────────────────── */
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 2px;
}

/* D-pad — 3×3 grid cross */
.dpad {
  display: grid;
  grid-template-areas:
    ".    up    ."
    "left center right"
    ".    down  .";
  grid-template-columns: 28px 28px 28px;
  grid-template-rows:    28px 28px 28px;
  gap: 2px;
}

.dpad-btn {
  background: var(--dpad-color);
  color: var(--dpad-text);
  font-size: 0.55rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.08s, color 0.08s;
}

.dpad-btn:active {
  background: #2a2a2a;
  color: #ccc;
}

.dpad-up    { grid-area: up;     border-radius: 4px 4px 0 0; }
.dpad-left  { grid-area: left;   border-radius: 4px 0 0 4px; }
.dpad-center {
  grid-area: center;
  background: var(--dpad-color);
}
.dpad-right { grid-area: right;  border-radius: 0 4px 4px 0; }
.dpad-down  { grid-area: down;   border-radius: 0 0 4px 4px; }

/* Action buttons */
.action-buttons {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn-action {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.8rem;
  font-weight: bold;
  font-family: 'Courier New', Courier, monospace;
  box-shadow:
    0 4px 7px rgba(0, 0, 0, 0.55),
    inset 0 1px 2px rgba(255, 255, 255, 0.18);
  transition: transform 0.08s, box-shadow 0.08s;
}

.btn-action:active {
  transform: translateY(2px);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.btn-a { background: var(--btn-a-color); }
.btn-b { background: var(--btn-b-color); }

/* ── Dynamic viewport content (Phase 4) ───────────────── */

.screen-viewport {
  align-items: stretch;
  overflow: hidden;
}

#search-input {
  flex-shrink: 0;
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--screen-text-dim);
  color: var(--screen-text);
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.65rem;
  padding: 4px 8px;
  outline: none;
  letter-spacing: 0.06em;
}

#search-input::placeholder {
  color: var(--screen-text-dim);
}

#enemy-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: none;
}

#enemy-list::-webkit-scrollbar { display: none; }

.enemy-list-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  cursor: pointer;
  border-left: 2px solid transparent;
}

.enemy-list-item.selected {
  background: rgba(124, 252, 124, 0.08);
  border-left-color: var(--screen-text);
}

.enemy-list-item:hover {
  background: rgba(124, 252, 124, 0.05);
}

.list-thumb {
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.3);
}

.enemy-list-name {
  color: var(--screen-text);
  font-size: 0.65rem;
  font-weight: bold;
  letter-spacing: 0.06em;
  flex: 1;
  text-shadow: 0 0 6px var(--screen-text);
}

.enemy-list-faction {
  color: var(--screen-text-dim);
  font-size: 0.55rem;
}

.silhouette {
  filter: brightness(0) saturate(0);
}

.detail-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 10px;
  overflow-y: auto;
  height: 100%;
  scrollbar-width: none;
}

.detail-view::-webkit-scrollbar { display: none; }

.detail-image-wrap {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 96px;
  height: 96px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 4px;
  margin-bottom: 6px;
}

.detail-img {
  object-fit: contain;
  max-width: 100%;
  max-height: 100%;
}

.detail-name {
  color: var(--screen-text);
  font-size: 0.85rem;
  font-weight: bold;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-shadow: 0 0 8px var(--screen-text);
  margin-bottom: 2px;
  text-align: center;
}

.detail-faction {
  color: var(--screen-text-dim);
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.detail-desc {
  color: var(--screen-text-dim);
  font-size: 0.58rem;
  line-height: 1.55;
  text-align: center;
}

.screen-error {
  color: var(--screen-text-dim);
  font-size: 0.65rem;
  text-align: center;
  padding: 20px 14px;
}

/* ── Aux buttons (STR / SET) ────────────────────────────── */
.aux-buttons {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
}

.btn-aux {
  background: #1a1a1a;
  color: #555;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.45rem;
  letter-spacing: 0.08em;
  padding: 3px 7px;
  border-radius: 10px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.5), inset 0 1px rgba(255,255,255,0.05);
  transition: background 0.08s, color 0.08s;
}

.btn-aux:active {
  background: #2a2a2a;
  color: #888;
}

/* ── Identify view ───────────────────────────────────────── */
.identify-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 10px 6px;
  height: 100%;
  gap: 4px;
  overflow: hidden;
}

.identify-img {
  object-fit: contain;
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.identify-name {
  color: var(--screen-text);
  font-size: 0.85rem;
  font-weight: bold;
  letter-spacing: 0.14em;
  text-align: center;
  text-shadow: 0 0 8px var(--screen-text);
}

.identify-hint {
  color: var(--screen-text-dim);
  font-size: 0.55rem;
  letter-spacing: 0.1em;
}

.identify-hint.hint-active {
  color: #b8e080;
  text-shadow: 0 0 6px rgba(184, 224, 128, 0.4);
}

.identify-input-wrap {
  width: 100%;
  margin-top: 4px;
}

.guess-input {
  width: 100%;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--screen-text-dim);
  border-radius: 3px;
  color: var(--screen-text);
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.65rem;
  padding: 4px 8px;
  outline: none;
  letter-spacing: 0.06em;
  text-align: center;
}

.guess-input:focus {
  border-color: var(--screen-text);
  box-shadow: 0 0 4px rgba(124, 252, 124, 0.3);
}

.guess-input::placeholder {
  color: var(--screen-text-dim);
}

.identify-error {
  color: #ff6b6b;
  font-size: 0.55rem;
  text-align: center;
  min-height: 1em;
  text-shadow: 0 0 6px rgba(255, 107, 107, 0.4);
}

.identify-skip-btn {
  background: transparent;
  border: 1px solid var(--screen-text-dim);
  color: var(--screen-text-dim);
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  padding: 3px 10px;
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 0.1s, color 0.1s;
  margin-top: 2px;
}

.identify-skip-btn:hover {
  border-color: var(--screen-text);
  color: var(--screen-text);
}

.identify-cta {
  color: var(--screen-text-dim);
  font-size: 0.5rem;
  letter-spacing: 0.06em;
  text-align: center;
  margin-top: 4px;
  opacity: 0.7;
}

/* ── Toast ───────────────────────────────────────────────── */
.device {
  position: relative;
}

.toast {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(57, 255, 20, 0.12);
  border: 1px solid var(--led-on);
  color: var(--led-on);
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  padding: 5px 14px;
  border-radius: 4px;
  pointer-events: none;
  text-shadow: 0 0 8px var(--led-on);
  box-shadow: 0 0 10px rgba(57, 255, 20, 0.2);
  white-space: nowrap;
  animation: toast-fade 2.2s ease forwards;
  z-index: 10;
}

@keyframes toast-fade {
  0%   { opacity: 0; transform: translateX(-50%) translateY(-6px); }
  15%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  75%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ── Theme view ──────────────────────────────────────────── */
.theme-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 10px;
  height: 100%;
  gap: 6px;
}

.theme-title {
  color: var(--screen-text);
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-shadow: 0 0 8px var(--screen-text);
  text-align: center;
  margin-bottom: 4px;
}

.theme-list {
  list-style: none;
  width: 100%;
  flex: 1;
  overflow-y: auto;
  scrollbar-width: none;
}

.theme-list::-webkit-scrollbar { display: none; }

.theme-item {
  color: var(--screen-text-dim);
  font-size: 0.65rem;
  font-family: 'Courier New', Courier, monospace;
  letter-spacing: 0.1em;
  padding: 3px 8px;
  cursor: pointer;
  white-space: pre;
}

.theme-item.selected {
  color: var(--screen-text);
  text-shadow: 0 0 6px var(--screen-text);
  background: rgba(124, 252, 124, 0.08);
}

.theme-hint {
  color: var(--screen-text-dim);
  font-size: 0.5rem;
  letter-spacing: 0.08em;
  opacity: 0.7;
}

/* ── Footer ────────────────────────────────────────────── */
.device-footer {
  text-align: center;
  padding: 2px 0 0;
}

.device-footer p {
  color: var(--footer-text);
  font-size: 0.52rem;
  letter-spacing: 0.03em;
  line-height: 1.4;
}

