/* ============================================================================
   Retro Arcade Sovereign Enclave - Master Stylesheet (v402)
   ============================================================================ */
:root {
  --bg-main: #0a0c10;
  --bg-card: #161b22;
  --bg-input: #0d1117;
  --border-color: #30363d;
  --text-main: #f0f6fc;
  --text-dim: #8b949e;
  --accent: #ff4b2b;
  --accent-hover: #ff6e40;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-family);
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* AUTHENTICATION MODAL */
#auth-modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 200000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  padding: 32px 28px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.auth-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
}

.badge {
  background: rgba(255, 75, 43, 0.15);
  color: var(--accent);
  border: 1px solid rgba(255, 75, 43, 0.3);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.auth-subtitle {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.4;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  color: #fff;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--accent);
}

.auth-submit-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
  transition: background 0.2s;
}

.auth-submit-btn:hover {
  background: var(--accent-hover);
}

.auth-error {
  color: #f85149;
  font-size: 0.85rem;
  text-align: center;
}

/* CATALOG VIEW */
#app-view {
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
}

.search-box {
  flex: 1;
  max-width: 450px;
}

.search-box input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 8px 16px;
  color: #fff;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-box input:focus {
  border-color: var(--accent);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.controller-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-dim);
  background: var(--bg-main);
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.controller-status.connected {
  color: #3fb950;
  border-color: rgba(63, 185, 80, 0.4);
  background: rgba(63, 185, 80, 0.1);
}

#lock-btn {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

#lock-btn:hover {
  color: #fff;
  border-color: var(--text-dim);
}

/* FILTERS BAR */
.filters {
  display: flex;
  gap: 8px;
  padding: 12px 24px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--bg-main);
  border-bottom: 1px solid var(--border-color);
}

.filters::-webkit-scrollbar {
  display: none;
}

.filter-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.filter-btn:hover {
  color: #fff;
  border-color: var(--text-dim);
}

.filter-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* GAMES GRID */
.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.game-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.game-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.game-card .game-title {
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  line-height: 1.3;
  word-break: break-word;
}

.game-card .card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.game-card .card-system {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.game-card .play-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.game-card:hover .play-btn {
  background: var(--accent-hover);
}

/* FULLSCREEN PLAYER VIEW */
#player-modal {
  display: none;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background-color: #000;
  z-index: 10000;
  overflow: hidden;
}

#game-container {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  background-color: #000;
}

.game-canvas-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: #000;
}

/* DISCREET OFF-CANVAS TRIGGER BUTTON (AUTO-HIDES ON IDLE) */
#drawer-toggle-btn {
  position: fixed;
  top: max(12px, env(safe-area-inset-top, 12px));
  left: max(12px, env(safe-area-inset-left, 12px));
  z-index: 99999;
  background: rgba(22, 27, 34, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #f0f6fc;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  transition: opacity 0.35s ease, transform 0.2s ease;
}

#player-modal.idle-hidden {
  cursor: none !important;
}

#player-modal.idle-hidden #drawer-toggle-btn {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translateY(-80%) !important;
}

/* OFF-CANVAS SLIDE-OUT DRAWER */
#drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100004;
  display: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}

#drawer-backdrop.active {
  display: block;
  opacity: 1;
}

#offcanvas-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 360px;
  max-width: 85vw;
  background: #161b22;
  border-right: 1px solid #30363d;
  z-index: 100005;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.85);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#offcanvas-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.drawer-title-group h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.drawer-close-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-dim);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.drawer-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.drawer-sec-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.action-btn {
  background: #21262d;
  border: 1px solid #30363d;
  color: #f0f6fc;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s;
  text-align: center;
}

.action-btn:hover {
  background: #30363d;
  border-color: #8b949e;
}

.btn-resume {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  padding: 12px 16px;
  font-size: 0.95rem;
}

.btn-resume:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-exit {
  background: rgba(218, 54, 51, 0.15);
  border-color: rgba(218, 54, 51, 0.4);
  color: #f85149;
}

.btn-exit:hover {
  background: #da3633;
  color: #fff;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* SLOT PICKER */
.slot-picker {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  background: var(--bg-input);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.slot-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.slot-btn.active {
  background: #30363d;
  color: #fff;
}

.subtext-note {
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.3;
}

/* VOLUME SLIDER */
.volume-slider-group {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  border-radius: 8px;
  margin-top: 4px;
}

.volume-slider-group input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}

.volume-slider-group span {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-weight: 600;
  min-width: 38px;
  text-align: right;
}

/* ADMIN DETAILS ACCORDION */
.admin-details {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
}

.admin-summary {
  padding: 10px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  outline: none;
  transition: background 0.15s;
}

.admin-summary:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.03);
}

