:root {
  color-scheme: light dark;
  --page-bg: #f4f7fb;
  --panel-bg: #ffffff;
  --panel-border: #d9e2ec;
  --text: #18212b;
  --heading: #111827;
  --muted: #617082;
  --field-border: #cfd9e5;
  --field-bg: #ffffff;
  --soft-bg: #eef3f8;
  --hover-bg: #edf4ff;
  --primary: #1f6feb;
  --primary-hover: #1558c7;
  --secondary: #314256;
  --secondary-hover: #243348;
  --danger: #c9352b;
  --focus-ring: rgb(31 111 235 / 0.22);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--page-bg);
  color: var(--text);
}

body.dark {
  --page-bg: #111418;
  --panel-bg: #1b2027;
  --panel-border: #303946;
  --text: #e6edf5;
  --heading: #f7fbff;
  --muted: #9aa8b7;
  --field-border: #3a4655;
  --field-bg: #151a20;
  --soft-bg: #252d37;
  --hover-bg: #23344c;
  --primary: #4c8dff;
  --primary-hover: #6aa0ff;
  --secondary: #3a4655;
  --secondary-hover: #465568;
  --danger: #d74c42;
  --focus-ring: rgb(76 141 255 / 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--page-bg);
  color: var(--text);
}

body:not(.dark) {
  color-scheme: light;
}

body.dark {
  color-scheme: dark;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.file-fallback {
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 650;
  min-height: 38px;
  padding: 8px 13px;
  transition: background 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

button:not(:disabled):hover,
.file-fallback:hover {
  background: var(--primary-hover);
}

button:not(:disabled):active,
.file-fallback:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--focus-ring);
  outline: none;
}

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

.topbar {
  align-items: center;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--panel-border);
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(220px, 1fr) auto;
  padding: 14px 18px;
}

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

.brand-logo {
  display: block;
  flex: 0 0 136px;
  height: 68px;
  position: relative;
  width: 136px;
}

.brand-logo-image {
  display: block;
  height: 100%;
  object-fit: contain;
  width: 100%;
}

.logo-dark {
  display: none;
}

.dark .logo-light {
  display: none;
}

.dark .logo-dark {
  display: block;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.2;
}

h2 {
  font-size: 15px;
  line-height: 1.3;
}

p {
  color: var(--muted);
  font-size: 13px;
}

.toolbar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.user-identity {
  display: grid;
  line-height: 1.2;
  max-width: min(280px, 42vw);
  min-width: 0;
  text-align: right;
}

.user-identity[hidden] {
  display: none;
}

.user-identity strong,
.user-identity span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-identity strong {
  color: var(--heading);
  font-size: 13px;
  font-weight: 700;
}

.user-identity span {
  color: var(--muted);
  font-size: 12px;
}

.authbar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  grid-column: 1 / -1;
}

.authbar input {
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: 8px;
  color: var(--text);
  min-height: 38px;
  min-width: 180px;
  padding: 8px 10px;
}

.create-account-form {
  display: grid;
  gap: 10px;
  grid-column: 1 / -1;
  grid-template-columns: 1fr 1fr;
}

.create-account-form[hidden] {
  display: none;
}

.create-account-form input {
  grid-column: 1 / -1;
  min-width: 0;
}

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

button.secondary:not(:disabled):hover {
  background: var(--secondary-hover);
}

.file-fallback {
  background: var(--secondary);
  display: inline-grid;
  place-items: center;
  position: relative;
}

.file-fallback input {
  inset: 0;
  opacity: 0;
  position: absolute;
  width: 100%;
}

.hidden-file-input {
  display: none;
}

.workspace {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(240px, 300px) minmax(360px, 1fr) minmax(280px, 380px);
  min-height: 0;
  padding: 14px;
}

body:not(.editor-open) .workspace {
  grid-template-columns: minmax(240px, 300px) minmax(360px, 1fr);
}

.signed-out .toolbar,
.signed-out .workspace {
  display: none;
}

body:not(.signed-out) .authbar {
  display: none;
}

.signed-out .app-shell {
  display: grid;
  grid-template-rows: 1fr;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
}

.signed-out .topbar {
  aspect-ratio: 1 / 1;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgb(15 23 42 / 0.14);
  display: grid;
  align-content: center;
  gap: 22px;
  grid-template-columns: 1fr;
  justify-items: center;
  max-height: min(560px, calc(100vh - 48px));
  max-width: min(440px, calc(100vw - 48px));
  min-height: 0;
  padding: 30px;
  width: min(440px, calc(100vw - 48px));
}

.signed-out .brand {
  align-self: center;
  display: grid;
  gap: 12px;
  justify-items: center;
  text-align: center;
  width: 100%;
}

.signed-out .brand-logo {
  height: 92px;
  width: 184px;
}

