/* The personal space: a library of the reader's works and the tenant's assets. */

.workspace-page {
  --ws-max: 1180px;
}

.workspace-page .stage {
  padding: var(--s8) var(--s8) calc(var(--s12) + env(safe-area-inset-bottom));
  scrollbar-color: var(--line) transparent;
  scrollbar-width: thin;
}

.workspace-page .stage::-webkit-scrollbar {
  width: 10px;
}

.workspace-page .stage::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 999px;
}

.workspace-page .stage::-webkit-scrollbar-thumb:hover {
  background: var(--accent-dim);
}

/* ---- the sign-in gate ---------------------------------------------------------------------- */

.ws-gate {
  display: grid;
  justify-items: start;
  gap: var(--s2);
  width: min(560px, 100%);
  margin: clamp(var(--s6), 12vh, 120px) auto 0;
  padding: var(--s8);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: 0 18px 44px -24px rgb(0 0 0 / 70%);
}

.ws-spinner {
  width: 24px;
  height: 24px;
  margin-bottom: var(--s2);
  border: 2px solid var(--accent-dim);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ws-spin 0.9s linear infinite;
}

.ws-gate.is-error .ws-spinner {
  display: none;
}

.ws-gate-title {
  font-size: 22px;
  font-weight: 650;
  line-height: 1.3;
  text-wrap: balance;
}

.ws-gate-note {
  max-width: 56ch;
  color: var(--secondary);
  overflow-wrap: anywhere;
}

.ws-gate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  margin-top: var(--s3);
}

/* ---- page heading and tabs ----------------------------------------------------------------- */

.ws {
  width: min(var(--ws-max), 100%);
  margin: 0 auto;
}

.ws-head {
  margin-bottom: var(--s8);
}

.ws-title {
  font-size: clamp(30px, 3.6vw, 42px);
  font-weight: 650;
  line-height: 1.12;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.ws-lead {
  max-width: 64ch;
  margin-top: var(--s3);
  color: var(--secondary);
  font-size: 16px;
  line-height: 1.7;
}

.ws-tablist {
  display: flex;
  gap: var(--s6);
}

.ws-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: none;
  min-height: 48px;
  padding: 0 2px;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.ws-tab::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 6px;
  left: 0;
  height: 2px;
  border-radius: 2px;
  background: transparent;
  transition: background-color 0.18s ease-out;
}

.ws-tab:hover {
  color: var(--text);
}

.ws-tab[aria-selected="true"] {
  color: var(--text);
}

.ws-tab[aria-selected="true"]::after {
  background: var(--accent);
}

.ws-panel {
  padding-top: var(--s6);
}

.ws-panel[hidden] {
  display: none;
}

.ws-panel:focus {
  outline: none;
}

.ws-panel:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 8px;
  border-radius: var(--r-control);
}

/* ---- toolbars ------------------------------------------------------------------------------ */

.ws-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--s3) var(--s4);
  margin-bottom: var(--s4);
}

.ws-toolbar-assets {
  margin-bottom: var(--s2);
}

.ws-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1);
}

.ws-chip {
  padding: 0 var(--s3);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--secondary);
  font-size: 14px;
  cursor: pointer;
}

.ws-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

.ws-chip[aria-pressed="true"] {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text);
}

.ws-toolbar-end {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s2);
  margin-inline-start: auto;
}