.admin-content {
  padding: 12px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-desc {
  font-size: 0.73rem;
  color: var(--text-dim);
  line-height: 1.35;
}

.action-btn-sm {
  background: #21262d;
  border: 1px solid #30363d;
  color: #f0f6fc;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.action-btn-sm:hover {
  background: #30363d;
  border-color: #8b949e;
}

/* GUIDE BOX */
.guide-box {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.guide-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
}

.guide-row span {
  color: var(--text-dim);
}

.guide-row b {
  color: #fff;
  background: #21262d;
  border: 1px solid var(--border-color);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.75rem;
}

/* TOUCH OVERLAY & ERGONOMICS */
#touch-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 100002;
}

.touch-cluster {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-cluster.editing {
  outline: 2px dashed #ff6e40;
  border-radius: 12px;
  background: rgba(255, 110, 64, 0.15);
  cursor: grab;
}

.drag-handle {
  display: none;
  position: absolute;
  top: -24px;
  left: 50%;
  transform: translateX(-50%);
  background: #ff6e40;
  color: #000;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

.touch-cluster.editing .drag-handle {
  display: block;
}

/* D-PAD (CLEAN CROSS WITH ZERO CORNER SQUARES) */
.dpad-cluster {
  left: max(20px, env(safe-area-inset-left, 20px));
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
  width: 150px;
  height: 150px;
}

.dpad-cross {
  position: relative;
  width: 100%;
  height: 100%;
}

.dpad-arm {
  position: absolute;
  background: rgba(30, 34, 42, 0.88);
  border: 2px solid rgba(255, 255, 255, 0.2);
  color: #8b949e;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;
}

.dpad-up {
  top: 0;
  left: 50px;
  width: 50px;
  height: 52px;
  border-radius: 10px 10px 0 0;
  border-bottom: none;
}

.dpad-down {
  bottom: 0;
  left: 50px;
  width: 50px;
  height: 52px;
  border-radius: 0 0 10px 10px;
  border-top: none;
}

.dpad-left {
  top: 50px;
  left: 0;
  width: 52px;
  height: 50px;
  border-radius: 10px 0 0 10px;
  border-right: none;
}

.dpad-right {
  top: 50px;
  right: 0;
  width: 52px;
  height: 50px;
  border-radius: 0 10px 10px 0;
  border-left: none;
}

.dpad-center {
  position: absolute;
  top: 50px;
  left: 50px;
  width: 50px;
  height: 50px;
  background: rgba(30, 34, 42, 0.88);
}

.dpad-arm:active, .dpad-arm.pressed {
  background: rgba(255, 75, 43, 0.9);
  color: #fff;
}

/* ACTION BUTTONS (A & B) */
.action-cluster {
  right: max(20px, env(safe-area-inset-right, 20px));
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
  width: 140px;
  height: 140px;
}

.action-pair {
  position: relative;
  width: 100%;
  height: 100%;
}

.act-btn {
  position: absolute;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(40, 44, 52, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
  touch-action: none;
}

.act-btn:active, .act-btn.pressed {
  background: rgba(255, 75, 43, 0.9);
  border-color: #ff4b2b;
  transform: scale(0.95);
}

.act-b {
  bottom: 25px;
  left: 10px;
}

.act-a {
  top: 15px;
  right: 10px;
}

/* START / SELECT */
.meta-cluster {
  position: absolute;
  bottom: max(12px, env(safe-area-inset-bottom, 12px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
}

.meta-btn {
  background: rgba(30, 34, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #8b949e;
  font-size: 10px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
  cursor: pointer;
  touch-action: none;
}

.meta-btn:active, .meta-btn.pressed {
  background: rgba(255, 75, 43, 0.9);
  color: #fff;
  border-color: #ff4b2b;
}

/* EDIT BAR */
#edit-bar {
  position: fixed;
  top: max(12px, env(safe-area-inset-top, 12px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 99999;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(10, 12, 16, 0.95);
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid #ff6e40;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
  font-size: 0.82rem;
  color: #ff6e40;
  font-weight: 700;
}

.save-pos-btn {
  background: #238636;
  border: none;
  color: #fff;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.reset-pos-btn {
  background: #da3633;
  border: none;
  color: #fff;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