.signed-out h1 {
  font-size: 24px;
}

.signed-out .authbar {
  align-self: center;
  display: grid;
  gap: 12px;
  grid-column: auto;
  grid-template-columns: 1fr 1fr;
  max-width: 360px;
  width: 100%;
}

.signed-out .authbar input {
  border-color: #b9c7d8;
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.06);
  grid-column: 1 / -1;
  min-height: 44px;
  min-width: 0;
  padding: 10px 12px;
  width: 100%;
}

.signed-out .authbar input::placeholder {
  color: #718096;
}

.dark.signed-out .authbar input {
  border-color: var(--field-border);
  box-shadow: none;
}

.dark.signed-out .authbar input::placeholder {
  color: var(--muted);
}

.signed-out.creating-account #emailInput,
.signed-out.creating-account #passwordInput,
.signed-out.creating-account #signInButton,
.signed-out.creating-account #googleSignInButton,
.signed-out.creating-account #createAccountButton,
.signed-out.creating-account #languageSelect,
.signed-out.creating-account #themeSelect {
  display: none;
}

.signed-out #signInButton,
.signed-out #googleSignInButton,
.signed-out #createAccountButton,
.signed-out #languageSelect,
.signed-out #themeSelect {
  min-height: 42px;
  min-width: 0;
  width: 100%;
}

.google-signin-button {
  align-items: center;
  background: #ffffff;
  border: 1px solid #b7c5d6;
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.07);
  color: var(--text);
  display: inline-flex;
  gap: 10px;
  grid-column: 1 / -1;
  justify-content: center;
}

.google-signin-button:not(:disabled):hover {
  background: #f8fbff;
  border-color: #8fb2df;
}

.dark .google-signin-button {
  background: var(--field-bg);
  border-color: var(--field-border);
  box-shadow: none;
}

.dark .google-signin-button:not(:disabled):hover {
  background: var(--hover-bg);
  border-color: var(--field-border);
}

.google-logo {
  align-items: center;
  background: #fff;
  border-radius: 50%;
  display: inline-flex;
  flex: 0 0 22px;
  height: 22px;
  justify-content: center;
  width: 22px;
}

.google-logo svg {
  display: block;
  height: 18px;
  width: 18px;
}

.signed-out #authStatus {
  color: var(--muted);
  font-size: 12px;
  grid-column: 1 / -1;
  justify-self: center;
  min-height: 18px;
  text-align: center;
  white-space: normal;
}

.signed-out .create-account-form {
  gap: 12px;
  width: 100%;
}

.signed-out .create-account-form input {
  min-height: 44px;
  padding: 10px 12px;
}

.signed-out .create-account-form button {
  min-height: 42px;
}

.signed-out.creating-account .create-account-form {
  display: grid;
}

.signed-out.creating-account .topbar {
  aspect-ratio: auto;
  min-height: min(540px, calc(100vh - 48px));
}

.signed-out.creating-account .brand {
  gap: 6px;
}

.signed-out.creating-account .brand-logo {
  height: 68px;
  width: 136px;
}

.signed-out.creating-account h1 {
  font-size: 20px;
}

.sidebar,
.results,
.editor {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  min-height: 0;
  overflow: hidden;
}

.editor[hidden] {
  display: none;
}

.sidebar,
.editor {
  display: flex;
  flex-direction: column;
}

.panel-header {
  align-items: center;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 14px;
}

.results .panel-header {
  flex-wrap: wrap;
}

.results .panel-header > div:first-child {
  flex: 1 1 190px;
}

