/* ==========================================================================
   共感文字雲 · 軌跡佈告欄 (LIVE WORD CLOUD · GAS BOARD)
   ========================================================================== */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-light: #64748b;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff6ff;
  --accent: #0f766e;
  --accent-hover: #115e59;
  --accent-soft: #f0fdfa;
  --warn: #b45309;
  --success: #15803d;
  --danger: #b91c1c;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px -4px rgba(15, 23, 42, 0.07), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 40px -12px rgba(15, 23, 42, 0.18);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: "Inter", "Noto Sans TC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.875em;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 0.1em 0.4em;
  border-radius: 5px;
  color: var(--primary);
}

/* Top Bar */
.topbar {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.conn-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.conn-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
}

.conn-badge.is-connecting .conn-indicator {
  background: #f59e0b;
  animation: pulse 1.4s infinite;
}

.conn-badge.is-online {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: var(--success);
}

.conn-badge.is-online .conn-indicator {
  background: #22c55e;
}

.conn-badge.is-local {
  background: var(--primary-soft);
  border-color: #bfdbfe;
  color: var(--primary);
}

.conn-badge.is-local .conn-indicator {
  background: var(--primary);
}

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

/* Container & Layout */
.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.35rem;
}

/* Hero Section */
.hero {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 1.5rem;
  align-items: center;
  padding: 0.5rem 0;
}

.hero-copy h1 {
  margin: 0 0 0.6rem;
  font-size: clamp(1.65rem, 3vw, 2.3rem);
  font-weight: 900;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--text);
}

.hero-copy p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.98rem;
  max-width: 58ch;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 0.9rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-light);
}

.kpi-value {
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

/* Card Base */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.4rem 1.5rem;
  box-shadow: var(--shadow-md);
}

/* Active Session Banner */
.session-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  flex-wrap: wrap;
  border-left: 5px solid var(--primary);
}

.session-info {
  flex: 1 1 420px;
}

.session-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.meta-pill {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
}

.meta-pill strong {
  color: var(--text);
  font-weight: 700;
}

.session-title {
  margin: 0 0 0.3rem;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text);
}

.session-desc {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.session-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.16s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.btn-sm {
  font-size: 0.82rem;
  padding: 0.42rem 0.8rem;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-accent {
  background: var(--accent);
  color: #ffffff;
  padding-inline: 1.35rem;
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-outline:hover:not(:disabled) {
  background: var(--surface-subtle);
  border-color: var(--text-light);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-subtle);
  color: var(--text);
}

/* Composer Form */
.composer-row {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
}

.field {
  position: relative;
  display: flex;
  align-items: center;
}

.field-author {
  flex: 0 0 200px;
}

.field-word {
  flex: 1 1 auto;
}

.composer-form input[type="text"] {
  width: 100%;
  height: 46px;
  padding: 0 0.95rem;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface-subtle);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}

.field-word input[type="text"] {
  padding-right: 4.3rem;
}

.composer-form input[type="text"]:focus {
  outline: none;
  background: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.14);
}

.char-counter {
  position: absolute;
  right: 0.85rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-light);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.composer-hints {
  margin-top: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--text-light);
}

.hint-warn {
  color: var(--warn);
  font-weight: 500;
}

/* Section Headers */
.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}

.eyebrow {
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--primary);
  margin-bottom: 0.15rem;
}

.section-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.sub-hint {
  font-size: 0.84rem;
  color: var(--text-light);
}

.spin {
  animation: spin 0.8s linear infinite;
}

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

/* Word Cloud Stage */
.cloud-viewport {
  position: relative;
  width: 100%;
  height: 430px;
  border-radius: var(--radius-md);
  background: radial-gradient(circle at 50% 45%, #ffffff 0%, #f8fafc 100%);
  border: 1px dashed var(--border-strong);
  overflow: hidden;
  user-select: none;
}

.cloud-viewport.has-words {
  border-style: solid;
  border-color: var(--border);
}

#wordCloudCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.cloud-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1.5rem;
  background: rgba(248, 250, 252, 0.85);
}

.cloud-empty[hidden] {
  display: none;
}

