:root {
  --bg: #f4efe6;
  --panel: #fffaf1;
  --panel-soft: #f8f1e3;
  --text: #15252e;
  --muted: #5d6f78;
  --line: #dbcdb3;
  --ink: #0b323f;
  --gold: #c78d2f;
  --teal: #14818d;
  --olive: #6c915b;
  --danger: #c53f38;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

html {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 0% 0%, #e8d8bb 0%, transparent 34%),
    radial-gradient(circle at 100% 100%, #c6e1de 0%, transparent 30%),
    var(--bg);
  padding-top: calc(1.1rem + env(safe-area-inset-top, 0px));
  padding-right: calc(1.1rem + env(safe-area-inset-right, 0px));
  padding-bottom: calc(1.1rem + env(safe-area-inset-bottom, 0px));
  padding-left: calc(1.1rem + env(safe-area-inset-left, 0px));
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 100vw;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

body::-webkit-scrollbar {
  display: none;
}

.scene-glow {
  position: fixed;
  z-index: 0;
  width: 24rem;
  height: 24rem;
  border-radius: 999px;
  filter: blur(80px);
  pointer-events: none;
  opacity: 0.18;
}

.glow-a {
  left: -10rem;
  top: -8rem;
  background: #d7a64a;
}

.glow-b {
  right: -10rem;
  bottom: -10rem;
  background: #5ca8b0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1220px;
  margin: 0 auto;
  display: grid;
  gap: 0.85rem;
  overflow: hidden;
  width: 100%;
  min-width: 0;
  min-height: 100%;
  padding-bottom: 1rem;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "DM Serif Display", Georgia, serif;
  letter-spacing: 0.01em;
}

h1 {
  font-size: clamp(1.5rem, 2.9vw, 2.4rem);
  line-height: 1.06;
}

h2 {
  font-size: 1.35rem;
  color: #0b323f;
}

.hero {
  background: linear-gradient(120deg, #0f3848, #154451);
  color: #f9f6f1;
  border: 1px solid #24596a;
  border-radius: 20px;
  padding: 1.2rem 1.35rem;
}

.hero__kicker {
  margin: 0;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #dfca97;
}

.hero__desc {
  margin: 0.65rem 0 0;
  max-width: 70ch;
  color: #d8e8ea;
}

.info-tip-wrap {
  position: relative;
  display: inline-flex;
  margin-left: 0.45rem;
  vertical-align: middle;
}

.info-tip-btn {
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 999px;
  border: 1px solid #8bb0bd;
  background: rgba(255, 255, 255, 0.12);
  color: #f6f3ee;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1;
  cursor: help;
}

.info-tip-pop {
  position: absolute;
  z-index: 6;
  top: calc(100% + 0.35rem);
  left: 0;
  min-width: 260px;
  max-width: 360px;
  background: #0f2f3f;
  color: #e3eef2;
  border: 1px solid #436a79;
  border-radius: 10px;
  padding: 0.5rem 0.55rem;
  font-size: 0.72rem;
  line-height: 1.35;
  box-shadow: 0 8px 24px rgba(6, 15, 20, 0.35);
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: all 0.16s ease;
}

.info-tip-wrap:hover .info-tip-pop,
.info-tip-wrap:focus-within .info-tip-pop {
  opacity: 1;
  transform: translateY(0);
}

.hero__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.8rem;
}

.hero__install-hint {
  margin: 0.6rem 0 0;
  font-size: 0.78rem;
  color: #d8e8ea;
}

.pill {
  border: 1px solid #3f7282;
  background: #0d2e3ccf;
  border-radius: 999px;
  padding: 0.34rem 0.67rem;
  font-size: 0.8rem;
}

.cta-btn {
  border: 1px solid #c6b390;
  background: #fff9ea;
  color: #24343b;
  border-radius: 999px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
}

.cta-btn:hover {
  background: #f9e9c6;
}

.cta-btn--roi {
  border-color: #ae6f12;
  background: linear-gradient(130deg, #dba53e, #bc7919);
  color: #17120a;
  font-weight: 700;
}

.cta-btn--roi:hover {
  background: linear-gradient(130deg, #e0ae4f, #c68426);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0.95rem;
  box-shadow: 0 6px 18px #7f744f14;
  min-width: 0;
  overflow: hidden;
}

.controls {
  background: linear-gradient(165deg, #fffaf0, #f8efdf);
}

.controls__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-bottom: 0.65rem;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
  overflow: hidden;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
}

select,
input[type="date"],
input[type="number"] {
  border: 1px solid #d9c69d;
  background: #fff;
  color: var(--ink);
  border-radius: 11px;
  font: inherit;
  padding: 0.52rem 0.65rem;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.02);
  transition: all 0.2s ease;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

input[type="date"] {
  text-align: center;
  font-size: 0.85rem;
}

select:focus,
input[type="date"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: #bd7f23;
  box-shadow: 0 0 0 3px rgba(189, 127, 35, 0.2);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b7a173' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 1.1em;
  padding-right: 2.2rem;
}

.preset-row,
.tab-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.preset-btn,
.tab-btn {
  border: 1px solid #ccb485;
  background: #fff5dc;
  color: #3b3d37;
  border-radius: 999px;
  font: inherit;
  font-size: 0.8rem;
  padding: 0.35rem 0.68rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}

.preset-btn:hover,
.tab-btn:hover {
  transform: translateY(-1px);
  background: #fbe8bc;
}

.preset-btn.is-active,
.tab-btn.is-active {
  background: linear-gradient(130deg, #d6a64f, #bd7f23);
  border-color: #bd7f23;
  color: #17120a;
  font-weight: 700;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.8rem;
}

.kpi {
  background: linear-gradient(160deg, #fff8ea, #f6ecd7);
  padding: 1.25rem 1rem;
}

.kpi p {
  margin: 0;
  font-size: 0.77rem;
  color: var(--muted);
}

.kpi h3 {
  margin-top: 0.4rem;
  font-size: clamp(1.02rem, 2.2vw, 1.44rem);
  color: #0f3f4b;
}

.chart-stage {
  background: linear-gradient(180deg, #fffaf3, #f8efde);
}

.chart-stage__head {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 0.65rem;
}

.chart-wrap {
  border: 1px solid #dfcfad;
  border-radius: 14px;
  background: #fffefb;
  padding: 0.45rem;
  height: 390px;
  min-width: 0;
  overflow: hidden;
}

.chart-wrap--small {
  height: 330px;
}

canvas {
  width: 100% !important;
  height: 100% !important;
}

.split-grid {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 0.7rem;
}

.trends {
  background: linear-gradient(160deg, #fff5e6, #f4ead7);
}

.trends__meta {
  margin: 0.35rem 0 0.6rem;
  color: #6f7d84;
  font-size: 0.78rem;
}

.trend-list {
  display: grid;
  gap: 0.45rem;
}

.trend-item {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 0.65rem;
  border: 1px solid #dfcfad;
  background: #fff9ef;
  border-radius: 10px;
  padding: 0.45rem 0.5rem;
}

.trend-item__query {
  margin: 0;
  font-size: 0.84rem;
  color: #2b3d45;
  line-height: 1.25;
}

.trend-item__query-link {
  color: inherit;
  text-decoration: none;
}

.trend-item__query-link:hover {
  text-decoration: underline;
}

.table-wrap {
  max-height: 400px;
  overflow: auto;
  border: 1px solid #decead;
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.58rem;
  font-size: 0.84rem;
  white-space: nowrap;
  border-bottom: 1px solid #eadcc2;
}

th {
  position: sticky;
  top: 0;
  background: #fff4dc;
  color: #3e4f55;
}

td small {
  color: #6d7e86;
}

.error {
  max-width: 1220px;
  margin: 0.8rem auto 0;
  background: #f9ece9;
  border-color: #dfb5ac;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(23, 29, 33, 0.45);
  z-index: 40;
}

.roi-modal {
  position: fixed;
  z-index: 50;
  width: min(840px, calc(100vw - 1.4rem));
  max-height: 90vh;
  overflow: auto;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(170deg, #fffaf0, #f8efdf);
  border: 1px solid #d2ba8f;
  border-radius: 24px;
  padding: 1.6rem;
  box-shadow: 0 24px 60px rgba(18, 22, 26, 0.35);
}

.roi-modal__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.7rem;
}

.icon-close {
  border: 1px solid #d2ba8f;
  background: #fff;
  color: #4e5d63;
  border-radius: 50%;
  width: 2.2rem;
  height: 2.2rem;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-close:hover {
  background: #fdf5e7;
  color: #1a2226;
  border-color: #c0a87d;
  transform: rotate(90deg);
}

.roi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.9rem;
}

.roi-label {
  margin: 0 0 0.4rem;
  font-size: 0.82rem;
  color: #57666d;
}

.toggle-row {
  display: flex;
  gap: 0.4rem;
}

.flex-wrap {
  flex-wrap: wrap;
}

.time-range-wrap {
  grid-column: 1 / -1;
}

.toggle-btn {
  border: 1px solid #ccb485;
  background: #fff5dc;
  color: #3b3d37;
  border-radius: 999px;
  font: inherit;
  font-size: 0.8rem;
  padding: 0.35rem 0.68rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.toggle-btn.is-active {
  background: linear-gradient(130deg, #d6a64f, #bd7f23);
  border-color: #bd7f23;
  color: #17120a;
  font-weight: 700;
}

.toggle-btn:hover:not(.is-active) {
  background: #fcebc7;
}

.fomo-graphic {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  border: 1px solid #e2cfb4;
  border-radius: 18px;
  padding: 1.5rem 1rem;
  margin-top: 1rem;
  margin-bottom: 1.2rem;
  box-shadow: 0 8px 24px rgba(200, 180, 140, 0.15);
}

.fomo-side {
  text-align: center;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.fomo-icon-wrap {
  width: 50px;
  height: 50px;
  background: #f4ecdf;
  border-radius: 50%;
  border: 1px dashed #c0aa8c;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.6rem;
}

.fomo-icon-wrap--highlight {
  background: linear-gradient(135deg, #f7dca1, #e3af42);
  border: 2px solid #fff;
  box-shadow: 0 4px 12px rgba(200, 140, 40, 0.4);
}

.fomo-icon {
  width: 24px;
  height: 24px;
  color: #79664c;
}

.fomo-icon--gold {
  color: #553e16;
}

.fomo-year {
  font-size: 0.8rem;
  color: #707b82;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.2rem;
}

.fomo-amt {
  font-size: 1.15rem;
  font-weight: 700;
  color: #273840;
}

.fomo-amt--highlight {
  font-size: 1.45rem;
  color: #176541;
}

.fomo-sub {
  font-size: 0.75rem;
  color: #8fa0a8;
  margin-top: 0.2rem;
}

.fomo-arrow-wrap {
  flex: 1.1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 0.5rem;
}

.fomo-badge {
  background: #1e714b;
  color: #fff;
  font-weight: 700;
  font-size: 1.2rem;
  padding: 0.25rem 0.8rem;
  border-radius: 999px;
  margin-bottom: 0.4rem;
  box-shadow: 0 4px 10px rgba(30, 113, 75, 0.3);
}

.fomo-badge.is-negative {
  background: #c53f38;
  box-shadow: 0 4px 10px rgba(197, 63, 56, 0.3);
}

.fomo-arrow {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-bottom: 0.4rem;
}

.fomo-profit-val {
  font-size: 0.85rem;
  font-weight: 600;
  color: #4a5c64;
}

.roi-details-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.roi-detail-item {
  background: #fbf5eb;
  border: 1px solid #e6d3b8;
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.roi-detail-item span {
  font-size: 0.75rem;
  color: #6a7981;
}

.roi-detail-item strong {
  font-size: 0.9rem;
  color: #163642;
}

.roi-actions {
  margin-top: 0.8rem;
  display: flex;
  justify-content: flex-end;
}

.seo-disclaimer {
  border: 1px solid #e7dac3;
  background: #fff8ec;
  border-radius: 12px;
  padding: 0.5rem 0.65rem;
  margin-top: 0.25rem;
}

.seo-disclaimer p {
  margin: 0;
  font-size: 0.62rem;
  line-height: 1.45;
  color: #6f787e;
}

.seo-disclaimer strong {
  font-weight: 600;
  color: #4c5358;
}

body.modal-open .app {
  filter: blur(4px);
  pointer-events: none;
  user-select: none;
}

.is-hidden {
  display: none;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #fff;
  border: 1px solid #e1d0ac;
  border-radius: 6px;
  padding: 0.08rem 0.32rem;
}

@media (max-width: 1040px) {
  .controls-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }

  .split-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  body {
    padding: 0.72rem;
  }

  .controls-grid {
    grid-template-columns: 1fr;
  }

  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .chart-wrap {
    height: 300px;
  }

  .chart-wrap--small {
    height: 280px;
  }

  .fomo-graphic {
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.2rem;
  }
  .fomo-arrow svg {
    transform: rotate(90deg);
    width: 24px;
    height: 80px;
  }

  .seo-disclaimer p {
    font-size: 0.6rem;
  }

  .hero {
    padding: 1rem;
  }

  .hero__meta {
    gap: 0.35rem;
  }

  .pill, .cta-btn {
    font-size: 0.72rem;
    padding: 0.3rem 0.55rem;
  }

  .controls__head {
    gap: 0.4rem;
  }

  .preset-btn, .tab-btn {
    font-size: 0.72rem;
    padding: 0.3rem 0.55rem;
  }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Hide Source column on narrow screens */
  th:nth-child(4),
  td:nth-child(4) {
    display: none;
  }
}

/* iOS PWA standalone: extra top padding for status bar */
@media (display-mode: standalone) {
  body {
    padding-top: calc(1.6rem + env(safe-area-inset-top, 20px));
    padding-bottom: 0;
    background:
      radial-gradient(circle at 0% 0%, #e8d8bb 0%, transparent 34%),
      var(--bg);
  }

  .seo-disclaimer {
    display: none;
  }

  .glow-b {
    display: none;
  }
}
