:root {
  --bg: #070912;
  --panel: rgba(15, 22, 38, 0.9);
  --card: rgba(19, 28, 48, 0.84);
  --card-hover: rgba(28, 40, 68, 0.95);
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.32);
  --text: #f8fafc;
  --text-soft: #cbd5e1;
  --muted: #94a3b8;
  --primary: #8b5cf6;
  --primary-hover: #7c3aed;
  --accent: #06b6d4;
  --success: #10b981;
  --danger: #f43f5e;
  --gold: #fbbf24;
  --radius: 14px;
}

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

html,
body {
  min-height: 100%;
  background-color: var(--bg);
  background-image:
    radial-gradient(860px 420px at 10% -5%, rgba(139, 92, 246, 0.18), transparent 60%),
    radial-gradient(760px 420px at 90% -5%, rgba(6, 182, 212, 0.15), transparent 60%);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* Auth Gate */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 410px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 30px 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.auth-logo {
  font-size: 42px;
  margin-bottom: 8px;
}

.auth-card h1 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.auth-sub {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
}

.notice {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(16, 185, 129, 0.14);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
  font-size: 12.5px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 20px 0 16px;
  background: rgba(7, 9, 18, 0.7);
  padding: 5px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.auth-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 9px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
}

.auth-tab.active {
  background: linear-gradient(135deg, var(--primary), #6366f1);
  color: #fff;
}

.auth-form,
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.auth-form label,
.form-stack label {
  font-size: 12px;
  color: var(--text-soft);
  margin-top: 4px;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="file"],
select {
  width: 100%;
  background: #080c17;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-msg {
  min-height: 20px;
  margin-top: 12px;
  font-size: 13px;
}

.auth-msg.err {
  color: var(--danger);
}

.auth-msg.ok {
  color: var(--success);
}

.auth-foot {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--muted);
}

/* Buttons */
.btn {
  border: none;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
  margin-top: 10px;
  padding: 11px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #6366f1);
  box-shadow: 0 6px 18px rgba(139, 92, 246, 0.35);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #a78bfa, var(--primary));
}

.btn-accent {
  background: linear-gradient(135deg, #06b6d4, #0284c7);
}

.btn-accent:hover:not(:disabled) {
  background: linear-gradient(135deg, #22d3ee, #0284c7);
}

.btn-ghost {
  background: rgba(30, 41, 59, 0.82);
  border: 1px solid var(--border-strong);
}

.btn-ghost:hover:not(:disabled) {
  background: #334155;
}

.btn-ghost.active {
  background: rgba(251, 191, 36, 0.18);
  border-color: rgba(251, 191, 36, 0.65);
  color: #fde68a;
}

.btn-danger {
  background: rgba(244, 63, 94, 0.2);
  border: 1px solid rgba(244, 63, 94, 0.55);
  color: #fda4af;
}

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}

/* Main App Shell */
.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px 18px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  padding: 14px 18px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
}

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

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.3), rgba(6, 182, 212, 0.3));
  border: 1px solid rgba(167, 139, 250, 0.4);
  display: grid;
  place-items: center;
  font-size: 24px;
}

.brand h1 {
  font-size: 19px;
  font-weight: 800;
}

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.stat-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(139, 92, 246, 0.18);
  border: 1px solid rgba(167, 139, 250, 0.35);
  color: #ddd6fe;
}

.stat-chip.muted {
  background: rgba(148, 163, 184, 0.1);
  border-color: var(--border);
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.user-pill {
  font-size: 12.5px;
  font-weight: 700;
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.14);
  border: 1px solid rgba(16, 185, 129, 0.38);
  color: #6ee7b7;
}

/* Search & Filters */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 240px;
}

