:root {
  --background: #ffffff;
  --surface: #f4f5f7;
  --text: #16181d;
  --text-muted: #5f6670;
  --accent: #2f6fec;
  --border: #d9dce1;
  --danger: #c62f2f;
  font-family: system-ui, sans-serif;
  color: var(--text);
  background: var(--background);
}

/* The six colors of the theme are set from main.ts (theme.ts); the others follow its mode. */
:root[data-mode="dark"] {
  --danger: #ff6b6b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100dvh;
  display: grid;
  grid-template-columns: 14rem 1fr;
}

[hidden] {
  display: none !important;
}

.gate {
  grid-column: 1 / -1;
  max-width: 40rem;
  margin: 0 auto;
  padding: 3rem 1.5rem;
}

.gate p {
  color: var(--text-muted);
}

.gate .actions {
  justify-content: start;
}

body.dragging main {
  outline: 3px dashed var(--accent);
  outline-offset: -12px;
}

.launcher {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  border-right: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
  overflow: hidden;
}

.launcher ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.25rem;
  min-height: 0;
  overflow-y: auto;
  align-content: start;
}

.launcher button,
.launcher-install {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.5rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.launcher button:hover,
.launcher button[aria-current="page"] {
  background: var(--background);
}

.launcher-home {
  font-weight: 700;
  flex: none;
}

.launcher img {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 6px;
}

/* Marketplace stays above the inner drawer while the Modules scroll independently above both. */
.launcher-marketplace {
  flex: none;
  margin-top: auto;
}

.launcher-tools {
  flex: none;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-rows: auto 0fr;
  transition: grid-template-rows 0.2s ease;
}

.launcher-tools.open {
  grid-template-rows: auto 1fr;
}

.launcher .launcher-tools-toggle {
  justify-content: space-between;
  min-height: 2.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.launcher-tools-chevron {
  flex: none;
  transition: transform 0.2s ease;
}

.launcher-tools.open .launcher-tools-chevron {
  transform: rotate(180deg);
}

.launcher-tools-panel {
  min-height: 0;
  overflow: hidden;
  visibility: hidden;
  transition: visibility 0.2s;
}

.launcher-tools.open .launcher-tools-panel {
  visibility: visible;
  transition: none;
}

.launcher-tools-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 45dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.launcher-tools-actions > button {
  flex: none;
}

.launcher .launcher-marketplace,
.launcher .launcher-install {
  color: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  .launcher-tools,
  .launcher-tools-chevron,
  .launcher-tools-panel {
    transition: none;
  }
}


.launcher .status {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.launcher .conflict .status,
.launcher .missing .status {
  color: var(--danger);
}

.launcher .missing .name {
  color: var(--text-muted);
}

.launcher .no-icon {
  width: 1.75rem;
  height: 1.75rem;
  flex: none;
  border-radius: 6px;
  background: var(--border);
}

.launcher-settings,
.launcher-folder {
  font-size: 0.85rem;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.launcher li {
  display: flex;
  align-items: center;
}

.launcher .entry-about {
  flex: none;
  width: auto;
  padding: 0.35rem 0.5rem;
  color: var(--text-muted);
}

/* What the Marketplace says of an installed Module (ADR 0018): a newer version, a Ban, a Withdrawal. */
.launcher .entry-notice {
  flex: none;
  width: auto;
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
  white-space: nowrap;
}

.entry-notice.update {
  color: var(--accent);
}

.entry-notice.banned,
.widget-notice.banned {
  color: var(--danger);
}

.entry-notice.withdrawn,
.widget-notice.withdrawn {
  color: var(--text-muted);
}

/* A strip under the Widget, so that it covers none of the Widget's own controls. */
.widget.has-notice {
  display: flex;
  flex-direction: column;
}

.widget.has-notice .widget-body {
  flex: 1;
  min-height: 0;
  height: auto;
}

.widget-notice {
  flex: none;
  padding: 0.25rem 0.6rem;
  border: 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
  font: inherit;
  font-size: 0.75rem;
  text-align: left;
  cursor: pointer;
}

.widget-notice.banned {
  border-top-color: var(--danger);
}

.ban-reason {
  margin: 0.5rem 0;
  padding: 0.5rem 0.75rem;
  border-left: 3px solid var(--danger);
  background: var(--surface);
  overflow-wrap: anywhere;
}

.permission-summary {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: var(--surface);
}

.permission-summary h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.permission-summary p {
  margin: 0.5rem 0;
}

.permission-summary .origins {
  margin: 0;
  padding-left: 1.25rem;
  overflow-wrap: anywhere;
}

.permission-summary .sensitive {
  margin: 0.5rem 0;
  padding: 0.25rem 0.75rem;
  border-left: 4px solid var(--danger);
  border-radius: 6px;
  background: color-mix(in srgb, var(--danger) 8%, transparent);
}

.permission-summary .sensitive strong {
  color: var(--danger);
}

.permission-summary .limits {
  font-size: 0.9rem;
  color: var(--text-muted);
}

main {
  position: relative;
  min-width: 0;
  overflow: hidden;
}

.home {
  /* The side of a cell of the Home: 160 px, the indicative size of an S Widget (CONVENTION.md §7.1). */
  --cell: 10rem;
  --gap: 1rem;
  height: 100%;
  overflow-y: auto;
  padding: 1.5rem;
}

.home-empty {
  max-width: 40rem;
  margin: 0 auto;
  padding-top: 1.5rem;
}

.home-empty p {
  color: var(--text-muted);
}

.home-toolbar {
  display: flex;
  justify-content: end;
  margin-bottom: 0.75rem;
}

.home-toolbar button {
  font: inherit;
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--background);
  color: inherit;
  cursor: pointer;
}

.arranging .home-toolbar button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.widgets {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--cell));
  grid-auto-rows: var(--cell);
  gap: var(--gap);
}

.widget {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
}

.widget.size-M {
  grid-column: span 2;
}

.widget.size-L {
  grid-column: span 2;
  grid-row: span 2;
}

.widget-body,
.widget-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.widget-error {
  height: 100%;
  padding: 0.75rem;
  overflow: hidden;
  font-size: 0.85rem;
  border: 1px solid var(--danger);
  border-radius: 14px;
}

.widget-error p {
  margin: 0.4rem 0 0;
  color: var(--text-muted);
}

.arrange {
  display: none;
}

.arranging .widget {
  cursor: grab;
}

.arranging .widget-frame {
  pointer-events: none;
}

.arranging .arrange {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem;
  background: rgb(0 0 0 / 0.08);
}

.arrange-name {
  position: absolute;
  top: 0.5rem;
  left: 0.6rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.arrange .move {
  font: inherit;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--background);
  color: inherit;
  cursor: pointer;
}

/* The Marketplace screen: drawn by the Host in the stage, where a View would be. */
.marketplace {
  height: 100%;
  overflow-y: auto;
  padding: 1.5rem max(1.5rem, calc((100% - 60rem) / 2));
}

.marketplace > .actions.start {
  margin: 0 0 1.25rem;
}

.marketplace h1 {
  margin: 0 0 1rem;
  font-size: 1.5rem;
}

.marketplace h2 {
  margin: 1.75rem 0 0.75rem;
  font-size: 1.1rem;
}

.marketplace .note {
  color: var(--text-muted);
}

.market-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  margin-bottom: 1.25rem;
}