.ws-status {
  min-height: 1.4em;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.ws-tool {
  padding: 0 var(--s2);
  background: transparent;
  border: 0;
  color: var(--secondary);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.ws-tool:hover {
  color: var(--accent);
}

.ws-search {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex: 1 1 320px;
  max-width: 480px;
  min-width: 0;
}

.ws-search .field-input {
  min-width: 0;
  background: var(--surface);
}

.ws-search .field-input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.ws-search input[type="search"]::-webkit-search-cancel-button,
.ws-search input[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.ws-clear {
  flex: none;
  padding: 0 var(--s3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  color: var(--secondary);
  font-size: 13px;
  cursor: pointer;
}

.ws-clear:hover {
  border-color: var(--accent);
  color: var(--text);
}

.ws-hint {
  max-width: 76ch;
  margin-bottom: var(--s4);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.ws-note {
  margin-bottom: var(--s3);
  padding: var(--s2) var(--s3);
  background: var(--surface);
  border: 1px solid var(--accent-dim);
  border-radius: var(--r-control);
  color: var(--secondary);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.ws-note.is-error {
  border-color: var(--danger);
  color: var(--danger);
}

.ws-error {
  margin-bottom: var(--s3);
  padding: var(--s3);
  border: 1px solid var(--danger);
  border-radius: var(--r-control);
  color: var(--danger);
  font-size: 14px;
  overflow-wrap: anywhere;
}

/* ---- the grid ------------------------------------------------------------------------------ */

.ws-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--s4);
}

.ws-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  overflow: hidden;
  transition: border-color 0.18s ease-out, box-shadow 0.18s ease-out,
    transform 0.18s ease-out;
}

.ws-card:hover {
  border-color: var(--accent);
  box-shadow: 0 14px 30px -18px rgb(0 0 0 / 58%);
  transform: translateY(-2px);
}

.ws-card:focus-within {
  border-color: var(--focus);
}

.ws-preview {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--rail);
  border-bottom: 1px solid var(--line);
}

.ws-preview--text {
  background: var(--rail);
}

.ws-kind {
  position: absolute;
  z-index: 2;
  top: var(--s2);
  left: var(--s2);
  padding: 2px var(--s2);
  background: var(--rail);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--secondary);
  font-size: 12px;
  line-height: 1.6;
  letter-spacing: 0.02em;
}

.ws-media {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.ws-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--rail);
}

.ws-media video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--rail);
}

.ws-media audio {
  width: calc(100% - var(--s6));
  max-width: 360px;
}

.ws-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--s2);
  padding: var(--s4);
  color: var(--muted);
  text-align: center;
}

.ws-fallback-mark {
  display: inline-grid;
  place-items: center;
  min-width: 54px;
  min-height: 54px;
  padding: 0 var(--s2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  color: var(--secondary);
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.04em;
}

.ws-fallback-note {
  font-size: 12.5px;
  line-height: 1.6;
}

/* A written work reads as a sheet lifted out of the card, not as another card. */
.ws-text-sheet {
  position: absolute;
  inset: var(--s8) var(--s4) -1px;
  display: -webkit-box;
  padding: var(--s3);
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 7;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 10px 10px 0 0;
  box-shadow: 0 12px 26px -16px rgb(0 0 0 / 70%);
  color: var(--secondary);
  font-size: 13px;
  line-height: 1.9;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ws-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--s1);
  min-width: 0;
  padding: var(--s4) var(--s4) var(--s3);
}

.ws-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  justify-self: start;
  padding: 0 var(--s2);
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
  white-space: nowrap;
}

.ws-title-line {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.ws-meta {
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.ws-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  margin-top: auto;
  padding: 0 var(--s4) var(--s4);
}

.ws-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 var(--s3);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  color: var(--secondary);
  font-size: 13px;
  text-decoration: none;
}

.ws-action:hover {
  border-color: var(--accent);
  color: var(--text);
}

.ws-action--primary {
  border-color: var(--accent-dim);
  color: var(--accent);
}

.ws-action--primary:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text);
}

.ws-action[type="button"] {
  cursor: pointer;
}

#panel-works :is(.ws-card--image, .ws-card--video) .ws-preview,
#works-skeleton .ws-skeleton-media {
  aspect-ratio: 1;
}

#panel-works .ws-body {
  padding: var(--s2) var(--s3) var(--s1);
}

#panel-works .ws-actions {
  align-items: center;
  gap: var(--s1) var(--s2);
  padding: var(--s1) var(--s3) var(--s2);
}

#panel-works .ws-action {
  min-height: 32px;
  padding-inline: var(--s2);
}

#panel-works .ws-publication-state {
  padding-inline: var(--s1);
  color: var(--muted);
  font-size: 12px;
}

@media (pointer: coarse) {
  #panel-works .ws-action {
    min-height: 44px;
  }
}

.sign-in.publication-dialog {
  width: min(520px, calc(100vw - 2 * var(--s4)));
  padding: var(--s6);
}

.publication-dialog .sign-in-panel {
  padding: 0;
}

@media (max-width: 480px) {
  .sign-in.publication-dialog {
    width: 100%;
    padding-inline: max(var(--s4), env(safe-area-inset-left))
      max(var(--s4), env(safe-area-inset-right));
    padding-bottom: max(var(--s6), env(safe-area-inset-bottom));
  }
}

