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

:root {
  --bg-deep: #0a0a0f;
  --bg-panel: #12121a;
  --bg-surface: #1a1a26;
  --border-dim: #2a2a3a;
  --border-bright: #3a3a50;
  --text-primary: #e0ddd4;
  --text-dim: #6a6a7a;
  --text-muted: #3a3a4a;
  --accent-red: #d43f3f;
  --accent-green: #3ad47a;
  --accent-blue: #3a7ad4;
  --accent-yellow: #d4c23a;
  --accent-orange: #d4813a;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-primary);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#root {
  width: 100%;
  height: 100%;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Header */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-dim);
  flex-shrink: 0;
  min-height: 40px;
  gap: 10px;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent-red);
  letter-spacing: -0.5px;
}

.logo span {
  color: var(--text-dim);
  font-weight: 300;
  font-size: 10px;
  margin-left: 4px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s, box-shadow 0.3s;
}

.status-dot.running {
  background: var(--accent-green);
  box-shadow: 0 0 6px var(--accent-green);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.status-label {
  font-size: 9px;
  color: var(--text-dim);
  font-weight: 300;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.top-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-dim);
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 400;
  padding: 4px 10px;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.5px;
}

.top-btn:hover {
  background: var(--border-dim);
  color: var(--text-primary);
}

.top-btn.active {
  color: var(--accent-green);
  border-color: var(--accent-green);
}

.top-btn.load-btn {
  color: var(--accent-yellow);
  border-color: rgba(212, 194, 58, 0.3);
}

.top-btn.load-btn:hover {
  border-color: var(--accent-yellow);
  background: rgba(212, 194, 58, 0.08);
}

.top-btn.danger {
  color: var(--accent-red);
  border-color: rgba(212, 63, 63, 0.3);
}

.top-btn.danger:hover {
  border-color: var(--accent-red);
}

/* Screen Area */
.screen-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  min-height: 0;
  position: relative;
  background: 
    radial-gradient(ellipse at 50% 40%, rgba(30, 30, 50, 0.6) 0%, transparent 70%),
    var(--bg-deep);
}

.screen-bezel {
  position: relative;
  background: #0e0e14;
  border-radius: 8px;
  padding: 10px;
  border: 1px solid var(--border-dim);
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen-inner {
  position: relative;
  background: #000;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 256/240;
  border-radius: 3px;
}

.screen-inner canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Empty state */
.empty-screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s;
}

.empty-screen:hover {
  color: var(--text-dim);
}

.empty-screen:hover .drop-icon {
  border-color: var(--accent-yellow);
  color: var(--accent-yellow);
}

.drop-icon {
  width: 48px;
  height: 48px;
  border: 2px dashed var(--border-bright);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: all 0.2s;
}

.empty-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-dim);
}

.empty-sub {
  font-size: 8px;
  font-weight: 300;
  max-width: 220px;
  text-align: center;
  line-height: 1.6;
}

.rom-name-tag {
  position: absolute;
  bottom: 6px;
  left: 8px;
  font-size: 7px;
  color: var(--text-muted);
  font-weight: 300;
  z-index: 5;
  pointer-events: none;
  background: rgba(0,0,0,0.6);
  padding: 2px 6px;
  border-radius: 3px;
}

.fps-tag {
  position: absolute;
  bottom: 6px;
  right: 8px;
  font-size: 7px;
  color: var(--accent-green);
  font-weight: 300;
  z-index: 5;
  pointer-events: none;
  background: rgba(0,0,0,0.6);
  padding: 2px 6px;
  border-radius: 3px;
}

/* CRT Effect */
.crt-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 10;
  border-radius: 3px;
}

.crt-scanlines {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0, 0, 0, 0.12) 1px,
    rgba(0, 0, 0, 0.12) 2px
  );
}

.crt-vignette {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(
    ellipse at center,
    transparent 55%,
    rgba(0, 0, 0, 0.35) 100%
  );
  border-radius: 3px;
}

/* Controller Area */
.controller-area {
  flex-shrink: 0;
  padding: 8px;
  display: flex;
  justify-content: center;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-dim);
}

.controller {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 380px;
  width: 100%;
  padding: 8px 0;
}

.dpad {
  position: relative;
  width: 80px;
  height: 80px;
  flex-shrink: 0;
}

