*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #0d1117;
  color: #e6edf3;
  min-height: 100vh;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

header {
  margin-bottom: 2rem;
}

/* Cards */
.card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  margin-bottom: 1.5rem;
}

.card.centered {
  text-align: center;
  max-width: 400px;
  margin: 4rem auto;
}

.card h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: #e6edf3;
}

.card.centered .muted {
  margin-bottom: 1.5rem;
}

/* Auth states */
.hidden { display: none !important; }

.muted {
  color: #8b949e;
  font-size: 0.9rem;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.55rem 1.25rem;
  border-radius: 8px;
  border: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: #238636;
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #2ea043;
}

.btn-secondary {
  background: #21262d;
  color: #c9d1d9;
  border: 1px solid #30363d;
}

.btn-secondary:hover:not(:disabled) {
  background: #30363d;
  color: #e6edf3;
}

.btn-danger {
  background: #21262d;
  color: #c9d1d9;
  border: 1px solid #30363d;
}

.btn-danger:hover:not(:disabled) {
  background: #3d1515;
  border-color: #f85149;
  color: #f85149;
}

/* Profile card */
.profile-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.profile-identity {
  flex: 1;
  min-width: 0;
}

.profile-identity h2 {
  margin-bottom: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Prompt card */
.prompt-card h2 {
  margin-bottom: 1rem;
}

.prompt-input-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.prompt-textarea {
  flex: 1;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  font-family: inherit;
  color: #e6edf3;
  resize: vertical;
  transition: border-color 0.15s;
}

.prompt-textarea::placeholder {
  color: #768390;
}

.prompt-textarea:focus {
  outline: none;
  border-color: #388bfd;
}

.generate-btn {
  flex-shrink: 0;
  align-self: flex-end;
}

.prompt-name-input {
  width: 100%;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  font-family: inherit;
  color: #e6edf3;
  box-sizing: border-box;
  margin-bottom: 0.5rem;
  transition: border-color 0.15s;
}

.prompt-name-input::placeholder {
  color: #768390;
}

.prompt-name-input:focus {
  outline: none;
  border-color: #388bfd;
}

.prompt-name-error {
  margin-top: 0.4rem;
  margin-bottom: 0.4rem;
  color: #f85149;
  font-size: 0.82rem;
}

.twist-name-input {
  width: 100%;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  font-family: inherit;
  color: #e6edf3;
  box-sizing: border-box;
  margin-bottom: 0.5rem;
  transition: border-color 0.15s;
}

.twist-name-input::placeholder {
  color: #768390;
}

.twist-name-input:focus {
  outline: none;
  border-color: #388bfd;
}

.prompt-status {
  margin-top: 0.75rem;
  color: #8b949e;
  font-size: 0.9rem;
  font-style: italic;
}

/* Plot cards */
.plot-card {
  padding: 0;
  overflow: hidden;
}

.plot-meta {
  padding: 0.75rem 1rem 0.5rem;
  border-bottom: 1px solid #30363d;
}

.plot-prompt-text {
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.plot-iframe {
  display: block;
  width: 100%;
  height: 500px;
  border: none;
  background: #fff;
}

.plot-fullscreen-iframe {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  z-index: 1000 !important;
  border: none !important;
  margin: 0 !important;
}

.plot-fullscreen-close {
  position: fixed;
  top: 0.5rem;
  right: 0.5rem;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
}

body.plot-fullscreen-open {
  overflow: hidden;
}

/* Share modal */
.share-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.share-modal-box {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 1.5rem;
  width: min(480px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}

.share-modal-title {
  font-size: 1rem;
  font-weight: 600;
  color: #e6edf3;
}

.share-modal-url-input {
  width: 100%;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  font-family: inherit;
  color: #e6edf3;
}

.share-modal-url-input:focus {
  outline: none;
  border-color: #388bfd;
}

.share-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.share-modal-actions .btn {
  min-width: 6rem;
  text-align: center;
}

.plot-reactions {
  padding: 0.4rem 0.75rem;
  border-top: 1px solid #30363d;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.btn-reaction {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
  color: #8b949e;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  line-height: 1;
}

.btn-reaction:hover:not(:disabled) {
  background: #21262d;
  border-color: #30363d;
  color: #e6edf3;
}

.btn-reaction.active {
  color: #e6edf3;
  border-color: #388bfd;
  background: #1c2433;
}

.btn-reaction.active:hover:not(:disabled) {
  background: #1c2433;
  border-color: #388bfd;
}

.btn-reaction:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.reaction-icon {
  font-size: 1rem;
  line-height: 1;
}

.plot-actions {
  padding: 0.6rem 0.75rem;
  border-top: 1px solid #30363d;
  display: flex;
  gap: 0.5rem;
}

.plot-actions .btn {
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

.btn-icon {
  min-width: 2.6rem;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  text-align: center;
}

/* Update form */
.update-form,
.twist-form {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid #30363d;
  background: #0d1117;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.update-textarea,
.twist-textarea {
  width: 100%;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  font-family: inherit;
  color: #e6edf3;
  resize: vertical;
  transition: border-color 0.15s;
}

.update-textarea::placeholder,
.twist-textarea::placeholder {
  color: #768390;
}

.update-textarea:focus,
.twist-textarea:focus {
  outline: none;
  border-color: #388bfd;
}

.update-form-actions,
.twist-form-actions {
  display: flex;
  gap: 0.5rem;
}

.update-status,
.twist-status {
  color: #8b949e;
  font-size: 0.85rem;
  font-style: italic;
}

/* Gallery */
.gallery-heading {
  font-size: 1.2rem;
  font-weight: 600;
  color: #e6edf3;
  margin-bottom: 1rem;
}

.plot-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.plot-user-left {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

a.plot-user-link {
  text-decoration: none;
  border-radius: 6px;
}

a.plot-user-link:hover .plot-user {
  color: #e6edf3;
}

a.plot-user-link:hover .plot-avatar {
  opacity: 0.85;
}

.plot-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.plot-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #30363d;
  color: #8b949e;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.plot-user {
  font-size: 0.85rem;
  color: #c9d1d9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.plot-title {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
  color: #e6edf3;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
}

.plot-title:hover {
  color: #58a6ff;
  text-decoration: underline;
}

.plot-meta-right {
  flex: 1;
  display: flex;
  gap: 0.4rem;
  align-items: center;
  justify-content: flex-end;
  flex-shrink: 0;
}

.plot-version,
.plot-date {
  font-size: 0.75rem;
  color: #8b949e;
  white-space: nowrap;
}

/* Version history toggle */
.plot-history-toggle {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  flex: 1;
  display: flex;
  gap: 0.4rem;
  align-items: center;
  justify-content: flex-end;
  flex-shrink: 0;
}

.plot-history-toggle:hover .plot-version,
.plot-history-toggle:hover .plot-date {
  color: #58a6ff;
  text-decoration: underline;
}

/* Version history panel */
.plot-history-panel {
  border-top: 1px solid #30363d;
  background: #161b22;
  padding: 0.5rem 1rem;
}

.plot-history-item {
  display: flex;
  flex-direction: column;
  padding: 0.35rem 0;
  border-bottom: 1px solid #21262d;
}

.plot-history-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.plot-history-item:last-child {
  border-bottom: none;
}

.plot-history-version {
  font-size: 0.8rem;
  font-weight: 600;
  color: #e6edf3;
  min-width: 2.5rem;
}

.plot-history-item-published .plot-history-version {
  color: #58a6ff;
}

.plot-history-date {
  font-size: 0.8rem;
  white-space: nowrap;
}

.plot-history-title {
  flex: 1;
  font-size: 0.8rem;
  color: #e6edf3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plot-history-badge {
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: #1f6feb;
  color: #e6edf3;
  font-weight: 600;
  white-space: nowrap;
  min-width: 5rem;
  text-align: center;
  box-sizing: border-box;
}

.plot-history-publish-btn {
  background: none;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 0.1rem 0.45rem;
  font-size: 0.72rem;
  color: #8b949e;
  cursor: pointer;
  white-space: nowrap;
  min-width: 5rem;
  text-align: center;
  box-sizing: border-box;
  transition: border-color 0.15s, color 0.15s;
}

.plot-history-publish-btn:hover {
  border-color: #58a6ff;
  color: #58a6ff;
}

.plot-history-publish-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.plot-history-item:not(.plot-history-parent-item) .plot-history-row {
  cursor: pointer;
}

.plot-history-delete-btn {
  background: none;
  border: none;
  padding: 0 0.2rem;
  font-size: 0.85rem;
  color: #484f58;
  cursor: pointer;
  line-height: 1;
  transition: color 0.15s;
}

.plot-history-delete-btn:hover {
  color: #f85149;
}

.plot-history-delete-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.plot-history-details {
  margin-top: 0.4rem;
  padding: 0.4rem 0.5rem;
  background: #0d1117;
  border-radius: 6px;
  border: 1px solid #21262d;
}

.plot-history-details-heading {
  margin: 0.4rem 0 0.2rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #6e7681;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.plot-history-details-heading:first-child {
  margin-top: 0;
}

.plot-history-messages {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.78rem;
  color: #8b949e;
}

.plot-history-messages li {
  margin-bottom: 0.2rem;
}

.plot-history-messages li:last-child {
  margin-bottom: 0;
}

.plot-history-debug-pre {
  margin: 0;
  font-size: 0.75rem;
  color: #8b949e;
  white-space: pre-wrap;
  word-break: break-word;
}

.plot-history-parent-heading {
  margin: 0.6rem 0 0.25rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #6e7681;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-top: 1px solid #21262d;
  padding-top: 0.5rem;
}

.plot-history-parent-item {
  opacity: 0.75;
}

.plot-history-parent-owner {
  font-size: 0.8rem;
  color: #8b949e;
  text-decoration: none;
  white-space: nowrap;
}

a.plot-history-parent-owner:hover {
  color: #58a6ff;
  text-decoration: underline;
}

.plot-history-parent-by {
  color: #8b949e;
  font-size: 0.8rem;
}

.plot-history-parent-named {
  color: #8b949e;
  font-size: 0.8rem;
  text-decoration: none;
}

.plot-history-parent-named:hover {
  color: #58a6ff;
  text-decoration: underline;
}

/* Lazy-load plot placeholder */
.plot-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
  background: #0d1117;
  border-bottom: 1px solid #30363d;
}

.error-banner {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: #2d1117;
  border: 1px solid #6e2c2c;
  border-radius: 8px;
  color: #f85149;
  font-size: 0.875rem;
}

/* Back link */
.back-link {
  font-size: 0.9rem;
  color: #8b949e;
  text-decoration: none;
}

.back-link:hover {
  color: #e6edf3;
}

/* Site header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  max-width: 720px;
  margin: 0 auto;
  background: #161b22;
  border-bottom: 1px solid #30363d;
}

.site-header-inner {
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-header-brand {
  font-size: 1rem;
  font-weight: 700;
  color: #e6edf3;
  text-decoration: none;
  flex-shrink: 0;
}

.site-header-brand:hover {
  color: #58a6ff;
}

.site-header-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.site-header-identity {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
}

.site-header-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.site-header-names {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.site-header-name {
  font-size: 0.85rem;
  color: #e6edf3;
  white-space: nowrap;
  line-height: 1.2;
}

.site-header-username {
  font-size: 0.75rem;
  color: #8b949e;
  white-space: nowrap;
  line-height: 1.2;
}

/* Plot wrapper page back nav */
.plot-page-nav {
  margin-bottom: 1rem;
}

/* Avatar fallback (large, used on profile page) */
.avatar-fallback {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #30363d;
  color: #8b949e;
  font-size: 1.5rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* User profile extras */
.profile-info {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #30363d;
}

.profile-last-login {
  margin-top: 0.4rem;
  font-size: 0.8rem;
}

.section-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 1.25rem 0 0.5rem;
}

@media (max-width: 480px) {
  .prompt-input-row {
    flex-direction: column;
  }

  .prompt-textarea {
    width: 100%;
  }

  .generate-btn {
    align-self: stretch;
    text-align: center;
  }

  .plot-iframe {
    height: 360px;
  }
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid #30363d;
  margin-bottom: 1.25rem;
}

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: #8b949e;
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
  color: #e6edf3;
}

.tab.active {
  color: #e6edf3;
  border-bottom-color: #f78166;
}

/* User list (Following / Followers) */
.user-list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}

.user-list-item:hover {
  border-color: #58a6ff;
  background: #1c2128;
}

.user-list-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.user-list-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: #e6edf3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-list-handle {
  font-size: 0.82rem;
}

/* Comments panel */
.comments-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  border-top: 1px solid #30363d;
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #8b949e;
  cursor: pointer;
  text-align: left;
  transition: color 0.15s, background 0.15s;
}

