* {
  box-sizing: border-box;
}

:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-soft: #fbfcff;
  --text: #162034;
  --muted: #59667d;
  --line: #d8deea;
  --line-soft: #e3e8f1;
  --accent: #1f4fd6;
  --danger-bg: #ffe4e4;
  --danger-text: #9e2323;
  --success-bg: #ddf7e8;
  --success-text: #17623a;
}

:root[data-theme='dark'] {
  --bg: #0f1625;
  --panel: #171f30;
  --panel-soft: #1c2639;
  --text: #e9eef8;
  --muted: #aab6ca;
  --line: #2b3954;
  --line-soft: #243148;
  --accent: #6d9bff;
  --danger-bg: #3e1d22;
  --danger-text: #ffc7c7;
  --success-bg: #183628;
  --success-text: #baf0ce;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: nowrap;
  gap: 16px;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
}

.brand a,
.nav a {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.brand a {
  display: inline-flex;
  align-items: center;
}

.brand-logo {
  display: block;
  width: clamp(230px, 24vw, 330px);
  height: 44px;
  background: currentColor;
  transform: translateY(3px);
  -webkit-mask: url("assets/hookshire-chowthaway/hookshire-chowthaway.svg") center / contain no-repeat;
  mask: url("assets/hookshire-chowthaway/hookshire-chowthaway.svg") center / contain no-repeat;
}

.nav {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: flex-end;
  margin-left: auto;
}

.inline-form {
  display: inline;
}

.inline-form button,
.auth-form button,
.nav-action {
  background: #1f4fd6;
  color: #fff;
  border: 0;
  border-radius: 6px;
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.settings-menu {
  position: relative;
}

.settings-menu summary {
  list-style: none;
}

.settings-menu summary::-webkit-details-marker {
  display: none;
}

.settings-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  z-index: 10;
  width: 240px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 40px rgba(22, 32, 52, 0.18);
  padding: 12px;
}

.settings-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  min-height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
}

.settings-trigger:hover,
.settings-menu[open] .settings-trigger {
  border-color: var(--accent);
  color: var(--accent);
}

.settings-group {
  display: grid;
  gap: 8px;
  padding: 8px;
}

.settings-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.settings-group + .settings-group {
  border-top: 1px solid var(--line-soft);
}

.settings-group > span {
  color: var(--muted);
  font-size: 0.9rem;
}

.account-summary {
  gap: 6px;
}

.account-summary strong {
  display: block;
  color: var(--text);
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.settings-account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.settings-form {
  margin: 0;
  display: flex;
}

.settings-secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  min-height: 34px;
  margin: 0;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
  font-family: inherit;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  appearance: none;
}

.settings-secondary-action:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.settings-actions {
  display: flex;
  gap: 8px;
}

.settings-actions a {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-width: 72px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  line-height: 1;
}

.settings-actions a.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.theme-toggle-switch {
  width: 50px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
}

.toggle-track {
  position: relative;
  display: block;
  width: 50px;
  height: 28px;
  border-radius: 999px;
  background: var(--line);
  transition: background 0.18s ease;
}

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(22, 32, 52, 0.22);
  transition: transform 0.18s ease;
}

.theme-toggle-switch[aria-pressed='true'] .toggle-track {
  background: var(--accent);
}

.theme-toggle-switch[aria-pressed='true'] .toggle-thumb {
  transform: translateX(22px);
}

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

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px;
}

.hero,
.summary-grid,
.section-grid {
  margin-bottom: 20px;
}

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

.page-heading {
  grid-template-columns: 1fr;
}

.notes-hero,
.notes-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.essay-stream {
  display: grid;
  gap: 18px;
}

.notes-hero-main,
.essay-card,
.private-gate {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
}

.notes-hero-main h1,
.essay-card h1,
.private-gate h1,
.post-detail h1 {
  margin: 8px 0 12px;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1.06;
  letter-spacing: 0;
}

.notes-hero-main p,
.essay-card p,
.private-gate p {
  max-width: 860px;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.65;
}

.eyebrow {
  color: var(--accent);
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.primary-link,
.read-link,
.back-link {
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.primary-link {
  display: inline-flex;
  margin-top: 10px;
  min-height: 40px;
  align-items: center;
}

.post-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.35;
}

.post-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 1.35em;
}

.post-list,
.owner-post-list {
  display: grid;
  gap: 12px;
}

.post-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  border-top: 1px solid var(--line-soft);
  padding: 16px 0 4px;
}

