:root {
  --bg: #0c0c0f;
  --surface: #14141a;
  --border: #2a2a34;
  --text: #ececf1;
  --muted: #9898a8;
  --accent: #6d9cf8;
  --accent-dim: #4a7ad4;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.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;
}

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

.brand {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 50%, var(--accent-dim) 100%);
  box-shadow: 0 4px 20px rgba(109, 156, 248, 0.25);
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.doc-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  align-self: center;
}

.doc-link:hover {
  background: var(--surface);
  border-color: var(--accent-dim);
}

.main {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  gap: 1.25rem;
  flex: 1;
  align-items: start;
}

@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.controls {
  position: sticky;
  top: 1rem;
}

@media (max-width: 900px) {
  .controls {
    position: static;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.library-label-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.library-label-text {
  text-transform: inherit;
  letter-spacing: inherit;
}

.help-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  text-transform: none;
  letter-spacing: normal;
}

.help-tip-trigger {
  width: 1.15rem;
  height: 1.15rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  flex-shrink: 0;
}

.help-tip-trigger:hover,
.help-tip-trigger:focus-visible {
  color: var(--accent);
  border-color: var(--accent-dim);
  outline: none;
  box-shadow: 0 0 0 2px rgba(109, 156, 248, 0.25);
}

.help-tip-panel {
  display: none;
  position: absolute;
  left: 0;
  top: calc(100% + 0.45rem);
  z-index: 50;
  width: min(22rem, calc(100vw - 2.5rem));
  padding: 0.65rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.45;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.help-tip-panel code {
  font-size: 0.72rem;
  word-break: break-all;
}

.help-tip:hover .help-tip-panel,
.help-tip:focus-within .help-tip-panel {
  display: block !important;
  pointer-events: auto;
}

.input,
.file-input {
  font: inherit;
  color: var(--text);
}

.input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(109, 156, 248, 0.2);
}

select.input {
  cursor: pointer;
}

.rom-filter-input {
  margin-bottom: 0.35rem;
}

.rom-filter-input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.rom-library-select {
  max-width: 100%;
  text-overflow: ellipsis;
}

.byor-disclosure {
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
}

.byor-summary {
  list-style: none;
  cursor: pointer;
  padding: 0.65rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  user-select: none;
}

.byor-summary::-webkit-details-marker {
  display: none;
}

.byor-summary::before {
  content: "";
  display: inline-block;
  width: 0.45em;
  height: 0.45em;
  margin-right: 0.55em;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  vertical-align: 0.15em;
  transition: transform 0.15s ease;
}

.byor-disclosure[open] .byor-summary::before {
  transform: rotate(45deg);
  vertical-align: 0.05em;
}

.byor-summary:hover {
  background: rgba(109, 156, 248, 0.06);
}

.byor-body {
  padding: 0 0.85rem 0.85rem;
  border-top: 1px solid var(--border);
}

.byor-body .field {
  margin-bottom: 0.85rem;
}

.byor-body .field:last-child {
  margin-bottom: 0;
}

.rom-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.file-input {
  font-size: 0.85rem;
  max-width: 100%;
}

.file-hint {
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-all;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 1rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn {
  font: inherit;
  cursor: pointer;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  border: 1px solid transparent;
}

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

.btn.primary {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-dim) 100%);
  color: #0a0a0c;
  font-weight: 600;
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn.ghost:hover:not(:disabled) {
  background: var(--bg);
  border-color: var(--muted);
}

.status {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.25em;
}

.status.error {
  color: #f87171;
}

.player-wrap {
  min-height: 520px;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.player-title {
  margin: 0;
  padding: 0.85rem 1.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}

.player {
  flex: 1;
  width: 100%;
  min-height: 480px;
  border: 0;
  background: #070708;
}

.footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
}

.footer p {
  margin: 0;
}
