:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #111821;
  --panel-2: #16202b;
  --line: #2b3744;
  --text: #f3f6f8;
  --muted: #9aa8b7;
  --soft: #6f7f91;
  --clear: #53c08b;
  --caution: #e66a5f;
  --focus: #7aa7ff;
  --amber: #deb25d;
  --chip: #1b2632;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background-color: var(--bg);
  background-image:
    linear-gradient(115deg, rgba(83, 192, 139, 0.08), transparent 38%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 34px);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.shell {
  width: min(100%, 1060px);
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 18px calc(88px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.1;
  font-weight: 950;
}

.mantra {
  margin: 8px 0 0;
  max-width: 680px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.45;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.icon-button,
.dialog-close {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

.icon-button:hover,
.dialog-close:hover {
  background: rgba(255, 255, 255, 0.09);
}

.icon-button.spinning svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

svg {
  width: 21px;
  height: 21px;
  fill: currentColor;
}

.summary-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  min-height: 72px;
  margin-top: 18px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--focus);
  border-radius: 8px;
  background: rgba(17, 24, 33, 0.92);
  box-shadow: var(--shadow);
}

.summary-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.summary-main strong,
.summary-main span {
  display: block;
  overflow: hidden;
  max-width: 520px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-main strong {
  font-size: 16px;
}

.summary-main span,
.summary-stats {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.live-dot {
  width: 10px;
  height: 36px;
  border-radius: 3px;
  background: var(--focus);
  flex: 0 0 auto;
}

.summary-stats {
  display: flex;
  gap: 12px;
  text-align: right;
  white-space: nowrap;
}

.summary-stats span {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
}

.summary-stats b {
  color: var(--text);
  font-size: 17px;
}

.control-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 360px);
  gap: 12px;
  align-items: center;
  margin: 16px 0;
}

.segments {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.segments::-webkit-scrollbar {
  display: none;
}

.segment,
.nav-item {
  border: 0;
  cursor: pointer;
}

.segment {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(22, 32, 43, 0.86);
  color: var(--muted);
  padding: 0 15px;
  font-weight: 900;
  white-space: nowrap;
}

.segment.active {
  border-color: rgba(122, 167, 255, 0.55);
  background: rgba(122, 167, 255, 0.12);
  color: var(--text);
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(9, 14, 20, 0.76);
  padding: 0 13px;
  color: var(--soft);
}

.search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-weight: 800;
}

.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.card {
  --accent: var(--score-color, #de9d4f);
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: rgba(17, 24, 33, 0.96);
  padding: 18px;
  box-shadow: 0 14px 26px rgba(0, 0, 0, 0.22);
  cursor: pointer;
}

.card:focus-visible {
  outline: 3px solid rgba(122, 167, 255, 0.75);
  outline-offset: 3px;
}

.card-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  margin-top: 16px;
}

.stock-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stock-title h2 {
  margin: 0;
  max-width: 100%;
  font-size: 21px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.code-line,
.metric-grid span,
.chip {
  color: var(--muted);
  font-weight: 800;
}

.code-line {
  margin-top: 5px;
  letter-spacing: 1px;
  font-size: 13px;
}

.tag {
  display: inline-flex;
  min-height: 23px;
  align-items: center;
  border-radius: 6px;
  padding: 0 7px;
  background: rgba(222, 178, 93, 0.13);
  color: var(--amber);
  font-size: 12px;
  font-weight: 950;
}

.tag.best {
  background: rgba(83, 192, 139, 0.16);
  color: #9ee4bd;
}

.score-box {
  display: grid;
  justify-items: end;
  gap: 3px;
  min-width: 112px;
}

.score-box em {
  min-height: 22px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  padding: 3px 7px;
  font-size: 11px;
  font-style: normal;
  font-weight: 950;
}

.score-box span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.score-box strong {
  color: var(--text);
  font-size: 30px;
  line-height: 1;
}

.score-meter {
  height: 7px;
  margin-top: 16px;
  overflow: hidden;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
}

.score-meter span {
  display: block;
  width: var(--score);
  height: 100%;
  border-radius: inherit;
  background: var(--score-color, var(--accent));
}

.metric-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr 0.8fr 0.8fr 0.65fr;
  gap: 10px;
  margin-top: 14px;
}

.metric-grid div {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  padding: 10px;
}

.metric-grid span {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
}

.metric-grid b {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 950;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  max-width: 100%;
  border-radius: 6px;
  background: var(--chip);
  padding: 0 10px;
  font-size: 12px;
}

.chip.warn {
  background: rgba(230, 136, 72, 0.15);
  color: #f2b47b;
}

.empty {
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 220px;
  color: var(--muted);
  text-align: center;
}

.empty strong {
  color: var(--text);
  font-size: 18px;
}

.hidden {
  display: none;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 12px;
  z-index: 20;
  display: none;
  grid-template-columns: repeat(5, 1fr);
  width: min(calc(100% - 24px), 520px);
  transform: translateX(-50%);
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13, 19, 26, 0.96);
  box-shadow: var(--shadow);
}

