:root {
  color-scheme: light;
  --paper: #f7f4ed;
  --surface: #fffcf5;
  --ink: #171512;
  --muted: #6f6a60;
  --line: #ded6c6;
  --green: #177b55;
  --green-soft: #dff3e8;
  --coral: #c7553d;
  --coral-soft: #f8ddd5;
  --gold: #9f6b12;
  --gold-soft: #f6e8bf;
  --blue: #27728a;
  --blue-soft: #d8edf2;
  --shadow: 0 18px 45px rgba(47, 37, 22, 0.09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 252, 245, 0.8), rgba(247, 244, 237, 0.96)),
    repeating-linear-gradient(90deg, rgba(23, 21, 18, 0.03) 0 1px, transparent 1px 84px);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 8px 0 22px;
}

.eyebrow,
.label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(36px, 6vw, 72px);
  line-height: 0.92;
  letter-spacing: 0;
}

h2 {
  font-size: 21px;
  line-height: 1.15;
}

.stamp {
  min-width: 220px;
  display: grid;
  gap: 6px;
  justify-items: end;
  color: var(--muted);
  font-size: 13px;
}

.stamp strong {
  color: var(--ink);
  font-size: 15px;
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.75fr);
  gap: 14px;
}

.savings-panel,
.controls-panel,
.chart-panel,
.detail-panel,
.history-panel,
.source-panel {
  background: rgba(255, 252, 245, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.savings-panel {
  min-height: 372px;
  padding: 24px;
  display: grid;
  align-content: space-between;
  gap: 26px;
  position: relative;
  overflow: hidden;
}

.savings-panel::before {
  content: "";
  position: absolute;
  inset: auto -10% -34% 36%;
  height: 250px;
  background: linear-gradient(105deg, rgba(23, 123, 85, 0.18), rgba(199, 85, 61, 0.16), rgba(39, 114, 138, 0.18));
  transform: rotate(-8deg);
}

.savings-panel > * {
  position: relative;
  z-index: 1;
}

.toy-stage {
  position: absolute;
  right: 18px;
  bottom: 14px;
  width: min(24vw, 218px);
  aspect-ratio: 1;
  z-index: 0;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  filter: drop-shadow(0 18px 18px rgba(47, 37, 22, 0.12));
}

.toy-stage img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 18px;
  animation: toy-bob 4.8s ease-in-out infinite;
}

.toy-stage:focus-visible,
.bar:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(39, 114, 138, 0.42);
  outline-offset: 3px;
}

.play-burst .toy-stage img {
  animation: toy-bounce 620ms ease, toy-bob 4.8s ease-in-out 620ms infinite;
}

.spark {
  position: absolute;
  width: 13px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 5px rgba(159, 107, 18, 0.12);
  animation: spark-pop 2.6s ease-in-out infinite;
}

.spark.one {
  left: 22%;
  top: 14%;
}

.spark.two {
  right: 12%;
  top: 30%;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(23, 123, 85, 0.12);
  animation-delay: 0.7s;
}

.spark.three {
  left: 38%;
  bottom: 20%;
  background: var(--coral);
  box-shadow: 0 0 0 5px rgba(199, 85, 61, 0.12);
  animation-delay: 1.35s;
}

@keyframes toy-bob {
  0%,
  100% {
    transform: translateY(0) rotate(-1deg);
  }
  50% {
    transform: translateY(-8px) rotate(1.5deg);
  }
}

@keyframes spark-pop {
  0%,
  100% {
    transform: translateY(0) scale(0.74);
    opacity: 0.45;
  }
  45% {
    transform: translateY(-13px) scale(1);
    opacity: 1;
  }
}

@keyframes toy-bounce {
  0%,
  100% {
    transform: translateY(0) rotate(0deg) scale(1);
  }
  40% {
    transform: translateY(-15px) rotate(-3deg) scale(1.05);
  }
}

