/* Shared platform-chrome components (forms, buttons, nav, page shell). */

/* Universal baseline for every select/input/textarea on the site, not
   just ones inside a <form> or a specific container. Bug found: reset.css
   sets color:inherit on these (near-white text), but nothing set a
   matching dark background on ones outside .auth-shell/form/.stack-form,
   so they fell back to the browser's native white background — near-
   white text on a white native dropdown, functionally invisible. Setting
   both color AND background explicitly here, on the bare elements, is
   what actually controls a <select>'s popup list rendering in every
   major browser (color-scheme alone isn't enough once color is
   overridden). More specific per-page rules (.auth-shell input etc.)
   still win where they exist; this is just the floor everywhere else.
   Excludes type=checkbox/radio/range/color/file, which have their own
   native rendering that this would break. Wrapped in :where() so this
   carries ZERO specificity — it's a floor, not a rule that should ever
   need to out-rank a page-specific selector like .auth-shell input. */
:where(select, textarea, input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"])) {
  background: var(--tilt-bg);
  color: var(--tilt-text);
  border: 1px solid var(--tilt-border);
  border-radius: calc(var(--tilt-radius) / 2);
  padding: 0.5rem 0.6rem;
  color-scheme: dark;
}

:where(select, textarea, input):focus-visible {
  border-color: var(--tilt-accent);
}

.auth-shell {
  max-width: 26rem;
  padding: 2rem;
  background: var(--tilt-surface);
  border: 2px solid var(--tilt-accent);
  border-radius: var(--tilt-radius);
  box-shadow: 0 0 0 4px rgba(255, 45, 149, 0.08), 0 20px 50px rgba(0, 0, 0, 0.5);
}

.auth-shell h1 {
  font-family: var(--tilt-font-display);
  font-size: 1.75rem;
  margin-bottom: 0.25rem;
  letter-spacing: 0.02em;
}

.auth-shell h1 .accent {
  color: var(--tilt-accent);
}

.auth-shell form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1rem;
}

.auth-shell label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--tilt-text-muted);
}

.auth-shell input,
.auth-shell select {
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--tilt-border);
  border-radius: calc(var(--tilt-radius) / 2);
  background: var(--tilt-bg);
  color: var(--tilt-text);
}

.auth-shell input:focus-visible,
.auth-shell select:focus-visible {
  border-color: var(--tilt-accent);
}

/* Bubblegum-grunge buttons: a hand-cut sticker look (uneven corner
   radii, a hard offset "pop" shadow instead of a soft blur, a slight
   rotate on hover as if it's peeling off the page) built entirely from
   the brand tokens above — no new assets. Platform chrome only (see this
   file's header + css/base.css's), so it can't bleed into user profile
   theming. */
button,
.button {
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 4px 9px 5px 10px;
  padding: 0.6rem 1.25rem;
  background: var(--tilt-accent-strong);
  color: var(--tilt-accent-contrast);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.35);
  transition: filter 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

button:hover {
  filter: brightness(1.15);
  transform: translate(-1px, -2px) rotate(-0.75deg);
  box-shadow: 3px 5px 0 rgba(0, 0, 0, 0.4);
}

button:active {
  transform: translate(0, 0) rotate(0deg);
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.35);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
  box-shadow: none;
}

/* Generic secondary/tertiary button — used across most pages
   (rooms/communities/editor/friends/admin/etc). Previously only had a
   style when nested inside .profile-actions, so it rendered as an
   ordinary accent button everywhere else; fixed here, not new. Dashed
   outline (vs. the primary button's solid sticker look) reads as "the
   quieter action" without needing a second colour. */
.secondary-button {
  background: transparent;
  border: 2px dashed var(--tilt-border);
  color: var(--tilt-text);
  box-shadow: none;
}

.secondary-button:hover {
  border-color: var(--tilt-accent);
  color: var(--tilt-accent);
  filter: none;
  box-shadow: none;
  transform: translateY(-1px);
}

.secondary-button:active {
  transform: translateY(0);
}

/* Destructive action (delete/remove/report-removal etc). Was previously
   defined only in css/editor.css (a single-property override) even
   though it's used across friends/rooms/communities/admin/theme/border
   pages too — moved here so every button variant has one home. */
