/* ============================================================
   C64er Emulator – Global Styles
   ============================================================ */

:root {
  --c64-primary:      #40318d;
  --c64-secondary:    #7869c4;
  --c64-blue:         #40318d;
  --c64-light-blue:   #7869c4;
  --c64-bg:           #1a1a2e;
  --c64-surface:      #16213e;
  --c64-surface-2:    #1e2d4a;
  --c64-text:         #e0e0e0;
  --c64-text-light:   #9f9fbb;
  --c64-success:      #10b981;
  --c64-danger:       #ef4444;
  --c64-warning:      #f59e0b;
  --c64-radius:       8px;
  --c64-shadow-lg:    0 10px 25px rgba(0,0,0,0.4);
  --c64-transition:   200ms ease;
  --c64-border-color: #7869c4;
  --c64-screen-glow:  0 0 30px rgba(120, 105, 196, 0.3);
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--c64-bg);
  color: var(--c64-text);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* ============================================================
   APP LAYOUT
   ============================================================ */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ============================================================
   NAVIGATION
   ============================================================ */
.c64-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 1rem;
  background: var(--c64-surface);
  border-bottom: 2px solid var(--c64-border-color);
  flex-shrink: 0;
  z-index: 100;
}

.c64-nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--c64-light-blue);
  text-decoration: none;
  font-family: 'Courier New', monospace;
}

.c64-nav-brand svg {
  width: 28px;
  height: 28px;
}

.c64-nav-links {
  display: flex;
  gap: 0.25rem;
}

.c64-nav-links a {
  color: var(--c64-text-light);
  text-decoration: none;
  padding: 0.35rem 0.75rem;
  border-radius: var(--c64-radius);
  font-size: 0.85rem;
  transition: all var(--c64-transition);
}

.c64-nav-links a:hover,
.c64-nav-links a.active {
  background: var(--c64-surface-2);
  color: var(--c64-light-blue);
}

.c64-nav-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.c64-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
  min-height: 0;
}

/* ============================================================
   EMULATOR SCREEN
   ============================================================ */
.c64-screen-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  width: 100%;
  height: 100%;
  flex: 1;
  justify-content: center;
}

.c64-monitor {
  background: #111;
  border: 3px solid #555;
  border-radius: 12px;
  padding: 8px;
  box-shadow: var(--c64-screen-glow), 0 0 60px rgba(0,0,0,0.6);
  position: relative;
  width: calc(100% - 16px);
  height: calc(100% - 50px);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 4px 8px;
}

.c64-monitor::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(255,255,255,0.03) 0%, transparent 50%);
  pointer-events: none;
}

#c64-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 4px;
  cursor: default;
  max-width: 100%;
  max-height: 100%;
  /* Scale to fill the monitor, keeping aspect ratio */
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Scanline effect */
.c64-scanlines {
  position: absolute;
  inset: 12px;
  border-radius: 4px;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.15) 0px,
    rgba(0, 0, 0, 0.15) 1px,
    transparent 1px,
    transparent 3px
  );
  pointer-events: none;
  opacity: 0.4;
}

.c64-scanlines.off {
  display: none;
}

/* ============================================================
   CONTROLS BAR
   ============================================================ */
.c64-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.c64-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--c64-border-color);
  border-radius: var(--c64-radius);
  background: var(--c64-surface);
  color: var(--c64-text);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--c64-transition);
  font-family: inherit;
  white-space: nowrap;
}

.c64-btn:hover {
  background: var(--c64-surface-2);
  border-color: var(--c64-light-blue);
}

.c64-btn:active {
  transform: scale(0.97);
}

.c64-btn.primary {
  background: var(--c64-primary);
  border-color: var(--c64-primary);
  color: white;
}

.c64-btn.primary:hover {
  background: var(--c64-secondary);
}

.c64-btn.danger {
  border-color: var(--c64-danger);
  color: var(--c64-danger);
}

.c64-btn.danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

.c64-btn.success {
  border-color: var(--c64-success);
  color: var(--c64-success);
}

/* ============================================================
   STATUS BAR
   ============================================================ */
.c64-status {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.3rem 1rem;
  background: var(--c64-surface);
  border-top: 1px solid var(--c64-border-color);
  font-size: 0.75rem;
  color: var(--c64-text-light);
  flex-shrink: 0;
  font-family: 'Courier New', monospace;
}

.c64-status-left,
.c64-status-center,
.c64-status-right {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.c64-status-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.c64-status-center a {
  color: #e30613;
  text-decoration: none;
}

.c64-status-center a:hover {
  color: #ff1a2a;
  text-decoration: underline;
}

.c64-status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c64-danger);
}

.c64-status-indicator.running {
  background: var(--c64-success);
  box-shadow: 0 0 6px var(--c64-success);
}

.c64-status-indicator.paused {
  background: var(--c64-warning);
  box-shadow: 0 0 6px var(--c64-warning);
}

/* ============================================================
   SETTINGS PAGE
   ============================================================ */
.c64-settings {
  max-width: 700px;
  width: 100%;
  padding: 1.5rem;
  overflow-y: auto;
}

.c64-settings h2 {
  font-size: 1.3rem;
  margin-bottom: 1.5rem;
  color: var(--c64-light-blue);
  font-family: 'Courier New', monospace;
}

.c64-card {
  background: var(--c64-surface);
  border: 1px solid var(--c64-border-color);
  border-radius: var(--c64-radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.c64-card h3 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
  color: var(--c64-text);
}

.c64-card p {
  font-size: 0.85rem;
  color: var(--c64-text-light);
  margin-bottom: 0.75rem;
  line-height: 1.5;
}

.c64-file-drop {
  border: 2px dashed var(--c64-border-color);
  border-radius: var(--c64-radius);
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--c64-transition);
  margin-bottom: 0.5rem;
}