.post-row:first-child {
  border-top: 0;
}

.post-row a:first-child {
  color: var(--text);
  display: inline-block;
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.25;
  text-decoration: none;
}

.post-row p {
  color: var(--muted);
  line-height: 1.55;
  margin: 8px 0;
}

.owner-content-panel {
  align-self: start;
}

.owner-post-list a {
  border-top: 1px solid var(--line-soft);
  color: var(--text);
  display: grid;
  gap: 5px;
  padding: 12px 0 0;
  text-decoration: none;
}

.owner-post-list span {
  color: var(--muted);
  font-size: 0.9rem;
}

.post-detail {
  max-width: 860px;
  margin: 0 auto;
  padding: 32px;
}

.post-detail-head {
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 24px;
  padding-bottom: 18px;
}

.markdown-body {
  color: var(--text);
  font-size: 1.04rem;
  line-height: 1.78;
}

.markdown-body h2,
.markdown-body h3 {
  line-height: 1.25;
  margin-top: 28px;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote {
  margin: 16px 0;
}

.markdown-body blockquote {
  border-left: 4px solid var(--accent);
  color: var(--muted);
  padding-left: 16px;
}

.markdown-body code {
  background: var(--panel-soft);
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  padding: 2px 5px;
}

.private-gate {
  min-height: 420px;
  display: grid;
  align-items: center;
}

.status-card,
.summary-card,
.panel,
.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  padding: 18px;
}

.panel + .panel {
  margin-top: 20px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.summary-card span {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

.summary-card strong {
  font-size: 1.25rem;
}

.section-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  min-width: 0;
}

.stacked-sections {
  display: grid;
  gap: 20px;
  margin-bottom: 20px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 16px;
}

.panel-head-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.panel-meta {
  color: var(--muted);
  font-size: 0.92rem;
}

.panel-inner {
  border: 0;
  padding: 0;
}

.chart-wrap {
  width: 100%;
  height: clamp(360px, 48vw, 520px);
  margin: 0 auto 18px;
  min-width: 0;
}

.chart-wrap-svg {
  display: flex;
  align-items: center;
  justify-content: center;
}

.portfolio-pie-svg {
  width: min(100%, 760px);
  height: 100%;
}

.pie-label-name {
  fill: var(--text);
  font-size: 12px;
  font-weight: 600;
}

.pie-label-pct {
  fill: var(--muted);
  font-size: 11px;
}

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

.holdings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
  table-layout: auto;
  min-width: 880px;
}

.holdings-table th,
.holdings-table td {
  border-top: 1px solid var(--line-soft);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: normal;
  word-break: normal;
  white-space: normal;
}

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

.flash-stack {
  margin-bottom: 16px;
}