.search-ico {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.search-box input {
  padding-left: 36px;
}

.filter-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.filter-controls select {
  width: auto;
}

.genre-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.genre-pill {
  border: 1px solid var(--border);
  background: rgba(15, 22, 38, 0.72);
  color: var(--text-soft);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.genre-pill:hover {
  border-color: var(--accent);
}

.genre-pill.active {
  background: rgba(6, 182, 212, 0.22);
  border-color: var(--accent);
  color: #67e8f9;
}

/* Game Grid */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.game-card {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.game-card:hover {
  transform: translateY(-3px);
  border-color: rgba(167, 139, 250, 0.65);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.42);
}

.game-card.is-hidden {
  opacity: 0.68;
  border-style: dashed;
}

.game-thumb {
  position: relative;
  height: 146px;
  background: linear-gradient(145deg, #0d1324, #1b1334);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.game-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 700;
}

.thumb-fallback span {
  font-size: 32px;
}

.badge-core {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 10.5px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(7, 9, 18, 0.82);
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: #7dd3fc;
}

.btn-fav {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(7, 9, 18, 0.78);
  color: #94a3b8;
  cursor: pointer;
  font-size: 15px;
}

.btn-fav.active {
  color: var(--gold);
  border-color: rgba(251, 191, 36, 0.65);
}

.game-info {
  padding: 13px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.game-title {
  font-size: 15.5px;
  font-weight: 800;
  line-height: 1.3;
  word-break: keep-all;
}

.game-sub {
  font-size: 12px;
  color: var(--muted);
}

.game-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 2px;
}

.g-tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-soft);
}

.g-tag-hidden {
  background: rgba(244, 63, 94, 0.16);
  color: #fda4af;
}

.game-actions {
  margin-top: auto;
  padding-top: 10px;
  display: flex;
  gap: 6px;
}

.game-actions .btn-play {
  flex: 1;
}

/* Empty Setup Guide */
.empty-guide {
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 32px 24px;
  text-align: center;
}

.empty-ico {
  font-size: 44px;
  margin-bottom: 10px;
}

.empty-guide h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.empty-guide p {
  font-size: 13.5px;
  color: var(--text-soft);
  max-width: 680px;
  margin: 0 auto 20px;
  line-height: 1.6;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  text-align: left;
}

.guide-box {
  background: rgba(7, 9, 18, 0.72);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.guide-box h3 {
  font-size: 14px;
  margin-bottom: 8px;
  color: #7dd3fc;
}

.guide-box ul {
  padding-left: 18px;
  font-size: 12.5px;
  color: var(--text-soft);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: rgba(139, 92, 246, 0.16);
  padding: 1px 5px;
  border-radius: 5px;
  color: #ddd6fe;
}

/* Modals & Player */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(3, 5, 11, 0.85);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 100;
}

.dialog-card {
  width: 100%;
  max-width: 440px;
  background: #0f172a;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 22px;
}

.dialog-wide {
  max-width: 600px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.dialog-head h2 {
  font-size: 17px;
}

.dialog-desc {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 14px;
}

.btn-close {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  cursor: pointer;
}

.check-row input {
  width: auto;
}

.users-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 380px;
  overflow-y: auto;
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(7, 9, 18, 0.72);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
}

.user-row-actions {
  display: flex;
  gap: 6px;
}

/* Player Dialog */
.player-dialog {
  width: 100%;
  max-width: 1120px;
  height: min(88vh, 780px);
  background: #05070e;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.player-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 14px;
  background: #0f172a;
  border-bottom: 1px solid var(--border);
}

.player-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.player-sub {
  font-size: 12px;
  color: #7dd3fc;
}

.player-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.key-hint {
  font-size: 11.5px;
  color: var(--muted);
}

.player-frame-wrap {
  flex: 1;
  position: relative;
  background: #000;
}

#player-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Inside /player iframe */
.player-body {
  background: #000;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
}

.game-stage,
#emu-root {
  width: 100%;
  height: 100%;
}

.player-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-soft);
  font-size: 14px;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(139, 92, 246, 0.25);
  border-top-color: #a78bfa;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid var(--accent);
  color: #e2e8f0;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

@media (max-width: 720px) {
  .key-hint {
    display: none;
  }
  .player-dialog {
    height: 92vh;
  }
}
