:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #697586;
  --line: #d9e0e8;
  --accent: #176b87;
  --accent-2: #c6503f;
  --good: #16875a;
  --warn: #a86612;
  --risk: #b83232;
  --shadow: 0 12px 30px rgba(26, 36, 52, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  min-height: 42px;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(24px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background:
    linear-gradient(120deg, rgba(23, 107, 135, 0.9), rgba(17, 24, 32, 0.88)),
    linear-gradient(45deg, #176b87 0%, #111820 100%);
}

.login-page .account-panel {
  width: min(760px, 100%);
  margin: 0 auto;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 22px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.login-brand .brand-mark {
  width: 46px;
  height: 46px;
  background: var(--accent);
  color: #fff;
}

.login-brand h1 {
  font-size: 32px;
}

.login-brand p {
  margin: 0;
  color: var(--muted);
}

.home-header,
.home-hero,
.home-features,
.home-nav,
.market-preview {
  display: none;
}

/*
.home-brand .brand-mark {
  background: #f5f7fa;
  color: var(--accent);
}

.home-brand span {
  color: rgba(255, 255, 255, 0.72);
}

.home-nav {
  display: flex;
  gap: 8px;
}

.home-nav button {
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 6px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
}

.home-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 430px);
  gap: 34px;
  align-items: center;
  width: min(1120px, 100%);
  min-height: 430px;
  margin: 0 auto;
  padding: 44px 0 34px;
  color: #fff;
}

.home-copy {
  max-width: 670px;
}

.home-copy .eyebrow {
  color: rgba(255, 255, 255, 0.72);
}

.home-copy h1 {
  max-width: 640px;
  margin-bottom: 16px;
  font-size: 46px;
  word-break: keep-all;
}

.home-copy p {
  max-width: 600px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 17px;
  line-height: 1.65;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.home-actions .primary {
  background: #f5f7fa;
  color: #111820;
}

.home-actions .secondary {
  border-color: rgba(255, 255, 255, 0.42);
  background: transparent;
  color: #fff;
}

.market-preview {
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 20px 42px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(10px);
}

.preview-top,
.preview-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.preview-top {
  margin-bottom: 14px;
  color: rgba(255, 255, 255, 0.72);
}

.preview-top strong {
  color: #fff;
  font-size: 24px;
}

.preview-row {
  margin-bottom: 9px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
}

.preview-row.strong {
  background: rgba(245, 247, 250, 0.22);
}

.preview-row span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.18);
  font-weight: 800;
}

.preview-row strong {
  flex: 1;
}

.preview-row em {
  color: #d8f3dc;
  font-style: normal;
  font-weight: 800;
}

.preview-bars {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: end;
  height: 92px;
  gap: 9px;
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(17, 24, 32, 0.3);
}

.preview-bars span {
  display: block;
  border-radius: 999px 999px 4px 4px;
  background: linear-gradient(180deg, #f5f7fa, #3aa6b9);
}

.home-features {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  width: min(1120px, 100%);
  margin: 0 auto 22px;
}

.home-features div {
  min-height: 128px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.home-features span,
.home-features strong,
.home-features p {
  display: block;
}

.home-features span {
  color: rgba(255, 255, 255, 0.66);
  font-size: 12px;
}

.home-features strong {
  margin-top: 7px;
  font-size: 20px;
}

.home-features p {
  margin: 10px 0 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  line-height: 1.45;
}
*/

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 18px;
  background: #111820;
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #3aa6b9;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 2px;
  color: #9facbd;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav button {
  border: 0;
  border-radius: 6px;
  padding: 10px 12px;
  background: transparent;
  color: #b9c5d3;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}

.nav button.active,
.nav button:hover {
  background: #23303d;
  color: #fff;
}

.run-status {
  margin-top: auto;
  padding: 14px;
  border: 1px solid #2f3d4b;
  border-radius: 8px;
}

.run-status span,
.run-status strong {
  display: block;
}

.run-status span {
  color: #9facbd;
  font-size: 12px;
}

.run-status strong {
  margin-top: 6px;
}

.workspace {
  padding: 28px;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}

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

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.2;
  letter-spacing: 0;
  word-break: keep-all;
}

.primary {
  min-width: 118px;
  border: 0;
  border-radius: 6px;
  padding: 11px 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.primary:disabled {
  cursor: wait;
  opacity: 0.72;
}

.secondary {
  min-width: 118px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 14px;
  background: #fff;
  color: #394454;
  cursor: pointer;
}

.account-panel {
  margin-bottom: 20px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-title {
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.auth-title h2 {
  margin-bottom: 8px;
  font-size: 30px;
  line-height: 1.2;
}

.auth-title p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.account-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.account-head h2 {
  margin-bottom: 0;
  font-size: 20px;
}

.auth-status {
  align-self: start;
  border-radius: 6px;
  padding: 7px 10px;
  background: #f1f4f7;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.auth-status.signed-in {
  background: #eaf7f1;
  color: var(--good);
}

.test-login-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.test-login-button {
  width: 100%;
  min-height: 72px;
  border-radius: 8px;
  font-size: 22px;
  font-weight: 800;
}

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

.auth-form {
  display: grid;
  gap: 11px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.auth-form h3 {
  margin-bottom: 0;
  font-size: 16px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  color: #4b5867;
  font-size: 13px;
}

.auth-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}

.form-message {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.form-message.success {
  color: var(--good);
}

.form-message.error {
  color: var(--risk);
}

.market-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.source-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.market-strip div,
.source-strip div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.market-strip span,
.market-strip strong,
.source-strip span,
.source-strip strong {
  display: block;
}

.market-strip span,
.source-strip span {
  color: var(--muted);
  font-size: 12px;
}

.market-strip strong {
  margin-top: 6px;
  color: var(--accent);
  font-size: 18px;
}

.source-strip strong {
  margin-top: 6px;
  color: #394454;
  font-size: 13px;
  line-height: 1.35;
}

.market-strip strong.good {
  color: var(--good);
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.8fr);
  gap: 18px;
  align-items: start;
}

.ranking-panel,
.detail-panel,
.exclusion-panel,
.backtest-panel,
.history-panel,
.settings-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.ranking-panel {
  padding: 18px;
}

.exclusion-panel {
  margin-top: 18px;
  padding: 18px;
}

.backtest-panel {
  margin-top: 18px;
  padding: 18px;
}

.history-panel {
  margin-top: 18px;
  padding: 18px;
}

.settings-panel {
  margin-top: 18px;
  padding: 18px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title h2 {
  margin-bottom: 0;
  font-size: 18px;
}

.section-title span {
  color: var(--muted);
  font-size: 12px;
}

.ranking {
  display: grid;
  gap: 10px;
}

.stock-row {
  display: grid;
  grid-template-columns: 42px minmax(130px, 1fr) minmax(108px, 0.55fr) minmax(140px, 0.85fr) 84px;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  cursor: pointer;
}

.stock-row.selected {
  border-color: var(--accent);
  background: #eef8fa;
}

.rank {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #e6edf4;
  font-weight: 800;
}

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

.stock-name span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.close-price span,
.close-price strong {
  display: block;
}

.close-price span {
  color: var(--muted);
  font-size: 12px;
}

.close-price strong {
  margin-top: 4px;
  color: #394454;
  font-size: 15px;
  white-space: nowrap;
}

.scorebar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4eaf0;
}

.scorebar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--good));
}

.score {
  text-align: right;
}

.score strong,
.score span {
  display: block;
}

.score span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.detail-panel {
  padding: 18px;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.detail-head h2 {
  margin-bottom: 4px;
  font-size: 21px;
}

.badge {
  align-self: start;
  border-radius: 6px;
  padding: 6px 8px;
  background: #edf4f8;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.badge.high {
  background: #fff1ee;
  color: var(--risk);
}

.price-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.price-box {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.price-box span,
.price-box strong {
  display: block;
}

.price-box span {
  color: var(--muted);
  font-size: 12px;
}

.price-box strong {
  margin-top: 6px;
  font-size: 20px;
}

.chart {
  width: 100%;
  height: 160px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.metric-list {
  display: grid;
  gap: 9px;
  margin-bottom: 18px;
}

.metric {
  display: grid;
  grid-template-columns: 92px 1fr 48px;
  gap: 9px;
  align-items: center;
  font-size: 13px;
}

.metric span:first-child {
  color: var(--muted);
}

.notes h3 {
  margin-bottom: 8px;
  font-size: 15px;
}

.notes ul {
  display: grid;
  gap: 7px;
  margin: 0 0 16px;
  padding-left: 18px;
  color: #394454;
  font-size: 14px;
}

.empty-state {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

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

.excluded-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.excluded-item strong,
.excluded-item span {
  display: block;
}

.excluded-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.excluded-item p {
  margin: 0;
  color: var(--risk);
  font-size: 13px;
  font-weight: 700;
  text-align: right;
}

.backtest-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.backtest-metric {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.backtest-metric span,
.backtest-metric strong {
  display: block;
}

.backtest-metric span {
  color: var(--muted);
  font-size: 12px;
}

.backtest-metric strong {
  margin-top: 7px;
  color: var(--accent);
  font-size: 22px;
}

.backtest-metric strong.danger {
  color: var(--risk);
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.history-item span {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.setting-item {
  min-height: 138px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.setting-item span,
.setting-item strong,
.setting-item p {
  display: block;
}

.setting-item span {
  color: var(--muted);
  font-size: 12px;
}

.setting-item strong {
  margin-top: 7px;
  color: var(--accent);
  font-size: 22px;
}

.setting-item p {
  margin: 12px 0 0;
  color: #4b5867;
  font-size: 13px;
  line-height: 1.45;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 1;
    flex-direction: row;
    align-items: center;
    gap: 16px;
    overflow-x: auto;
    padding: 14px max(14px, env(safe-area-inset-right)) 14px max(14px, env(safe-area-inset-left));
    scrollbar-width: none;
  }

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

  .sidebar .brand {
    min-width: max-content;
  }

  .nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
  }

  .nav button {
    padding: 10px 11px;
  }

  .run-status {
    display: none;
  }

  .market-strip,
  .source-strip,
  .main-grid,
  .excluded-list,
  .backtest-summary,
  .settings-grid,
  .auth-grid,
  .home-hero,
  .home-features {
    grid-template-columns: 1fr;
  }

  .home-hero {
    min-height: 0;
    padding-top: 28px;
  }

  .home-copy h1 {
    font-size: 36px;
  }

  .account-head {
    align-items: stretch;
    flex-direction: column;
  }

  .auth-status {
    width: fit-content;
  }
}

@media (max-width: 640px) {
  .login-page {
    padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }

  .account-panel,
  .ranking-panel,
  .detail-panel,
  .exclusion-panel,
  .backtest-panel,
  .history-panel,
  .settings-panel {
    padding: 14px;
  }

  .login-brand h1 {
    font-size: 28px;
  }

  .workspace {
    padding: 16px max(14px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }

  .topbar,
  .section-title {
    align-items: stretch;
    flex-direction: column;
  }

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

  .source-strip {
    grid-template-columns: 1fr;
  }

  .stock-row {
    grid-template-columns: 34px minmax(0, 1fr) 92px 70px;
    gap: 9px;
    padding: 12px;
  }

  .stock-row > .scorebar {
    grid-column: 2 / 5;
  }

  .stock-row > .score {
    grid-column: 4 / 5;
    grid-row: 1;
  }

  .detail-head,
  .excluded-item {
    align-items: stretch;
    flex-direction: column;
  }

  .excluded-item p {
    text-align: left;
  }

  .price-grid,
  .backtest-summary {
    grid-template-columns: 1fr;
  }

  .history-item {
    grid-template-columns: 1fr;
  }

  .history-item span {
    white-space: normal;
  }
}

@media (max-width: 420px) {
  .brand-mark {
    width: 34px;
    height: 34px;
  }

  h1 {
    font-size: 24px;
  }

  .topbar .primary {
    width: 100%;
  }

  .market-strip {
    grid-template-columns: 1fr;
  }

  .stock-row {
    grid-template-columns: 32px minmax(0, 1fr) 62px;
  }

  .close-price {
    grid-column: 2 / 4;
    grid-row: 2;
  }

  .close-price strong {
    font-size: 14px;
  }

  .stock-row > .scorebar {
    grid-column: 2 / 4;
    grid-row: 3;
  }

  .stock-row > .score {
    grid-column: 3 / 4;
    grid-row: 1;
  }

  .score strong {
    font-size: 14px;
  }

  .metric {
    grid-template-columns: 76px 1fr 42px;
  }
}
