:root {
  color-scheme: light;
  --bg: #f2f3f4;
  --ink: #111318;
  --muted: #5a6472;
  --card: #ffffff;
  --line: #d8dde3;
  --accent: #ff7828;
  --btn-bg: #0f172a;
  --btn-fg: #ffffff;
  --btn-hover: #ff7828;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, sans-serif;
}

.bg-app-page {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.menu-btn {
  position: fixed;
  top: calc(0.75em + env(safe-area-inset-top));
  left: calc(0.75em + env(safe-area-inset-left));
  z-index: 1200;
  --menu-btn-size: 40px;
  --menu-btn-gap: 0.75rem;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid #d8dde3;
  background: #0f172a;
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.menu-btn:hover {
  background: #ff7828;
}

.container {
  width: min(1240px, 92%);
  margin: 1.5rem auto 2rem;
  display: grid;
  gap: 1rem;
}

.bg-app-page main.container {
  margin: 0 auto;
  padding: 2rem 0 2.5rem;
  align-content: start;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
}

.bg-app-page .card {
  padding: 1.25rem;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.muted {
  color: var(--muted);
}

.error {
  color: #b91c1c;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: none;
  background: var(--btn-bg);
  color: var(--btn-fg);
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.2s;
}

button:hover {
  background: var(--btn-hover);
}

button.secondary {
  background: var(--muted);
}

button.danger {
  background: #dc2626;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font-size: 16px;
}

input:focus,
textarea:focus {
  outline: 2px solid rgba(255, 120, 40, 0.4);
  outline-offset: 1px;
  border-color: var(--accent);
}

.search-form {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: 1fr auto;
  align-items: center;
}

.search-form input {
  min-width: 0;
}

.list {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(3, 1fr);
}

.manual-form {
  display: grid;
  gap: 0.6rem;
}

.manual-form label {
  display: grid;
  gap: 0.3rem;
}

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

.item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem;
  display: grid;
  gap: 0.6rem;
}

.view-mode {
  display: grid;
  gap: 0.6rem;
}

.edit-mode {
  display: grid;
  gap: 0.6rem;
}

.edit-mode label {
  display: grid;
  gap: 0.3rem;
}

.notes-display {
  background: #f2f3f4;
  border-left: 3px solid var(--accent);
  padding: 0.75rem;
  border-radius: 4px;
}

.notes-display strong {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.notes-text {
  margin: 0;
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.4;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #f2f3f4;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    width 0.2s ease,
    height 0.2s ease;
}

@media (hover: hover) and (pointer: fine) {
  .thumb:hover {
    transform: scale(1.5);
    width: 72px;
    height: 72px;
    z-index: 10;
    position: relative;
  }
}

body.side-menu-open {
  overflow: hidden;
}

.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 1250;
}

.menu-panel {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: min(280px, calc(100vw - 3.25rem));
  background: #f2f3f4;
  border-right: 2px solid var(--line);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.12);
  z-index: 1300;
  padding: calc(14px + env(safe-area-inset-top)) 14px
    calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-105%);
  transition: transform 0.18s ease;
  display: flex;
  flex-direction: column;
}

.menu-panel.open {
  transform: translateX(0);
}

.menu-title {
  display: flex;
  justify-content: center;
  padding: 2px 0 8px;
}

.menu-title-img {
  display: block;
  width: min(180px, 100%);
  height: auto;
}