.sort-control {
  align-items: center;
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.result-controls {
  align-items: center;
  display: flex;
  flex: 0 1 auto;
  flex-wrap: wrap;
  gap: 8px 12px;
  justify-content: flex-end;
}

.sort-control span {
  white-space: nowrap;
}

.sort-control select {
  min-height: 34px;
  min-width: 118px;
}

.page-size-control select {
  min-width: 78px;
}

.icon-button {
  border-radius: 50%;
  font-size: 22px;
  font-weight: 500;
  height: 36px;
  line-height: 1;
  padding: 0;
  width: 36px;
}

.toolbar-icon-button {
  align-items: center;
  display: inline-flex;
  justify-content: center;
}

.toolbar-icon-button svg {
  fill: none;
  height: 20px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 20px;
}

.search {
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  color: var(--text);
  border-radius: 8px;
  margin: 12px;
  min-height: 38px;
  padding: 8px 10px;
}

.console-list,
.game-list {
  overflow: auto;
}

.console-list {
  padding: 0 8px 10px;
}

.console-button {
  align-items: center;
  background: transparent;
  border-radius: 8px;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  margin: 2px 0;
  padding: 9px 10px;
  text-align: left;
  width: 100%;
}

.console-name {
  align-items: center;
  display: inline-flex;
  gap: 9px;
  min-width: 0;
}

.console-name > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.console-icon {
  align-items: center;
  --console-icon-color: var(--primary);
  --console-icon-bg: #dceaff;
  --console-icon-border: #9ec4ff;
  background: var(--console-icon-bg);
  border: 1px solid var(--console-icon-border);
  border-radius: 8px;
  color: var(--console-icon-color);
  display: inline-flex;
  flex: 0 0 32px;
  height: 32px;
  justify-content: center;
  width: 32px;
}

.console-icon svg {
  fill: color-mix(in srgb, currentColor 18%, transparent);
  height: 24px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  width: 24px;
}

.console-icon svg circle {
  fill: currentColor;
}

.console-icon-logo svg {
  display: block;
  fill: currentColor;
  height: 22px;
  stroke: none;
  width: 22px;
}

.console-icon-nintendo,
.console-icon-nintendoswitch {
  --console-icon-color: #e60012;
  --console-icon-bg: #ffe1e4;
  --console-icon-border: #ffa4ad;
}

.console-icon-nintendo3ds {
  --console-icon-color: #d01928;
  --console-icon-bg: #ffe1e5;
  --console-icon-border: #ffa2ac;
}

.console-icon-snes {
  --console-icon-color: #5a4aa3;
  --console-icon-bg: #ece8ff;
  --console-icon-border: #bcb1f1;
}

.console-icon-nes {
  --console-icon-color: #4b5563;
  --console-icon-bg: #eef1f5;
  --console-icon-border: #c4ccd7;
}

.console-icon-playstation {
  --console-icon-color: #006fcd;
  --console-icon-bg: #ddecff;
  --console-icon-border: #97c6ff;
}

.console-icon-xbox {
  --console-icon-color: #107c10;
  --console-icon-bg: #ddf4dd;
  --console-icon-border: #98d598;
}

.console-icon-sega {
  --console-icon-color: #0089cf;
  --console-icon-bg: #d9f2ff;
  --console-icon-border: #91d3f5;
}

.console-icon-atari {
  --console-icon-color: #e4202e;
  --console-icon-bg: #ffe2e4;
  --console-icon-border: #ffa3aa;
}

.console-icon-cartridge-console,
.console-icon-cube-console,
.console-icon-switch {
  --console-icon-color: #e7333f;
  --console-icon-bg: #ffe1e4;
  --console-icon-border: #ff9fa8;
}

.console-icon-dual-screen,
.console-icon-handheld {
  --console-icon-color: #7b3dd6;
  --console-icon-bg: #eadfff;
  --console-icon-border: #c3a8ff;
}

.console-icon-disc-console,
.console-icon-tower {
  --console-icon-color: #2367d8;
  --console-icon-bg: #dce8ff;
  --console-icon-border: #9bbdff;
}

.console-icon-classic-console {
  --console-icon-color: #9b5a24;
  --console-icon-bg: #ffe6c8;
  --console-icon-border: #efbd84;
}

.console-icon-slim-console,
.console-icon-tablet-console {
  --console-icon-color: #189070;
  --console-icon-bg: #d6f6ec;
  --console-icon-border: #8bdcc5;
}

.console-icon-controller,
.console-icon-collection {
  --console-icon-color: #4d667f;
  --console-icon-bg: #e3ebf2;
  --console-icon-border: #b7c7d5;
}

.dark .console-icon {
  --console-icon-bg: color-mix(in srgb, var(--console-icon-color) 24%, #111418);
  --console-icon-border: color-mix(in srgb, var(--console-icon-color) 52%, #111418);
}

.console-button.active,
.console-button:hover {
  background: var(--hover-bg);
}

.count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.results {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.status {
  background: var(--soft-bg);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  padding: 5px 9px;
  white-space: nowrap;
}

.status.changed {
  background: #fff4d5;
  color: #7a5300;
}

.status.saved {
  background: #e8f6ed;
  color: #216e39;
}

.status.error {
  background: #ffe8e6;
  color: #a5281c;
}

.status.hidden-status {
  background: transparent;
  padding-left: 0;
  padding-right: 0;
}

.game-list {
  padding: 8px;
  overflow: auto;
}

.game-list.empty-state {
  color: var(--muted);
  display: grid;
  min-height: 280px;
  place-items: center;
  text-align: center;
}

.game-card {
  align-items: center;
  background: var(--panel-bg);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  display: grid;
  gap: 12px;
  grid-template-columns: 56px 1fr auto;
  margin: 4px 0;
  padding: 10px;
  text-align: left;
  width: 100%;
}

.game-card strong {
  color: var(--heading);
}

.game-card:hover {
  background: var(--panel-bg);
  border-color: #a9c7f7;
}

.game-card.active {
  border-color: #a9c7f7;
  background: var(--hover-bg);
}

.game-card:hover .meta {
  color: var(--text);
}

.game-card.active .meta {
  color: var(--muted);
}

.thumb {
  align-items: center;
  background: var(--soft-bg) center / cover no-repeat;
  border-radius: 7px;
  color: var(--heading);
  display: flex;
  font-size: 12px;
  font-weight: 700;
  height: 42px;
  justify-content: center;
  letter-spacing: 0;
  width: 56px;
}

.thumb.console-thumb {
  background: transparent;
}

.thumb .console-icon {
  border-radius: 10px;
  flex-basis: 46px;
  height: 42px;
  width: 46px;
}

.thumb .console-icon svg {
  height: 30px;
  width: 30px;
}

.thumb .console-icon-logo svg {
  height: 30px;
  width: 30px;
}

.pagination-controls {
  border-top: 1px solid var(--panel-border);
  padding: 10px;
}

.pagination-controls button {
  width: 100%;
}

.meta {
  color: var(--muted);
  font-size: 12px;
}

.price {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.form-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
  overflow: auto;
  padding: 14px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  gap: 5px;
}

input,
select,
textarea {
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: 8px;
  color: var(--text);
  min-height: 38px;
  padding: 8px 9px;
  width: 100%;
}

textarea {
  min-height: 86px;
  resize: vertical;
}

.span-2 {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.modal-backdrop {
  align-items: center;
  background: rgb(15 23 42 / 0.42);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 20;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgb(15 23 42 / 0.2);
  display: grid;
  gap: 14px;
  max-width: 420px;
  padding: 18px;
  width: min(420px, 100%);
}

.modal-message {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  margin: 0;
  min-height: 18px;
}

.modal-message.error {
  color: var(--danger);
}

.modal-message.saved {
  color: #1f8f4d;
}

.modal-message.changed {
  color: var(--muted);
}

.settings-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
}

.settings-actions > * {
  min-width: 0;
  width: 100%;
}

.danger {
  background: var(--danger);
}

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

body.signed-out:not(.dark) .authbar input {
  background: #ffffff !important;
  border-color: #8fa9c9;
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.08), 0 0 0 1px rgb(143 169 201 / 0.18);
  caret-color: #17202b;
  color: #17202b !important;
  -webkit-text-fill-color: #17202b;
}

body.signed-out:not(.dark) .authbar input::placeholder {
  color: #5f7085;
  -webkit-text-fill-color: #5f7085;
}

body.signed-out:not(.dark) .authbar input:-webkit-autofill,
body.signed-out:not(.dark) .authbar input:-webkit-autofill:hover,
body.signed-out:not(.dark) .authbar input:-webkit-autofill:focus {
  border-color: #8fa9c9;
  box-shadow: 0 0 0 1000px #ffffff inset, 0 1px 2px rgb(15 23 42 / 0.08);
  caret-color: #17202b;
  -webkit-text-fill-color: #17202b;
}

body.signed-out:not(.dark) .google-signin-button.secondary {
  background: #ffffff;
  border: 1px solid #8fa9c9;
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.08), 0 0 0 1px rgb(143 169 201 / 0.18);
  color: #17202b;
}

body.signed-out:not(.dark) .google-signin-button.secondary:not(:disabled):hover {
  background: #f4f8ff;
  border-color: #5f8fc9;
}

.image-editor {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  padding: 10px;
}

.image-preview {
  align-items: center;
  aspect-ratio: 4 / 3;
  background: var(--soft-bg) center / contain no-repeat;
  border: 1px dashed #b8c6d6;
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  justify-content: center;
  min-height: 150px;
  overflow: hidden;
  text-align: center;
}

.image-preview.has-image {
  border-style: solid;
  color: transparent;
}

.image-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.image-actions > * {
  flex: 1 1 140px;
}

.image-file {
  text-align: center;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: minmax(220px, 280px) 1fr;
  }

  .editor {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    justify-content: stretch;
  }

  .toolbar > * {
    flex: 1 1 120px;
  }

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

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

@media (max-width: 480px) {
  .signed-out .app-shell {
    padding: 16px;
  }

  .signed-out .topbar {
    gap: 12px;
    max-width: calc(100vw - 32px);
    padding: 18px;
    width: calc(100vw - 32px);
  }

  .signed-out .brand {
    gap: 8px;
  }

  .signed-out .brand-logo {
    height: 72px;
    width: 144px;
  }

  .signed-out h1 {
    font-size: 20px;
  }

  .signed-out .authbar {
    gap: 8px;
  }

  .signed-out .authbar input,
  .signed-out .authbar button,
  .signed-out .authbar select {
    min-height: 34px;
    padding-bottom: 6px;
    padding-top: 6px;
  }
}
