:root {
  --color-bg: #0a0a0a;
  --color-surface: #141414;
  --color-surface-hover: #1a1a1a;
  --color-border: #2a2a2a;
  --color-text: #fafafa;
  --color-accent: #888888;
  --color-success: #4ade80;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  --radius: 16px;
  --radius-sm: 8px;
}

:root.light {
  --color-bg: #ffffff;
  --color-surface: #f5f5f5;
  --color-surface-hover: #ebebeb;
  --color-border: #e0e0e0;
  --color-text: #1a1a1a;
  --color-accent: #666666;
}

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

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

svg {
  display: block;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.steam-mark {
  fill: currentColor;
  stroke: none;
}

.steam-mark path {
  fill: currentColor;
  stroke: none;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  background:
    radial-gradient(circle at 80% 0%, color-mix(in srgb, var(--color-surface-hover) 60%, transparent), transparent 26rem),
    var(--color-bg);
}

.sidebar {
  position: sticky;
  top: 0;
  width: 60px;
  height: 100vh;
  height: 100dvh;
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
  background: var(--color-bg);
  flex-shrink: 0;
}

.logo,
.mobile-logo {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--color-accent);
}

.logo {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  font-size: 1.25rem;
  transition: background .15s ease, color .15s ease;
}

.logo:hover,
.icon-btn:hover,
.icon-btn.active {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

.nav-stack {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-accent);
  transition: background .15s ease, color .15s ease;
}

.page-content {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 2rem;
}

.mobile-header {
  display: none;
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

.hero {
  min-height: 190px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 2.5rem;
}

.section-label,
.category-title,
.count-pill,
dt,
.status-pill {
  font-family: var(--font-mono);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--color-accent);
}

h1 {
  margin-top: .35rem;
  font-family: var(--font-mono);
  font-size: clamp(2.7rem, 7vw, 5.2rem);
  font-weight: 650;
  letter-spacing: 0;
  line-height: .95;
}

.tagline {
  margin-top: .75rem;
  color: var(--color-accent);
  font-size: .95rem;
}

.logout-btn,
.primary-btn,
.download-link,
.store-link,
.unlock-btn,
.history-download,
.history-store {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 9999px;
  font-weight: 650;
  transition: opacity .15s ease, transform .15s ease, border-color .15s ease, background .15s ease, color .15s ease;
}

.logout-btn {
  background: var(--color-surface);
  color: var(--color-accent);
  border: 1px solid var(--color-border);
  padding: 0 1rem;
  font-family: var(--font-mono);
  font-size: .78rem;
}

.logout-btn:hover {
  color: var(--color-text);
  border-color: var(--color-accent);
}

.category-section {
  width: 100%;
  margin-bottom: 2rem;
}

.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 1rem;
}

.count-pill {
  border: 1px solid var(--color-border);
  border-radius: 9999px;
  background: var(--color-surface);
  padding: .35rem .7rem;
  letter-spacing: .05em;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.game-card {
  position: relative;
  min-height: 286px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 1.35rem;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}

.game-card.has-game-image::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  z-index: 0;
  height: 9rem;
  background-image:
    linear-gradient(to bottom, rgb(20 20 20 / .08), rgb(20 20 20 / .46) 48%, var(--color-surface) 100%),
    linear-gradient(to right, rgb(20 20 20 / .55), transparent 65%),
    var(--game-image);
  background-position: center top;
  background-repeat: no-repeat;
  background-size: cover;
  opacity: .74;
  transition: opacity .18s ease, transform .18s ease;
}

:root.light .game-card.has-game-image::before {
  background-image:
    linear-gradient(to bottom, rgb(245 245 245 / .05), rgb(245 245 245 / .42) 48%, var(--color-surface) 100%),
    linear-gradient(to right, rgb(245 245 245 / .62), transparent 70%),
    var(--game-image);
  opacity: .68;
}

.game-card.has-game-image:hover::before {
  opacity: .86;
  transform: scale(1.02);
}

.game-card > * {
  position: relative;
  z-index: 1;
}

.game-card:hover {
  transform: translateY(-2px);
  border-color: var(--color-text);
  background: var(--color-surface-hover);
}

.game-topline {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: .75rem;
  margin-bottom: 1rem;
}

.status-pill {
  max-width: 8rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: .22rem .45rem;
  background: var(--color-bg);
  backdrop-filter: blur(8px);
  letter-spacing: .05em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-pill.ready {
  color: var(--color-success);
  border-color: color-mix(in srgb, var(--color-success) 50%, var(--color-border));
}

.game-card h3 {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 650;
  margin-bottom: .45rem;
}

.game-description {
  color: var(--color-accent);
  font-size: .83rem;
  line-height: 1.45;
}

.game-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  margin-top: auto;
  padding-top: 1.4rem;
}

.game-meta div {
  min-width: 0;
}

dt {
  margin-bottom: .25rem;
  letter-spacing: .07em;
}