.menu-items {
  display: grid;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.menu-link {
  width: 100%;
  min-height: 44px;
  border: 1px solid #d8dde3;
  border-radius: 10px;
  background: #0f172a;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.72rem 1rem;
  cursor: pointer;
  text-decoration: none;
}

.menu-link:hover {
  background: #ff7828;
}

.menu-link-danger {
  background: #0f172a;
}

.menu-divider {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 8px 0;
}

.menu-spacer {
  flex: 1;
}

.menu-bottom {
  display: grid;
}

.back-to-top {
  position: fixed;
  right: calc(0.9rem + env(safe-area-inset-right));
  bottom: calc(0.9rem + env(safe-area-inset-bottom));
  z-index: 1100;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid #d8dde3;
  background: #0f172a;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  padding: 0;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.2);
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease,
    background 0.2s ease;
}

.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.back-to-top:hover {
  background: #ff7828;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--card);
  border-radius: 14px;
  padding: 1.5rem;
  width: min(500px, 100% - 2rem);
  max-height: 90vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

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

.modal-header h2 {
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  color: var(--muted);
  padding: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--ink);
}

button.primary {
  background: var(--btn-bg);
}

button.primary:hover {
  background: var(--btn-hover);
}

.auth-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

/* Board Games login scene (matches Movies/TV/RPI auth styling) */
.bg-login-page {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.bg-login-page .auth-wrap {
  min-height: auto;
}

.wrap {
  width: min(1240px, 92%);
  margin: 0 auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.header-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  padding: 10px 0;
}

.header-left {
  justify-self: start;
}

.header-right {
  justify-self: end;
}

.brand {
  justify-self: center;
}

.brand-logo {
  display: block;
  width: min(640px, 78vw);
  height: 96px;
  object-fit: contain;
  object-position: center;
}

main.wrap.auth-wrap {
  position: relative;
  isolation: isolate;
  padding: 28px 0 44px;
}

.is-login-scene main.wrap.auth-wrap::before {
  content: "";
  position: fixed;
  inset: 70px -16vw -8vh -16vw;
  pointer-events: none;
  z-index: -1;
  background:
    radial-gradient(
      40% 30% at 18% 22%,
      rgba(255, 120, 40, 0.2),
      transparent 70%
    ),
    radial-gradient(
      36% 26% at 78% 28%,
      rgba(15, 23, 42, 0.12),
      transparent 70%
    ),
    radial-gradient(
      45% 36% at 52% 74%,
      rgba(255, 120, 40, 0.13),
      transparent 72%
    );
  filter: blur(26px);
}

.narrow {
  max-width: 640px;
}

.stack {
  display: grid;
  gap: 14px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.82rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
}

.login-title {
  display: inline-block;
  margin: 0;
  font-size: clamp(2rem, 5vw, 2.8rem);
  line-height: 1.06;
  letter-spacing: -0.02em;
}

.login-card {
  position: relative;
  overflow: hidden;
  width: min(640px, 100%);
  padding: 28px;
  border-radius: 18px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.09);
}

.login-card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.04;
  background: repeating-linear-gradient(
    180deg,
    rgba(15, 23, 42, 0.26) 0px,
    rgba(15, 23, 42, 0.26) 1px,
    transparent 1px,
    transparent 3px
  );
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 2px;
}

.btn {
  min-width: 122px;
  border: none;
  background: var(--btn-bg);
  color: var(--btn-fg);
  padding: 0.72rem 1rem;
  border-radius: 10px;
  cursor: pointer;
  min-height: 44px;
  font-size: 16px;
  font-weight: 700;
  transition:
    background 0.2s,
    transform 0.1s;
}

.btn:hover {
  background: var(--btn-hover);
  transform: translateY(-1px);
}

.alert {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(178, 50, 43, 0.28);
  background: rgba(178, 50, 43, 0.12);
  color: #7a241f;
}

.hub-footer {
  background: #0f172a;
  color: #ffffff;
  text-align: center;
  padding: 16px;
  margin-top: auto;
}

.hub-footer-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.auth-card {
  width: min(640px, 100%);
}

.auth-form {
  display: grid;
  gap: 14px;
  margin-top: 12px;
}

.auth-form label {
  display: grid;
  gap: 0.3rem;
}

@media (max-width: 560px) {
  .search-form {
    grid-template-columns: 1fr;
  }

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

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

  .menu-panel {
    width: min(300px, calc(100vw - 2rem));
  }
}

@media (max-width: 640px) {
  .brand-logo {
    height: 72px;
  }
}

@media (max-width: 1024px) {
  .bg-app-page .header-row {
    padding-left: calc(
      var(--menu-btn-size) + var(--menu-btn-gap) + env(safe-area-inset-left) +
        12px
    );
    padding-right: calc(
      var(--menu-btn-size) + var(--menu-btn-gap) + env(safe-area-inset-right) +
        12px
    );
  }
}

@media (max-width: 1024px) and (min-width: 561px) {
  .list {
    grid-template-columns: repeat(2, 1fr);
  }
}
