/* ABOUTME: Neobrutalist CSS for Cast community platform. */
/* ABOUTME: Bold borders, hard shadows, vivid accents, chunky typography. */

@import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400;12..96,500;12..96,600;12..96,700;12..96,800&family=DM+Sans:opsz,wght@9..40,400;9..40,500;9..40,600&display=swap');

:root {
  --bg: #F5F0EB;
  --surface: #FFFFFF;
  --text: #000000;
  --text-secondary: #444444;
  --text-muted: #888888;
  --accent: #5B5FFF;
  --accent-hover: #4347E0;
  --coral: #FF5C38;
  --green: #00C853;
  --yellow: #FFD600;
  --border: #000000;
  --border-w: 2px;
  --shadow: 4px 4px 0 #000000;
  --shadow-sm: 2px 2px 0 #000000;
  --shadow-hover: 6px 6px 0 #000000;
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --radius: 8px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--accent);
  color: #fff;
}

a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 2px;
}

/* --- App Layout --- */

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* --- Sidebar --- */

.sidebar__toggle-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--surface);
  border-right: var(--border-w) solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.15s, min-width 0.15s;
}

.sidebar__logo {
  padding: 1.5rem 1.25rem;
  border-bottom: var(--border-w) solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sidebar__toggle {
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-muted);
  flex-shrink: 0;
  user-select: none;
  line-height: 1;
}

.sidebar__toggle::after {
  content: '«';
}

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

/* Collapsed sidebar */
#sidebar-toggle:checked ~ .app .sidebar {
  width: 48px;
  min-width: 48px;
}

#sidebar-toggle:checked ~ .app .sidebar__logo a {
  display: none;
}

#sidebar-toggle:checked ~ .app .sidebar__nav {
  display: none;
}

#sidebar-toggle:checked ~ .app .sidebar__user-info,
#sidebar-toggle:checked ~ .app .sidebar__logout {
  display: none;
}

#sidebar-toggle:checked ~ .app .sidebar__logo {
  justify-content: center;
  padding: 1.25rem 0.5rem;
}

/* Flip chevron when collapsed */
#sidebar-toggle:checked ~ .app .sidebar__toggle::after {
  content: '»';
}

#sidebar-toggle:checked ~ .app .sidebar__user {
  justify-content: center;
  padding: 0.85rem 0.5rem;
}

.sidebar__logo a {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
  text-decoration: none;
}

.sidebar__logo a:hover {
  text-decoration: none;
}

.sidebar__cursor {
  color: var(--accent);
}

.sidebar__nav {
  flex: 1;
  padding: 0.75rem;
  overflow-y: auto;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  color: var(--text-secondary);
  font-size: 0.93rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: var(--border-w) solid transparent;
  transition: all 0.1s;
}

.sidebar__link:hover {
  background: var(--bg);
  border-color: var(--border);
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.sidebar__link--active {
  background: var(--accent);
  color: #FFFFFF;
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.sidebar__link--active:hover {
  background: var(--accent-hover);
  color: #FFFFFF;
  box-shadow: var(--shadow);
}

.sidebar__icon {
  font-size: 0.8rem;
  width: 1rem;
  text-align: center;
}

.sidebar__divider {
  height: var(--border-w);
  background: var(--border);
  margin: 0.5rem 0.75rem;
}

.sidebar__user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.85rem 1rem;
  border-top: var(--border-w) solid var(--border);
  background: var(--yellow);
}

.sidebar__avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
}

.sidebar__user-info {
  flex: 1;
  min-width: 0;
}

.sidebar__user-name {
  font-size: 0.87rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__user-role {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__logout {
  color: var(--text-secondary);
  font-size: 1rem;
  padding: 0.25rem;
  flex-shrink: 0;
}

.sidebar__logout:hover {
  color: var(--coral);
  text-decoration: none;
}

/* --- Main Content --- */

.main {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
}

/* --- Feed --- */

.feed {
  max-width: 680px;
  margin: 0 auto;
  padding: 2.5rem 2rem;
}

.feed__header {
  margin-bottom: 1.5rem;
}

.feed__title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
}

/* --- Compose --- */

.compose {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  margin-bottom: 2rem;
  padding: 1rem;
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: box-shadow 0.1s;
}

.compose:focus-within {
  box-shadow: var(--shadow-hover);
}

.compose__body {
  flex: 1;
  min-width: 0;
}

.compose__preview:empty {
  display: none;
}

.compose__preview {
  margin-top: 8px;
}

.compose__preview .link-preview {
  margin-top: 0;
}

.compose__input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  resize: none;
  outline: none;
  line-height: 1.55;
  display: block;
}

.compose__input::placeholder {
  color: var(--text-muted);
}

