/* ---------- Settings page ----------

   Profile is one full-width tile on top; the other categories below are a
   collage of tiles packed edge to edge (tiles sharing a row stretch to the
   same height):

     Profile ------------------------------------
     Theme (2 rows)            | Animations
                               | Card density
     Defaults -----------------------------------
     Your Data ----------------------------------

   Layout reacts to the width the grid actually gets (container queries),
   not the viewport — the sidebar takes a varying share of it. */

.settings-bento {
  container-type: inline-size;
  max-width: 1100px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
}

.settings-tile {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 22px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
}

.settings-tile-title {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.settings-group-label {
  margin: 0 0 12px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}

.tile-profile,
.tile-defaults,
.tile-data,
.tile-danger {
  grid-column: 1 / -1;
}

.tile-theme {
  grid-column: span 8;
  grid-row: span 2;
}

.tile-motion,
.tile-density {
  grid-column: span 4;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}

.settings-row:first-of-type {
  border-top: none;
}

/* The label side gives way first, so a small control (the toggle) stays on
   the same line; wider ones wrap underneath on narrow screens. */
.settings-row > :first-child {
  flex: 1 1 160px;
  min-width: 0;
}

.settings-row-title {
  display: block;
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

/* ---------- Select ---------- */

.settings-select-wrap {
  position: relative;
  flex-shrink: 0;
}

.settings-select-wrap::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 14px;
  width: 7px;
  height: 7px;
  margin-top: -6px;
  border: solid var(--ink-muted);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  pointer-events: none;
}

.settings-select {
  appearance: none;
  min-width: 220px;
  min-height: 44px;
  padding: 0 38px 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  /* Every theme's settings card is light paper, so the native option
     list should be too, whatever the page's own theme is. */
  color-scheme: light;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.settings-select:hover {
  border-color: var(--accent-deep);
}

.settings-select:focus-visible {
  outline: none;
  border-color: var(--accent-deep);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-deep) 25%, transparent);
}

/* ---------- Segmented control ---------- */

.settings-segmented {
  display: flex;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.settings-segmented button {
  min-height: 44px;
  padding: 0 16px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  transition: background var(--transition), color var(--transition);
}

.settings-segmented button + button {
  border-left: 1px solid var(--border);
}

.settings-segmented button:hover:not(.is-active) {
  background: color-mix(in srgb, var(--accent-deep) 8%, transparent);
}

.settings-segmented button.is-active {
  background: var(--accent-strong);
  color: #fff;
}

.settings-row-hint {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--ink-muted);
}

/* ---------- Theme swatches ---------- */

/* Each swatch is a miniature Slate screen painted in its own theme's
   colors (the --sw-* values set inline per swatch by js/settings.js), so
   the choice is judged on how the app will actually look, not a dot. */
.theme-swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 14px;
}

.theme-swatch {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 7px 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
  transition: transform var(--transition), box-shadow var(--transition);
}

.theme-swatch:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.18);
}

.theme-swatch.is-active {
  border-color: transparent;
  box-shadow: 0 0 0 3px var(--sw-accent);
}

.theme-swatch.is-active:hover {
  box-shadow: 0 0 0 3px var(--sw-accent), 0 6px 14px rgba(0, 0, 0, 0.18);
}

.theme-swatch-preview {
  position: relative;
  display: flex;
  height: 96px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--sw-bg);
  /* Light themes' page color sits close to this card's own paper. */
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.tsp-sidebar {
  flex: 0 0 32%;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px 6px;
  background: var(--sw-sidebar);
}

.tsp-tag {
  width: 62%;
  height: 6px;
  border-radius: 1px;
  background: var(--sw-pop);
}

.tsp-nav {
  height: 10px;
  border-radius: 2px;
  background: var(--sw-paper);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.tsp-nav.is-active {
  background: var(--sw-strong);
}

.tsp-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px;
}

.tsp-sub {
  width: 46%;
  height: 6px;
  background: var(--sw-accent);
  transform: rotate(-3deg);
}

.tsp-title {
  width: 64%;
  height: 7px;
  border-radius: 1px;
  background: var(--sw-text);
}

.tsp-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border-radius: 3px;
  background: var(--sw-paper);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.tsp-line {
  height: 4px;
  border-radius: 1px;
  background: var(--sw-ink);
  opacity: 0.55;
}

.tsp-line.is-short {
  width: 60%;
}

.tsp-btn {
  margin-top: auto;
  align-self: flex-end;
  width: 42%;
  height: 8px;
  border-radius: 2px;
  background: var(--sw-strong);
  box-shadow: 1px 1.5px 0 var(--sw-deep);
}

.theme-swatch-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--sw-strong);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity var(--transition), transform var(--transition);
}

.theme-swatch.is-active .theme-swatch-check {
  opacity: 1;
  transform: scale(1);
}

.theme-swatch-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  padding: 0 2px;
}

