:root {
  --bg-1: #f7f2e9;
  --bg-2: #efe4d3;
  --panel: rgba(255, 251, 245, 0.88);
  --line: #e1d1b9;
  --line-strong: #c8b08b;
  --text: #2e2317;
  --muted: #7f6b55;
  --accent: #9d5b1f;
  --positive: #e24d2e;
  --negative: #2f65d9;
  --shadow: 0 18px 45px rgba(72, 44, 20, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 20%, rgba(212, 161, 89, 0.18), transparent 28%),
    radial-gradient(circle at 80% 10%, rgba(193, 124, 48, 0.16), transparent 25%),
    linear-gradient(180deg, var(--bg-1), #f8f4ed 40%, #f2eadf 100%);
}

.page-shell {
  max-width: 1480px;
  margin: 0 auto;
  padding: 28px 18px 36px;
}

.hero {
  text-align: center;
  padding: 28px 12px 20px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 54px);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.subcopy {
  margin: 12px auto 0;
  max-width: 760px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.tabs-card {
  background: rgba(255, 248, 239, 0.78);
  border: 1px solid rgba(196, 167, 126, 0.28);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 18px;
  backdrop-filter: blur(8px);
}

.tabs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.tab-button {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #f1e6d2, #ead9bb);
  color: #5f4526;
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.tab-button.active {
  background: linear-gradient(180deg, #fffdfa, #f7e7cc);
  color: #2b2014;
  border-color: var(--line-strong);
}

.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.6);
  font-size: 14px;
  color: var(--muted);
}

.summary-strip {
  margin-bottom: 14px;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 248, 237, 0.95), rgba(250, 240, 226, 0.95));
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.mobile-summary-grid {
  display: none;
}

.mobile-detail-switch {
  display: none;
}

.mobile-summary-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 249, 240, 0.96), rgba(248, 237, 218, 0.94));
  padding: 14px;
}

.mobile-summary-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
}

.mobile-summary-value {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.top-grid {
  display: grid;
  grid-template-columns: 1.1fr 1.6fr;
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  padding: 16px;
}

.panel-title {
  margin-bottom: 14px;
  font-size: 23px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.table-scroll {
  overflow: auto;
  max-height: 410px;
}

.table-scroll.tall {
  max-height: 520px;
}

.table-scroll.leaders-tall {
  max-height: 760px;
}

.mobile-sort-bar {
  display: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f5e7cf;
  color: #654928;
}

thead th.sortable-header {
  cursor: pointer;
  user-select: none;
}

thead th.sortable-header::after {
  content: "↕";
  display: inline-block;
  margin-left: 6px;
  color: rgba(101, 73, 40, 0.55);
  font-size: 12px;
  vertical-align: middle;
}

thead th.sortable-header[data-sort-state="asc"]::after {
  content: "▲";
  color: #9d5b1f;
}

thead th.sortable-header[data-sort-state="desc"]::after {
  content: "▼";
  color: #9d5b1f;
}

thead th.sortable-header:hover {
  background: #f0ddbf;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th:nth-child(n + 2),
td:nth-child(n + 2) {
  text-align: right;
}

.row-button {
  cursor: pointer;
}

.row-button.active {
  background: rgba(233, 189, 119, 0.38);
}

.sector-ranking-table tbody tr:hover {
  background: rgba(233, 189, 119, 0.22);
}

.leaders-panel {
  padding: 12px;
}

.leaders-table {
  font-size: 13px;
}

.leaders-table th,
.leaders-table td {
  padding: 8px 10px;
}

.leaders-table th:nth-child(1),
.leaders-table td:nth-child(1) {
  width: 62px;
  text-align: center;
}

.leaders-table th:nth-child(2),
.leaders-table td:nth-child(2),
.leaders-table th:nth-child(3),
.leaders-table td:nth-child(3) {
  text-align: left;
}

.leaders-table th:nth-child(4),
.leaders-table td:nth-child(4),
.leaders-table th:nth-child(5),
.leaders-table td:nth-child(5),
.leaders-table th:nth-child(6),
.leaders-table td:nth-child(6),
.leaders-table th:nth-child(7),
.leaders-table td:nth-child(7),
.leaders-table th:nth-child(8),
.leaders-table td:nth-child(8),
.leaders-table th:nth-child(9),
.leaders-table td:nth-child(9) {
  text-align: right;
}

.rate-up {
  color: var(--positive);
  font-weight: 700;
}

.rate-down {
  color: var(--negative);
  font-weight: 700;
}

.news-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.news-list a {
  display: block;
  color: var(--text);
  text-decoration: none;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.62);
  line-height: 1.55;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.calendar-panel {
  padding: 16px;
  overflow-x: auto;
}

.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.calendar-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.calendar-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.calendar-nav-button {
  border: 1px solid var(--line);
  background: #fff8ee;
  color: #5f4526;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.calendar-month-label {
  min-width: 120px;
  text-align: center;
  font-size: 20px;
  font-weight: 800;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  min-width: 960px;
}

.calendar-weekday {
  padding: 10px 8px;
  text-align: center;
  border-radius: 12px;
  background: #f5e7cf;
  color: #654928;
  font-weight: 800;
}

.calendar-day {
  min-height: 130px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.66);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.calendar-day:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(72, 44, 20, 0.08);
}

.calendar-day-muted {
  opacity: 0.45;
}

.calendar-day-today {
  border-color: #ca7a24;
  background:
    radial-gradient(circle at top right, rgba(242, 171, 74, 0.24), transparent 36%),
    linear-gradient(180deg, rgba(255, 248, 233, 0.98), rgba(255, 240, 214, 0.94));
  box-shadow:
    inset 0 0 0 1px rgba(202, 122, 36, 0.3),
    0 12px 28px rgba(190, 114, 29, 0.18);
}

.calendar-day-number {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 16px;
  font-weight: 800;
}

.calendar-today-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  padding: 4px 8px;
  border-radius: 999px;
  background: linear-gradient(180deg, #c56e18, #9d5b1f);
  color: #fff9f0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.calendar-items {
  display: grid;
  gap: 6px;
}

.calendar-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(126, 106, 83, 0.08);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
}

.calendar-item-sector {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-item-rate {
  flex: 0 0 auto;
}

.calendar-item-positive {
  background: rgba(226, 77, 46, 0.12);
  color: var(--positive);
}

.calendar-item-negative {
  background: rgba(47, 101, 217, 0.12);
  color: var(--negative);
}

.calendar-item-more {
  justify-content: center;
  background: rgba(157, 91, 31, 0.1);
  color: #7d4b18;
  font-weight: 800;
}

.calendar-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(46, 35, 23, 0.36);
  backdrop-filter: blur(4px);
}

.calendar-modal-backdrop.hidden {
  display: none;
}

.calendar-modal {
  width: min(520px, 100%);
  border: 1px solid rgba(196, 167, 126, 0.4);
  border-radius: 24px;
  background: linear-gradient(180deg, #fffaf3, #f8efe1);
  box-shadow: 0 24px 60px rgba(46, 35, 23, 0.22);
  overflow: hidden;
}

.calendar-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
}

.calendar-modal-title {
  font-size: 22px;
  font-weight: 800;
}

.calendar-modal-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.calendar-modal-close {
  border: 1px solid var(--line);
  background: #fff;
  color: #5f4526;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.calendar-modal-body {
  display: grid;
  gap: 10px;
  padding: 18px 20px 22px;
}

.calendar-modal-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.66);
}

