/* Community forum — unified terminal (countdown seal + archive rail) */

:root {
  --tmf-community-rail-w: 292px;
  --tmf-community-fab-size: 52px;
  --tmf-community-inset: var(--tmf-counter-inset, 14px);
  --tmf-chat-gold: rgba(201, 162, 39, 0.88);
  --tmf-chat-gold-dim: rgba(201, 162, 39, 0.28);
  --tmf-chat-jade: rgba(94, 207, 154, 0.88);
  --tmf-chat-jade-dim: rgba(94, 207, 154, 0.32);
  --tmf-chat-ink: rgba(8, 7, 6, 0.94);
  --tmf-chat-radius: 6px;
}

/* ── Archive: FAB circle + expandable panel (after unseal) ── */
.tmf-community-rail--archive {
  position: fixed;
  right: var(--tmf-community-inset);
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
  top: auto;
  left: auto;
  width: auto;
  height: auto;
  z-index: 168;
  display: none;
  pointer-events: none;
  box-sizing: border-box;
}

.tmf-community-rail--archive.is-active:not(.is-off) {
  display: block;
}

.tmf-community-rail--archive.tmf-community-rail--off {
  display: none !important;
}

.tmf-forum-fab {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--tmf-community-fab-size);
  height: var(--tmf-community-fab-size);
  margin: 0;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--tmf-chat-gold-dim);
  background:
    radial-gradient(circle at 35% 28%, rgba(201, 162, 39, 0.22) 0%, transparent 55%),
    linear-gradient(165deg, rgba(24, 20, 15, 0.98) 0%, rgba(8, 7, 6, 0.99) 100%);
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  color: var(--tmf-chat-gold);
  font-family: 'Cinzel Decorative', serif;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.tmf-forum-fab:hover {
  border-color: rgba(201, 162, 39, 0.55);
  box-shadow:
    0 12px 32px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(201, 162, 39, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.tmf-forum-fab:focus-visible {
  outline: 2px solid rgba(201, 162, 39, 0.65);
  outline-offset: 3px;
}

.tmf-forum-fab-ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1px solid rgba(201, 162, 39, 0.2);
  pointer-events: none;
  animation: tmfForumFabPulse 2.8s ease-in-out infinite;
}

.tmf-community-rail--archive.is-expanded .tmf-forum-fab-ring {
  animation: none;
  opacity: 0.35;
}

@keyframes tmfForumFabPulse {
  0%, 100% { transform: scale(1); opacity: 0.45; }
  50% { transform: scale(1.08); opacity: 0.85; }
}

.tmf-community-rail--archive.is-expanded .tmf-forum-fab {
  transform: scale(0.94);
  border-color: rgba(201, 162, 39, 0.5);
}

.tmf-community-rail--archive.is-expanded .tmf-forum-fab-glyph {
  transform: rotate(45deg);
}

.tmf-forum-fab-glyph {
  display: block;
  transition: transform 0.22s ease;
}

.tmf-community-terminal--archive {
  position: absolute;
  right: 0;
  bottom: calc(var(--tmf-community-fab-size) + 14px);
  width: var(--tmf-community-rail-w);
  height: min(440px, 58vh);
  max-height: calc(100dvh - var(--tmf-counter-top, 54px) - 120px);
  display: none;
  flex-direction: column;
  overflow: hidden;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(10px) scale(0.97);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.tmf-community-rail--archive.is-expanded .tmf-community-terminal--archive {
  display: flex;
  opacity: 1;
  transform: translateY(0) scale(1);
}

.tmf-forum-panel-close {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 4;
  width: 28px;
  height: 28px;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(201, 162, 39, 0.25);
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.45);
  color: rgba(201, 162, 39, 0.9);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  transition: background 0.15s ease, color 0.15s ease;
}

.tmf-forum-panel-close:hover {
  background: rgba(201, 162, 39, 0.15);
  color: #efe6d2;
}

.tmf-community-terminal {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  box-sizing: border-box;
  border-radius: var(--tmf-chat-radius);
  overflow: hidden;
}

/* Archive terminal — parchment / gold (matches folio) */
.tmf-community-terminal--archive {
  position: relative;
  border: 1px solid var(--tmf-chat-gold-dim);
  background:
    linear-gradient(180deg, rgba(201, 162, 39, 0.1) 0%, transparent 22%),
    linear-gradient(168deg, rgba(22, 18, 14, 0.98) 0%, rgba(10, 9, 7, 0.99) 100%);
  box-shadow:
    0 16px 40px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* Seal terminal — signal / jade (matches countdown dossier) */
.tmf-community-terminal--seal {
  flex: 1 1 0;
  min-height: 0;
  height: min(520px, 58vh);
  max-height: min(520px, 58vh);
  overflow: hidden;
  border: 1px solid var(--tmf-chat-jade-dim);
  background:
    linear-gradient(180deg, rgba(94, 207, 154, 0.08) 0%, transparent 24%),
    linear-gradient(168deg, rgba(10, 16, 13, 0.98) 0%, rgba(5, 7, 6, 0.99) 100%);
  box-shadow:
    0 14px 36px rgba(0, 0, 0, 0.45),
    inset 0 0 0 1px rgba(94, 207, 154, 0.08);
}

.tmf-chat-mount,
.tmf-chat-mount--archive {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  margin: 0;
  max-width: none;
  display: flex;
  flex-direction: column;
}

.tmf-forum-dock--archive {
  position: static;
  top: auto;
  right: auto;
  width: 100%;
  flex: 1 1 0;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  pointer-events: auto;
}

.tmf-community-rail--archive:not(.is-expanded) .tmf-forum-dock--archive {
  display: none;
}

.tmf-community-rail--archive.is-expanded .tmf-forum-dock--archive {
  display: flex;
}

.tmf-chat-compose-dock {
  box-sizing: border-box;
  flex-shrink: 0;
}

.tmf-chat-compose-dock--archive {
  position: static;
  left: auto;
  right: auto;
  bottom: auto;
  width: 100%;
  display: block;
  border-top: 1px solid rgba(201, 162, 39, 0.18);
  background: rgba(0, 0, 0, 0.28);
}

.tmf-community-rail--archive:not(.is-expanded) .tmf-chat-compose-dock--archive {
  display: none;
}

.tmf-community-rail--archive.is-expanded .tmf-chat-compose-dock--archive {
  display: block;
}

.tmf-chat-compose-dock--seal {
  position: relative;
  border-top: 1px solid rgba(94, 207, 154, 0.22);
  background: rgba(0, 0, 0, 0.32);
}

body.tmf-locked .tmf-chat-compose-dock--seal.tmf-chat-compose-dock--inline {
  display: block;
}

body.tmf-locked .tmf-chat-compose-dock--seal:not(.tmf-chat-compose-dock--inline) {
  display: none;
}

.tmf-community-chat {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

/* ── Message feed ── */
.tmf-chat-panel {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  margin: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  overflow: hidden;
}

.tmf-community-terminal--archive .tmf-chat-panel {
  flex: 1 1 0;
  min-height: 0;
  max-height: 100%;
}

.tmf-chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.tmf-community-chat--admin .tmf-chat-subtitle::after {
  content: ' · Admin';
  color: rgba(201, 162, 39, 0.75);
}

.tmf-community-terminal--seal .tmf-community-chat--admin .tmf-chat-subtitle::after {
  color: rgba(94, 207, 154, 0.75);
}

.tmf-community-terminal--seal .tmf-chat-head {
  border-bottom-color: rgba(94, 207, 154, 0.16);
}

.tmf-community-terminal--archive .tmf-chat-head {
  border-bottom-color: rgba(201, 162, 39, 0.14);
}

.tmf-chat-title {
  margin: 0;
  font-family: 'Cinzel', serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--tmf-chat-gold);
}

.tmf-community-terminal--seal .tmf-chat-title {
  color: rgba(160, 235, 195, 0.92);
  font-size: 10px;
}

.tmf-chat-subtitle {
  margin: 3px 0 0;
  font-family: 'Special Elite', monospace;
  font-size: 7px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(140, 120, 90, 0.65);
}

.tmf-community-terminal--seal .tmf-chat-subtitle {
  color: rgba(94, 207, 154, 0.45);
}

.tmf-chat-live-badge {
  flex-shrink: 0;
  margin-top: 1px;
  padding: 3px 8px;
  font-family: 'Special Elite', monospace;
  font-size: 7px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(110, 207, 154, 0.55);
  border: 1px solid rgba(110, 207, 154, 0.28);
  border-radius: 3px;
}

.tmf-chat-live-badge.is-on {
  color: rgba(175, 245, 205, 0.95);
  border-color: rgba(110, 207, 154, 0.45);
  background: rgba(94, 207, 154, 0.1);
}

.tmf-community-terminal--seal .tmf-chat-live-badge.is-on {
  animation: tmf-chat-live-pulse 2s ease-in-out infinite;
}

@keyframes tmf-chat-live-pulse {
  0%, 100% { box-shadow: 0 0 6px rgba(94, 207, 154, 0.2); }
  50% { box-shadow: 0 0 12px rgba(94, 207, 154, 0.45); }
}

.tmf-chat-log {
  flex: 1 1 0;
  min-height: 0;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(201, 162, 39, 0.35) transparent;
}

.tmf-community-terminal--seal .tmf-chat-log {
  scrollbar-color: rgba(94, 207, 154, 0.35) transparent;
}

.tmf-chat-log::-webkit-scrollbar {
  width: 6px;
}

.tmf-chat-log::-webkit-scrollbar-thumb {
  border-radius: 3px;
  background: rgba(201, 162, 39, 0.35);
}

.tmf-community-terminal--seal .tmf-chat-log::-webkit-scrollbar-thumb {
  background: rgba(94, 207, 154, 0.35);
}

.tmf-chat-empty {
  margin: 0;
  padding: 16px 8px;
  font-family: 'EB Garamond', serif;
  font-size: 14px;
  line-height: 1.5;
  color: rgba(160, 145, 120, 0.72);
  text-align: center;
}

.tmf-community-terminal--archive .tmf-chat-empty {
  font-size: 13px;
}

.tmf-chat-msg {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-left: 2px solid rgba(201, 162, 39, 0.24);
  background: rgba(0, 0, 0, 0.22);
  border-radius: 0 3px 3px 0;
}

.tmf-community-terminal--seal .tmf-chat-msg {
  border-left-color: rgba(94, 207, 154, 0.28);
}

.tmf-chat-msg:last-child {
  margin-bottom: 0;
}

.tmf-chat-msg-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.tmf-chat-msg-delete {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  margin: 0 0 0 auto;
  padding: 0;
  border: 1px solid rgba(201, 162, 39, 0.35);
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.35);
  color: rgba(201, 162, 39, 0.9);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.tmf-chat-msg-delete:hover {
  background: rgba(180, 60, 50, 0.35);
  border-color: rgba(220, 120, 90, 0.55);
  color: #f5e0d8;
}

.tmf-community-terminal--seal .tmf-chat-msg-delete {
  border-color: rgba(94, 207, 154, 0.35);
  color: rgba(160, 230, 190, 0.95);
}

.tmf-community-terminal--seal .tmf-chat-msg-delete:hover {
  background: rgba(94, 207, 154, 0.18);
  border-color: rgba(94, 207, 154, 0.55);
}

.tmf-chat-msg-name {
  font-family: 'Special Elite', monospace;
  font-size: 8px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(201, 162, 39, 0.78);
}

.tmf-chat-msg-name--glitch {
  display: inline-block;
  color: rgba(110, 207, 154, 0.92);
  text-shadow:
    0 0 8px rgba(110, 207, 154, 0.35),
    1px 0 rgba(201, 162, 39, 0.25),
    -1px 0 rgba(255, 80, 80, 0.2);
  animation: tmf-chat-name-flicker 2.8s ease-in-out infinite;
}

@keyframes tmf-chat-name-flicker {
  0%, 100% { opacity: 1; filter: none; }
  48% { opacity: 0.88; filter: brightness(1.15); }
  52% { opacity: 0.95; filter: contrast(1.2); }
}

.tmf-chat-msg-time {
  font-family: 'Special Elite', monospace;
  font-size: 7px;
  color: rgba(120, 105, 85, 0.65);
  white-space: nowrap;
}

.tmf-chat-msg-text {
  margin: 0;
  font-family: 'EB Garamond', serif;
  font-size: 14px;
  line-height: 1.45;
  color: rgba(220, 210, 190, 0.92);
  word-break: break-word;
}

.tmf-community-terminal--archive .tmf-chat-msg-text {
  font-size: 13px;
}

/* ── Compose strip (footer of terminal) ── */
.tmf-chat-compose {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 10px 12px 12px;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.tmf-compose-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
}

.tmf-compose-field-label {
  font-family: 'Cinzel', serif;
  font-size: 7px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(201, 162, 39, 0.55);
}

.tmf-community-terminal--seal .tmf-compose-field-label {
  color: rgba(94, 207, 154, 0.6);
}

.tmf-chat-name,
.tmf-chat-text {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid rgba(201, 162, 39, 0.22);
  border-radius: 4px;
  background: var(--tmf-chat-ink);
  color: #efe6d2;
  font-family: 'EB Garamond', serif;
  font-size: 14px;
}

.tmf-community-terminal--seal .tmf-chat-name,
.tmf-community-terminal--seal .tmf-chat-text {
  border-color: rgba(94, 207, 154, 0.28);
}

.tmf-chat-name {
  font-size: 13px;
}

.tmf-chat-text {
  min-height: 48px;
  max-height: 96px;
  resize: vertical;
  line-height: 1.45;
}

.tmf-community-terminal--seal .tmf-chat-text {
  min-height: 32px;
  max-height: 60px;
}

/* Compact compose strip on the sealed countdown page */
.tmf-community-terminal--seal .tmf-chat-compose {
  gap: 6px;
  padding: 8px 12px 10px;
}

.tmf-community-terminal--seal .tmf-compose-field {
  gap: 2px;
}

.tmf-community-terminal--seal .tmf-chat-name {
  padding: 5px 10px;
}

.tmf-chat-name:focus,
.tmf-chat-text:focus {
  outline: none;
  border-color: rgba(201, 162, 39, 0.48);
}

.tmf-community-terminal--seal .tmf-chat-name:focus,
.tmf-community-terminal--seal .tmf-chat-text:focus {
  border-color: rgba(94, 207, 154, 0.5);
}

.tmf-chat-compose-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.tmf-chat-send {
  flex-shrink: 0;
  padding: 8px 14px;
  border: 1px solid rgba(201, 162, 39, 0.45);
  border-radius: 4px;
  background: rgba(201, 162, 39, 0.14);
  color: #f0e6d0;
  font-family: 'Cinzel', serif;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
}

.tmf-community-terminal--seal .tmf-chat-send {
  border-color: rgba(94, 207, 154, 0.5);
  background: rgba(94, 207, 154, 0.18);
  color: #f2faf5;
}

.tmf-chat-send:hover {
  background: rgba(201, 162, 39, 0.26);
}

.tmf-community-terminal--seal .tmf-chat-send:hover {
  background: rgba(94, 207, 154, 0.32);
}

.tmf-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.tmf-chat-compose.is-readonly {
  opacity: 0.72;
  pointer-events: none;
}

.tmf-chat-status {
  flex: 1 1 auto;
  min-height: 1em;
  margin: 0;
  font-family: 'Special Elite', monospace;
  font-size: 7px;
  letter-spacing: 0.08em;
  color: rgba(180, 120, 90, 0.85);
}

/* Visibility guards */
body.tmf-locked .tmf-community-rail--archive {
  display: none !important;
}

body:not(.tmf-locked) .tmf-community-terminal--seal,
body:not(.tmf-locked) #tmf-community-terminal-seal {
  display: none !important;
}

body.tmf-locked .tmf-chat-mount--archive,
body.tmf-locked #tmf-community-rail-archive.is-active {
  display: none !important;
}

body:not(.tmf-locked) .tmf-chat-mount:not(.tmf-chat-mount--archive) {
  display: none !important;
}

@media (max-width: 900px) {
  :root {
    --tmf-community-rail-w: min(272px, calc(100vw - 24px));
  }
}

@media (max-width: 720px) {
  .tmf-community-rail--archive.is-expanded .tmf-community-terminal--archive {
    width: min(var(--tmf-community-rail-w), calc(100vw - var(--tmf-community-inset) * 2));
    height: min(400px, 52vh);
    max-height: calc(100dvh - var(--tmf-counter-top, 54px) - 100px);
  }

  .tmf-community-terminal--seal {
    min-height: min(440px, 56vh);
  }
}

@media (max-width: 520px) {
  :root {
    --tmf-community-inset: 8px;
    --tmf-community-fab-size: 48px;
  }

  .tmf-community-rail--archive.is-expanded .tmf-community-terminal--archive {
    height: min(360px, 48vh);
  }

  .tmf-chat-compose-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .tmf-chat-send {
    width: 100%;
  }
}

@media (min-width: 901px) {
  :root {
    --tmf-community-rail-w: 300px;
  }
}