.c64-file-drop:hover,
.c64-file-drop.dragover {
  border-color: var(--c64-light-blue);
  background: rgba(120, 105, 196, 0.05);
}

.c64-file-drop input {
  display: none;
}

.c64-rom-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.c64-rom-status .loaded {
  color: var(--c64-success);
}

.c64-rom-status .missing {
  color: var(--c64-text-light);
}

/* Toggle switch */
.c64-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.c64-toggle input {
  display: none;
}

.c64-toggle-track {
  width: 36px;
  height: 20px;
  background: #444;
  border-radius: 10px;
  position: relative;
  transition: background var(--c64-transition);
  flex-shrink: 0;
}

.c64-toggle input:checked + .c64-toggle-track {
  background: var(--c64-primary);
}

.c64-toggle-track::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  top: 2px;
  left: 2px;
  transition: transform var(--c64-transition);
}

.c64-toggle input:checked + .c64-toggle-track::after {
  transform: translateX(16px);
}

/* ============================================================
   ABOUT PAGE
   ============================================================ */
.c64-about {
  max-width: 700px;
  width: 100%;
  padding: 1.5rem;
  overflow-y: auto;
}

.c64-about h2 {
  font-size: 1.3rem;
  margin-bottom: 1rem;
  color: var(--c64-light-blue);
  font-family: 'Courier New', monospace;
}

.c64-about h3 {
  font-size: 1rem;
  margin: 1rem 0 0.5rem;
  color: var(--c64-text);
}

.c64-about p, .c64-about li {
  font-size: 0.85rem;
  color: var(--c64-text-light);
  line-height: 1.6;
}

.c64-about ul {
  padding-left: 1.5rem;
  margin-bottom: 0.75rem;
}

.c64-about code {
  background: var(--c64-surface-2);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--c64-light-blue);
}

.c64-keyboard-help {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 1rem;
  font-size: 0.85rem;
}

.c64-keyboard-help dt {
  color: var(--c64-text);
  font-family: 'Courier New', monospace;
}

.c64-keyboard-help dd {
  color: var(--c64-text-light);
}

/* ============================================================
   VIRTUAL KEYBOARD (Mobile)
   ============================================================ */
.c64-virtual-keyboard {
  display: none;
  background: var(--c64-surface);
  border-top: 1px solid var(--c64-border-color);
  padding: 0.3rem;
  flex-shrink: 0;
}

.c64-vk-row {
  display: flex;
  justify-content: center;
  gap: 2px;
  margin-bottom: 2px;
}

.c64-vk-key {
  padding: 0.5rem 0.3rem;
  min-width: 28px;
  border: 1px solid #555;
  border-radius: 4px;
  background: #333;
  color: var(--c64-text);
  font-size: 0.7rem;
  font-family: 'Courier New', monospace;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
}

.c64-vk-key:active {
  background: var(--c64-primary);
}

.c64-vk-key.wide {
  min-width: 50px;
  flex-grow: 0.5;
}

.c64-vk-key.extra-wide {
  min-width: 100px;
  flex-grow: 2;
}

/* ============================================================
   LISTINGS
   ============================================================ */
.c64-listing {
  background: var(--c64-bg);
  color: #7869c4;
  padding: 1rem;
  border-radius: var(--c64-radius);
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  line-height: 1.6;
  overflow-x: auto;
  margin-bottom: 0.75rem;
}

.c64-btn-load-listing {
  margin-top: 0.25rem;
  width: 100%;
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 380px;
}

.c64-toast {
  background: var(--c64-surface);
  border-radius: var(--c64-radius);
  box-shadow: var(--c64-shadow-lg);
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--c64-primary);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: slideInRight 0.3s ease;
  font-size: 0.85rem;
}

.c64-toast.toast-success { border-left-color: var(--c64-success); }
.c64-toast.toast-danger  { border-left-color: var(--c64-danger); }
.c64-toast.toast-warning { border-left-color: var(--c64-warning); }

.c64-toast .toast-msg { flex: 1; }

.c64-toast .toast-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--c64-text-light);
  padding: 0;
  line-height: 1;
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(100%); }
}

.c64-toast.removing {
  animation: fadeOut 0.3s ease forwards;
}

/* ============================================================
   FULLSCREEN MODE
   ============================================================ */
.c64-fullscreen .c64-nav,
.c64-fullscreen .c64-status,
.c64-fullscreen .c64-controls {
  display: none;
}

.c64-fullscreen .c64-main {
  padding: 0;
}

.c64-fullscreen .c64-monitor {
  border: none;
  border-radius: 0;
  padding: 0;
}

.c64-fullscreen #c64-canvas {
  max-width: 100vw;
  max-height: 100vh;
  border-radius: 0;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .c64-nav-brand span {
    display: none;
  }

  .c64-nav {
    padding: 0.3rem 0.5rem;
  }

  .c64-controls {
    gap: 0.25rem;
  }

  .c64-btn {
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
  }

  .c64-virtual-keyboard {
    display: block;
  }

  .c64-monitor {
    padding: 4px;
    border-width: 2px;
  }
}

@media (max-width: 480px) {
  .c64-nav-links {
    display: none;
  }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--c64-surface);
}

::-webkit-scrollbar-thumb {
  background: var(--c64-primary);
  border-radius: 3px;
}
