/* Basic Engine Hub — browser menu theme.
   Mirrors the desktop palette from hub/theme.qss: dark background #101216,
   card surface #181c22, accent #ff8c42, hover glow on cards. */

:root {
  color-scheme: dark;
  --bg: #101216;
  --surface: #181c22;
  --surface-raised: #1f242c;
  --surface-hover: #1b2027;
  --border: #2b2f36;
  --border-hover: #3a4754;
  --accent: #ff8c42;
  --accent-hover: #ffa05e;
  --accent-pressed: #e6792e;
  --text: #e8e8e8;
  --text-strong: #f2f2f2;
  --text-muted: #9aa0a8;
  --text-dim: #6a7077;
  --font: "Inter", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
}

body.player-open { overflow: hidden; }

.hidden { display: none !important; }

/* Header ------------------------------------------------------------------ */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid #262a30;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.app-logo {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(255, 140, 66, 0.25);
}

.app-title {
  margin: 0;
  font-size: clamp(1.1rem, 2vw, 1.6rem);
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.header-actions .search { min-width: 160px; }

.search {
  flex: 1 1 220px;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
}

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

/* Language selector (header) -------------------------------------------------- */

.language-select {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}

.language-select:hover { border-color: var(--border-hover); }
.language-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Buttons (mirror QPushButton styles) --------------------------------------- */

.btn {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.btn:hover { background: #262c36; border-color: var(--border-hover); }
.btn:active { background: #181c22; }
.btn:disabled { color: var(--text-dim); background: var(--surface); border-color: #23272d; cursor: default; }
.btn:focus-visible, .card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Primary button (mirrors QPushButton[role="primary"]) ---------------------- */

.btn-primary { background: var(--accent); color: #141414; border: 0; font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { background: var(--accent-pressed); }

/* Status line ---------------------------------------------------------------- */

.status {
  margin: 0;
  padding: 8px 16px 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* Card grid (the scrolling area, like the desktop QScrollArea) --------------- */

.grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  grid-auto-rows: max-content;
  gap: 12px;
  padding: 12px 16px 24px;
  align-content: start;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

/* Project card (mirrors ProjectCard: border-radius 12, hover accent) --------- */

.card {
  display: flex;
  flex-direction: column;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  overflow: hidden;
  text-align: left;
  font-family: inherit;
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.card:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 4px 14px rgba(0, 0, 0, 0.35);
}

/* Hero image: project thumbnail with placeholder surface when missing --------- */

.hero {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  /* Placeholder art stands in while the thumbnail loads and stays when it never
   * arrives. It is a CSS background rather than a second <img>, so a slow or
   * failed request needs no JavaScript. "../Assets" resolves to /Assets/ under
   * both hosting layouts. */
  background: var(--surface-raised) url("../Assets/Placeholders/thumbnail.png")
              center / cover no-repeat;
}

.favorite-mark {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: #ffd75e;
}

/* Featured card (mirrors ProjectCard[featured="true"] in hub/theme.qss) ------ */

.card.featured {
  border: 2px solid #ffd700;
  background: #1c1a10;
}

.card.featured:hover {
  border-color: #ffb300;
}

.featured-badge {
  font-size: 11px;
  font-weight: 600;
  color: #ffd700;
}

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

/* Avatar badge overlaid on top of the hero image ------------------------------ */

.avatar {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  /* Same deal as .hero: the profile placeholder shows until the real avatar
   * paints, and remains if the request fails. */
  background: var(--surface-raised) url("../Assets/Placeholders/profile.png")
              center / cover no-repeat;
  object-fit: cover;
}

/* Card info: title and @username (mirror #cardTitle / #cardMeta) --------------- */

.info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px 10px;
}

.title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Error box -------------------------------------------------------------------- */

.error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 48px 16px;
  text-align: center;
}

.error-text {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
}

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

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.overlay-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

#player {
  flex: 1;
  width: 100%;
  border: 0;
  background: #000;
}

.detail-dialog, .variables-dialog, .auth-dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: min(86vh, 900px);
  padding: 16px;
  overflow: auto;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.detail-dialog::backdrop, .variables-dialog::backdrop, .auth-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.dialog-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 240px) minmax(0, 1fr);
  gap: 16px;
}

.detail-cover {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  background: var(--surface-raised) url("../Assets/Placeholders/thumbnail.png")
              center / cover no-repeat;
}

.detail-main h2, .variables-dialog h2 {
  margin: 0 0 6px;
  font-size: 20px;
  overflow-wrap: anywhere;
}

.detail-author { color: var(--accent); }
.detail-stats, .detail-muted { color: var(--text-muted); font-size: 13px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.detail-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.detail-section h3 { margin: 0 0 5px; font-size: 13px; color: var(--text-muted); }
.detail-section p { margin: 0 0 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.comments-list { display: grid; gap: 8px; }
.comment-item { padding: 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.comment-user { margin: 0 0 4px; color: var(--accent); font-size: 12px; font-weight: 700; }
.comment-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }
.comment-time { display: block; margin-top: 5px; color: var(--text-dim); font-size: 11px; }

.variables-dialog { width: min(1000px, calc(100vw - 24px)); }
.variables-dialog textarea {
  width: 100%;
  margin-top: 8px;
  padding: 9px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.table-wrap { overflow: auto; }
.variables-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.variables-table th, .variables-table td { padding: 7px; border-bottom: 1px solid var(--border); text-align: left; }
.variables-table th { position: sticky; top: 0; background: var(--surface-raised); color: var(--text-muted); }
.variables-table td.value { max-width: 45vw; overflow-wrap: anywhere; white-space: pre-wrap; }
.variables-table input[type="checkbox"] { accent-color: var(--accent); }

/* Scratch sign-in (Scratch Auth) ---------------------------------------------- */

.session {
  display: flex;
  align-items: center;
  gap: 8px;
}

.session-user {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}

.session-user:hover { text-decoration: underline; }

.auth-intro {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.auth-field select, .auth-field input {
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.auth-field select:focus, .auth-field input:focus { outline: none; border-color: var(--accent); }

#auth-username-row .btn { margin-bottom: 12px; }

.auth-code {
  margin: 0;
  padding: 12px;
  font-size: clamp(20px, 5vw, 30px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.12em;
  text-align: center;
  overflow-wrap: anywhere;
  user-select: all;
  color: var(--text-strong);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.auth-status {
  margin: 12px 0 0;
  min-height: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

.player-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--text-muted);
}

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

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

/* First-visit language chooser ------------------------------------------------ */

.language-chooser {
  width: min(520px, calc(100vw - 28px));
  padding: 20px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.language-chooser::backdrop { background: rgba(0, 0, 0, 0.72); }

.language-chooser h2 {
  margin: 0 0 16px;
  font-size: 17px;
  text-align: center;
}

/* The option's name is the language title art: one shared height keeps the four
 * wordmarks aligned even though the files have different aspect ratios. */
.language-option-title {
  height: 26px;
  max-width: 100%;
  object-fit: contain;
}

.language-chooser-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.language-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 6px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.language-option:hover { background: #262c36; border-color: var(--border-hover); }
.language-option:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.language-option-flag svg {
  display: block;
  width: 40px;
  height: 27px;
  border-radius: 3px;
}

/* Scrollbars (mirror theme.qss scrollbar colors) ------------------------------- */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* Small screens ------------------------------------------------------------------ */

@media (max-width: 520px) {
  .app-title { font-size: 18px; }
  .search { max-width: none; }
  .app-header { align-items: stretch; }
  .header-actions { width: 100%; }
  .header-actions .search { flex-basis: 100%; max-width: none; }
  .header-actions .btn { flex: 1; }
  .language-select { flex: 1; }
  .language-chooser-options { grid-template-columns: repeat(2, 1fr); }
  .detail-layout { grid-template-columns: 1fr; }
  .detail-cover { max-width: 100%; }
  .player-controls .btn { padding: 6px 8px; font-size: 12px; }
}