#stock-intro {
  margin-top: 1em;
}

#stock-intro h1 {
  font-weight: 700;
  font-size: 2em;
  line-height: 1.1;
  margin: 0.2em 0 0.1em 0;
}

#stock-intro h3.sub {
  font-weight: 400;
  font-style: italic;
  font-size: 1em;
  color: #666;
  margin: 0 0 1em 0;
}

#stock-intro h3 {
  font-weight: 600;
  font-size: 1.25em;
  margin: 1.5em 0 0.5em 0;
}

#stock-intro p {
  margin: 0.4em 0;
}

.mechanics-layout {
  display: flex;
  gap: 1.5em;
  align-items: flex-start;
  margin: 0.6em 0 1em 0;
}

.mechanics-text {
  flex: 1.3;
}

#stock-intro .mechanics-text > p {
  margin: 0;
}

#stock-intro .mechanics-text > p + p {
  margin-top: 0.45em;
}

.mechanics-layout .decay-example {
  flex: 1;
  margin: 0;
}

@media (max-width: 720px) {
  .mechanics-layout {
    flex-direction: column;
  }
  .mechanics-layout .decay-example {
    margin-top: 0.6em;
    max-width: 380px;
    width: 100%;
  }
  #stock-intro .mechanics-text > p + p {
    margin-top: 0.5em;
  }
}

.decay-example {
  display: flex;
  gap: 1em;
  margin: 1em 0;
}

.decay-col {
  flex: 1;
  background-color: #f7f4ec;
  border-left: 3px solid #d9c9a8;
  padding: 0.7em 1em;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.92em;
  border-radius: 2px;
}

.decay-col-head {
  font-family: "Inter", Arial, sans-serif;
  font-weight: 600;
  color: #222;
  margin-bottom: 0.4em;
}

.decay-col-sub {
  color: #888;
  font-weight: 400;
  margin-left: 0.25em;
}

.decay-row {
  display: flex;
  justify-content: space-between;
  padding: 0.15em 0;
}

.decay-label {
  color: #555;
}

.decay-val {
  color: #222;
}

.decay-row.decay-net {
  margin-top: 0.4em;
  padding-top: 0.4em;
  border-top: 1px solid #d9c9a8;
  font-weight: 600;
}

.decay-row.decay-net .decay-label {
  color: #1f1f1f;
}

.decay-row.decay-net .decay-pct {
  color: #b00020;
  font-weight: 400;
}

@media (max-width: 540px) {
  .decay-col {
    padding: 0.5em 0.7em;
    font-size: 0.85em;
  }
  .decay-example {
    gap: 0.5em;
  }
}

#stock-status {
  color: #666;
  font-style: italic;
}

.amount-control {
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  margin: 1.2em 0 0.4em 0;
  padding: 0.5em 0.8em;
  background-color: #f4f0e6;
  border: 1px solid #d9c9a8;
  border-radius: 4px;
}

.amount-control label {
  font-weight: 600;
  color: #444;
}

.amount-input {
  font-weight: 600;
  color: #222;
}

#amount {
  width: 5.5em;
  margin-left: 0.15em;
  padding: 0.25em 0.4em;
  font: inherit;
  font-weight: 600;
  /* iOS Safari auto-zooms when a form field is focused if its font-size is < 16px.
     Forcing 16px keeps the page at 1:1 scale on tap. */
  font-size: 16px;
  border: 1px solid #ccc;
  border-radius: 3px;
  background-color: #fff;
}

#amount:focus {
  outline: 2px solid #c5e1a5;
  border-color: #4a7c2e;
}

#stock-results {
  margin-top: 1em;
}

.table-wrap {
  /* No overflow constraint — overflow-x: auto would create a scrolling ancestor
     and prevent the thead/category-row from sticking to the viewport. */
}

#stock-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  table-layout: fixed;
}

#stock-table thead th:nth-child(1) { width: 28%; }
#stock-table thead th:nth-child(2) { width: 12%; }
#stock-table thead th:nth-child(3) { width: 12%; }
#stock-table thead th:nth-child(4) { width: 48%; }

#stock-table thead th {
  background-color: #d9e8c7;
  font-family: "Inter", Arial, sans-serif;
  font-weight: 600;
  padding: 0.6em 0.8em;
  text-align: right;
  white-space: nowrap;
  /* box-shadow instead of border-bottom: collapsed borders detach from sticky cells while scrolling */
  box-shadow: inset 0 -1px 0 #c0d4a8;
  position: sticky;
  top: 0;
  z-index: 3;
}

#stock-table thead th:first-child {
  text-align: left;
}