dd {
  font-family: var(--font-mono);
  color: var(--color-text);
  font-size: .82rem;
  overflow-wrap: anywhere;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr 38px;
  gap: .5rem;
  margin-top: 1rem;
}

.download-link,
.primary-btn {
  gap: .45rem;
  background: var(--color-text);
  color: var(--color-bg);
  padding: 0 1rem;
}

.download-link:hover,
.primary-btn:hover,
.unlock-btn:hover {
  opacity: .88;
}

.download-link svg,
.primary-btn svg {
  color: var(--color-bg);
}

.store-link {
  width: 38px;
  padding: 0;
  background: var(--color-surface-hover);
  border: 1px solid var(--color-border);
  color: var(--color-accent);
  font-size: 0;
}

.store-link:hover {
  color: var(--color-text);
  border-color: var(--color-accent);
}

.history-panel {
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-surface);
  padding: 1.25rem;
  margin-bottom: 2rem;
}

.history-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.history-copy {
  margin-top: .35rem;
  color: var(--color-accent);
  font-size: .84rem;
  line-height: 1.5;
}

.search-box {
  width: min(100%, 280px);
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: .55rem;
  border: 1px solid var(--color-border);
  border-radius: 9999px;
  background: var(--color-bg);
  color: var(--color-accent);
  padding: 0 .85rem;
  transition: border-color .15s ease, color .15s ease;
}

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

.search-box svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: .8rem;
}

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

.history-list {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.history-item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, .45fr) auto;
  align-items: center;
  gap: 1rem;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-bg);
  padding: .9rem;
  overflow: hidden;
  transition: background .15s ease, border-color .15s ease;
}

.history-item.has-game-image::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image:
    linear-gradient(to left, var(--color-bg) 20%, transparent 100%),
    var(--game-image);
  background-position: left center;
  background-repeat: no-repeat;
  background-size: auto 100%;
  opacity: .45;
  transition: opacity .15s ease;
}

:root.light .history-item.has-game-image::before {
  background-image:
    linear-gradient(to left, var(--color-bg) 20%, transparent 100%),
    var(--game-image);
  opacity: .32;
}

.history-item.has-game-image:hover::before {
  opacity: .52;
}

.history-item > * {
  position: relative;
  z-index: 1;
}

.history-item:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-accent);
}

.history-main {
  min-width: 0;
}

.history-main h3 {
  margin-bottom: .25rem;
  font-family: var(--font-mono);
  font-size: .92rem;
  font-weight: 650;
  color: var(--color-text);
}

.history-main p {
  color: var(--color-accent);
  font-size: .8rem;
  line-height: 1.4;
}

.history-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  min-width: 0;
}

.history-actions {
  display: flex;
  gap: .5rem;
}

.history-download,
.history-store {
  width: 38px;
  min-height: 38px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-accent);
}

.history-download:hover,
.history-store:hover {
  color: var(--color-text);
  border-color: var(--color-accent);
  background: var(--color-surface-hover);
}

.empty-state {
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-bg);
  color: var(--color-accent);
  font-family: var(--font-mono);
  font-size: .85rem;
  padding: 1rem;
  text-align: center;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.admin-form,
.admin-list-panel {
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-surface);
  padding: 1.25rem;
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: .85rem;
}

.form-header,
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}

.form-header h2 {
  margin-bottom: .25rem;
  font-family: var(--font-mono);
  font-size: 1rem;
}

.form-header p {
  color: var(--color-accent);
  font-size: .8rem;
}

.admin-auth-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.admin-auth-screen .auth-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 320px;
  margin: 0 auto;
  gap: 1rem;
}

.admin-auth-screen .auth-box input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-family: var(--font-mono);
}

.admin-auth-screen .auth-box .primary-btn {
  width: 100%;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .35rem;
  font-size: .75rem;
  font-family: var(--font-mono);
  color: var(--color-accent);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-accent);
  opacity: .5;
}

.connection-status.online .status-dot {
  background: var(--color-success);
  box-shadow: 0 0 8px var(--color-success);
  opacity: 1;
}

.connection-status.online .status-text {
  color: var(--color-text);
}

.connection-status.offline .status-dot {
  background: var(--color-error);
  opacity: 1;
}

/* Loading States */
.loading-container {
  position: relative;
  min-height: 200px;
}