.theme-swatch-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.theme-swatch.is-active .theme-swatch-label {
  font-weight: 700;
}

.theme-swatch-mode {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}

/* ---------- Toggle switch ---------- */

.settings-toggle {
  width: 48px;
  height: 44px;
  padding: 0;
  border: none;
  background: transparent;
  position: relative;
  flex-shrink: 0;
}

.settings-toggle-track {
  position: absolute;
  top: 50%;
  left: 2px;
  transform: translateY(-50%);
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: var(--border);
  transition: background var(--transition);
}

.settings-toggle.is-on .settings-toggle-track {
  background: var(--accent-strong);
}

.settings-toggle-thumb {
  position: absolute;
  top: 50%;
  left: 4px;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: left var(--transition);
}

.settings-toggle.is-on .settings-toggle-thumb {
  left: 26px;
}

/* ---------- Profile ---------- */

.profile-field {
  margin-bottom: 18px;
}

.profile-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.profile-counter {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-muted);
}

.profile-input {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  color-scheme: light;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.profile-input::placeholder {
  color: var(--ink-muted);
  opacity: 0.8;
}

.profile-input:hover {
  border-color: var(--accent-deep);
}

.profile-input:focus-visible {
  outline: none;
  border-color: var(--accent-deep);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-deep) 25%, transparent);
}

.profile-input[aria-invalid="true"] {
  border-color: #b42318;
}

.profile-bio {
  min-height: 88px;
  line-height: 1.5;
  resize: vertical;
}

.profile-username-wrap {
  position: relative;
  max-width: 320px;
  margin-top: 6px;
}

.profile-username-wrap .profile-input {
  margin-top: 0;
  padding-left: 30px;
}

.profile-at {
  position: absolute;
  top: 50%;
  left: 13px;
  transform: translateY(-50%);
  color: var(--ink-muted);
  font-weight: 700;
  pointer-events: none;
}

.profile-error {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 600;
  color: #b42318;
}

/* The card's single save, for everything above it (favorites included). */
.profile-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.profile-dirty {
  font-family: var(--font-hand);
  font-size: 16px;
  color: var(--accent-deep);
}

/* The same raised "sticker" as .add-btn, the app's primary action. */
.profile-save-btn,
.data-btn {
  min-height: 44px;
  padding: 0 22px;
  border-radius: var(--radius-sm);
  background: var(--accent-strong);
  color: #fff;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  box-shadow: 3px 4px 0 var(--accent-deep);
  transform: rotate(1deg);
  transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
}

.profile-save-btn:hover:not(:disabled),
.data-btn:hover:not(:disabled) {
  transform: rotate(0deg) translateY(-2px);
  box-shadow: 4px 6px 0 var(--accent-deep);
}

.profile-save-btn:active:not(:disabled),
.data-btn:active:not(:disabled) {
  transform: rotate(0deg) translateY(0);
  box-shadow: 1px 2px 0 var(--accent-deep);
}

.profile-save-btn:disabled,
.data-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ---------- Favorites ---------- */

.profile-favorites-label {
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}

/* Two Polaroids, then the profile preview filling the rest of the row. */
.profile-favorites {
  display: grid;
  grid-template-columns: repeat(2, 150px) minmax(0, 1fr);
  gap: 26px;
}

.favorite-slot {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.favorite-kind {
  font-family: var(--font-hand);
  font-size: 16px;
  color: var(--ink-muted);
}

.favorite-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

/* A Polaroid pinned to the settings "paper" — same frame as the library's
   own cards. */
.favorite-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
  padding: 9px 9px 12px;
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--ink);
  text-align: left;
  box-shadow: 2px 6px 14px rgba(0, 0, 0, 0.22);
  transform: rotate(-1.5deg);
  transition: transform var(--transition), box-shadow var(--transition);
}

.favorite-slot:nth-child(2) .favorite-card {
  transform: rotate(1.3deg);
}

.favorite-card:hover,
.favorite-slot:nth-child(2) .favorite-card:hover {
  transform: rotate(0deg) translateY(-4px);
  box-shadow: 0 0 0 2px var(--accent-strong),
    0 0 22px 4px color-mix(in srgb, var(--accent-glow) 40%, transparent),
    3px 10px 18px rgba(0, 0, 0, 0.3);
}

.favorite-poster {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface);
}

.favorite-poster-empty {
  background: linear-gradient(135deg, color-mix(in srgb, var(--ink) 75%, var(--accent-deep)), var(--ink));
}

.favorite-title {
  font-family: var(--font-hand);
  font-size: 16px;
  line-height: 1.15;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.favorite-year {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
}

.favorite-remove {
  min-height: 36px;
  padding: 0 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  transition: color var(--transition);
}

.favorite-remove:hover {
  color: #b42318;
}

.favorite-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  aspect-ratio: 150 / 262;
  border: 2px dashed color-mix(in srgb, var(--ink-muted) 60%, transparent);
  color: var(--ink-muted);
  transition: transform var(--transition), border-color var(--transition), color var(--transition);
}

