:root {
  color-scheme: light;
  --page: #f7f8fa;
  --surface: #ffffff;
  --surface-soft: #f2f4f6;
  --ink: #191f28;
  --muted: #6b7684;
  --subtle: #8b95a1;
  --line: #e5e8eb;
  --line-strong: #d1d6db;
  --blue: #3182f6;
  --blue-soft: #e8f3ff;
  --profit: #f04452;
  --loss: #3182f6;
  --shadow: 0 18px 40px rgba(25, 31, 40, 0.045);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--page);
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background: var(--page);
  color: var(--ink);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: rgba(49, 130, 246, 0.12);
}

button,
select {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.skip-link {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 20;
  translate: 0 -180%;
  border-radius: 10px;
  background: var(--ink);
  color: var(--surface);
  padding: 10px 14px;
  text-decoration: none;
}

.skip-link:focus-visible {
  translate: 0;
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

.shell {
  width: min(1680px, 100%);
  margin: 0 auto;
  padding: calc(30px + env(safe-area-inset-top)) clamp(20px, 4vw, 64px) 56px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 28px;
  align-items: end;
  padding: 10px 0 28px;
  animation: rise 420ms ease-out both;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
  text-wrap: balance;
}

h1 {
  font-size: clamp(1.9rem, 3.6vw, 3.1rem);
  font-weight: 800;
  line-height: 1.08;
}

h2 {
  font-size: clamp(1.25rem, 2.5vw, 1.75rem);
  font-weight: 800;
  line-height: 1.16;
}

.summary {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
  font-weight: 500;
  text-wrap: pretty;
}

.hero-actions,
.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border-radius: 14px;
  background: var(--surface-soft);
  padding: 4px;
}

.seg-button {
  min-height: 36px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  padding: 8px 13px;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.seg-button:hover {
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
}

.seg-button:active {
  transform: scale(0.98);
}

.seg-button:focus-visible,
select:focus-visible,
.table-scroll:focus-visible {
  outline: 3px solid rgba(49, 130, 246, 0.35);
  outline-offset: 3px;
}

.seg-button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(25, 31, 40, 0.08);
}

.totals-grid {
  display: grid;
  grid-template-columns: 1.28fr 1fr 1fr;
  gap: clamp(16px, 2vw, 24px);
  margin: 0 0 clamp(20px, 2vw, 28px);
}

.metric-card {
  min-width: 0;
  border: 1px solid rgba(229, 232, 235, 0.9);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: clamp(20px, 2vw, 30px);
  animation: rise 460ms ease-out both;
}

.metric-card:nth-child(2) {
  animation-delay: 70ms;
}

.metric-card:nth-child(3) {
  animation-delay: 140ms;
}

.metric-card--primary {
  background: linear-gradient(145deg, #1b64da, #3182f6);
  color: var(--surface);
  border-color: transparent;
}

.metric-card strong {
  display: block;
  margin: 9px 0 9px;
  font-size: clamp(1.65rem, 2.7vw, 2.55rem);
  font-weight: 850;
  line-height: 1.02;
  overflow-wrap: anywhere;
}

.metric-label,
.metric-card span:last-child {
  color: color-mix(in srgb, currentColor 62%, transparent);
  font-size: 0.92rem;
  font-weight: 650;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: clamp(20px, 2.4vw, 32px);
}

.chart-panel,
.table-panel {
  min-width: 0;
  border: 1px solid rgba(229, 232, 235, 0.9);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: clamp(22px, 2.3vw, 34px);
  animation: rise 540ms ease-out both;
}

.panel-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.chart-readout,
.table-time {
  color: var(--subtle);
  font-size: 0.88rem;
  font-weight: 600;
  text-align: right;
}

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

.toolbar-toggles {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  margin-left: auto;
}

.stock-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  margin-bottom: 0;
  font-size: 0.94rem;
  font-weight: 650;
}

.stock-picker select {
  min-width: 180px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--ink);
  padding: 10px 34px 10px 12px;
  font-weight: 700;
}

.chart-wrap {
  position: relative;
  height: clamp(320px, 38vh, 460px);
  min-height: 320px;
  border-radius: 22px;
  background: linear-gradient(180deg, #ffffff, #fbfcfd);
  overflow: hidden;
}

#chart {
  display: block;
  width: 100%;
  height: 100%;
}

.table-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  max-height: none;
  border-top: 1px solid var(--line);
}

table {
  width: 100%;
  min-width: 740px;
  border-collapse: collapse;
}

th,
td {
  padding: 15px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(255, 255, 255, 0.96);
  color: var(--subtle);
  font-size: 0.78rem;
  font-weight: 800;
}

th:first-child,
td:first-child {
  text-align: left;
}

td {
  color: var(--ink);
  font-size: 0.94rem;
  font-weight: 650;
}

.stock-name {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 4px;
}

.stock-name strong,
.stock-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stock-name strong {
  font-weight: 800;
}

.stock-name span {
  color: var(--subtle);
  font-size: 0.8rem;
  font-weight: 600;
}

.positive {
  color: var(--profit);
}

.negative {
  color: var(--loss);
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 48px 12px;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

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

  .chart-wrap {
    height: 340px;
    min-height: 340px;
  }
}

@media (max-width: 720px) {
  .shell {
    padding-inline: 16px;
    padding-bottom: 32px;
  }

  .hero {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .panel-heading,
  .toolbar,
  .toolbar-toggles {
    align-items: stretch;
    flex-direction: column;
  }

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

  .toolbar .segmented {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .toolbar .segmented::-webkit-scrollbar {
    display: none;
  }

  .seg-button {
    flex: 1 0 auto;
    min-width: 0;
    width: auto;
    padding-inline: 10px;
    white-space: nowrap;
  }

  .toolbar .seg-button {
    flex-basis: 0;
    font-size: 0.86rem;
  }

  .stock-picker {
    align-items: stretch;
    flex-direction: column;
  }

  .stock-picker select {
    width: 100%;
  }

  .chart-wrap {
    height: 300px;
    min-height: 300px;
    margin-inline: -4px;
  }

  .metric-card,
  .chart-panel,
  .table-panel {
    border-radius: 18px;
    padding: 20px;
  }
}