#stock-table thead th:nth-child(2) {
  text-align: center;
}

#stock-table tbody td {
  padding: 0.5em 0.8em;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid #f0f0f0;
}

#stock-table tbody td:first-child {
  text-align: left;
}

.category-row {
  cursor: pointer;
  background-color: #f4f0e6;
}

.category-row td {
  padding: 0.7em 0.8em !important;
  /* box-shadow instead of borders so the lines stay attached to the sticky cell while scrolling */
  border-bottom: none !important;
  border-top: none !important;
  box-shadow: inset 0 -1px 0 #d9c9a8, inset 0 1px 0 #d9c9a8;
  position: sticky;
  top: var(--cat-top, 36px);
  z-index: 2;
  background-color: #f4f0e6;
}

.category-row:hover td {
  background-color: #ebe2cc;
}

.cat-label-cell {
  font-family: "Inter", Arial, sans-serif;
}

.cat-name {
  font-weight: 600;
  color: #2a2a2a;
}

.cat-count {
  color: #999;
  font-weight: 400;
  font-size: 0.95em;
  margin-left: 0.2em;
}

.cat-winner-cell {
  text-align: center !important;
  font-family: "Inter", Arial, sans-serif;
  font-size: 0.95em;
}

.cat-margin-cell {
  /* base text not bold; the % portion gets .pct-bold */
}

.cat-margin-text {
  font-family: "JetBrains Mono", monospace;
}

.detail-header th {
  position: sticky;
  top: var(--detail-header-top, 78px);
  z-index: 1;
  background-color: #ebf0e4;
  font-family: "Inter", Arial, sans-serif;
  font-weight: 600;
  font-size: 12px;
  padding: 0.4em 0.8em;
  text-align: right;
  white-space: nowrap;
  /* box-shadow instead of border-bottom so the line stays attached while scrolling */
  box-shadow: inset 0 -1px 0 #c0d4a8;
  color: #444;
}

.detail-header th:first-child {
  text-align: left;
}

.triangle {
  display: inline-block;
  width: 1em;
  color: #666;
  font-size: 0.8em;
}

.detail-row td {
  font-size: 12px;
}

.detail-row td.indent {
  padding-left: 2.5em !important;
  color: #555;
}

.info-icon {
  margin-left: 0.4em;
  color: #555;
  font-size: 1.05em;
  font-family: "Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols 2", "Noto Sans Symbols", system-ui, sans-serif;
}

.detail-row:hover .info-icon {
  color: #222;
}

.detail-row:hover td {
  background-color: #f6f9f1;
}

.tqqq-win {
  color: #4a7c2e;
}

.qqq-win {
  color: #b00020;
}

.muted {
  color: #999;
}

.pct-bold {
  font-weight: 700;
}

.margin-cell {
  white-space: nowrap;
}

.margin-inner {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.7em;
}

.margin-value {
  flex: 1;
  text-align: right;
}

.squares {
  display: inline-flex;
  gap: 2px;
  flex-shrink: 0;
  vertical-align: middle;
}

.square {
  display: inline-block;
  width: 8px;
  height: 8px;
  border: 1px solid #d0d0d0;
  background-color: #fff;
  box-sizing: border-box;
}

.square.filled {
  background-color: #4a7c2e;
  border-color: #4a7c2e;
}

.square.filled.qqq {
  background-color: #b00020;
  border-color: #b00020;
}

@media (max-width: 768px) {
  #stock-table {
    font-size: 12px;
  }

  #stock-table thead th,
  #stock-table tbody td {
    padding: 0.4em 0.6em;
  }

  .detail-row td {
    font-size: 11px;
  }

  .detail-row td.indent {
    padding-left: 1.5em !important;
  }
}

@media (max-width: 700px) {
  /* On small screens, drop fixed table-layout entirely and let the browser
     auto-size the surviving cells based on content. Hidden cells contribute
     zero to column width under auto layout, which avoids the chrome bug
     where intermediate display:none cells confuse the fixed-layout column
     mapping. */
  #stock-table {
    table-layout: auto;
  }
  #stock-table colgroup col {
    width: auto !important;
  }

  /* Scope to detail rows: category rows have a different cell layout
     (label + colspan winner + margin), so we don't want to hit their
     3rd td which is the avg-margin cell we want to keep. */
  .detail-row td:nth-child(2),
  .detail-row td:nth-child(3),
  #stock-table thead th:nth-child(2),
  .detail-header th:nth-child(2),
  .detail-header th:nth-child(3),
  .category-row .cat-winner-cell {
    display: none;
  }
}
