/* ==========================================================================
   Book Vault — Semester Reflection (Group Chat)
   Small, token-driven design system. Every value below comes from a token.
   ========================================================================== */

:root {
  /* Surface & ink */
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-muted: #faf9f6;
  --line: #e7e4dc;
  --line-strong: #d6d2c7;
  --ink: #1f1d1a;
  --ink-2: #57534e;
  --ink-3: #8a857c;

  /* Brand */
  --brand: #2e7d32;
  --brand-ink: #1b5e20;
  --brand-tint: #e8f2e8;

  /* Rainbow bubble palette — every swatch passes WCAG AA with white text */
  --rb-1: #b91c1c; /* red    */
  --rb-2: #c2410c; /* orange */
  --rb-3: #a16207; /* amber  */
  --rb-4: #15803d; /* green  */
  --rb-5: #0f766e; /* teal   */
  --rb-6: #1d4ed8; /* blue   */
  --rb-7: #4338ca; /* indigo */
  --rb-8: #7e22ce; /* violet */
  --rb-9: #be185d; /* pink   */

  /* Type */
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Space Grotesk', var(--font-ui);
  --fs-xs: 0.6875rem;  /* 11 */
  --fs-sm: 0.8125rem;  /* 13 */
  --fs-md: 0.9375rem;  /* 15 */
  --fs-lg: 1.125rem;   /* 18 */

  /* Spacing (4pt scale) */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;

  /* Shape & depth */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-pill: 999px;
  --shadow-panel: 0 1px 2px rgba(31, 29, 26, 0.04), 0 12px 32px -12px rgba(31, 29, 26, 0.18);
  --shadow-bubble: 0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow-menu: 0 8px 24px -6px rgba(31, 29, 26, 0.22);

  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }

/* No glow / focus halos anywhere — keyboard users still get a crisp underline cue */
*:focus, *:focus-visible { outline: none; box-shadow: none; }
input, textarea, button { -webkit-tap-highlight-color: transparent; }

/* ---------- Loader (white canvas, green OPEN BOOK reveal) ---------- */
.rf-loader {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: #ffffff;
  transition: opacity 0.45s var(--ease), visibility 0.45s;
}
.rf-loader.is-done { opacity: 0; visibility: hidden; }
.rf-loader__prefix {
  display: block;
  text-align: center;
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.45em;
  color: var(--ink-2);
  margin-bottom: var(--s-2);
  opacity: 0;
  animation: rf-fade 0.4s var(--ease) 0.05s forwards;
}
.rf-loader__word {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.2rem, 7vw, 4rem);
  letter-spacing: 0.18em;
  color: var(--brand);
  clip-path: inset(0 100% 0 0);
  animation: rf-reveal 0.7s var(--ease) 0.1s forwards;
}
@keyframes rf-reveal { to { clip-path: inset(0 0 0 0); } }
@keyframes rf-fade { to { opacity: 1; } }

/* ---------- Page shell ---------- */
.rf-page {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.rf-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(244, 242, 236, 0.92);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.rf-topbar__inner {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--s-3) var(--s-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}
.rf-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-sm);
  letter-spacing: 0.12em;
}
.rf-brand img { width: 24px; height: 24px; object-fit: contain; }