.market-filters label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.market-filters input,
.market-filters select {
  min-width: 14rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--background);
  color: inherit;
  font: inherit;
  font-weight: normal;
}

.market-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.market-results .note {
  grid-column: 1 / -1;
}

.market-card {
  display: grid;
  grid-template-columns: 3rem 1fr;
  grid-template-areas: "icon name" "icon creator" "description description";
  gap: 0.15rem 0.75rem;
  align-content: start;
  width: 100%;
  height: 100%;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.market-card:hover,
.market-card:focus-visible {
  border-color: var(--accent);
}

.market-card img {
  grid-area: icon;
  width: 3rem;
  height: 3rem;
  border-radius: 10px;
}

.market-card .name {
  grid-area: name;
  align-self: end;
  font-weight: 600;
}

.market-card .creator {
  grid-area: creator;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.market-card .description {
  grid-area: description;
  margin-top: 0.6rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.marketplace .module-summary h1 {
  margin: 0;
  font-size: 1.3rem;
}

.listing-guide-frame {
  display: block;
  width: 100%;
  height: 32rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--background);
}

.screenshots {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
}

.screenshots img {
  max-width: 100%;
  max-height: 16rem;
  border: 1px solid var(--border);
  border-radius: 10px;
}

/* The ADR 0015 warning, on the listing and on the Accept screen. */
.marketplace-risk {
  margin-top: 1.5rem;
  padding: 0.6rem 1rem;
  border-left: 3px solid var(--danger);
  border-radius: 0 10px 10px 0;
  background: var(--surface);
}

.marketplace-risk p {
  margin: 0.35rem 0;
}

.view-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.surface-error {
  max-width: 40rem;
  margin: 3rem auto;
  padding: 1.5rem;
  border: 1px solid var(--danger);
  border-radius: 12px;
}

dialog {
  width: min(32rem, calc(100vw - 2rem));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  color: var(--text);
  background: var(--background);
}

/* The User guide of a Module: wide and tall, its iframe fills what the title and the buttons leave. */
dialog.guide[open] {
  display: flex;
  flex-direction: column;
  width: min(60rem, calc(100vw - 2rem));
  height: calc(100vh - 3rem);
  max-height: none;
  padding: 1rem 1.25rem;
}

dialog.guide h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.guide-frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--background);
}

