:root {
  --bg: #1a1e1d;
  --bg-elevated: #232928;
  --bg-recessed: #161a19;
  --border: #333b39;
  --text: #eef2ef;
  --text-dim: #8a9a95;
  --accent: #6fd9ab;
  --accent-2: #4fb894;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", system-ui, -apple-system, sans-serif;
}

.mono {
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 28px;
  background: linear-gradient(180deg, #1c2120 0%, rgba(26, 30, 29, 0.94) 100%);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.5px;
  white-space: nowrap;
  cursor: pointer;
}

header h1 .logo-echo {
  color: var(--accent);
}

header h1 .logo-arcade {
  color: var(--text);
}

.tab-nav {
  display: flex;
  gap: 4px;
}

.tab-link {
  padding: 7px 14px;
  border-radius: 8px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  text-decoration: none;
  border: 1px solid transparent;
  transition: color 0.12s ease, border-color 0.12s ease;
}

.tab-link:hover {
  color: var(--text);
}

.tab-link.active {
  color: var(--accent);
  border-color: var(--border);
  background: var(--bg-recessed);
}

#search {
  flex: 1;
  max-width: 340px;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-recessed);
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
  font-size: 14px;
  transition: border-color 0.15s ease;
}

#search::placeholder {
  color: var(--text-dim);
}

#search:focus {
  outline: none;
  border-color: var(--accent);
}

#count {
  color: var(--text-dim);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
  white-space: nowrap;
  margin-left: auto;
}

main {
  padding: 32px 28px;
  max-width: 1400px;
  margin: 0 auto;
}

#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

/* ---- Text-only cards, no imagery ---- */

.card {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  padding: 18px 20px;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.card:hover,
.card:focus-visible {
  transform: translateY(-2px);
  border-color: var(--border);
  border-left-color: var(--accent);
  background: var(--bg-recessed);
}

.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card .title {
  font-family: "Space Grotesk", sans-serif;
  font-size: 15.5px;
  font-weight: 600;
  line-height: 1.35;
  margin: 0;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

#empty-state {
  text-align: center;
  padding: 90px 20px;
  color: var(--text-dim);
}

#empty-state code {
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

/* ---- ROM library: sections by system ---- */

.system-section {
  margin-bottom: 34px;
}

.system-heading {
  font-family: "Fraunces", serif;
  font-size: 19px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 14px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.system-heading::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 10px;
}

.webretro-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* ---- Buttons ---- */

.btn {
  padding: 9px 16px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--bg-recessed);
  color: var(--text);
  cursor: pointer;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  transition: border-color 0.12s ease, transform 0.08s ease;
}

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

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0f1a16;
  font-weight: 700;
}

.btn.primary:hover {
  border-color: var(--accent-2);
}

/* ---- Player overlay ---- */

#player-overlay {
  position: fixed;
  inset: 0;
  background: #0c0f0e;
  z-index: 100;
  display: none;
  flex-direction: column;
}

#player-overlay.open {
  display: flex;
}

#player-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

#player-bar h2 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: 17px;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#player-stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: radial-gradient(ellipse at center, #1a201e 0%, #0a0d0c 100%);
}

#player-stage ruffle-player {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
}

footer {
  text-align: center;
  padding: 34px 20px 54px;
  color: var(--text-dim);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11.5px;
  letter-spacing: 0.3px;
}

footer a {
  color: var(--accent);
}

/* ---- Saves modal ---- */

#saves-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 13, 12, 0.72);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}

#saves-overlay.open {
  display: flex;
}

#saves-modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  max-width: 440px;
  width: 90%;
}

#saves-modal h2 {
  margin-top: 0;
  font-family: "Fraunces", serif;
  font-size: 21px;
  font-weight: 600;
}

#saves-modal .hint {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.55;
}

.saves-row {
  display: flex;
  gap: 10px;
  margin: 18px 0;
}

.saves-row .btn {
  flex: 1;
}

#saves-modal #close-saves-modal {
  margin-top: 10px;
  width: 100%;
}

#toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 12px 22px;
  border-radius: var(--radius);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

#toast.show {
  opacity: 1;
}