.rf-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  height: 34px;
  padding: 0 var(--s-3);
  border-radius: var(--r-pill);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink);
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
  white-space: nowrap;
}
.rf-btn:hover { background: var(--surface-muted); border-color: var(--ink-3); }
.rf-btn--brand { background: var(--brand); border-color: var(--brand); color: #fff; }
.rf-btn--brand:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.rf-btn svg { width: 16px; height: 16px; }

.rf-main {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: var(--s-3) var(--s-4) var(--s-6);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

/* ---------- Floating chat panel ---------- */
.rf-panel {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: calc(100vh - 200px);
  height: calc(100dvh - 200px);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-panel);
  overflow: hidden;
}

.rf-panel__head {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

/* Watermark wallpaper from Book Vault diagram (Image 3) */
.rf-wallpaper {
  position: absolute;
  top: 72px;
  bottom: 84px;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  user-select: none;
  z-index: 1;
}
.rf-wallpaper img {
  width: min(340px, 70%);
  max-height: 70%;
  object-fit: contain;
  opacity: 0.085;
  filter: grayscale(15%);
}
.rf-room { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.rf-room__badge {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 4px;
}
.rf-room__badge img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.rf-room__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 700;
  line-height: 1.2;
}
.rf-room__meta {
  margin: 2px 0 0;
  font-size: var(--fs-xs);
  color: var(--ink-3);
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
}
.rf-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); display: inline-block; }
.rf-dot--live { background: #16a34a; }

.rf-identity {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--fs-xs);
  color: var(--ink-2);
  white-space: nowrap;
}
.rf-identity__chip {
  padding: 3px 10px;
  border-radius: var(--r-pill);
  color: #fff;
  font-weight: 600;
}

/* ---------- Message stream ---------- */
.rf-stream {
  position: relative;
  z-index: 2;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  background:
    radial-gradient(circle at 1px 1px, rgba(31, 29, 26, 0.04) 1px, transparent 0) 0 0 / 22px 22px,
    transparent;
  scroll-behavior: smooth;
}

.rf-day {
  align-self: center;
  margin: var(--s-2) 0;
  padding: 2px 10px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--ink-3);
}

.rf-empty {
  margin: auto;
  text-align: center;
  max-width: 320px;
  color: var(--ink-2);
}
.rf-empty__title { margin: 0 0 var(--s-1); font-weight: 700; color: var(--ink); font-size: var(--fs-md); }
.rf-empty__text { margin: 0; font-size: var(--fs-sm); line-height: 1.5; }

/* Row holds bubble + 3-dot action on its right */
.rf-row {
  display: flex;
  align-items: flex-start;
  gap: var(--s-1);
  max-width: min(78%, 560px);
  align-self: flex-start;
  animation: rf-in 0.25s var(--ease);
}
.rf-row--mine { align-self: flex-end; }
@keyframes rf-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.rf-bubble {
  position: relative;
  min-width: 140px;
  padding: var(--s-2) var(--s-3) var(--s-2);
  border-radius: var(--r-lg);
  border-top-left-radius: 6px;
  background: var(--bubble, var(--rb-6));
  color: #fff;
  box-shadow: var(--shadow-bubble);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.rf-row--mine .rf-bubble { border-top-left-radius: var(--r-lg); border-top-right-radius: 6px; }

.rf-bubble__name {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #fff;
  margin-bottom: 2px;
}
.rf-bubble__text {
  margin: 0;
  font-size: var(--fs-sm);
  line-height: 1.5;
  white-space: pre-wrap;
}
.rf-bubble__time {
  display: block;
  margin-top: var(--s-1);
  text-align: right;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.78);
  font-variant-numeric: tabular-nums;
}

.rf-quote {
  margin: 2px 0 var(--s-2);
  padding: var(--s-1) var(--s-2);
  border-left: 3px solid rgba(255, 255, 255, 0.7);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.16);
  font-size: var(--fs-xs);
  line-height: 1.4;
}
.rf-quote strong { display: block; font-weight: 700; }
.rf-quote span {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  opacity: 0.9;
}

/* 3-dot trigger */
.rf-more {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  margin-top: 2px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  color: var(--ink-3);
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.rf-more:hover, .rf-more[aria-expanded="true"] { background: var(--line); color: var(--ink); }
.rf-more svg { width: 16px; height: 16px; }

/* Action menu */
.rf-menu {
  position: fixed;
  z-index: 50;
  min-width: 168px;
  padding: var(--s-1);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-menu);
  animation: rf-pop 0.14s var(--ease);
}
.rf-menu[hidden] { display: none; }
@keyframes rf-pop { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
.rf-menu__item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  color: var(--ink);
  text-align: left;
}
.rf-menu__item:hover { background: var(--surface-muted); }
.rf-menu__item svg { width: 16px; height: 16px; color: var(--ink-2); }
.rf-menu__note {
  padding: var(--s-2) var(--s-3);
  font-size: var(--fs-xs);
  color: var(--ink-3);
}