.calendar-modal-item-sector {
  font-size: 16px;
  font-weight: 800;
}

.calendar-modal-item-rate {
  font-size: 16px;
  font-weight: 800;
}

.calendar-modal-empty {
  padding: 18px 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  color: var(--muted);
  text-align: center;
  font-size: 15px;
}

@media (max-width: 980px) {
  .top-grid {
    grid-template-columns: 1fr;
  }

  .summary-strip {
    font-size: 23px;
  }
}

@media (max-width: 640px) {
  body {
    background:
      radial-gradient(circle at top right, rgba(212, 161, 89, 0.2), transparent 22%),
      linear-gradient(180deg, #f9f4eb, #f4ecde 100%);
  }

  .page-shell {
    padding: 0 0 18px;
  }

  .hero {
    padding: 18px 14px 12px;
  }

  .eyebrow,
  .subcopy {
    display: none;
  }

  .hero h1 {
    font-size: 26px;
  }

  .tabs-card {
    padding: 10px;
    border-radius: 18px 18px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    box-shadow: none;
    background: rgba(250, 244, 235, 0.9);
  }

  .tab-button {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
    padding: 10px 8px;
    font-size: 14px;
  }

  .tabs {
    position: sticky;
    top: 0;
    z-index: 18;
    margin: 0 -2px 10px;
    padding: 2px;
    background: rgba(249, 244, 235, 0.96);
  }

  .status-bar {
    position: sticky;
    top: 62px;
    z-index: 17;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    margin-bottom: 10px;
    padding: 8px 10px;
    font-size: 12px;
    border-radius: 14px;
  }

  .summary-strip {
    display: none;
  }

  .mobile-summary-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 10px;
  }

  .mobile-detail-switch {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 10px;
  }

  .mobile-detail-button {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: linear-gradient(180deg, #f3e4ca, #ead6b4);
    color: #6a5132;
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 700;
  }

  .mobile-detail-button.active {
    background: #ffffff;
    border-color: var(--line-strong);
    color: #2e2317;
  }

  .mobile-summary-card:last-child {
    grid-column: 1 / -1;
  }

  .panel {
    padding: 12px;
    border-radius: 18px;
  }

  .top-grid {
    margin-bottom: 10px;
  }

  .top-grid > .panel:first-child .table-scroll {
    max-height: 280px;
    overflow: auto;
  }

  .mobile-detail-hidden {
    display: none !important;
  }

  .table-scroll,
  .table-scroll.tall,
  .table-scroll.leaders-tall {
    max-height: none;
    overflow: visible;
  }

  .mobile-sort-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.82);
  }

  .mobile-sort-label {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  .mobile-sort-select {
    min-width: 0;
    flex: 1 1 auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fffaf3;
    color: var(--text);
    padding: 8px 10px;
    font-size: 13px;
  }

  .mobile-sort-direction {
    flex: 0 0 auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: linear-gradient(180deg, #f7ead5, #efddc2);
    color: #5f4526;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 700;
  }

  .calendar-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .calendar-nav {
    width: 100%;
    justify-content: space-between;
  }

  .calendar-panel {
    padding: 10px;
    overflow-x: visible;
  }

  .calendar-note {
    font-size: 12px;
    line-height: 1.5;
  }

  .calendar-grid {
    min-width: 0;
    gap: 4px;
  }

  .calendar-weekday {
    padding: 8px 2px;
    border-radius: 10px;
    font-size: 11px;
  }

  .calendar-day {
    min-height: 84px;
    padding: 6px 5px;
    border-radius: 12px;
  }

  .calendar-day-number {
    margin-bottom: 5px;
    font-size: 12px;
  }

  .calendar-today-badge {
    min-width: 34px;
    padding: 2px 5px;
    font-size: 8px;
  }

  .calendar-items {
    gap: 3px;
  }

  .calendar-item {
    display: block;
    padding: 3px 4px;
    border-radius: 8px;
    font-size: 9px;
    line-height: 1.2;
  }

  .calendar-item-more {
    text-align: center;
    font-size: 10px;
    letter-spacing: 0.02em;
  }

  .calendar-item-sector {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .calendar-item-rate {
    display: none;
  }

  .calendar-modal {
    border-radius: 18px;
  }

  .panel-title {
    margin-bottom: 10px;
    font-size: 18px;
  }

  .news-list {
    gap: 8px;
  }

  .news-list a {
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.5;
  }

  .sector-ranking-table,
  .mobile-card-table {
    display: block;
    width: 100%;
  }

  .sector-ranking-table thead,
  .mobile-card-table thead {
    display: none;
  }

  .sector-ranking-table tbody,
  .mobile-card-table tbody {
    display: grid;
    gap: 10px;
  }

  .sector-ranking-table tr,
  .mobile-card-table tr {
    display: block;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.82);
    padding: 10px 12px;
  }

  .sector-ranking-table td,
  .mobile-card-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px dashed rgba(201, 176, 139, 0.45);
    font-size: 13px;
    white-space: normal;
  }

  .sector-ranking-table td:last-child,
  .mobile-card-table td:last-child {
    border-bottom: 0;
  }

  .sector-ranking-table td:nth-child(1),
  .mobile-card-table td:nth-child(1) {
    font-weight: 800;
  }

  .sector-ranking-table td::before,
  .mobile-card-table td::before {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    flex: 0 0 auto;
  }

  .sector-ranking-table td:nth-child(1)::before {
    content: "섹터";
  }

  .sector-ranking-table td:nth-child(2)::before {
    content: "평균 상승률";
  }

  .sector-ranking-table td:nth-child(3)::before {
    content: "거래대금";
  }

  .sector-ranking-table td:nth-child(4)::before {
    content: "종목 수";
  }

  .sector-stocks-table td:nth-child(1)::before {
    content: "종목명";
  }

  .sector-stocks-table td:nth-child(2)::before {
    content: "현재가";
  }

  .sector-stocks-table td:nth-child(3)::before {
    content: "등락률";
  }

  .sector-stocks-table td:nth-child(4)::before {
    content: "거래대금";
  }

  .leaders-table td:nth-child(1)::before {
    content: "순위";
  }

  .leaders-table td:nth-child(2)::before {
    content: "종목명";
  }

  .leaders-table td:nth-child(3)::before {
    content: "섹터";
  }

  .leaders-table td:nth-child(4)::before {
    content: "현재가";
  }

  .leaders-table td:nth-child(5)::before {
    content: "등락률";
  }

  .leaders-table td:nth-child(6)::before {
    content: "전일대비";
  }

  .leaders-table td:nth-child(7)::before {
    content: "최근 1분 상승률";
  }

  .leaders-table td:nth-child(8)::before {
    content: "1분 등락폭";
  }

  .leaders-table td:nth-child(9)::before {
    content: "거래대금";
  }

  .leaders-table td:nth-child(1),
  .leaders-table td:nth-child(1)::before {
    color: #9d5b1f;
  }

}
