:root {
  color-scheme: light;
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: #f4f6f5;
  color: #17201d;
  font-synthesis: none;
  --ink: #17201d;
  --muted: #66716d;
  --line: #d9dfdc;
  --surface: #ffffff;
  --call: #d45245;
  --call-soft: #f8ded9;
  --put: #087f71;
  --put-soft: #d8eee9;
  --action: #087f71;
  --accent: #d8a121;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: #f4f6f5;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  min-height: 180px;
  padding: 34px clamp(20px, 5vw, 72px) 30px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  color: #f7faf8;
  background: #17201d;
  border-bottom: 4px solid var(--accent);
}

.market-code,
.eyebrow {
  margin: 0 0 8px;
  color: #8fa29b;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: clamp(2.5rem, 5vw, 4.5rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.brand-subtitle {
  margin: 12px 0 0;
  color: #bcc8c3;
  font-size: 1rem;
}

.source-link {
  color: #e1e9e5;
  font-size: 0.88rem;
  text-decoration: none;
  border-bottom: 1px solid #63746d;
  padding-bottom: 3px;
}

.source-link:hover {
  color: #ffffff;
  border-color: #ffffff;
}

main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 28px clamp(16px, 4vw, 56px) 52px;
}

.control-band {
  display: grid;
  grid-template-columns: minmax(300px, 0.8fr) minmax(360px, 1.2fr);
  gap: 32px;
  padding: 24px 0 28px;
  border-bottom: 1px solid var(--line);
}

.import-control,
.filter-control {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.filter-control {
  justify-content: flex-end;
}

.field-group {
  display: grid;
  gap: 7px;
  min-width: 170px;
}

.contract-field {
  min-width: 220px;
}

label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

input,
select {
  height: 42px;
  width: 100%;
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #cbd3cf;
  border-radius: 4px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--action);
  box-shadow: 0 0 0 3px rgba(8, 127, 113, 0.12);
}

select:disabled {
  color: #929c98;
  background: #edf0ee;
}

.primary-button {
  height: 42px;
  padding: 0 18px;
  color: #ffffff;
  background: var(--action);
  border: 1px solid var(--action);
  border-radius: 4px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.primary-button:hover {
  background: #066c61;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.status-line {
  min-height: 44px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 0.88rem;
}

.status-line.error {
  color: #ad342a;
}

.status-line.success {
  color: #086f63;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}

.metric {
  min-height: 96px;
  padding: 18px 20px;
  display: grid;
  align-content: space-between;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.metric span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.metric strong {
  font-size: 1.72rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.call-metric {
  border-top: 3px solid var(--call);
}

.put-metric {
  border-top: 3px solid var(--put);
}

.neutral-metric {
  border-top: 3px solid #7f8c87;
}

.chart-section,
.ranking-section {
  margin-top: 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.section-heading {
  min-height: 78px;
  padding: 18px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
}

.section-heading h2 {
  margin: 0;
  font-size: 1.12rem;
  letter-spacing: 0;
}

.section-heading .eyebrow {
  margin-bottom: 5px;
}

.legend {
  display: flex;
  gap: 18px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend-swatch {
  width: 11px;
  height: 11px;
  display: inline-block;
  border-radius: 2px;
}

.legend-swatch.call {
  background: var(--call);
}

.legend-swatch.put {
  background: var(--put);
}

.empty-state {
  min-height: 380px;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong {
  color: #45514c;
}

.empty-state span {
  font-size: 0.88rem;
}

.chart-scroll {
  max-height: 70vh;
  overflow: auto;
}

.chart-stage {
  position: relative;
  min-width: 720px;
  height: 520px;
  padding: 16px 20px 20px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th,
td {
  height: 44px;
  padding: 0 22px;
  text-align: left;
  border-bottom: 1px solid #e7ebe9;
  font-variant-numeric: tabular-nums;
}

th {
  color: var(--muted);
  background: #fafbfa;
  font-size: 0.75rem;
}

tr:last-child td {
  border-bottom: 0;
}

.numeric {
  text-align: right;
}

.table-empty {
  height: 100px;
  color: var(--muted);
  text-align: center;
}

footer {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 56px) 32px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  color: #7a8580;
  font-size: 0.75rem;
}

@media (max-width: 820px) {
  .app-header {
    min-height: 160px;
    align-items: flex-start;
    flex-direction: column;
  }

  .control-band {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .filter-control {
    justify-content: flex-start;
  }

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

  .metric:nth-child(2) {
    border-right: 0;
  }

  .metric:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 540px) {
  .app-header {
    padding: 26px 18px;
  }

  main {
    padding-inline: 12px;
  }

  .import-control,
  .filter-control {
    align-items: stretch;
    flex-direction: column;
  }

  .field-group,
  .contract-field {
    min-width: 0;
  }

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

  .metric {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .metric:last-child {
    border-bottom: 0;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  footer {
    flex-direction: column;
  }
}
