:root {
  color-scheme: dark;
  --bg: #0d0e10;
  --surface: #17191d;
  --surface-2: #202329;
  --line: #30343c;
  --muted: #9ba1ad;
  --text: #f6f7f9;
  --accent: #e21d2f;
  --accent-soft: #43151c;
  --radius: 18px;
  font-family: Pretendard, "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 12px clamp(18px, 4vw, 64px);
  background: rgba(13, 14, 16, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: var(--accent);
  color: white;
  font-weight: 900;
  font-size: 24px;
  transform: skew(-6deg);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 20px;
  letter-spacing: -0.04em;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.15em;
}

.header-badge {
  color: #d7dae0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.header-badge span {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: #3cd87f;
  box-shadow: 0 0 12px rgba(60, 216, 127, 0.8);
}

.library-shell {
  width: min(1760px, 100%);
  margin: 0 auto;
  padding: 34px clamp(16px, 3vw, 54px) 64px;
}

.library-toolbar {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(260px, 460px) minmax(170px, 220px) auto auto auto;
  gap: 12px;
  align-items: end;
}

.system-filter {
  height: 48px;
}

.system-filter select {
  width: 100%;
  height: 100%;
  padding: 0 38px 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: 0;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.system-filter select:focus {
  border-color: #686e79;
  box-shadow: 0 0 0 3px rgba(104, 110, 121, 0.15);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.18em;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 3vw, 42px);
  letter-spacing: -0.055em;
}

.search-box {
  height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--muted);
}

.search-box:focus-within {
  border-color: #686e79;
  box-shadow: 0 0 0 3px rgba(104, 110, 121, 0.15);
}

.search-box span {
  font-size: 25px;
  line-height: 1;
}

.search-box input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.toolbar-button,
.card-actions button,
.title-editor button {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  cursor: pointer;
}

.toolbar-button {
  height: 48px;
  padding: 0 17px;
  font-weight: 800;
  white-space: nowrap;
}

.toolbar-button:hover,
.toolbar-button.active {
  border-color: #666d78;
  background: #292d34;
}

.toolbar-button.primary {
  border-color: var(--accent);
  background: var(--accent);
}

.toolbar-button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.library-summary {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin: 34px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.library-summary p {
  margin: 0;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 18px;
}

.game-grid[aria-busy="true"] {
  opacity: 0.55;
}

.game-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.22);
  transition: transform 160ms ease, border-color 160ms ease;
}

.game-card:hover {
  transform: translateY(-3px);
  border-color: #505661;
}

.cover-frame {
  position: relative;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  background: #0b0c0e;
}

.cover-frame > img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.cover-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  background: linear-gradient(145deg, #292d33, #101114 65%);
  color: #606671;
}

.cover-placeholder::before {
  content: "";
  width: 54px;
  height: 5px;
  margin: 0 auto 10px;
  border-radius: 99px;
  background: var(--accent);
}

.cover-placeholder span {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.2em;
}

.cover-placeholder strong {
  color: #c9cdd4;
  font-size: 44px;
  letter-spacing: -0.08em;
}

.platform-chip {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 4px 8px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  background: rgba(4, 5, 7, 0.78);
  font-size: 10px;
  font-weight: 800;
}

.favorite-button {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 50%;
  background: rgba(4, 5, 7, 0.76);
  color: #a9aeb7;
  font-size: 17px;
  cursor: pointer;
}

.favorite-button.active {
  color: #ffd552;
  border-color: rgba(255, 213, 82, 0.65);
}

.play-button {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-decoration: none;
}

.play-button span {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  padding-left: 4px;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 50%;
  background: rgba(226, 29, 47, 0.9);
  color: white;
  font-size: 21px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  transition: transform 150ms ease;
}

.play-button:hover span {
  transform: scale(1.08);
}

.card-body {
  padding: 14px;
}