.danger-button {
  background: #b3261e;
  border-color: transparent;
}

.danger-button:hover {
  filter: brightness(1.2);
}

.link-button {
  background: none;
  border: none;
  color: var(--tilt-accent);
  padding: 0;
  font-weight: 600;
  text-transform: none;
  letter-spacing: normal;
  text-decoration: underline;
  box-shadow: none;
  border-radius: 0;
}

.link-button:hover {
  transform: none;
  filter: none;
  box-shadow: none;
  color: #ff5cab;
}

/* A themed back-navigation link (replaces ad-hoc "&larr; Back to X" text
   scattered per-page) — an arrow that nudges left on hover, added via
   ::before so call sites only need the class, not a hardcoded glyph. */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--tilt-text-muted);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.back-link::before {
  content: "\2190";
  display: inline-block;
  transition: transform 0.15s ease;
}

.back-link:hover {
  color: var(--tilt-accent);
}

.back-link:hover::before {
  transform: translateX(-3px);
}

/* Native range/checkbox/color controls, restyled from OS-default chrome
   to match the brand — every slider and tick-box on the site runs
   through these three rules (settings, theme editor, border editor,
   room-edit, tile editor), so this is a one-time global pass rather than
   per-page overrides. */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1.5rem;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 0.4rem;
  border-radius: 1rem;
  background: var(--tilt-bg);
  border: 1px solid var(--tilt-border);
}

input[type="range"]::-moz-range-track {
  height: 0.4rem;
  border-radius: 1rem;
  background: var(--tilt-bg);
  border: 1px solid var(--tilt-border);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  margin-top: -0.55rem;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background: var(--tilt-accent);
  border: 3px solid var(--tilt-bg);
  box-shadow: 0 0 0 2px var(--tilt-accent), 0 2px 6px rgba(0, 0, 0, 0.5);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

input[type="range"]::-moz-range-thumb {
  width: 1.4rem;
  height: 1.4rem;
  border: 3px solid var(--tilt-bg);
  border-radius: 50%;
  background: var(--tilt-accent);
  box-shadow: 0 0 0 2px var(--tilt-accent), 0 2px 6px rgba(0, 0, 0, 0.5);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

input[type="range"]:hover::-webkit-slider-thumb {
  transform: scale(1.12);
}

input[type="range"]:hover::-moz-range-thumb {
  transform: scale(1.12);
}

input[type="range"]:focus-visible {
  outline: none;
}

input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 2px var(--tilt-accent), 0 0 0 5px rgba(255, 45, 149, 0.35);
}

input[type="range"]:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 2px var(--tilt-accent), 0 0 0 5px rgba(255, 45, 149, 0.35);
}

input[type="range"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  margin: 0;
  vertical-align: -0.3em;
  background: var(--tilt-bg);
  border: 2px solid var(--tilt-border);
  border-radius: 4px 7px 5px 8px;
  cursor: pointer;
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

input[type="checkbox"]:hover {
  border-color: var(--tilt-accent);
}

input[type="checkbox"]:checked {
  background: var(--tilt-accent);
  border-color: var(--tilt-accent-strong);
}

input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 0.34rem;
  top: 0.12rem;
  width: 0.3rem;
  height: 0.6rem;
  border: solid var(--tilt-accent-contrast);
  border-width: 0 3px 3px 0;
  transform: rotate(40deg);
}

input[type="checkbox"]:active {
  transform: scale(0.9);
}