.coin-burst {
  position: absolute;
  width: 12px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(159, 107, 18, 0.13);
  z-index: 3;
  pointer-events: none;
  animation: coin-fly 900ms ease-out forwards;
}

@keyframes coin-fly {
  from {
    transform: translate(0, 0) scale(0.6);
    opacity: 1;
  }
  to {
    transform: translate(var(--x), var(--y)) scale(0.15);
    opacity: 0;
  }
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

#apiCost {
  display: block;
  font-size: clamp(44px, 6.4vw, 76px);
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

.model-select {
  display: grid;
  grid-template-columns: 48px minmax(150px, 1fr);
  gap: 6px 10px;
  width: min(100%, 236px);
  align-items: end;
}

.model-select label {
  grid-column: 1 / -1;
}

.model-select img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

select,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  min-height: 42px;
  padding: 0 12px;
}

.delta-line {
  display: grid;
  gap: 9px;
  max-width: calc(100% - 270px);
}

#savingsBadge {
  width: fit-content;
  border-radius: 999px;
  padding: 7px 10px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

#savingsBadge.good {
  background: var(--green-soft);
  color: var(--green);
}

#savingsBadge.warn {
  background: var(--gold-soft);
  color: var(--gold);
}

#savingsText {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.45;
}

.meter-row {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: calc(100% - 280px);
}

.meter-row strong {
  display: block;
  margin-bottom: 5px;
}

.meter-row span {
  color: var(--muted);
  font-size: 13px;
}

.radial {
  width: 88px;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background:
    radial-gradient(circle at center, var(--surface) 0 57%, transparent 58%),
    conic-gradient(var(--green) calc(var(--pct) * 1%), rgba(23, 21, 18, 0.12) 0);
}

.radial span {
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
}

.controls-panel {
  padding: 20px;
  display: grid;
  align-content: start;
  gap: 18px;
}

.field {
  display: grid;
  gap: 8px;
}

.money-input {
  position: relative;
}

.money-input span {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

.money-input input {
  padding-left: 28px;
  font-size: 24px;
  font-weight: 850;
}

.percent-input span {
  left: auto;
  right: 12px;
}

.percent-input input {
  padding-left: 12px;
  padding-right: 34px;
}

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.compare-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.42);
}

.compare-grid span,
.muted-note span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.compare-grid strong {
  display: block;
  margin-top: 5px;
  font-size: 21px;
}

.discount-grid strong {
  color: var(--green);
}

.muted-note {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  gap: 7px;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--line);
}

.metric-strip div {
  min-height: 98px;
  padding: 16px;
  background: rgba(255, 252, 245, 0.92);
  display: grid;
  align-content: space-between;
  gap: 12px;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

.token-card img {
  position: absolute;
  right: 8px;
  top: 10px;
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 14px;
  opacity: 0.72;
  pointer-events: none;
}

.token-card strong,
.token-card span {
  position: relative;
}

.metric-strip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.metric-strip strong {
  font-size: clamp(19px, 2.15vw, 28px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr);
  gap: 14px;
}

.model-mix-panel {
  margin-bottom: 14px;
  padding: 20px;
  background: rgba(255, 252, 245, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.model-mix-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.model-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  background: rgba(255, 255, 255, 0.42);
}

.model-row strong,
.model-row span {
  display: block;
}

.model-row span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 5px;
}

.chart-panel,
.detail-panel,
.history-panel,
.source-panel {
  padding: 20px;
}

.section-head,
.source-panel {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.section-head > span,
#fileCount {
  color: var(--muted);
  font-size: 13px;
}

.bars {
  min-height: 290px;
  display: flex;
  align-items: end;
  gap: 8px;
  padding-top: 28px;
}

.bar {
  flex: 1 1 0;
  min-width: 38px;
  display: grid;
  align-content: end;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.bar-track {
  height: 220px;
  display: flex;
  align-items: end;
  border-left: 1px solid rgba(23, 21, 18, 0.08);
}

.bar-fill {
  width: 100%;
  min-height: 3px;
  border-radius: 999px 999px 0 0;
  background:
    repeating-linear-gradient(180deg, rgba(255, 252, 245, 0.38) 0 7px, transparent 7px 14px),
    linear-gradient(180deg, var(--green), var(--blue));
  transition: height 240ms ease;
}

.bar span {
  color: var(--muted);
  font-size: 11px;
}

.bar em {
  color: var(--green);
  font-size: 10px;
  font-style: normal;
  font-weight: 850;
  white-space: nowrap;
}

.session-list {
  display: grid;
  gap: 10px;
  margin-top: 20px;
  max-height: 326px;
  overflow: auto;
  padding-right: 4px;
}

.session-row {
  display: grid;
  gap: 7px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.session-row:last-child {
  border-bottom: 0;
}

.session-row strong {
  font-size: 14px;
  overflow-wrap: anywhere;
}

.session-row span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.history-panel {
  margin-top: 14px;
}

.history-tabs {
  display: flex;
  gap: 8px;
  margin: 18px 0 14px;
}

.range-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

.compact-tabs {
  margin: 0;
}

.history-tabs button,
.range-arrows button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.42);
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
  cursor: pointer;
}

.history-tabs button.active,
.range-arrows button:not(:disabled):hover {
  background: var(--blue-soft);
  color: var(--blue);
}

.range-arrows {
  display: flex;
  gap: 8px;
}

.range-arrows button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.history-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.history-summary div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.42);
}