.comments-heading:hover {
  color: #e6edf3;
  background: #161b22;
}

.comments-chevron {
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.2s;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.comments-chevron-open {
  transform: rotate(225deg);
  margin-bottom: -2px;
}

.comments-panel {
  border-top: 1px solid #30363d;
  background: #0d1117;
  padding: 0.75rem 1rem 1rem;
}

.comment {
  padding: 0.6rem 0;
  border-bottom: 1px solid #21262d;
}

.comment:last-of-type {
  border-bottom: none;
}

.comment-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}

.comment-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.comment-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #30363d;
  color: #8b949e;
  font-size: 0.7rem;
  font-weight: 600;
  flex-shrink: 0;
}

.comment-username {
  font-size: 0.85rem;
  font-weight: 600;
  color: #c9d1d9;
  text-decoration: none;
}

.comment-username:hover {
  color: #58a6ff;
}

.comment-date {
  font-size: 0.75rem;
  flex: 1;
}

.comment-actions {
  display: flex;
  gap: 0.3rem;
}

.comment-action-btn {
  background: none;
  border: none;
  color: #8b949e;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.1rem 0.25rem;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}

.comment-action-btn:hover {
  color: #e6edf3;
  background: #30363d;
}

.comment-message {
  font-size: 0.875rem;
  color: #e6edf3;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.comment-edit-form {
  margin-top: 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.comment-edit-textarea {
  width: 100%;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.875rem;
  font-family: inherit;
  color: #e6edf3;
  resize: vertical;
}

.comment-edit-textarea:focus {
  outline: none;
  border-color: #388bfd;
}

.comment-edit-actions {
  display: flex;
  gap: 0.4rem;
}

.comment-add-section {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #30363d;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.comment-textarea {
  width: 100%;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-family: inherit;
  color: #e6edf3;
  resize: vertical;
}

.comment-textarea:focus {
  outline: none;
  border-color: #388bfd;
}

.comment-form-actions {
  display: flex;
  justify-content: flex-end;
}

