:root {
  color-scheme: dark;
  --bg: #080a12;
  --panel: #10131d;
  --top: #1d2030;
  --raised: #282c40;
  --line: #2b3040;
  --text: #f4f5fb;
  --muted: #9da4b7;
  --purple: #7c5cff;
  --purple-soft: #9990ff;
  --mint: #80e7c7;
  font-family: Inter, Pretendard, "Noto Sans KR", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  scroll-behavior: smooth;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 320px; background: var(--bg); }
body { min-height: 100vh; }
button, input, select { font: inherit; }
a { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.topbar {
  position: sticky; top: 0; z-index: 30; height: 72px; display: grid;
  grid-template-columns: 38px 170px minmax(260px, 520px) 1fr; align-items: center;
  gap: 14px; padding: 0 22px; background: var(--top); border-bottom: 1px solid #24283a;
}
.menu-button { width: 32px; height: 32px; border: 0; background: transparent; display: grid; align-content: center; gap: 5px; cursor: pointer; }
.menu-button span { display: block; width: 21px; height: 2px; background: #dfe2ef; }
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; font-size: .95rem; letter-spacing: -.02em; }
.brand-mark { width: 29px; height: 29px; border: 3px solid var(--text); border-radius: 50%; position: relative; }
.brand-mark::after { content: ""; position: absolute; width: 7px; height: 7px; right: -4px; top: 1px; background: var(--purple); border: 2px solid var(--top); border-radius: 50%; }
.brand-mark i { position: absolute; left: 6px; top: 7px; width: 11px; height: 8px; border: 2px solid var(--text); border-top: 0; }
.global-search { width: min(100%, 520px); height: 44px; justify-self: center; display: flex; align-items: center; padding: 0 17px; border-radius: 24px; background: #35394f; color: #c5cad9; }
.global-search input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-weight: 700; }
.global-search input::placeholder { color: #aeb4c7; }
.global-search > span:last-child { font-size: 1.6rem; transform: rotate(-20deg); }
.top-actions { justify-self: end; display: flex; align-items: center; gap: 10px; }
.language-picker select { min-width: 100px; padding: 9px 30px 9px 12px; color: var(--text); background: var(--raised); border: 1px solid #42475d; border-radius: 20px; cursor: pointer; }
.local-pill { padding: 10px 14px; border-radius: 20px; background: var(--purple); font-size: .75rem; font-weight: 900; letter-spacing: .06em; }

.app-layout { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: calc(100vh - 72px); }
.sidebar { position: sticky; top: 72px; height: calc(100vh - 72px); padding: 17px 15px; background: #0b0d15; border-right: 1px solid var(--line); overflow-y: auto; }
.sidebar nav { display: grid; gap: 2px; }
.sidebar a { display: flex; align-items: center; gap: 13px; min-height: 36px; padding: 7px 9px; border-radius: 8px; text-decoration: none; font-size: .9rem; }
.sidebar a span { width: 22px; color: var(--purple-soft); text-align: center; font-size: 1.05rem; }
.sidebar a:hover, .sidebar a.active { background: #202437; color: #fff; }
.nav-divider { height: 1px; margin: 12px 4px; background: var(--line); }
.sidebar-stats { margin: 18px 8px 0; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: .7rem; }
.sidebar-stats strong { display: block; margin-top: 4px; color: var(--mint); font: 700 .9rem monospace; }

main { min-width: 0; overflow: hidden; }
.archive { min-height: calc(100vh - 72px); padding: 18px clamp(20px, 4vw, 76px) 72px; }
.breadcrumbs { margin: 0 0 9px; color: var(--purple-soft); font-size: .78rem; font-weight: 800; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 22px; }
h1 { margin: 0; font-size: clamp(2rem, 3vw, 3.25rem); line-height: 1.05; letter-spacing: -.05em; }
.page-heading p { margin: 10px 0 0; color: var(--muted); font-size: .88rem; }
.collection-tabs { display: flex; flex-wrap: wrap; justify-content: end; gap: 7px; }
.collection-tabs button, .filter-row button { padding: 9px 14px; border: 1px solid #3b4053; border-radius: 9px; background: #12151f; color: #c9cede; cursor: pointer; font-size: .78rem; font-weight: 800; }
.collection-tabs button:hover, .filter-row button:hover, .collection-tabs button.active, .filter-row button.active { border-color: var(--purple); background: var(--purple); color: white; }
.collection-tabs span { margin-left: 4px; font: .72rem monospace; }
.catalog-notice { margin: 0 0 14px; padding: 12px 14px; border: 1px solid #3d3a58; border-radius: 8px; background: #242238; color: #d6d2ff; font-size: .82rem; }
.filter-row { display: flex; gap: 7px; margin: 0 0 15px; padding-bottom: 5px; overflow-x: auto; scrollbar-width: thin; }
.filter-row button { white-space: nowrap; }
.result-summary { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; color: var(--muted); font-size: .76rem; }
.result-summary p { margin: 0; }
.result-summary b { margin-right: 3px; color: var(--text); }

.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 22px 15px; }
.game-card { min-width: 0; position: relative; }
.game-card .game-cover { display: block; width: 100%; position: relative; aspect-ratio: 16 / 9; padding: 0; overflow: hidden; border: 0; border-radius: 13px; background: #1c2030; color: white; cursor: pointer; box-shadow: 0 1px 0 rgba(255,255,255,.05); }
.game-card .game-cover:disabled { cursor: default; }
.game-card .game-cover img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .24s ease, filter .24s ease; }
.game-card:hover .game-cover img { transform: scale(1.035); filter: brightness(.82); }
.game-card .play-button { position: absolute; right: 12px; bottom: 12px; display: grid; place-items: center; width: 40px; height: 40px; padding-left: 3px; border-radius: 50%; background: var(--purple); color: white; font-size: .88rem; opacity: 0; transform: translateY(5px); transition: .2s ease; box-shadow: 0 7px 20px rgba(0,0,0,.38); }
.game-card:hover .play-button { opacity: 1; transform: none; }
.game-card .status { position: absolute; left: 9px; top: 9px; padding: 5px 8px; border-radius: 7px; background: rgba(7,9,15,.85); color: #fff; font-size: .62rem; font-weight: 900; letter-spacing: .04em; }
.game-card .status.downloaded, .game-card .status.local-test { background: #1b9d7a; }
.game-card .status.embedded { background: var(--purple); }
.game-card .status.external { background: rgba(7,9,15,.85); }
.game-card .game-info { display: flex; justify-content: space-between; gap: 8px; margin: 8px 2px 0; }
.game-card .game-info > div { min-width: 0; }
.game-card .game-info p { margin: 0 0 3px; overflow: hidden; color: #858ca0; font-size: .65rem; text-overflow: ellipsis; white-space: nowrap; }
.game-card h3 { margin: 0; overflow: hidden; color: #f3f4f8; font-size: .93rem; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.game-card .year { flex: none; color: #777f94; font: .62rem monospace; }
.game-card .controls { display: none; }
.game-diagnosis { margin: 8px 2px 0; color: #c4ccdc; font-size: .75rem; line-height: 1.5; }
.game-diagnosis summary { cursor: pointer; color: #d9b575; }
.game-diagnosis summary:focus-visible { outline: 2px solid var(--purple); outline-offset: 3px; }
.game-diagnosis p { margin: 6px 0 0; overflow-wrap: anywhere; }
.empty-state { padding: 70px 20px; border: 1px dashed #363b4d; border-radius: 12px; color: var(--muted); text-align: center; }
.empty-state strong, .empty-state span { display: block; margin: 4px; }
.pagination { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 38px; }
.pagination button { min-width: 36px; height: 36px; border: 1px solid #3a3f50; border-radius: 8px; background: #141722; color: #d4d7e2; cursor: pointer; }
.pagination button.active { background: var(--purple); border-color: var(--purple); color: white; }
.about { display: flex; gap: 20px; align-items: center; padding: 24px clamp(20px, 4vw, 76px); border-top: 1px solid var(--line); color: var(--muted); font-size: .76rem; }
.about strong { color: var(--text); }
.about p { margin: 0; }

dialog { width: min(1000px, calc(100vw - 30px)); max-height: calc(100vh - 30px); padding: 0; border: 1px solid #394052; background: #090c12; color: var(--text); overflow: auto; }
dialog::backdrop { background: rgba(5,8,13,.9); backdrop-filter: blur(9px); }
.player-shell > header { display: flex; justify-content: space-between; align-items: center; min-height: 66px; padding: 10px 14px; border-bottom: 1px solid #333949; background: #0d1119; }
.player-shell > header > div:first-child { display: flex; align-items: center; gap: 10px; }
.player-shell header p { margin: 0; color: var(--mint); font: 700 .6rem monospace; letter-spacing: .08em; }
.player-shell header h2 { margin: 2px 0 0; font-size: .95rem; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: #ef6d59; box-shadow: 0 0 0 5px rgba(239,109,89,.16); }
.player-actions { display: flex; gap: 8px; }
.player-actions button { height: 40px; min-width: 40px; border: 1px solid #41495d; background: #111621; color: white; cursor: pointer; }
#close-player { font-size: 2rem; line-height: 1; }
.player-stage { min-height: min(66vh, 650px); display: grid; place-items: center; background: #000; overflow: hidden; }
.player-stage iframe, .player-stage ruffle-player, .player-stage object { display: block; width: 100%; height: min(66vh, 650px); border: 0; }
.player-ad-slot { height: 68px; display: grid; place-items: center; color: #6e7482; border-top: 1px solid #282e3b; border-bottom: 1px solid #282e3b; font: 700 .7rem monospace; letter-spacing: .16em; }
.online-help { margin: 0; padding: 8px 14px; color: #b0b6c5; font-size: .7rem; }
.player-meta { display: flex; justify-content: space-between; gap: 15px; padding: 12px 14px; color: #999faf; font-size: .7rem; }
.player-meta p { margin: 0; }
.minimal-player #fullscreen-player, .minimal-player .online-help, .minimal-player .player-meta { display: none !important; }
.player-runtime-warning { margin: 0; padding: 10px 14px; color: #e2c78f; font-size: .8rem; line-height: 1.5; overflow-wrap: anywhere; }
.player-runtime-warning[hidden] { display: none; }

@media (min-width: 1500px) { .game-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .topbar { grid-template-columns: 38px 135px minmax(180px, 1fr) auto; padding: 0 12px; }
  .local-pill { display: none; }
  .app-layout { grid-template-columns: 174px minmax(0, 1fr); }
  .sidebar { padding-inline: 9px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .collection-tabs { justify-content: flex-start; }
}
@media (max-width: 680px) {
  .topbar { height: auto; min-height: 62px; grid-template-columns: 32px 1fr auto; gap: 8px; padding: 8px 10px; }
  .brand strong { font-size: .8rem; }
  .global-search { grid-column: 1 / -1; grid-row: 2; height: 40px; }
  .language-picker select { min-width: 84px; padding: 7px; }
  .app-layout { display: block; }
  .sidebar { position: sticky; top: 110px; z-index: 20; width: 100%; height: auto; padding: 7px 10px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .sidebar nav { display: flex; min-width: max-content; }
  .sidebar a { min-height: 34px; padding: 6px 10px; }
  .sidebar a span, .genre-nav, .nav-divider, .sidebar-stats { display: none; }
  .archive { padding: 20px 12px 55px; }
  .page-heading p { font-size: .78rem; }
  .game-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 9px; }
  .game-card h3 { font-size: .8rem; }
  .game-card .card-meta { font-size: .6rem; }
  .result-summary { align-items: flex-start; gap: 10px; }
  .result-summary p:last-child { text-align: right; }
  .about { display: block; }
  .about p { margin-top: 6px; }
  dialog { width: 100vw; max-height: 100vh; border: 0; }
}