/* ---------- Composer ---------- */
.rf-composer {
  position: relative;
  z-index: 5;
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: var(--s-3) var(--s-4) var(--s-4);
}
.rf-replying {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  background: var(--surface-muted);
  border-left: 3px solid var(--reply-color, var(--brand));
  font-size: var(--fs-xs);
  color: var(--ink-2);
}
.rf-replying[hidden] { display: none; }
.rf-replying strong { color: var(--ink); }
.rf-replying__text {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60vw;
}
.rf-replying__close {
  width: 24px;
  height: 24px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  color: var(--ink-3);
}
.rf-replying__close:hover { background: var(--line); color: var(--ink); }

.rf-form { display: flex; align-items: flex-end; gap: var(--s-2); }
.rf-input {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  resize: none;
  padding: 11px var(--s-4);
  border-radius: 22px;
  border: 1px solid var(--line-strong);
  background: var(--surface-muted);
  font-size: var(--fs-sm);
  line-height: 1.45;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.rf-input::placeholder { color: var(--ink-3); }
.rf-input:focus { border-color: var(--ink-3); background: var(--surface); }

.rf-send {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  transition: background 0.15s var(--ease), transform 0.1s var(--ease), opacity 0.15s;
}
.rf-send:hover { background: var(--brand-ink); }
.rf-send:active { transform: scale(0.94); }
.rf-send:disabled { opacity: 0.4; cursor: not-allowed; }
.rf-send svg { width: 18px; height: 18px; }

.rf-hint {
  margin-top: var(--s-2);
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--ink-3);
}

/* ---------- Toast ---------- */
.rf-toast {
  position: fixed;
  left: 50%;
  bottom: var(--s-6);
  z-index: 60;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-pill);
  background: var(--ink);
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 600;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}
.rf-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .rf-main { padding: var(--s-3) var(--s-2) var(--s-3); }
  .rf-panel { height: calc(100dvh - 92px); border-radius: var(--r-md); }
  .rf-panel__head { padding: var(--s-3) var(--s-4); }
  .rf-identity__label { display: none; }
  .rf-row { max-width: 88%; }
  .rf-stream { padding: var(--s-4) var(--s-3); }
  .rf-hide-sm { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .rf-loader__word { clip-path: none; }
  .rf-loader__prefix { opacity: 1; }
}

/* ---------- Green Notice Banner (Upside Space) ---------- */
.rf-notice {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: 10px var(--s-4);
  border-radius: var(--r-md);
  background: linear-gradient(135deg, #1b5e20, #2e7d32);
  color: #ffffff;
  box-shadow: 0 4px 14px -3px rgba(27, 94, 32, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.18);
  animation: rf-in 0.3s var(--ease);
}
.rf-notice__icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  display: grid;
  place-items: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  margin-top: 1px;
}
.rf-notice__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #dc2626; /* bright red */
  box-shadow: 0 0 8px rgba(220, 38, 38, 0.85);
  animation: rf-pulse-red 1.8s ease-in-out infinite;
}
@keyframes rf-pulse-red {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.28); opacity: 0.85; }
}
.rf-notice__content {
  flex: 1;
  font-size: var(--fs-xs);
  line-height: 1.55;
  color: rgba(255, 255, 255, 0.95);
  font-weight: 500;
}
.rf-notice__label {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #ffffff;
  margin-right: 6px;
  background: rgba(255, 255, 255, 0.18);
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 10px;
  vertical-align: middle;
}
.rf-notice__cursor {
  display: inline-block;
  font-weight: 700;
  color: #ffffff;
  animation: rf-blink 0.8s steps(2, start) infinite;
  margin-left: 2px;
}
@keyframes rf-blink {
  to { visibility: hidden; }
}
