:root {
  color-scheme: light;
  --bg: #eef7f4;
  --panel: #ffffff;
  --panel-soft: #f7fbfa;
  --text: #162321;
  --muted: #61726e;
  --line: #d5e6e2;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #d9f4ef;
  --gold-soft: #fff6d6;
  --shadow: 0 14px 34px rgba(15, 118, 110, .1);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #dff3ee 0, var(--bg) 340px);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.app-shell {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px calc(78px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.topnav a {
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--accent-strong);
  text-decoration: none;
  font-weight: 700;
}

.topnav a:hover {
  background: var(--accent-soft);
}

.primary-button,
.search-row button,
.tool-button,
.text-button,
.chip,
.tab,
.list-item,
.bottom-nav button,
.bottom-nav a {
  border: 0;
  border-radius: 8px;
  font-weight: 700;
}

.primary-button,
.search-row button {
  min-height: 44px;
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 460px);
  gap: 18px;
  align-items: stretch;
}

.hero-copy,
.search-card,
.status-strip,
.viewer-panel,
.side-panel,
.info-section,
.affiliate-panel,
.associate-notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .94);
  box-shadow: var(--shadow);
}

.hero-copy {
  padding: clamp(22px, 4vw, 42px);
}

.eyebrow,
.viewer-label {
  margin-bottom: 6px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.hero h1 {
  margin-bottom: 14px;
  font-size: clamp(30px, 5vw, 52px);
  line-height: 1.12;
}

.hero p {
  max-width: 720px;
  color: var(--muted);
  line-height: 1.8;
}

.search-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 18px;
}

.search-card label {
  margin-bottom: 8px;
  font-weight: 800;
}

.search-row {
  display: flex;
  gap: 8px;
}

input {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 13px 12px;
  font-size: 16px;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  padding: 8px 10px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.associate-notice,
.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 0;
  padding: 13px 16px;
}

.associate-notice {
  background: linear-gradient(180deg, #fff, var(--gold-soft));
}

.associate-notice span {
  color: var(--muted);
  line-height: 1.6;
}

.setup-pill,
.badge {
  flex: 0 0 auto;
  padding: 5px 9px;
  border-radius: 999px;
  background: #fff1f0;
  color: #b42318;
  font-size: 12px;
  font-weight: 800;
}

.setup-pill.ready,
.badge {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.badge.offline {
  background: #fff1f0;
  color: #b42318;
}

.status-strip p {
  margin-bottom: 0;
  color: var(--muted);
}

.content-grid {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 250px;
  gap: 16px;
  align-items: start;
}

.side-panel,
.affiliate-panel {
  position: sticky;
  top: 12px;
}

.side-panel {
  overflow: hidden;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
}

.tab {
  min-height: 42px;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.item-list {
  display: grid;
  gap: 8px;
  max-height: 58vh;
  overflow: auto;
  padding: 12px;
}

.list-item {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
  text-align: left;
}

.list-title,
.list-url {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-url {
  color: var(--muted);
  font-size: 12px;
}

.viewer-panel {
  min-height: 68vh;
  overflow: hidden;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .95);
  position: sticky;
  top: 0;
  z-index: 2;
}

.viewer-toolbar h2 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1.35;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tool-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  padding: 0 11px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--accent-strong);
  text-decoration: none;
}

.tool-button.active {
  background: var(--accent);
  color: #fff;
}

.tool-button:disabled {
  cursor: default;
  opacity: .5;
}

.article {
  padding: 18px 20px 24px;
  line-height: 1.85;
  overflow-wrap: anywhere;
}

.article.empty {
  color: var(--muted);
}

.article h1,
.article h2,
.article h3 {
  line-height: 1.38;
  margin: 1.25em 0 .55em;
}

.article a {
  color: var(--accent-strong);
  font-weight: 800;
}

.article a.wiki-link {
  text-decoration-style: dotted;
}

.article ul {
  padding-left: 1.35em;
}

.article table {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 14px 0;
}

.article th,
.article td {
  border: 1px solid var(--line);
  padding: 8px;
  vertical-align: top;
}

.article th {
  background: var(--panel-soft);
}

.article hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}

.affiliate-panel {
  padding: 14px;
}

.panel-heading.compact h2 {
  margin-bottom: 6px;
  font-size: 18px;
}

.panel-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.affiliate-links {
  display: grid;
  gap: 9px;
}

.affiliate-card {
  display: grid;
  gap: 4px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  text-decoration: none;
}

.affiliate-card:hover {
  border-color: var(--accent);
  background: #fff;
}

.affiliate-kicker {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.affiliate-text {
  color: var(--muted);
  line-height: 1.55;
}

.info-section {
  margin-top: 16px;
  padding: 20px;
  line-height: 1.8;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading h2,
.info-section h2 {
  margin-bottom: 8px;
}

.text-button {
  padding: 9px 10px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.bottom-nav {
  display: none;
}

@media (max-width: 1040px) {
  .hero,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .side-panel,
  .affiliate-panel {
    position: static;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topnav {
    display: none;
  }

  .hero-copy,
  .search-card,
  .article,
  .info-section {
    padding: 16px;
  }

  .hero h1 {
    font-size: 34px;
  }

  .search-row,
  .viewer-toolbar,
  .section-heading,
  .associate-notice,
  .status-strip {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .item-list {
    max-height: 260px;
  }

  .bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, .96);
    backdrop-filter: blur(12px);
  }

  .bottom-nav a,
  .bottom-nav button {
    display: grid;
    min-height: 42px;
    place-items: center;
    background: var(--panel-soft);
    color: var(--accent-strong);
    text-decoration: none;
    font-size: 13px;
  }

  .bottom-nav button:disabled {
    color: var(--muted);
    opacity: .6;
  }
}
