:root {
  color-scheme: light;
  --bg: #f3efe6;
  --ink: #231b14;
  --muted: #75665a;
  --panel: rgba(255, 250, 243, 0.84);
  --panel-border: rgba(101, 79, 60, 0.15);
  --panel-strong: rgba(255, 255, 255, 0.68);
  --shadow: 0 18px 40px rgba(58, 40, 24, 0.08);
  --brand: #b6512d;
  --brand-soft: #f6d4be;
  --brand-line: #d67f58;
  --success: #21543d;
  --success-soft: rgba(33, 84, 61, 0.12);
  --warning: #8a4d20;
  --warning-soft: rgba(182, 81, 45, 0.12);
  --grid-line: rgba(35, 27, 20, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(182, 81, 45, 0.12), transparent 32%),
    radial-gradient(circle at top right, rgba(33, 84, 61, 0.12), transparent 28%),
    linear-gradient(180deg, #f7f2ea, #efe7dc 62%, #e8dece);
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.hero,
.panel,
.metric-card,
.fold-card {
  backdrop-filter: blur(12px);
}

.hero {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 14px;
  padding: 14px 18px;
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  background: linear-gradient(135deg, rgba(255, 251, 244, 0.95), rgba(250, 240, 229, 0.88));
  box-shadow: var(--shadow);
}

.hero-brand {
  display: grid;
  gap: 6px;
  flex: 1.3 1 300px;
  min-width: 240px;
}

.hero-status {
  display: grid;
  gap: 8px;
  flex: 0.95 1 280px;
  min-width: 220px;
  padding: 10px 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(182, 81, 45, 0.12);
}

.eyebrow {
  margin: 0;
  color: var(--brand);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.72rem;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.8rem, 3vw, 2.7rem);
  line-height: 1.02;
  letter-spacing: -0.03em;
}

h2 {
  font-size: clamp(1.12rem, 2vw, 1.4rem);
  letter-spacing: -0.02em;
}

.hero-copy {
  max-width: 40ch;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.9rem;
}

.hero-range-group {
  display: grid;
  gap: 6px;
  flex: 0 0 320px;
  min-width: 320px;
}

.range-caption {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.range-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#usage-range-controls {
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

#usage-range-controls::-webkit-scrollbar {
  display: none;
}

#usage-range-controls .range-chip {
  flex: 0 0 auto;
}

.range-chip {
  border: 1px solid rgba(35, 27, 20, 0.08);
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 12px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background-color 160ms ease,
    color 160ms ease,
    border-color 160ms ease;
}

.range-chip:hover:not(:disabled),
.range-chip:focus-visible:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(182, 81, 45, 0.28);
  color: var(--ink);
  outline: none;
}

.range-chip[data-active="true"] {
  background: var(--brand);
  border-color: transparent;
  color: #fffaf3;
  box-shadow: 0 10px 24px rgba(182, 81, 45, 0.18);
}

.range-chip:disabled {
  cursor: wait;
  opacity: 0.66;
}

.hero-note-top {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-start;
}

.hero-window {
  display: inline-flex;
  align-items: center;
  padding: 7px 11px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  background: rgba(35, 27, 20, 0.06);
}

.badge {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 700;
  background: var(--brand-soft);
  color: var(--warning);
}

.badge.ready {
  background: var(--success-soft);
  color: var(--success);
}

.hero-metrics {
  display: grid;
  gap: 8px;
  flex: 1.55 1 420px;
  min-width: 340px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric-card,
.panel,
.fold-card {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-card {
  position: relative;
  overflow: hidden;
  display: grid;
  gap: 4px;
  min-height: 68px;
  padding: 10px 12px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.76), rgba(255, 247, 239, 0.72));
}

.metric-card::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand-line), transparent 88%);
  opacity: 0.85;
}