input[type="checkbox"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input[type="color"] {
  width: 2.75rem;
  height: 2.25rem;
  padding: 2px;
  border: 2px solid var(--tilt-border);
  border-radius: 4px 8px 5px 7px;
  background: var(--tilt-bg);
  cursor: pointer;
}

input[type="color"]:hover {
  border-color: var(--tilt-accent);
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}

input[type="color"]::-moz-color-swatch {
  border: none;
  border-radius: 2px;
}

/* Native <dialog>-based avatar crop/zoom step (js/media/avatar-cropper.js)
   — shown wherever an avatar is uploaded, not just settings.html. */
.avatar-cropper-dialog {
  background: var(--tilt-surface);
  color: var(--tilt-text);
  border: 2px solid var(--tilt-accent);
  border-radius: 4px 10px 5px 10px;
  padding: 1.5rem;
  max-width: 90vw;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.avatar-cropper-dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
}

.avatar-cropper-dialog h2 {
  font-family: var(--tilt-font-display);
  font-weight: normal;
  margin: 0 0 1rem;
}

.avatar-cropper-viewport {
  position: relative;
  overflow: hidden;
  margin: 0 auto 1rem;
  border-radius: 50%;
  border: 2px dashed var(--tilt-border);
  background: repeating-conic-gradient(#2a2a2a 0% 25%, #1a1a1a 0% 50%) 50% / 16px 16px;
  cursor: grab;
  touch-action: none;
}

.avatar-cropper-viewport:active {
  cursor: grabbing;
}

.avatar-cropper-image {
  position: absolute;
  max-width: none;
  user-select: none;
  -webkit-user-drag: none;
}

.avatar-cropper-dialog label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--tilt-text-muted);
  margin-bottom: 0.35rem;
}

.avatar-cropper-dialog input[type="range"] {
  width: 100%;
}

.avatar-cropper-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
}

a {
  color: var(--tilt-accent);
}

/* Legacy top bar — still used by pages that don't (yet) have the
   app-shell sidebar: login.html and profile.html (Phase C). */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--tilt-surface);
  border-bottom: 1px solid var(--tilt-border);
}

.site-header .brand-mark {
  display: block;
  height: 2.25rem;
}

.site-header nav ul {
  display: flex;
  gap: 1.25rem;
  align-items: center;
}

.site-header nav a {
  color: var(--tilt-text);
  text-decoration: none;
  font-weight: 600;
}

.site-header nav a:hover {
  color: var(--tilt-accent);
}

.home-shell {
  max-width: 60rem;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  gap: 1.5rem;
}

.home-shell section {
  background: var(--tilt-surface);
  border: 1px solid var(--tilt-border);
  border-radius: var(--tilt-radius);
  padding: 1.25rem;
  position: relative;
}

.home-shell h1,
.home-shell h2 {
  font-family: var(--tilt-font-display);
  letter-spacing: 0.02em;
  font-weight: normal;
}

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

.home-shell #search-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.home-shell #search-form input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--tilt-border);
  border-radius: calc(var(--tilt-radius) / 2);
  background: var(--tilt-bg);
  color: var(--tilt-text);
}

.notification-row.is-unread {
  font-weight: 600;
}

.empty-note {
  color: var(--tilt-text-muted);
  font-style: italic;
}

.report-details {
  display: block;
  color: var(--tilt-text-muted);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* admin.html's "Overview" stat row (js/ui/admin-page.js's loadStats) — a
   <dl> of plain dt/dd pairs, not a table, since there's no header row to
   align against. */
.admin-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem 2.5rem;
  margin-bottom: 1rem;
}

.admin-stats dt {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--tilt-text-muted);
}

.admin-stats dd {
  font-family: var(--tilt-font-display);
  font-size: 1.75rem;
  margin: 0;
}

.manage-row {
  flex-wrap: wrap;
}

/* admin.html's urgent-priority reports (child_safety/terrorism_or_extremism,
   see submit_report in migration 042) — listReports() already sorts these
   first; this makes them visually unmissable in the list too. */
.is-urgent-report {
  border: 1px solid crimson;
  background: rgba(220, 20, 60, 0.08);
}

/* settings.html's account-status banner (js/ui/settings-page.js) —
   :not([hidden]) beats the UA [hidden] rule the same way every other
   toggled panel in this app already does. */
.account-status-banner:not([hidden]) {
  display: block;
  margin-bottom: 1.5rem;
  padding: 1rem;
  border: 1px solid crimson;
  border-radius: var(--tilt-radius);
  background: rgba(220, 20, 60, 0.1);
}

.manage-row a {
  color: var(--tilt-text);
  text-decoration: none;
  font-weight: 600;
}

.manage-row a:hover {
  color: var(--tilt-accent);
}

/* Themed confirm/prompt dialogs (js/ui/dialogs.js) — the site-wide
   replacement for window.confirm()/window.prompt(). Built on the native
   <dialog> element so Esc-to-close, focus trapping and the ::backdrop
   come for free; everything else here is just brand styling on top. */