.compose__submit {
  background: var(--coral);
  color: #FFFFFF;
  border: var(--border-w) solid var(--border);
  padding: 0.5rem 1.25rem;
  font-family: var(--font-display);
  font-size: 0.93rem;
  font-weight: 700;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.1s;
  white-space: nowrap;
}

.compose__submit:hover {
  box-shadow: var(--shadow);
  transform: translate(-1px, -1px);
}

.compose__submit:active {
  box-shadow: none;
  transform: translate(2px, 2px);
}

.compose--thread {
  position: sticky;
  bottom: 0;
  margin: 1.5rem 0 0;
  z-index: 5;
}

/* --- Messages --- */

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.message {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.85rem;
  padding: 1rem 1.15rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: all 0.1s;
}

.message:hover {
  box-shadow: var(--shadow);
  transform: translate(-1px, -1px);
}

.message--parent {
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  border-left: 5px solid var(--accent);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 0.5rem;
}

.message--parent:hover {
  box-shadow: var(--shadow-hover);
  transform: translate(-1px, -1px);
}

.message--reply {
  padding: 0.65rem 1rem;
  border-left: 3px solid var(--text-muted);
  border-top: none;
  border-right: none;
  border-bottom: none;
  margin-left: 1rem;
}

.message--reply:hover {
  border-left-color: var(--accent);
  box-shadow: none;
  border-top: none;
  border-right: none;
  border-bottom: none;
}

.message--system {
  padding: 0.65rem 1rem;
  background: var(--green);
  color: #FFFFFF;
  font-size: 0.88rem;
  font-weight: 600;
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.message--system a {
  color: #FFFFFF;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 700;
}

.message__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg);
  border: var(--border-w) solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
  transition: all 0.1s;
}

.message:hover .message__avatar {
  background: var(--accent);
  color: #FFFFFF;
}

.message__avatar--sm {
  width: 28px;
  height: 28px;
  font-size: 0.58rem;
}

.message__body {
  flex: 1;
  min-width: 0;
}

.message__meta {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}

.message__author {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.message__role {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.message__time {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: auto;
}

.message__content {
  font-size: 1rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}

/* --- Link Preview --- */

.link-preview {
  display: flex;
  flex-direction: column;
  margin-top: 8px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  background: var(--bg);
  transition: box-shadow 0.1s, transform 0.1s;
}

.link-preview:hover {
  box-shadow: var(--shadow-sm);
  transform: translate(-1px, -1px);
  text-decoration: none;
}

.link-preview__image {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-bottom: 1.5px solid var(--border);
}

.link-preview__text {
  padding: 10px 12px;
}

.link-preview__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1.3;
  color: var(--text);
  margin-bottom: 2px;
}

.link-preview__desc {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}

.link-preview__domain {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.link-preview--minimal {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 4px;
}

.message__actions {
  margin-top: 0.45rem;
}

.message__reply-link {
  font-size: 0.87rem;
  color: var(--text-muted);
  font-weight: 500;
}

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

.message__delete {
  background: none;
  border: none;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  font-family: var(--font-body);
  margin-left: 0.75rem;
}

.message__delete:hover {
  color: var(--coral);
}

.message__thread-link {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-left: 0.75rem;
}

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

.message__reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.message__reactions:empty {
  display: none;
}

.message__picker {
  margin-top: 4px;
}

.message__picker:empty {
  display: none;
}

.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  font-size: 0.8rem;
  cursor: pointer;
  background: transparent;
  font-family: var(--font-body);
  line-height: 1.4;
  transition: all 0.1s;
}

.reaction-pill:hover {
  border-color: var(--accent);
  transform: scale(1.05);
}

.reaction-pill--active {
  background: #EDEDFF;
  border-color: var(--accent);
}

.reaction-pill--add {
  color: var(--text-muted);
  border-style: dashed;
  font-size: 0.85rem;
  padding: 2px 10px;
}

.reaction-pill--add:hover {
  color: var(--accent);
  border-color: var(--accent);
  border-style: solid;
}

.emoji-picker {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  padding: 8px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  max-width: 240px;
}

.emoji-picker__btn {
  width: 32px;
  height: 32px;
  font-size: 1.2rem;
  cursor: pointer;
  background: none;
  border: none;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
}

.emoji-picker__btn:hover {
  transform: scale(1.2);
  background: var(--bg);
}

@keyframes reaction-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.reaction-pill--active {
  animation: reaction-pop 200ms ease-out;
}

.message__expansion {
  grid-column: 1 / -1;
}

.message__expansion:empty {
  display: none;
}

/* --- Inline Thread --- */

.inline-thread {
  border-left: 3px solid var(--accent);
  padding-left: 0.85rem;
  margin-top: 0.5rem;
}

.inline-thread__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}

.inline-thread__label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.inline-thread__close {
  background: none;
  border: none;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 0.15rem;
  font-family: var(--font-body);
}