.dpad-btn {
  position: absolute;
  background: var(--bg-surface);
  border: 1px solid var(--border-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.05s, border-color 0.05s;
  color: var(--text-muted);
  font-size: 11px;
}

.dpad-btn:active, .dpad-btn.pressed {
  background: var(--border-bright);
  border-color: var(--text-dim);
  color: var(--text-dim);
}

.dpad-btn.up { top: 0; left: 26px; width: 28px; height: 28px; border-radius: 4px 4px 0 0; }
.dpad-btn.down { bottom: 0; left: 26px; width: 28px; height: 28px; border-radius: 0 0 4px 4px; }
.dpad-btn.left { top: 26px; left: 0; width: 28px; height: 28px; border-radius: 4px 0 0 4px; }
.dpad-btn.right { top: 26px; right: 0; width: 28px; height: 28px; border-radius: 0 4px 4px 0; }

.dpad-center {
  position: absolute;
  top: 26px; left: 26px;
  width: 28px; height: 28px;
  background: var(--bg-surface);
}

.center-btns {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.small-btn {
  background: var(--border-dim);
  border: 1px solid var(--border-bright);
  border-radius: 10px;
  width: 38px;
  height: 12px;
  cursor: pointer;
  transition: background 0.05s;
}

.small-btn:active, .small-btn.pressed {
  background: var(--text-dim);
}

.small-btn-label {
  font-size: 6px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 3px;
  font-weight: 300;
}

.ab-btns {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}

.ab-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: #fff;
  transition: all 0.05s;
  border: 2px solid;
}

.ab-btn.btn-b {
  background: var(--accent-red);
  border-color: #a03030;
}

.ab-btn.btn-a {
  background: var(--accent-red);
  border-color: #a03030;
}

.ab-btn:active, .ab-btn.pressed {
  transform: scale(0.92);
  filter: brightness(0.75);
}

/* Keyboard hints */
.key-hints {
  font-size: 7px;
  color: var(--text-muted);
  text-align: center;
  padding: 3px 0;
  font-weight: 300;
  background: var(--bg-panel);
  border-top: 1px solid rgba(42, 42, 58, 0.4);
}

/* Footer */
.footer {
  flex-shrink: 0;
  padding: 5px 14px;
  background: var(--bg-deep);
  border-top: 1px solid var(--border-dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 7px;
  color: var(--text-muted);
  font-weight: 300;
  min-height: 22px;
}

.footer a {
  color: var(--accent-red);
  text-decoration: none;
  font-weight: 400;
}

.footer a:hover {
  text-decoration: underline;
}

/* Error banner */
.error-banner {
  background: rgba(212, 63, 63, 0.1);
  border: 1px solid rgba(212, 63, 63, 0.3);
  color: var(--accent-red);
  padding: 6px 12px;
  font-size: 8px;
  text-align: center;
  font-weight: 400;
}

/* Info table */
.rom-info {
  position: absolute;
  top: 6px;
  left: 8px;
  z-index: 5;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rom-info-tag {
  font-size: 7px;
  color: var(--text-muted);
  background: rgba(0,0,0,0.65);
  padding: 1px 5px;
  border-radius: 2px;
  font-weight: 300;
  display: inline-block;
  width: fit-content;
}

/* Drag overlay */
.drag-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(10, 10, 15, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  pointer-events: none;
}

.drag-inner {
  border: 2px dashed var(--accent-yellow);
  border-radius: 12px;
  padding: 40px 60px;
  text-align: center;
}

.drag-inner .big {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-yellow);
  margin-bottom: 8px;
}

.drag-inner .small {
  font-size: 9px;
  color: var(--text-dim);
  font-weight: 300;
}

/* Responsive */
@media (max-width: 500px) {
  .top-bar { padding: 4px 8px; gap: 6px; }
  .logo { font-size: 11px; }
  .logo span { display: none; }
  .screen-area { padding: 6px; }
  .screen-bezel { padding: 6px; }
  .controller { gap: 10px; }
  .dpad { width: 72px; height: 72px; }
  .dpad-btn.up, .dpad-btn.down { width: 24px; height: 24px; left: 24px; }
  .dpad-btn.left, .dpad-btn.right { width: 24px; height: 24px; top: 24px; }
  .dpad-center { top: 24px; left: 24px; width: 24px; height: 24px; }
  .ab-btn { width: 38px; height: 38px; font-size: 10px; }
  .status-label { display: none; }
}

@media (min-width: 900px) {
  .screen-bezel { padding: 16px; max-width: 580px; }
}

/* Hidden file input */
.hidden-input {
  display: none;
}