.tilt-dialog {
  max-width: 26rem;
  width: calc(100% - 2rem);
  padding: 1.5rem;
  background: var(--tilt-surface);
  color: var(--tilt-text);
  border: 2px solid var(--tilt-accent);
  border-radius: var(--tilt-radius);
  box-shadow: 0 0 0 4px rgba(255, 45, 149, 0.08), 0 20px 50px rgba(0, 0, 0, 0.5);
}

.tilt-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.tilt-dialog-title {
  font-family: var(--tilt-font-display);
  font-size: 1.25rem;
  margin: 0 0 0.5rem;
}

.tilt-dialog-message {
  color: var(--tilt-text-muted);
  margin: 0 0 1rem;
}

.tilt-dialog-input {
  width: 100%;
  margin-bottom: 1rem;
}

.tilt-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Discover Photos' detail dialog (js/ui/photos-page.js) — a plain
   .tilt-dialog with an image + byline on top, not a separate component. */
.photo-detail-dialog {
  max-width: 32rem;
}

.photo-detail-dialog img {
  width: 100%;
  max-height: 24rem;
  object-fit: contain;
  border-radius: calc(var(--tilt-radius) / 2);
  background: #000;
  margin-bottom: 0.75rem;
}

.photo-detail-byline {
  margin: 0 0 1rem;
}

.photo-detail-byline a {
  font-weight: 700;
}

/* Direct messages inbox (messages.html, js/ui/messages-page.js) — a
   conversation list beside a thread, same two-pane shape as most chat
   apps. The thread pane itself reuses .room-chat/.chat-messages/
   .chat-message wholesale (css/rooms.css) rather than duplicating that
   styling here. */
.messages-layout {
  display: grid;
  grid-template-columns: 18rem 1fr;
  gap: 1.5rem;
  align-items: start;
  padding: 1.5rem;
  max-width: 72rem;
  margin: 0 auto;
}

.messages-list-panel {
  background: var(--tilt-surface);
  border: 1px solid var(--tilt-border);
  border-radius: var(--tilt-radius);
  padding: 0.5rem;
  max-height: 32rem;
  overflow-y: auto;
}

.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.conversation-row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.6rem 0.75rem;
  background: transparent;
  border: none;
  border-radius: calc(var(--tilt-radius) / 2);
  box-shadow: none;
  color: var(--tilt-text);
  text-transform: none;
  font-weight: 400;
  cursor: pointer;
}

.conversation-row:hover {
  background: color-mix(in srgb, var(--tilt-accent) 10%, transparent);
  filter: none;
  transform: none;
  box-shadow: none;
}

.conversation-row[aria-current="true"] {
  background: var(--tilt-accent);
  color: var(--tilt-accent-contrast);
}

.conversation-row-name {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.9rem;
}

.conversation-row-preview {
  font-size: 0.8rem;
  color: inherit;
  opacity: 0.75;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-unread-badge {
  flex-shrink: 0;
  background: var(--tilt-accent);
  color: var(--tilt-accent-contrast);
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.05rem 0.4rem;
}

.conversation-row[aria-current="true"] .conversation-unread-badge {
  background: var(--tilt-accent-contrast);
  color: var(--tilt-accent);
}

.messages-thread {
  height: 32rem;
}

.thread-with {
  padding: 0.75rem 1rem 0;
  font-weight: 700;
}

@media (max-width: 60rem) {
  .messages-layout {
    grid-template-columns: 1fr;
  }

  .messages-list-panel {
    max-height: 16rem;
  }
}

/* Themed toast notifications (js/ui/dialogs.js's showToast()) — the
   site-wide replacement for any native browser notification. Stacks
   bottom-right, newest on top; each toast dismisses itself after a delay
   or on click. */
.tilt-toast-stack {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 60;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
  max-width: 22rem;
}

.tilt-toast {
  padding: 0.75rem 1rem;
  background: var(--tilt-surface);
  color: var(--tilt-text);
  border: 2px solid var(--tilt-accent);
  border-radius: calc(var(--tilt-radius) / 2);
  box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.35);
  cursor: pointer;
  animation: tilt-toast-in 0.15s ease;
}

.tilt-toast--error {
  border-color: crimson;
}

@keyframes tilt-toast-in {
  from {
    opacity: 0;
    transform: translateY(0.5rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