.metric-card[data-tone="total"]::before {
  background: linear-gradient(90deg, #b6512d, transparent 88%);
}

.metric-card[data-tone="input"]::before {
  background: linear-gradient(90deg, #21543d, transparent 88%);
}

.metric-card[data-tone="output"]::before {
  background: linear-gradient(90deg, #ca6f42, transparent 88%);
}

.metric-card[data-tone="events"]::before {
  background: linear-gradient(90deg, #7d5b40, transparent 88%);
}

.metric-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.metric-value {
  font-size: clamp(1rem, 1.45vw, 1.35rem);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.metric-hint {
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.4;
}

.panel-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 18px;
}

.panel {
  margin-top: 18px;
  padding: 22px;
  border-radius: 24px;
}

.panel-grid .panel {
  margin-top: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-header-stack {
  align-items: start;
}

.subtle {
  color: var(--muted);
  font-size: 0.9rem;
}

.stack {
  display: grid;
  gap: 12px;
}

.fold-card {
  overflow: hidden;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 247, 239, 0.68));
}

.fold-card summary {
  list-style: none;
  cursor: pointer;
}

.fold-card summary::-webkit-details-marker {
  display: none;
}

.fold-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
}

.fold-summary-copy,
.fold-summary-side {
  display: grid;
  gap: 6px;
}

.fold-summary-side {
  justify-items: end;
  text-align: right;
}

.fold-kicker {
  color: var(--brand);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.fold-title {
  font-size: 1.08rem;
}

.fold-value {
  font-size: 1.02rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.fold-toggle {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.fold-toggle::before {
  content: "展開完整排行";
}

.fold-card[open] .fold-toggle::before {
  content: "收合";
}

.fold-content {
  padding: 0 18px 18px;
  border-top: 1px solid rgba(35, 27, 20, 0.08);
}

.row-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  border-radius: 18px;
  background: var(--panel-strong);
  border: 1px solid rgba(35, 27, 20, 0.07);
}

.row-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.row-lead {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.row-rank {
  display: inline-flex;
  min-width: 34px;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(182, 81, 45, 0.12);
  color: var(--brand);
  font-size: 0.76rem;
  font-weight: 700;
}

.row-title {
  min-width: 0;
  overflow-wrap: anywhere;
}

.row-value {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 700;
  white-space: nowrap;
}

.bar-track {
  overflow: hidden;
  height: 8px;
  border-radius: 999px;
  background: rgba(35, 27, 20, 0.08);
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #d67f58, #b6512d);
}

.chart-shell {
  display: grid;
  gap: 18px;
}

.sustainability-shell {
  display: grid;
  gap: 16px;
}

.sustainability-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.context-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 12px;
}

.context-card {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid rgba(35, 27, 20, 0.07);
  background: rgba(255, 255, 255, 0.58);
}

.context-kicker {
  color: var(--brand);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.context-value {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.context-copy {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.estimate-card {
  position: relative;
  overflow: hidden;
  display: grid;
  gap: 8px;
  min-height: 138px;
  padding: 18px;
  border-radius: 20px;
  border: 1px solid rgba(35, 27, 20, 0.08);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 247, 239, 0.64));
}

.estimate-card::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  opacity: 0.88;
}

.estimate-card[data-tone="energy"]::before {
  background: linear-gradient(90deg, #21543d, transparent 88%);
}

.estimate-card[data-tone="carbon"]::before {
  background: linear-gradient(90deg, #8a4d20, transparent 88%);
}

.estimate-card[data-tone="total"]::before {
  background: linear-gradient(90deg, #b6512d, transparent 88%);
}

.estimate-card[data-tone="input"]::before {
  background: linear-gradient(90deg, #21543d, transparent 88%);
}

.estimate-card[data-tone="events"]::before {
  background: linear-gradient(90deg, #7d5b40, transparent 88%);
}

.estimate-label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.estimate-value {
  font-size: clamp(1.35rem, 2vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.estimate-range {
  color: var(--brand);
  font-size: 0.92rem;
  font-weight: 700;
}

.estimate-hint {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.55;
}

.sustainability-method .row-card {
  background: rgba(255, 255, 255, 0.56);
}

.chart-summary {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.chart-stat {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.64);
  border: 1px solid rgba(35, 27, 20, 0.07);
}

.chart-stat-label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.chart-stat-value {
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.chart-wrap {
  overflow: hidden;
  border-radius: 22px;
  padding: 14px 12px 6px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.68), rgba(255, 247, 239, 0.62));
  border: 1px solid rgba(35, 27, 20, 0.07);
}

.chart-svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-grid-line {
  stroke: var(--grid-line);
  stroke-width: 1;
  stroke-dasharray: 4 8;
}

.chart-grid-label {
  fill: var(--muted);
  font-size: 11px;
}

.chart-area {
  fill: url(#dailyAreaGradient);
}

.chart-line {
  fill: none;
  stroke: #b6512d;
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-dot {
  fill: #fffaf3;
  stroke: #b6512d;
  stroke-width: 2;
}

.chart-dot.is-peak {
  fill: #b6512d;
  stroke: #fffaf3;
}

.chart-dot.is-latest {
  stroke: #21543d;
}

.chart-axis-label {
  fill: var(--muted);
  font-size: 12px;
}

.empty-state {
  padding: 18px;
  border-radius: 18px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
}

.warning-panel .row-card {
  border-color: rgba(182, 81, 45, 0.18);
}

@media (max-width: 960px) {
  .panel-grid,
  .chart-summary,
  .sustainability-grid,
  .context-grid {
    grid-template-columns: 1fr;
  }

  .hero-metrics {
    flex-basis: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding-top: 20px;
  }

  .hero,
  .panel,
  .metric-card,
  .fold-card,
  .chart-wrap {
    border-radius: 20px;
  }

  .hero {
    padding: 16px;
  }

  .hero-metrics,
  .chart-summary,
  .sustainability-grid,
  .context-grid {
    grid-template-columns: 1fr 1fr;
  }

  .hero-brand,
  .hero-status,
  .hero-range-group,
  .hero-metrics {
    flex-basis: 100%;
    min-width: 0;
  }

  .panel-header,
  .fold-summary,
  .row-line,
  .panel-header-stack {
    align-items: start;
    flex-direction: column;
  }

  .fold-summary-side {
    justify-items: start;
    text-align: left;
  }

  .row-value {
    white-space: normal;
  }
}

@media (max-width: 420px) {
  .hero-metrics,
  .chart-summary,
  .sustainability-grid,
  .context-grid {
    grid-template-columns: 1fr;
  }
}
