:root {
  --bg: var(--tg-theme-bg-color, #1c1c1e);
  --text: var(--tg-theme-text-color, #fff);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #64b5f6);
  --card: var(--tg-theme-secondary-bg-color, #2c2c2e);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #fff);
  --accent: #ff9500;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); touch-action: manipulation; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 15px; line-height: 1.45; }
button { font: inherit; border: none; background: none; touch-action: manipulation; color: inherit; }
.hidden { display: none !important; }
.shell { width: 100%; padding: 0 3%; }
.shell .core { width: 100%; margin: 0 auto; padding: 12px 0 96px; }

.welcome-splash {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  opacity: 1; transition: opacity 0.75s ease;
}
.welcome-splash.is-dismissed { opacity: 0; pointer-events: none; }
.welcome-splash__bg {
  position: absolute; inset: 0; background: linear-gradient(145deg, #1a2332 0%, #0d1117 55%, #1c1c1e 100%);
}
.welcome-splash__bg--server {
  background: linear-gradient(145deg, #1e3a5f 0%, #0d1117 50%, #1c1c1e 100%);
}
.welcome-splash__content { position: relative; text-align: center; padding: 24px; }
.welcome-splash__title { font-size: 2rem; margin: 0 0 8px; font-weight: 700; }
.welcome-splash__tagline { margin: 0; color: var(--hint); }

.tabs-bar { position: relative; display: flex; align-items: stretch; gap: 8px; margin-bottom: 18px; }
.tabs { flex: 1; display: flex; gap: 8px; min-width: 0; }
.tab {
  flex: 1; border-radius: 10px; padding: 10px 8px; background: var(--card); color: var(--hint);
  font-weight: 600; font-size: 14px;
}
.tab.active { background: var(--btn); color: var(--btn-text); }

.menu-btn {
  width: 44px; border-radius: 10px; background: var(--card); display: flex; align-items: center; justify-content: center;
}
.menu-icon { display: flex; flex-direction: column; gap: 4px; width: 18px; }
.menu-icon span { display: block; height: 2px; background: var(--text); border-radius: 1px; }

.menu-sheet {
  position: absolute; top: calc(100% + 8px); right: 0; min-width: 220px; z-index: 20;
  background: var(--card); border-radius: 12px; padding: 8px; box-shadow: 0 8px 32px rgba(0,0,0,.35);
}
.menu-item {
  display: block; width: 100%; text-align: left; padding: 12px 14px; border-radius: 8px; font-weight: 600;
}
.menu-item:active { background: rgba(255,255,255,.08); }

.card {
  background: var(--card); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px;
}
.meta { color: var(--hint); font-size: 13px; margin: 0 0 12px; line-height: 1.4; }
.intro-block { margin-bottom: 8px; }
.summary { font-weight: 650; margin-bottom: 8px; }
.paragraph { margin: 0 0 8px; color: var(--text); opacity: .92; }
code { font-size: 12px; background: rgba(255,255,255,.08); padding: 2px 6px; border-radius: 4px; }

/* topic accordion — marriage pattern §19b */
.topic {
  background: var(--card); border-radius: 12px; margin-bottom: 10px; overflow: hidden;
}
.topic-head {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; text-align: left; gap: 12px;
}
.topic-title { flex: 1; font-weight: 650; font-size: 15px; }
.topic-chevron { color: var(--hint); font-size: 18px; transition: transform .2s ease; }
.topic.is-open .topic-chevron { transform: rotate(90deg); }
.topic-body { padding: 0 16px 16px; }
.topic.is-collapsed .topic-body { display: none; }

.term-examples { margin-top: 12px; }
.term-examples-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin-bottom: 8px; }
.term-examples-box { background: rgba(0,0,0,.2); border-radius: 10px; padding: 10px 12px; }
.term-example + .term-example { margin-top: 8px; border-top: 1px solid rgba(255,255,255,.08); padding-top: 8px; }
.term-example-text { margin: 0; font-size: 14px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--link); word-break: break-word; }

/* term-context — marriage §19d */
.term-context { margin-top: 14px; border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; }
.term-context-toggle {
  width: 100%; display: flex; align-items: center; gap: 8px; padding: 8px 0; color: var(--accent); font-weight: 650;
}
.term-context-toggle-count {
  background: rgba(255,149,0,.2); color: var(--accent); font-size: 12px; padding: 2px 8px; border-radius: 999px;
}
.term-context-toggle-chevron { margin-left: auto; transition: transform .2s; }
.term-context.is-open .term-context-toggle-chevron { transform: rotate(90deg); }
.term-context-list { display: none; flex-direction: column; gap: 6px; padding-top: 8px; }
.term-context.is-open .term-context-list { display: flex; }
.term-context-pill {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  padding: 10px 12px; border-radius: 8px; background: rgba(255,255,255,.06); text-align: left;
}
.term-context-pill-title { font-size: 14px; font-weight: 600; }
.term-context-pill-chevron { color: var(--hint); }

.log-submit {
  display: block; width: 100%; padding: 14px; border-radius: 10px; background: var(--btn); color: var(--btn-text);
  font-weight: 700; margin-top: 12px;
}
.log-submit--secondary { background: rgba(255,255,255,.12); color: var(--text); }
.flipside-hub-stats { margin-bottom: 0; }
.log-done-title { font-weight: 700; margin: 0 0 8px; }

/* hosts + digest (§19b accordion) */
.host-head { align-items: flex-start; }
.host-head-main { display: flex; gap: 12px; flex: 1; min-width: 0; }
.host-emoji { font-size: 22px; line-height: 1.2; flex-shrink: 0; }
.host-head-copy { min-width: 0; }
.host-meta { display: block; font-size: 12px; color: var(--hint); font-weight: 500; margin-top: 2px; }
.host-body { padding-top: 0; }
.digest-mount { padding-top: 4px; }
.digest-window { margin-bottom: 10px; }
.digest-status {
  display: flex; gap: 10px; align-items: flex-start;
  background: rgba(0,0,0,.18); border-radius: 10px; padding: 12px; margin-bottom: 12px;
}
.digest-status--urgent { background: rgba(255,59,48,.12); }
.digest-status-icon { font-size: 20px; line-height: 1.2; }
.digest-status-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); }
.digest-status-headline { font-size: 14px; line-height: 1.4; margin-top: 4px; }
.digest-section-label {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--hint); margin: 12px 0 6px;
}
.digest-list { margin: 0; padding-left: 18px; }
.digest-list li { margin-bottom: 4px; font-size: 14px; }
.digest-list--inline { list-style: none; padding-left: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.digest-list--inline li { background: rgba(255,255,255,.06); padding: 4px 8px; border-radius: 6px; }
.digest-loading { padding: 8px 0; }
.digest-error { color: #ff6b6b; margin: 0 0 10px; font-size: 14px; }
.digest-retry { margin-top: 4px; }

@media (prefers-reduced-motion: reduce) {
  .welcome-splash { transition: none; }
  .topic-chevron, .term-context-toggle-chevron { transition: none; }
}
