/* PS1 CloudDeck — App Styles */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #1f1f3a;
  --bg-hover: #252545;
  --foreground: #e8e8e8;
  --foreground-muted: #a0a0b0;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --accent-secondary: #7c5cff;
  --border: #2a2a45;
  --success: #00d68f;
  --warning: #ffb84d;
  --error: #ff5a5a;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'Cascadia Code', 'SF Mono', monospace;
}

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

html, body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--foreground);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 4px; }

h1, h2, h3, h4 { font-weight: 700; line-height: 1.3; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; }
p { margin-bottom: 0.75rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  height: 64px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--foreground);
}

.brand-emoji { font-size: 1.5rem; }

.nav-links { display: flex; gap: 0.25rem; }
.nav-link {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  color: var(--foreground-muted);
  font-weight: 500;
  transition: all 0.2s;
}
.nav-link:hover { background: var(--bg-hover); color: var(--foreground); }
.nav-link.active { background: var(--bg-card); color: var(--accent); }

.nav-actions { display: flex; gap: 0.5rem; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  flex: 1;
  width: 100%;
}

.view { display: none; }
.view.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.btn {
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--accent-secondary); color: #fff; }
.btn-secondary:hover { opacity: 0.9; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--foreground); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-block { width: 100%; }
.btn-lg { padding: 0.8rem 1.5rem; font-size: 1.1rem; }
.icon-btn {
  background: transparent;
  border: none;
  color: var(--foreground-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
}
.icon-btn:hover { color: var(--foreground); }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.game-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: all 0.2s;
  cursor: pointer;
}
.game-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.game-card img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  background: var(--bg-hover);
}
.game-card .card-body { padding: 0.75rem; }
.game-card .title { font-weight: 700; margin-bottom: 0.25rem; }
.game-card .meta { font-size: 0.85rem; color: var(--foreground-muted); }

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

.pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1.5rem; }
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }

.stats { display: flex; gap: 1rem; margin: 1.5rem 0; }
.stat-card {
  flex: 1;
  text-align: center;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat-value { display: block; font-size: 2rem; font-weight: 800; color: var(--accent); }
.stat-label { font-size: 0.85rem; color: var(--foreground-muted); }

.hero {
  text-align: center;
  padding: 2.5rem 0 1.5rem;
}
.hero h1 { font-size: 2.2rem; color: var(--foreground); }
.hero p { max-width: 600px; margin: 0.5rem auto 1.5rem; color: var(--foreground-muted); }
.hero-actions { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; }

.featured-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.featured-section h2 { text-align: center; margin-bottom: 1rem; }

.catalog-filters {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 1rem 0;
}
.search-input, .select-input {
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--foreground);
  font-size: 0.95rem;
  outline: none;
}
.search-input:focus, .select-input:focus { border-color: var(--accent); }
.select-input { flex: 1; min-width: 140px; }

.detail-back {
  display: inline-block;
  margin-bottom: 1rem;
  color: var(--foreground-muted);
  cursor: pointer;
}
.detail-card { display: flex; gap: 1.5rem; align-items: flex-start; }
.detail-card img { width: 280px; height: 280px; object-fit: cover; border-radius: var(--radius); background: var(--bg-hover); }
.detail-card .info { flex: 1; }
.detail-card .info h3 { margin-bottom: 0.5rem; }
.detail-card .info .meta { color: var(--foreground-muted); font-size: 0.9rem; margin-bottom: 1rem; }
.detail-card .info .desc { color: var(--foreground-muted); font-size: 0.95rem; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.auth-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}
.auth-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.auth-tab {
  padding: 0.5rem 1rem;
  border: none;
  background: transparent;
  color: var(--foreground-muted);
  cursor: pointer;
  font-weight: 600;
  border-bottom: 2px solid transparent;
}
.auth-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.auth-form { padding-top: 1rem; }
.auth-form h3 { margin-bottom: 1rem; }
.auth-form input {
  width: 100%;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--foreground);
  margin-bottom: 0.75rem;
  outline: none;
}
.auth-form input:focus { border-color: var(--accent); }
.error-msg { color: var(--error); font-size: 0.85rem; margin-top: 0.25rem; }

.qr-box {
  width: 100%;
  max-width: 320px;
  height: 320px;
  background: var(--bg-card);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0.75rem auto;
}
.qr-box canvas, .qr-box img { max-width: 100%; max-height: 300px; }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.modal-desc { font-size: 0.9rem; color: var(--foreground-muted); line-height: 1.7; }
.modal-actions { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1rem; }
.code-input {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--foreground);
  font-family: var(--mono);
  text-align: center;
}
.room-hosts { margin-top: 1rem; font-size: 0.9rem; color: var(--foreground-muted); }

.game-loader-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }

.global-loading {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--foreground-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

.empty-state { text-align: center; padding: 3rem; color: var(--foreground-muted); }

/* Controller page (HP) styles */
.controller-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: #000;
}
.controller-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
}
.controller-header .back-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}
.controller-header .back-btn:hover { color: #fff; opacity: 0.8; }
.controller-header .status { color: #00ff88; font-size: 0.9rem; }
.controller-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 1rem;
  background: #0a0a0a;
}
.controller-viewport canvas {
  max-width: 100%;
  max-height: 100%;
  border: 3px solid #333;
  border-radius: 8px;
  background: #000;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}
.controller-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  padding: 1rem;
  justify-content: center;
  flex-shrink: 0;
}
.controller-button {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid #fff;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
  touch-action: manipulation;
  user-select: none;
}
.controller-button:active { background: rgba(233, 69, 96, 0.85); }
.controller-button .label { font-size: 0.6rem; margin-top: 0.2rem; }

.controller-analog-indicators {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.6);
}
.analog-indicator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: #fff;
}
.analog-indicator .value {
  font-family: monospace;
  color: #00ff88;
  min-width: 40px;
}

.controller-host-row {
  flex-shrink: 0;
  padding: 0.75rem 1rem;
  background: rgba(0, 0, 0, 0.6);
  border-top: 1px solid #333;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}
.controller-hosts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}
.controller-host-chip {
  padding: 0.3rem 0.7rem;
  border-radius: 20px;
  border: 1px solid #555;
  background: #1a1a1a;
  font-size: 0.75rem;
  color: #fff;
}
.controller-host-chip.host { border-color: var(--accent); background: rgba(233, 69, 96, 0.2); }

.controller-bottom-bar {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.8);
  border-top: 1px solid #333;
}
.controller-bottom-bar .btn { font-size: 0.85rem; }

@media (pointer: coarse) {
  .controller-button { padding: 0.75rem; font-size: 1.2rem; }
}
@media (min-width: 1024px) {
  .controller-page { orientation: landscape; }
}