.card-body h2 {
  overflow: hidden;
  margin: 0;
  color: #f7f8fa;
  font-size: 15px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.original-title {
  overflow: hidden;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metadata-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
}

.metadata-row span,
.title-editor > span {
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: #b8bdc6;
  font-size: 10px;
}

.metadata-row .bios-warning {
  border-color: #8d3b46;
  background: #38151b;
  color: #ff9eaa;
  font-weight: 800;
}

.title-editor {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.core-editor {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 7px;
  align-items: center;
  margin-top: 8px;
}

.parent-editor {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 7px;
  align-items: center;
  margin-top: 7px;
}

.parent-editor span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.parent-editor input {
  min-width: 0;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  background: #111317;
  color: var(--text);
  font-size: 10px;
}

.core-editor span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.core-editor select {
  min-width: 0;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  background: #111317;
  color: var(--text);
  font-size: 11px;
}

.title-editor input {
  min-width: 0;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  background: #111317;
  color: var(--text);
  font-size: 11px;
}

.title-editor input:focus {
  border-color: #737985;
}

.title-editor button {
  height: 34px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 800;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 8px;
}

.card-actions button {
  min-height: 36px;
  font-size: 11px;
  font-weight: 800;
}

.card-actions button:hover,
.title-editor button:hover {
  border-color: #656b75;
  background: #2b2f36;
}

.empty-state {
  margin-top: 40px;
  padding: 72px 24px;
  border: 1px dashed #3d424b;
  border-radius: 22px;
  text-align: center;
  background: #131519;
}

.empty-icon {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  margin: 0 auto 22px;
  border: 2px solid #555c67;
  border-radius: 20px;
  color: var(--accent);
  font-weight: 900;
}

.empty-state h2 {
  margin: 0 0 8px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.empty-state code {
  color: #d8dbe0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 1000;
  max-width: min(420px, calc(100vw - 32px));
  padding: 13px 18px;
  border: 1px solid #5c636e;
  border-radius: 12px;
  background: #252932;
  color: white;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  border-color: var(--accent);
  background: #39141a;
}

/* Player */
.player-page {
  min-height: 100dvh;
  overflow: hidden;
  background: #08090b;
}

.player-toolbar {
  min-height: 64px;
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 9px 16px;
  border-bottom: 1px solid #2d3138;
  background: #111318;
}

.back-button,
.player-actions button {
  min-height: 42px;
  display: inline-grid;
  place-items: center;
  padding: 0 15px;
  border: 1px solid #414751;
  border-radius: 13px;
  background: #1d2026;
  color: #edf0f4;
  text-decoration: none;
  font-weight: 800;
  cursor: pointer;
}

.player-title {
  min-width: 0;
}

.player-title strong,
.player-title span {
  overflow: hidden;
  display: block;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-title strong {
  font-size: 16px;
}

.player-title span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.player-actions {
  display: flex;
  gap: 8px;
}

.player-actions button:hover,
.back-button:hover {
  border-color: #747b87;
  background: #292d34;
}

.player-shell {
  position: relative;
  min-height: calc(100dvh - 64px);
  background: #050607;
}

#game {
  width: 100%;
  min-height: calc(100dvh - 64px);
}

.player-notice {
  position: absolute;
  top: 18px;
  left: 50%;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border: 1px solid #343944;
  border-radius: 11px;
  background: rgba(20, 22, 27, 0.92);
  color: #bdc2cb;
  font-size: 12px;
  text-align: center;
  transform: translateX(-50%);
  transition: opacity 180ms ease;
}

.player-notice.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 900ms infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.35; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1.15); }
}

@media (max-width: 1450px) {
  .game-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

@media (max-width: 1180px) {
  .library-toolbar { grid-template-columns: 1fr 1fr; }
  .game-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .player-toolbar { grid-template-columns: auto minmax(0, 1fr); }
  .player-actions { grid-column: 1 / -1; }
  .player-toolbar { min-height: 112px; }
  .player-shell,
  #game { min-height: calc(100dvh - 112px); }
}

@media (max-width: 860px) {
  .game-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
  .header-badge { display: none; }
  .library-toolbar { grid-template-columns: 1fr 1fr; }
  .library-toolbar > div:first-child,
  .search-box { grid-column: 1 / -1; }
  .system-filter { grid-column: 1 / -1; }
}

@media (max-width: 600px) {
  .site-header { min-height: 62px; padding: 9px 14px; }
  .brand-mark { width: 39px; height: 39px; }
  .library-shell { padding: 24px 10px 48px; }
  .library-toolbar { gap: 8px; }
  .toolbar-button { padding: 0 10px; font-size: 12px; }
  .library-summary { margin-top: 25px; }
  .library-summary p:last-child { display: none; }
  .game-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .game-card { border-radius: 13px; }
  .card-body { padding: 10px; }
  .card-body h2 { font-size: 13px; }
  .metadata-row { gap: 4px; margin: 9px 0; }
  .metadata-row span { font-size: 9px; }
  .title-editor { grid-template-columns: 1fr auto; }
  .title-editor > span { display: none; }
  .card-actions { grid-template-columns: 1fr; }
  .play-button span { width: 50px; height: 50px; }
  .player-toolbar { min-height: 101px; padding: 7px 9px; gap: 7px; }
  .back-button { min-height: 38px; padding: 0 12px; }
  .player-title strong { font-size: 13px; }
  .player-actions { gap: 5px; overflow-x: auto; }
  .player-actions button { min-height: 36px; padding: 0 10px; font-size: 11px; white-space: nowrap; }
  .player-shell,
  #game { min-height: calc(100dvh - 101px); }
}

@media (orientation: landscape) and (max-height: 620px) {
  .player-toolbar { min-height: 54px; display: flex; padding: 5px 8px; }
  .player-title span { display: none; }
  .player-actions { margin-left: auto; overflow: visible; }
  .player-actions button { min-height: 38px; padding: 0 11px; }
  .player-shell,
  #game { min-height: calc(100dvh - 54px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