.history-summary span,
.history-summary strong {
  display: block;
}

.history-summary span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.history-summary strong {
  margin-top: 5px;
  font-size: 22px;
}

.history-list {
  display: grid;
  gap: 9px;
  max-height: 470px;
  overflow: auto;
  padding-right: 4px;
}

.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, auto);
  gap: 8px 16px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.history-row:last-child {
  border-bottom: 0;
}

.history-row strong,
.history-row span {
  display: block;
}

.history-row strong {
  overflow-wrap: anywhere;
}

.history-row span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  margin-top: 4px;
}

.history-row > div:nth-child(2) {
  text-align: right;
}

.history-row .mini-track {
  grid-column: 1 / -1;
}

.mini-track {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(23, 21, 18, 0.11);
}

.mini-track i {
  display: block;
  height: 100%;
  width: var(--w);
  background: var(--coral);
  border-radius: inherit;
}

.source-panel {
  margin-top: 14px;
  align-items: start;
}

.source-body {
  display: grid;
  gap: 12px;
  width: min(100%, 760px);
}

.truth-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.truth-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.42);
}

.truth-grid span,
.truth-grid strong {
  display: block;
}

.truth-grid span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
  text-transform: uppercase;
}

.truth-grid strong {
  margin-top: 5px;
  font-size: 19px;
}

#sourceNote {
  max-width: 700px;
  color: var(--muted);
  line-height: 1.45;
}

@media (max-width: 860px) {
  .shell {
    width: min(100vw - 22px, 720px);
    padding-top: 18px;
  }

  .topbar,
  .panel-head,
  .source-panel {
    align-items: start;
    flex-direction: column;
  }

  .stamp {
    justify-items: start;
  }

  .hero-grid,
  .workspace-grid,
  .model-mix-list {
    grid-template-columns: 1fr;
  }

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

  .history-row > div:nth-child(2) {
    text-align: left;
  }

  .range-tools,
  .history-tabs,
  .range-arrows {
    flex-wrap: wrap;
  }

  .history-summary {
    grid-template-columns: 1fr;
  }

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

  .metric-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-strip {
    gap: 1px;
  }

  .metric-strip div:first-child {
    grid-column: 1 / -1;
  }

  .toy-stage {
    width: 118px;
    right: 10px;
    bottom: 12px;
    opacity: 0.68;
  }

  .delta-line,
  .meter-row {
    max-width: none;
    padding-right: 118px;
  }

  .bars {
    overflow-x: auto;
    align-items: end;
    padding-bottom: 8px;
  }

  .bar {
    flex-basis: 54px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