.empty-plus {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.cloud-empty h3 {
  margin: 0 0 0.3rem;
  font-size: 1.1rem;
  font-weight: 700;
}

.cloud-empty p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-light);
}

.cloud-tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 15;
  background: rgba(15, 23, 42, 0.92);
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.38rem 0.7rem;
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
  transform: translate(-50%, -125%);
}

.section-footnote {
  margin: 0.85rem 0 0;
  font-size: 0.82rem;
  color: var(--text-light);
}

/* Trending Pills */
.trending-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.trend-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  background: var(--surface-subtle);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.trend-chip:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

.trend-chip.is-top {
  background: var(--accent-soft);
  border-color: #99f6e4;
  color: var(--accent);
}

.trend-chip.is-top:hover {
  background: #ccfbf1;
}

.trend-count {
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #ffffff;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.empty-inline {
  font-size: 0.9rem;
  color: var(--text-light);
  padding: 0.75rem 0;
}

/* Bulletin Board Tabs & Panels */
.tab-group {
  display: inline-flex;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.22rem;
  gap: 0.22rem;
}

.tab-btn {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn.is-active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.panel-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.9rem;
}

.count-badge {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

/* Sessions Grid */
.sessions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 0.9rem;
}

.session-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.1rem;
  background: var(--surface-subtle);
  cursor: pointer;
  transition: all 0.16s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.75rem;
}

.session-item:hover {
  border-color: var(--primary);
  background: #ffffff;
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.session-item.is-current {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.12);
}

.session-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.session-code-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--primary);
  background: #ffffff;
  border: 1px solid #bfdbfe;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
}

.session-active-pill {
  font-size: 0.72rem;
  font-weight: 700;
  color: #ffffff;
  background: var(--primary);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.session-item h4 {
  margin: 0.35rem 0 0.25rem;
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
}

.session-item-note {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.session-item-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-light);
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
}

/* Audit Table */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.audit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: left;
}

.audit-table th {
  background: var(--surface-subtle);
  color: var(--text-muted);
  font-weight: 700;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.audit-table td {
  padding: 0.68rem 0.85rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.audit-table tbody tr:last-child td {
  border-bottom: none;
}

.audit-table tbody tr:hover {
  background: var(--surface-subtle);
}

.table-empty {
  text-align: center;
  color: var(--text-light) !important;
  padding: 1.5rem !important;
}

.action-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
}

.action-create {
  background: #ede9fe;
  color: #5b21b6;
}

.action-add {
  background: var(--accent-soft);
  color: var(--accent);
}

.action-vote {
  background: #fef3c7;
  color: #b45309;
}

/* Footer */
.footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: auto;
}

.footer-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.82rem;
  color: var(--text-light);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-dialog {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  animation: modalIn 0.18s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  padding: 1.2rem 1.4rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.18rem;
  font-weight: 800;
}

.modal-close {
  border: none;
  background: var(--surface-subtle);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
}

.modal-close:hover {
  background: var(--border);
  color: var(--text);
}

.modal-body {
  padding: 1.25rem 1.4rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
}

.modal-desc {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.65;
}

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

.form-group label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}

.req {
  color: var(--danger);
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.6rem 0.85rem;
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--text);
  background: var(--surface-subtle);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  background: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.14);
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 0.8rem;
}

.input-with-btn {
  display: flex;
  gap: 0.45rem;
}

.feedback-box {
  font-size: 0.84rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.feedback-box.is-ok {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: var(--success);
}

.feedback-box.is-err {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--danger);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 0.35rem;
}

.modal-footer-between {
  justify-content: space-between;
  flex-wrap: wrap;
}

.modal-footer-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: #0f172a;
  color: #ffffff;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.68rem 1.2rem;
  border-radius: 999px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.25);
  max-width: calc(100vw - 2rem);
  text-align: center;
}

/* Responsive */
@media (max-width: 860px) {
  .hero {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .composer-row {
    flex-direction: column;
  }
  .field-author {
    flex: 1 1 auto;
  }
  .form-row-2 {
    grid-template-columns: 1fr;
  }
  .cloud-viewport {
    height: 340px;
  }
  .card {
    padding: 1.15rem 1.1rem;
  }
}