.favorite-empty:hover {
  transform: translateY(-4px);
  border-color: var(--accent-deep);
  color: var(--accent-deep);
}

.favorite-empty-slot {
  font-size: 34px;
  font-weight: 300;
  line-height: 1;
}

.favorite-empty-label {
  font-family: var(--font-hand);
  font-size: 16px;
}

/* ---------- Profile preview ----------

   Drawn in the page's own colors (not the settings card's paper), so it
   reads as the profile itself sitting on the card — and shows off the
   active theme. */

.profile-preview {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  box-shadow: 2px 6px 14px rgba(0, 0, 0, 0.22);
}

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

.pp-monogram {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-strong);
  color: #fff;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  box-shadow: 2px 3px 0 var(--accent-deep);
}

.pp-names {
  min-width: 0;
}

.pp-username {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}

.pp-since {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-muted);
}

.pp-bio {
  font-family: var(--font-hand);
  font-size: 17px;
  line-height: 1.3;
  overflow-wrap: anywhere;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

.pp-bio.is-empty {
  color: var(--text-muted);
  font-style: italic;
}

.pp-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.pp-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pp-num {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
}

.pp-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.profile-preview-slot .profile-preview {
  flex: 1;
}

/* ---------- Tile contents ---------- */

/* Defaults: three fields side by side (stacked when narrow), each a
   label, a hint, then the select at full width. */
.settings-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px 22px;
}

.settings-field .settings-select-wrap {
  margin-top: 8px;
}

.settings-field .settings-select {
  width: 100%;
  min-width: 0;
}

.settings-field-toggle {
  display: block;
  margin-top: 6px;
}

.tile-motion .settings-row {
  padding: 0;
}

.tile-density .settings-segmented {
  margin-top: 14px;
}

.tile-density .settings-segmented button {
  flex: 1;
}

/* Favorites row inside the profile preview: mini poster + title. */
.pp-favs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

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

.pp-fav-poster {
  flex-shrink: 0;
  display: block;
  width: 38px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 3px;
  box-shadow: 1px 2px 5px rgba(0, 0, 0, 0.4);
}

.pp-fav-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.pp-fav-kind {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.pp-fav-title {
  font-family: var(--font-hand);
  font-size: 15px;
  line-height: 1.15;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Your Data: one row per action (export, import), each an icon, what it
   does, and its button. */
.data-actions {
  display: flex;
  flex-direction: column;
  margin-top: 16px;
}

.data-action {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
  border-top: 1px dashed var(--border);
}

.data-action:last-child {
  padding-bottom: 2px;
}

.data-action-icon {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent-deep);
}

.data-action-icon svg {
  width: 20px;
  height: 20px;
}

.data-action-text {
  flex: 1 1 auto;
  min-width: 0;
}

.data-action-text .settings-row-hint {
  margin-top: 2px;
}

.data-ext {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--accent-deep);
}

.data-btn {
  flex-shrink: 0;
  min-width: 150px;
}

/* Delete account: set apart in red, so it's never mistaken for the tiles
   above it. */
.tile-danger {
  border: 1px dashed rgba(220, 38, 38, 0.55);
}

.tile-danger .settings-tile-title {
  color: #b42318;
}

.tile-danger .data-action {
  padding-top: 0;
  border-top: none;
}

.tile-danger .data-action-icon {
  background: rgba(220, 38, 38, 0.12);
  color: #dc2626;
}

.data-btn.danger-btn {
  background: #dc2626;
  box-shadow: 3px 4px 0 #991b1b;
}

.data-btn.danger-btn:hover:not(:disabled) {
  background: #ef4444;
  box-shadow: 4px 6px 0 #991b1b;
}

.data-btn.danger-btn:active:not(:disabled) {
  box-shadow: 1px 2px 0 #991b1b;
}

/* ---------- Narrow layouts ----------
   Last in the file on purpose: these override base rules above with the
   same specificity, so they have to come after them. */

/* Too narrow for the collage: one column, the two small toggles still
   sharing a row. */
@container (max-width: 760px) {
  .tile-theme {
    grid-column: 1 / -1;
    grid-row: auto;
  }

  .tile-motion,
  .tile-density {
    grid-column: span 6;
  }

  .settings-fields {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* No room left for the preview beside the two Polaroids (it needs ~260px):
   it drops below at full width, and the Polaroids share the row above. */
@container (max-width: 660px) {
  .profile-favorites {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .profile-preview-slot {
    grid-column: 1 / -1;
  }
}

@container (max-width: 480px) {
  .tile-motion,
  .tile-density {
    grid-column: 1 / -1;
  }

  /* The button drops under the text, full width. */
  .data-action {
    flex-wrap: wrap;
  }

  .data-action-text {
    flex-basis: calc(100% - 58px);
  }

  .data-btn {
    width: 100%;
  }
}