dialog.guide .actions {
  margin-top: 1rem;
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.35);
}

.module-summary {
  display: grid;
  grid-template-columns: 4rem 1fr;
  gap: 1rem;
  align-items: start;
}

.module-summary img {
  width: 4rem;
  height: 4rem;
  border-radius: 12px;
}

.module-summary dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
}

.module-summary dt {
  color: var(--text-muted);
}

.module-summary dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.issues {
  padding-left: 1.25rem;
}

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

.issues code {
  color: var(--text-muted);
}

.actions {
  display: flex;
  justify-content: end;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.actions.start {
  justify-content: start;
  margin-top: 1rem;
}

.actions button {
  font: inherit;
  padding: 0.45rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--background);
  color: inherit;
  cursor: pointer;
}

.actions button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.actions button.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #ffffff;
}

.versions {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
}

.versions dt {
  color: var(--text-muted);
}

.versions dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.warning {
  color: var(--danger);
}

.url-form label {
  display: grid;
  gap: 0.35rem;
}

.url-form input {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--background);
  color: inherit;
}

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

.settings fieldset {
  margin: 0 0 1rem;
  padding: 0;
  border: 0;
  display: grid;
  gap: 0.35rem;
}

.settings legend {
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.settings fieldset label {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.settings .language {
  display: grid;
  gap: 0.35rem;
  font-weight: 600;
}

.settings select {
  font: inherit;
  font-weight: normal;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--background);
  color: inherit;
}

.settings .note {
  color: var(--text-muted);
  font-size: 0.9rem;
}

dialog code,
.pending-install code {
  overflow-wrap: anywhere;
}

@media (max-width: 40rem) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .launcher {
    flex-direction: row;
    flex-wrap: wrap;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }

  .launcher ul {
    display: flex;
    flex: 1;
    overflow-x: auto;
  }

  .launcher button,
  .launcher-install {
    width: auto;
    white-space: nowrap;
  }

  .launcher .launcher-marketplace,
  .launcher-tools {
    width: 100%;
  }

  .launcher .launcher-tools-toggle,
  .launcher-tools-actions > button {
    width: 100%;
    white-space: normal;
  }

  .home {
    --gap: 0.75rem;
    --cell: calc((100vw - 3rem - var(--gap)) / 2);
  }
}

/*
 * Behind a View, the Launcher slides out to the left: it comes back while the pointer is near the left edge of the
 * page or over it, or while the keyboard moves in it. The edge lies above the View, whose iframe takes the pointer.
 */
.launcher-edge {
  display: none;
}

body.drawer {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

body.drawer .launcher-edge {
  display: block;
  position: fixed;
  inset: 0 auto 0 0;
  width: 0.5rem;
  z-index: 1;
}

body.drawer .launcher {
  position: fixed;
  inset: 0 auto 0 0;
  width: 14rem;
  z-index: 2;
  flex-direction: column;
  flex-wrap: nowrap;
  border-right: 1px solid var(--border);
  border-bottom: 0;
  overflow-x: hidden;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
}

body.drawer .launcher-edge:hover + .launcher,
body.drawer .launcher:hover,
body.drawer .launcher:has(:focus-visible) {
  transform: none;
  box-shadow: 0 0 1.5rem rgb(0 0 0 / 0.2);
}

body.drawer .launcher ul {
  display: grid;
  flex: 0 1 auto;
}

body.drawer .launcher button,
body.drawer .launcher-install {
  width: 100%;
  white-space: normal;
}

body.drawer .launcher-install,
body.drawer .launcher-marketplace {
  margin-left: 0;
}

body.drawer.drawer-dismissed .launcher-edge + .launcher {
  transform: translateX(-100%);
  box-shadow: none;
}