.loader-overlay {
  position: absolute;
  inset: 0;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 10;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.loader-overlay[hidden] {
  display: none;
  opacity: 0;
  visibility: hidden;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-surface);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.input-with-action {
  display: flex;
  gap: .5rem;
}

.input-with-action input {
  flex: 1;
}

.admin-form label {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.admin-form label span {
  color: var(--color-accent);
  font-family: var(--font-mono);
  font-size: .68rem;
  font-weight: 650;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.admin-form input,
.admin-form select,
.admin-form textarea {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  outline: 0;
  background: var(--color-bg);
  color: var(--color-text);
  padding: .7rem .8rem;
  font-size: .85rem;
}

.admin-form textarea {
  min-height: 82px;
  resize: vertical;
  line-height: 1.45;
}

.admin-form input:focus,
.admin-form select:focus,
.admin-form textarea:focus {
  border-color: var(--color-accent);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem;
}

.primary-action,
.ghost-btn {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  padding: 0 .9rem;
  font-family: var(--font-mono);
  font-size: .76rem;
  font-weight: 650;
  transition: border-color .15s ease, background .15s ease, color .15s ease, opacity .15s ease;
}

.primary-action {
  border: 1px solid var(--color-text);
  background: var(--color-text);
  color: var(--color-bg);
}

.primary-action:hover {
  opacity: .88;
}

.ghost-btn {
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-accent);
}

.ghost-btn:hover {
  border-color: var(--color-accent);
  color: var(--color-text);
}

.ghost-btn.danger:hover {
  border-color: #ff6b6b;
  color: #ff6b6b;
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, .4fr) auto;
  align-items: center;
  gap: 1rem;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-bg);
  padding: .9rem;
}

.admin-row-main {
  min-width: 0;
}

.mode-pill {
  display: inline-flex;
  margin-bottom: .45rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  color: var(--color-accent);
  font-family: var(--font-mono);
  font-size: .64rem;
  font-weight: 650;
  letter-spacing: .06em;
  padding: .18rem .4rem;
  text-transform: uppercase;
}

.admin-row h3 {
  margin-bottom: .25rem;
  font-family: var(--font-mono);
  font-size: .92rem;
}

.admin-row p {
  color: var(--color-accent);
  font-size: .78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-row-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}

.admin-row-actions {
  display: flex;
  gap: .5rem;
}

.password-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgb(0 0 0 / .86);
  backdrop-filter: blur(12px);
}

:root.light .password-overlay {
  background: rgb(255 255 255 / .86);
}

.app-shell[data-locked="false"] .password-overlay {
  display: none;
}

.app-shell[data-locked="true"] .page-content {
  filter: blur(10px);
  pointer-events: none;
  user-select: none;
}

.password-modal {
  width: min(calc(100vw - 2rem), 400px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-surface);
  padding: 2.4rem;
  text-align: center;
  box-shadow: 0 25px 50px -12px rgb(0 0 0 / .5);
}

.lock-icon {
  width: 34px;
  height: 34px;
  color: var(--color-text);
}

.password-modal h2 {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 650;
}

.password-modal p {
  color: var(--color-accent);
  font-size: .88rem;
}

.input-wrapper {
  position: relative;
  width: 100%;
}

.input-wrapper input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  outline: none;
  background: var(--color-bg);
  color: var(--color-text);
  padding: .85rem 3rem .85rem 1rem;
  text-align: center;
  font-size: 1rem;
}

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

.toggle-visibility {
  position: absolute;
  top: 50%;
  right: .9rem;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--color-accent);
}

.toggle-visibility:hover {
  color: var(--color-text);
}

.unlock-btn {
  min-width: 130px;
  background: var(--color-text);
  color: var(--color-bg);
  padding: 0 1.5rem;
}

.error-msg {
  min-height: 1.2rem;
  color: #ff6b6b !important;
}

.password-modal.shake {
  animation: shake .45s ease-in-out;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }

  20%,
  60% {
    transform: translateX(-8px);
  }

  40%,
  80% {
    transform: translateX(8px);
  }
}

@media (max-width: 820px) {
  .sidebar {
    display: none;
  }

  .page-content {
    padding: 1rem;
  }

  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    margin-bottom: 1rem;
  }

  .mobile-logo {
    font-size: .95rem;
  }

  .hero {
    min-height: 140px;
    padding-bottom: 1.75rem;
  }

  .history-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .search-box {
    width: 100%;
  }

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .admin-row {
    grid-template-columns: 1fr;
  }

  .admin-row-actions {
    width: 100%;
  }

  .admin-row-actions .ghost-btn {
    flex: 1;
  }

  .games-grid {
    grid-template-columns: 1fr;
  }

  .history-item {
    grid-template-columns: 38px minmax(0, 1fr);
    align-items: flex-start;
  }

  .history-meta,
  .history-actions {
    grid-column: 2;
  }

  .history-actions {
    width: 100%;
  }

  .history-download,
  .history-store {
    flex: 1;
  }
}

@media (min-width: 821px) and (max-width: 1120px) {
  .games-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .password-modal {
    width: min(calc(100vw - 2rem), 320px);
  }
}

@media (max-width: 420px) {
  .hero {
    align-items: flex-start;
    flex-direction: column;
    justify-content: flex-end;
  }

  .logout-btn {
    width: 100%;
  }

  .category-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .history-item {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-header,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .history-meta,
  .history-actions {
    grid-column: 1;
  }

  .password-modal {
    width: min(calc(100vw - 2rem), 320px);
    padding: 1.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