.flash {
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.flash.error {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.flash.success {
  background: var(--success-bg);
  color: var(--success-text);
}

.stale-note {
  margin-top: 8px;
  color: #9d6b00;
}

.auth-card {
  max-width: 420px;
  margin: 40px auto;
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-subtitle {
  color: var(--muted);
  line-height: 1.5;
  margin: -4px 0 18px;
}

.auth-form input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
}

.auth-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  cursor: pointer;
}

.auth-check input {
  width: 16px;
  height: 16px;
  padding: 0;
}

.hint {
  color: var(--muted);
}

.blurred-value {
  display: inline-block;
  filter: blur(7px);
  user-select: none;
  pointer-events: none;
}

.table-wrap {
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.col-ticker {
  min-width: 7rem;
  width: 7rem;
  white-space: nowrap;
}

.col-name {
  min-width: 16rem;
  width: 16rem;
  overflow-wrap: break-word;
}

.col-weight-total,
.col-qty {
  width: 6rem;
}

.col-value,
.col-price,
.col-cost,
.col-pnl {
  width: 9rem;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
}

.transaction-empty {
  display: grid;
  gap: 8px;
  min-height: 220px;
  place-content: center;
}

.transaction-empty h2 {
  margin: 0;
  font-size: 1.35rem;
}

.transaction-empty p {
  margin: 0;
  color: var(--muted);
}

.trade-table {
  min-width: 980px;
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
}

.market-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.range-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.market-tab {
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 600;
}

.market-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.range-tab {
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
}

.range-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.performance-wrap {
  width: 100%;
  min-height: 360px;
}

.performance-page {
  display: grid;
  gap: 16px;
}

.performance-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.performance-toolbar-bottom {
  justify-content: center;
  margin-top: 10px;
}

.performance-toolbar-bottom .performance-periods {
  gap: 4px;
  justify-content: center;
  width: min(100%, 620px);
}

.performance-toolbar-bottom .performance-periods a {
  flex: 1 1 0;
  min-width: 0;
  padding: 6px 8px;
  font-size: 0.82rem;
  border-radius: 5px;
}

.performance-panel {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}

.performance-panel-head {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(280px, 0.8fr);
  gap: 20px;
  align-items: start;
  margin-bottom: 16px;
}

.performance-metric {
  min-width: 0;
}

.performance-big-number {
  font-size: clamp(2.5rem, 7vw, 4.4rem);
  line-height: 1;
  font-weight: 500;
  letter-spacing: 0;
}

.performance-big-number.value-number {
  font-size: clamp(2rem, 5vw, 3.4rem);
}

.performance-metric.positive .performance-big-number {
  color: #12b969;
}

.performance-metric.negative .performance-big-number {
  color: #ff4054;
}

.performance-caption {
  margin-top: 12px;
  font-size: 1.05rem;
  color: var(--text);
}

.performance-chart-card {
  position: relative;
  margin-top: 10px;
}

.performance-return-svg {
  overflow: visible;
}

.performance-panel .perf-grid {
  stroke: var(--line-soft);
}

.performance-panel .perf-axis-label {
  fill: var(--muted);
  font-size: 15px;
}

.performance-panel .perf-x-axis-label {
  fill: var(--muted);
  font-size: 14px;
}

.perf-area {
  fill: rgba(18, 185, 105, 0.15);
}

.perf-line-segment {
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.perf-line-up {
  stroke: #12b969;
}

.perf-line-down {
  stroke: #ff4054;
}

.perf-zero {
  stroke-dasharray: 3 4;
  stroke: #8b909b;
}

.perf-hit {
  fill: transparent;
  cursor: crosshair;
}

.perf-point {
  fill: #f4f7fb;
  stroke: #12b969;
  stroke-width: 2;
  opacity: 0;
  pointer-events: none;
}

.perf-point-group:hover .perf-point {
  opacity: 1;
}

.performance-tooltip {
  position: absolute;
  z-index: 3;
  min-width: 180px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  pointer-events: none;
}

.performance-tooltip strong,
.performance-tooltip span {
  display: block;
}

.performance-tooltip span {
  margin-top: 4px;
  color: var(--muted);
}

.performance-periods {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.performance-periods a {
  color: var(--muted);
  text-align: center;
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}

.performance-periods a.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.performance-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.performance-stats div {
  min-width: 0;
}

.performance-stats span {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

.performance-stats strong {
  display: block;
  overflow-wrap: anywhere;
}

.performance-svg {
  width: 100%;
  height: auto;
  display: block;
}

.perf-grid {
  stroke: var(--line-soft);
  stroke-width: 1;
}

.perf-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.perf-dot {
  fill: var(--accent);
  stroke: var(--panel);
  stroke-width: 2;
}

.perf-axis-label {
  fill: var(--muted);
  font-size: 12px;
}

.lang-switch {
  display: flex;
  gap: 6px;
  align-items: center;
}

@media (max-width: 1024px) {
  .topbar {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 12px 16px;
  }

  .brand {
    flex: 1 0 100%;
    display: flex;
    justify-content: center;
  }

  .nav {
    flex: 1 0 100%;
    justify-content: flex-end;
    margin-left: 0;
  }

  .hero,
  .notes-hero,
  .notes-layout,
  .summary-grid,
  .section-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px 14px;
    padding: 12px 16px;
  }

  .brand {
    width: 100%;
    display: flex;
    justify-content: center;
  }

  .nav {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px 12px;
    overflow: visible;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav a,
  .inline-form button {
    flex: 0 0 auto;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
  }

  .settings-menu {
    flex: 0 0 auto;
  }

  .container {
    padding: 16px;
  }

  .brand-logo {
    width: min(220px, calc(100vw - 32px));
    height: 34px;
  }

  .performance-panel {
    padding: 18px;
  }

  .performance-panel-head {
    grid-template-columns: 1fr;
  }

  .performance-stats {
    grid-template-columns: 1fr;
  }

  .notes-hero-main,
  .essay-card,
  .private-gate,
  .post-detail {
    padding: 20px;
  }

  .post-row {
    grid-template-columns: 1fr;
  }
}