.inline-thread__close:hover {
  color: var(--coral);
}

.inline-thread__replies {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.inline-reply {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.3rem 0;
}

.inline-reply__avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5rem;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.inline-reply__body {
  min-width: 0;
}

.inline-reply__author {
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--text);
}

.inline-reply__time {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-left: 0.35rem;
}

.inline-reply__content {
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.inline-thread__more {
  display: block;
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
  padding: 0.35rem 0 0.15rem;
}

.inline-thread__compose {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--bg);
}

.inline-thread__input {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--text-muted);
  padding: 0.25rem 0;
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--text);
  outline: none;
}

.inline-thread__input:focus {
  border-bottom-color: var(--accent);
}

.inline-thread__input::placeholder {
  color: var(--text-muted);
}

.inline-thread__send {
  background: var(--accent);
  color: #FFFFFF;
  border: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.1s;
}

.inline-thread__send:hover {
  background: var(--accent-hover);
}

/* --- Thread --- */

.thread {
  max-width: 680px;
  margin: 0 auto;
  padding: 2.5rem 2rem;
}

.thread__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.thread__back {
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
}

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

.thread__branch-tag {
  font-size: 0.72rem;
  font-weight: 700;
  color: #FFFFFF;
  background: var(--accent);
  padding: 0.2rem 0.7rem;
  border-radius: 20px;
  border: var(--border-w) solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.thread__divider {
  height: var(--border-w);
  background: var(--border);
  margin: 1rem 0;
}

.thread__replies {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* --- Catchup --- */

.catchup {
  background: var(--yellow);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-bottom: 1.5rem;
  font-size: 0.88rem;
  box-shadow: var(--shadow-sm);
}

.catchup__header {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.catchup__summary {
  color: var(--text);
  line-height: 1.7;
}

.catchup--error {
  background: #FEE2E2;
  color: var(--coral);
}

/* --- Auth Pages --- */

.auth {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  background: var(--accent);
}

.auth__card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  padding: 3rem 2.5rem;
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  box-shadow: 8px 8px 0 #000000;
}

.auth__logo {
  font-family: var(--font-display);
  font-size: 3rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1;
  margin-bottom: 0.15rem;
}

.auth__cursor {
  color: var(--accent);
}

.auth__tagline {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 2.5rem;
  font-weight: 400;
}

.auth__hint {
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.65;
}

.auth__error {
  background: #FEE2E2;
  border: var(--border-w) solid var(--coral);
  color: var(--coral);
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 1.25rem;
}

.auth__form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.auth__label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 0.85rem;
}

.auth__input {
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.85rem;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.92rem;
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.1s;
}

.auth__input:focus {
  box-shadow: var(--shadow);
}

.auth__input::placeholder {
  color: var(--text-muted);
}

.auth__submit {
  background: var(--coral);
  color: #FFFFFF;
  border: var(--border-w) solid var(--border);
  padding: 0.8rem;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  border-radius: var(--radius);
  cursor: pointer;
  margin-top: 1.5rem;
  box-shadow: var(--shadow);
  transition: all 0.1s;
}

.auth__submit:hover {
  box-shadow: var(--shadow-hover);
  transform: translate(-1px, -1px);
}

.auth__submit:active {
  box-shadow: none;
  transform: translate(2px, 2px);
}

/* --- Responsive --- */

@media (max-width: 768px) {
  .app {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-width: auto;
    flex-direction: row;
    border-right: none;
    border-bottom: var(--border-w) solid var(--border);
    overflow-x: auto;
  }

  .sidebar__logo {
    padding: 0.85rem 1.25rem;
    flex-shrink: 0;
    border-bottom: none;
    border-right: var(--border-w) solid var(--border);
  }

  .sidebar__logo a {
    font-size: 1.25rem;
  }

  .sidebar__nav {
    display: flex;
    padding: 0.35rem;
    overflow-x: auto;
  }

  .sidebar__link {
    white-space: nowrap;
    padding: 0.5rem 0.75rem;
  }

  .sidebar__divider {
    width: var(--border-w);
    height: auto;
    margin: 0.35rem 0;
  }

  .sidebar__user {
    display: none;
  }

  .sidebar__toggle {
    display: none;
  }

  .main {
    height: calc(100vh - 56px);
  }

  .feed, .thread {
    padding: 1.5rem 1rem;
  }

  .feed__title {
    font-size: 1.5rem;
  }

  .message--parent {
    box-shadow: var(--shadow-sm);
  }

  .compose {
    box-shadow: var(--shadow-sm);
  }
}

@media (max-width: 480px) {
  .auth__card {
    padding: 2rem 1.5rem;
    box-shadow: var(--shadow);
  }

  .auth__logo {
    font-size: 2.5rem;
  }
}