.publication-preview {
  display: grid;
  gap: var(--s1);
  padding: var(--s3);
  background: var(--page);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  overflow-wrap: anywhere;
}

.publication-work-title {
  font-weight: 600;
}

.publication-prompt {
  max-height: min(26dvh, 200px);
  overflow: auto;
  white-space: pre-wrap;
}

.publication-status:empty {
  display: none;
}

.publication-status {
  color: var(--danger);
}

.publication-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--s2);
}

/* ---- empty and loading states -------------------------------------------------------------- */

.ws-empty {
  display: grid;
  grid-column: 1 / -1;
  justify-items: center;
  gap: var(--s2);
  padding: clamp(var(--s8), 5vw, var(--s12)) var(--s4);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid color-mix(in srgb, var(--line) 55%, var(--surface));
  border-radius: var(--r-card);
  text-align: center;
}

.ws-empty-title {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
}

.ws-empty-text {
  max-width: 52ch;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.ws-empty .button {
  margin-top: var(--s3);
  min-width: 112px;
}

.ws-empty .button-primary {
  color: var(--on-accent);
}

.ws-empty .button-primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, var(--on-accent));
}

.ws-more-row {
  display: flex;
  justify-content: center;
  margin-top: var(--s6);
}

.ws-card-skeleton {
  pointer-events: none;
}

.ws-card-skeleton:hover {
  border-color: var(--line);
  box-shadow: none;
  transform: none;
}

.ws-skeleton-media {
  aspect-ratio: 4 / 3;
  background: linear-gradient(100deg, var(--raised) 20%, var(--surface) 50%, var(--raised) 80%);
  background-size: 220% 100%;
  border-bottom: 1px solid var(--line);
  animation: ws-shimmer 1.4s ease-in-out infinite;
}

.ws-skeleton-body {
  display: grid;
  gap: var(--s2);
  padding: var(--s4);
}

.ws-skeleton-line {
  width: 82%;
  height: 13px;
  border-radius: 999px;
  background: var(--raised);
}

.ws-skeleton-line.is-short {
  width: 50%;
  height: 11px;
}

/* ---- motion -------------------------------------------------------------------------------- */

@keyframes ws-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes ws-shimmer {
  from {
    background-position: 120% 0;
  }
  to {
    background-position: -120% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ws-card:hover {
    transform: none;
  }

  .ws-spinner,
  .ws-skeleton-media {
    animation: none;
  }

  .ws-skeleton-media {
    background: var(--raised);
  }
}

/* ---- narrower screens ---------------------------------------------------------------------- */

@media (max-width: 1100px) {
  .ws-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }
}

@media (max-width: 900px) {
  .workspace-page .stage {
    padding: var(--s6) var(--s4) calc(var(--s12) + env(safe-area-inset-bottom));
  }

  .ws-head {
    margin-bottom: var(--s6);
  }
}

@media (max-width: 767px) {
  .workspace-page .stage {
    padding: var(--s6) max(var(--s4), env(safe-area-inset-right))
      calc(var(--s12) + env(safe-area-inset-bottom)) max(var(--s4), env(safe-area-inset-left));
  }

  .ws-title {
    font-size: clamp(28px, 9vw, 34px);
  }

  .ws-lead {
    font-size: 14px;
  }

  .ws-toolbar-assets .ws-search {
    flex-basis: 100%;
    max-width: none;
  }

  .ws-toolbar-end {
    width: 100%;
    margin-inline-start: 0;
  }

  .ws-status {
    flex-basis: 100%;
    order: -1;
  }

  .ws-gate {
    margin-top: var(--s6);
    padding: var(--s6);
  }
}

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

  .ws-tablist {
    gap: var(--s4);
  }

  .ws-tab {
    flex: 1;
    justify-content: center;
  }

  .ws-filters {
    width: 100%;
  }

  .ws-toolbar-end .button-primary {
    flex: 1;
  }

  .ws-search {
    flex-basis: 100%;
  }
}

:root[data-theme="light"] .ws-card:hover {
  box-shadow: 0 14px 30px -18px rgb(24 46 36 / 26%);
}

:root[data-theme="light"] .ws-gate {
  box-shadow: 0 18px 44px -24px rgb(24 46 36 / 28%);
}

:root[data-theme="light"] .ws-text-sheet {
  box-shadow: 0 12px 26px -16px rgb(24 46 36 / 28%);
}