.nav-item {
  display: grid;
  place-items: center;
  gap: 3px;
  min-width: 0;
  min-height: 50px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.nav-item.active {
  background: rgba(122, 167, 255, 0.12);
  color: var(--text);
}

.stock-dialog {
  width: min(92vw, 600px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111821;
  color: var(--text);
  padding: 22px;
  box-shadow: var(--shadow);
}

.stock-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.dialog-close {
  position: absolute;
  right: 14px;
  top: 14px;
  width: 38px;
  height: 38px;
}

.dialog-title {
  padding-right: 42px;
}

.dialog-title h3 {
  margin: 0 0 6px;
  font-size: 24px;
}

.metric-box {
  margin-top: 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  padding: 14px;
}

.metric-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.metric-value {
  margin-top: 9px;
  font-size: 16px;
  font-weight: 900;
  line-height: 1.45;
}

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

.detail {
  min-height: 72px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  padding: 12px;
}

.detail span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.detail b {
  display: block;
  margin-top: 7px;
  font-size: 16px;
  overflow-wrap: anywhere;
}

.detail small {
  display: block;
  margin-top: 5px;
  color: var(--soft);
  font-size: 11px;
  font-weight: 800;
}

.live-detail b {
  color: var(--score-color, var(--text));
}

.news-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  margin-top: 16px;
  border-radius: 8px;
  background: #edf3ff;
  color: #111722;
  padding: 0 14px;
  font-weight: 950;
  text-decoration: none;
}

@media (max-width: 820px) {
  .shell {
    width: min(100%, 620px);
  }

  .control-row,
  .cards {
    grid-template-columns: 1fr;
  }

  .bottom-nav {
    display: grid;
  }

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

@media (max-width: 520px) {
  .shell {
    padding-left: 14px;
    padding-right: 14px;
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
  }

  h1 {
    font-size: 23px;
  }

  .mantra {
    margin-top: 6px;
    font-size: 11px;
  }

  .summary-band {
    grid-template-columns: 1fr;
    min-height: 58px;
    margin-top: 12px;
    padding: 11px 12px;
  }

  .summary-stats {
    justify-content: space-between;
    text-align: left;
  }

  .control-row {
    gap: 9px;
    margin: 12px 0;
  }

  .segment {
    min-height: 34px;
    padding: 0 12px;
    font-size: 12px;
  }

  .search {
    min-height: 38px;
  }

  .cards {
    gap: 10px;
  }

  .card {
    padding: 12px;
  }

  .card-main {
    gap: 10px;
    margin-top: 0;
  }

  .stock-title h2 {
    font-size: 17px;
  }

  .code-line {
    margin-top: 3px;
    font-size: 11px;
  }

  .tag {
    min-height: 20px;
    padding: 0 6px;
    font-size: 10px;
  }

  .score-box {
    min-width: 82px;
  }

  .score-box em {
    min-height: 20px;
    padding: 3px 6px;
    font-size: 10px;
  }

  .score-box span {
    font-size: 10px;
  }

  .score-box strong {
    font-size: 24px;
  }

  .score-meter {
    height: 5px;
    margin-top: 11px;
  }

  .metric-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    gap: 6px;
    margin-top: 10px;
  }

  .metric-grid div {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    align-items: center;
    min-height: 34px;
    padding: 7px 8px;
  }

  .metric-grid span {
    margin-bottom: 0;
    font-size: 10px;
  }

  .metric-grid b {
    font-size: 12px;
    text-align: right;
  }

  .chips {
    gap: 6px;
    margin-top: 9px;
  }

  .chip {
    min-height: 24px;
    padding: 0 8px;
    font-size: 11px;
  }

  .bottom-nav {
    bottom: 8px;
    padding: 6px;
  }

  .nav-item {
    min-height: 42px;
    font-size: 10px;
  }
}
