:root {
  color-scheme: light;
  --topbar-height: 72px;
  --ink: #191919;
  --muted: #6f706b;
  --line: #d9dad3;
  --paper: #f3f2eb;
  --card: #fbfaf5;
  --lime: #d8ff48;
  --blue: #1f4fff;
  --red: #d6422b;
  --shadow: 0 20px 60px rgba(30, 30, 23, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(25, 25, 25, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(25, 25, 25, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
  font-family:
    Inter, Pretendard, "Noto Sans KR", -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 clamp(24px, 5vw, 72px);
  border-bottom: 1px solid var(--line);
  background: rgba(243, 242, 235, 0.9);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: inherit;
  font-size: 16px;
  font-weight: 800;
  text-decoration: none;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: flex;
  align-items: end;
  gap: 3px;
  width: 24px;
  height: 22px;
}

.brand-mark span {
  width: 6px;
  background: var(--ink);
}

.brand-mark span:nth-child(1) { height: 9px; }
.brand-mark span:nth-child(2) { height: 16px; }
.brand-mark span:nth-child(3) { height: 22px; background: var(--blue); }

.environment {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  text-transform: uppercase;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3cb371;
  box-shadow: 0 0 0 4px rgba(60, 179, 113, 0.13);
}

main {
  width: min(1380px, calc(100% - 40px));
  margin: 0 auto;
}

.hero {
  padding: clamp(72px, 10vw, 140px) 0 64px;
}

.eyebrow {
  margin-bottom: 18px;
  color: var(--blue);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1 {
  max-width: 900px;
  margin: 0;
  font-size: clamp(52px, 8vw, 112px);
  line-height: 0.91;
  letter-spacing: -0.075em;
}

.hero > p {
  max-width: 650px;
  margin: 36px 0 42px;
  color: var(--muted);
  font-size: clamp(16px, 2vw, 20px);
  line-height: 1.7;
  word-break: keep-all;
}

.search-panel {
  padding: 22px;
  border: 1px solid var(--ink);
  background: var(--card);
  box-shadow: 8px 8px 0 var(--ink);
}

.search-panel > label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 800;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
}

textarea {
  width: 100%;
  min-height: 96px;
  padding: 18px;
  resize: vertical;
  border: 1px solid var(--line);
  outline: none;
  background: #fff;
  font-size: 19px;
  line-height: 1.5;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 79, 255, 0.12);
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 220px;
}

.limit-label {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  height: 42px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select {
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 800;
}

button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 18px;
  border: 1px solid var(--ink);
  background: var(--lime);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

button:hover {
  transform: translate(-2px, -2px);
  box-shadow: 4px 4px 0 var(--ink);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
  transform: none;
  box-shadow: none;
}

.form-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.results-section {
  padding: 70px 0 100px;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 28px;
}

.section-heading h2,
.empty-state h2 {
  margin: 0;
  font-size: clamp(30px, 4vw, 52px);
  letter-spacing: -0.055em;
}

.section-heading p {
  color: var(--muted);
  font-size: 13px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin-bottom: 28px;
  border: 1px solid var(--ink);
  background: var(--ink);
}

.metric-card {
  min-height: 170px;
  padding: 22px;
  background: var(--card);
}

.metric-card > span,
.metric-card small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric-card strong {
  display: block;
  margin: 35px 0 8px;
  font-size: clamp(30px, 4vw, 52px);
  letter-spacing: -0.055em;
}

.metric-card.accent {
  background: var(--lime);
}

.metric-card.accent span,
.metric-card.accent small {
  color: #39400f;
}

.trend-card {
  z-index: 8;
  margin-bottom: 28px;
  padding: 24px;
  border: 1px solid var(--ink);
  background: var(--card);
  box-shadow: var(--shadow);
  transition:
    padding 180ms ease,
    box-shadow 180ms ease;
}

.trend-sticky-sentinel {
  height: 0;
}

.trend-card.is-stuck {
  position: fixed;
  padding: 14px 18px 12px;
  box-shadow: 8px 8px 0 rgba(25, 25, 25, 0.88);
}

.trend-card.is-stuck .trend-heading {
  align-items: center;
  margin-bottom: 10px;
}

.trend-card.is-stuck .trend-kicker,
.trend-card.is-stuck .trend-help {
  display: none;
}

.trend-card.is-stuck .trend-heading h3 {
  margin-top: 0;
  font-size: 24px;
}

.trend-card.is-stuck .trend-stats strong {
  margin-top: 3px;
  font-size: 14px;
}

.trend-card.is-stuck .chart-wrap {
  min-height: 220px;
}

.trend-card.is-stuck #trend-chart {
  min-height: 210px;
  max-height: 230px;
}

.trend-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 30px;
  margin-bottom: 28px;
}

.trend-kicker {
  color: var(--blue);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.trend-heading h3 {
  margin: 8px 0 0;
  font-size: clamp(28px, 4vw, 46px);
  letter-spacing: -0.05em;
}

.trend-stats {
  display: flex;
  gap: 32px;
}

.trend-stats span {
  color: var(--muted);
  font-size: 11px;
}

.trend-stats strong {
  display: block;
  margin-top: 8px;
  color: var(--ink);
  font-size: 18px;
}

.chart-wrap {
  position: relative;
  width: 100%;
  min-height: 300px;
  overflow: hidden;
  border-top: 1px solid var(--line);
}

#trend-chart {
  display: block;
  width: 100%;
  height: auto;
  min-height: 280px;
}

.chart-grid {
  stroke: #ddddd5;
  stroke-width: 1;
}

.chart-area {
  fill: url("#area-gradient");
}

.chart-line {
  fill: none;
  stroke: var(--blue);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

.chart-point {
  fill: var(--lime);
  stroke: var(--ink);
  stroke-width: 2;
  cursor: crosshair;
  transition: r 120ms ease;
}

.chart-point:hover,
.chart-point:focus {
  r: 9px;
  outline: none;
}

.chart-tooltip {
  position: absolute;
  z-index: 3;
  min-width: 132px;
  padding: 9px 11px;
  pointer-events: none;
  border: 1px solid var(--ink);
  background: var(--ink);
  box-shadow: 4px 4px 0 var(--lime);
  color: #fff;
  font-size: 11px;
  line-height: 1.5;
  white-space: nowrap;
}

.chart-tooltip[data-placement="top"] {
  transform: translate(-50%, calc(-100% - 14px));
}

.chart-tooltip[data-placement="bottom"] {
  transform: translate(-50%, 14px);
}

.chart-tooltip strong {
  display: block;
  color: var(--lime);
  font-size: 14px;
}

.chart-label {
  fill: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.chart-value {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.trend-help {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.expand-chart {
  display: none;
  width: 100%;
  margin-top: 10px;
}

.chart-dialog {
  width: min(1100px, calc(100vw - 32px));
  max-width: none;
  padding: 0;
  border: 1px solid var(--ink);
  background: var(--card);
  box-shadow: 10px 10px 0 var(--ink);
}

.chart-dialog::backdrop {
  background: rgba(15, 15, 13, 0.72);
  backdrop-filter: blur(4px);
}

.chart-dialog-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}

.chart-dialog-header span {
  color: var(--blue);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.1em;
}

.chart-dialog-header h2 {
  margin: 6px 0 0;
  font-size: clamp(24px, 4vw, 42px);
  letter-spacing: -0.05em;
}

.chart-dialog-header button {
  flex: 0 0 auto;
  background: #fff;
}

.dialog-chart-wrap {
  position: relative;
  min-width: 900px;
  padding: 10px 20px 0;
}

.dialog-scroll-hint {
  display: none;
}

.dialog-chart-wrap svg {
  display: block;
  width: 100%;
  min-height: 420px;
}

.dialog-trend-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
}

.dialog-trend-stats span {
  padding: 16px 20px;
  color: var(--muted);
  font-size: 11px;
}

.dialog-trend-stats span + span {
  border-left: 1px solid var(--line);
}

.dialog-trend-stats strong {
  display: block;
  margin-top: 5px;
  color: var(--ink);
  font-size: 18px;
}

.table-shell {
  border: 1px solid var(--ink);
  background: var(--card);
  box-shadow: var(--shadow);
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.table-toolbar strong {
  margin-right: 10px;
}

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

.score-formula {
  display: block;
  margin-top: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px !important;
}

.table-toolbar input {
  width: min(320px, 45%);
  padding: 10px 12px;
  border: 1px solid var(--line);
  outline: none;
  background: #fff;
}

.table-controls {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  width: min(570px, 58%);
}

.export-menu {
  display: flex;
  gap: 6px;
}

.export-button {
  height: 38px;
  padding: 0 12px;
  border-color: var(--line);
  background: #fff;
  font-size: 11px;
}

.export-button:hover {
  border-color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
}

.table-controls select {
  min-width: 180px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  outline: none;
  background: #fff;
}

.table-controls input {
  width: min(320px, 100%);
}

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

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

th,
td {
  padding: 15px 20px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

th {
  color: var(--muted);
  background: #eeede5;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

th:first-child,
td:first-child {
  position: sticky;
  left: 0;
  text-align: left;
  background: var(--card);
}

th:first-child {
  background: #eeede5;
}

td:first-child {
  min-width: 260px;
  font-weight: 800;
}

.competition-index-trigger {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  padding: 5px 8px;
  border: 1px dashed #9b9c94;
  background: transparent;
  cursor: help;
  font-weight: 900;
}

.competition-index-trigger::after {
  margin-left: 5px;
  color: var(--blue);
  content: "?";
  font-size: 10px;
}

.competition-index-trigger:focus-visible {
  outline: 3px solid rgba(31, 79, 255, 0.25);
  outline-offset: 2px;
}

.competitiveness-score {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 110px;
}

.score-number {
  display: grid;
  place-items: center;
  width: 42px;
  height: 32px;
  border: 1px solid var(--ink);
  background: var(--lime);
  font-size: 14px;
  font-weight: 950;
}

.score-meta {
  display: grid;
  gap: 2px;
  text-align: left;
}

.score-meta strong {
  font-size: 11px;
}

.score-meta small {
  color: var(--muted);
  font-size: 9px;
}

.score-components {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 14px;
}

.score-component {
  padding: 9px;
  border: 1px solid var(--line);
  background: #f6f5ee;
  text-align: center;
}

.score-component span {
  display: block;
  color: var(--muted);
  font-size: 9px;
}

.score-component strong {
  display: block;
  margin-top: 5px;
  font-size: 16px;
}

.competition-assistant {
  position: fixed;
  z-index: 50;
  width: min(420px, calc(100vw - 24px));
  max-height: min(620px, calc(100vh - 24px));
  padding: 20px;
  overflow-y: auto;
  border: 1px solid var(--ink);
  background: #fffef8;
  box-shadow: 8px 8px 0 var(--ink);
}

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

.assistant-label {
  color: var(--blue);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.1em;
}

.assistant-header h4 {
  margin: 6px 0 0;
  font-size: 22px;
  letter-spacing: -0.04em;
}

.assistant-score {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  border: 1px solid var(--ink);
  background: var(--lime);
  font-size: 20px;
  font-weight: 950;
}

.assistant-band {
  display: inline-block;
  margin: 16px 0 10px;
  padding: 5px 8px;
  background: #e8edff;
  color: #1839a7;
  font-size: 11px;
  font-weight: 900;
}

.assistant-judgment {
  margin: 0;
  color: #41423d;
  font-size: 13px;
  line-height: 1.65;
}

.assistant-section {
  margin-top: 18px;
}

.assistant-section h5 {
  margin: 0 0 9px;
  font-size: 12px;
}

.assistant-section ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 18px;
  color: #50514b;
  font-size: 12px;
  line-height: 1.55;
}

.assistant-alternatives {
  display: grid;
  gap: 7px;
}

.assistant-alternative {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 10px;
  border: 1px solid var(--line);
  background: #f6f5ee;
}

.assistant-alternative strong {
  font-size: 12px;
}

.assistant-alternative span,
.assistant-alternative small {
  color: var(--muted);
  font-size: 10px;
}

.assistant-source {
  margin: 16px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.assistant-source a {
  color: var(--blue);
}

tbody tr:hover td {
  background: #f1f4ff;
}

tbody tr {
  cursor: pointer;
}

tbody tr.selected td {
  background: #e8edff;
}

tbody tr.selected td:first-child {
  box-shadow: inset 4px 0 0 var(--blue);
}

.competition {
  display: inline-block;
  min-width: 72px;
  padding: 4px 8px;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
}

.competition.low { background: #e1f5e9; color: #237443; }
.competition.medium { background: #fff0c7; color: #885d00; }
.competition.high { background: #ffe0d9; color: #a93722; }

.empty-state {
  display: grid;
  place-items: center;
  min-height: 360px;
  padding: 60px 20px;
  border-top: 1px solid var(--line);
  text-align: center;
}

.empty-state p {
  color: var(--muted);
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: 22px;
  border: 1px solid var(--ink);
  background: var(--lime);
  font-size: 32px;
  box-shadow: 5px 5px 0 var(--ink);
}

.error-message {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 520px;
  padding: 16px 20px;
  border: 1px solid var(--ink);
  background: #ffe2dc;
  box-shadow: 6px 6px 0 var(--ink);
  color: #7b2112;
  font-weight: 700;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 28px clamp(24px, 5vw, 72px);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 900px) {
  .search-row,
  .metric-grid {
    grid-template-columns: 1fr 1fr;
  }

  textarea {
    grid-column: 1 / -1;
  }

  .form-actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .trend-heading {
    flex-direction: column;
  }
}

@media (max-width: 620px) {
  :root {
    --topbar-height: 60px;
  }

  main {
    width: min(100% - 24px, 1380px);
  }

  .topbar {
    height: 60px;
    padding: 0 16px;
  }

  .environment {
    font-size: 10px;
  }

  .hero {
    padding-top: 64px;
  }

  h1 {
    font-size: 54px;
  }

  .search-panel {
    padding: 14px;
    box-shadow: 5px 5px 0 var(--ink);
  }

  .search-row,
  .metric-grid,
  .form-actions {
    grid-template-columns: 1fr;
  }

  .form-meta,
  .section-heading,
  .table-toolbar,
  .trend-stats,
  footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .trend-stats {
    width: 100%;
    gap: 16px;
  }

  .trend-stats span {
    flex: 1;
  }

  .trend-card.is-stuck {
    padding: 10px;
  }

  .trend-card.is-stuck .trend-heading {
    gap: 8px;
  }

  .trend-card.is-stuck .trend-stats {
    display: none;
  }

  .trend-card.is-stuck .chart-wrap,
  .trend-card.is-stuck #trend-chart {
    min-height: 140px;
    max-height: 150px;
  }

  .trend-card.is-stuck .expand-chart {
    display: flex;
  }

  .expand-chart {
    display: flex;
  }

  .chart-dialog {
    width: 100vw;
    height: 100dvh;
    max-height: none;
    margin: 0;
    overflow: auto;
    border: 0;
    box-shadow: none;
  }

  .chart-dialog-header {
    position: sticky;
    z-index: 2;
    top: 0;
    left: 0;
    width: 100vw;
    padding: 14px 16px;
    background: var(--card);
  }

  .chart-dialog-header h2 {
    font-size: 26px;
  }

  .chart-dialog-header button {
    height: 38px;
    padding: 0 12px;
  }

  .dialog-chart-wrap {
    width: 100%;
    min-width: 0;
    padding: 20px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  .dialog-chart-wrap svg {
    width: 900px;
    min-height: 500px;
  }

  .dialog-scroll-hint {
    position: sticky;
    left: 0;
    display: block;
    width: calc(100vw - 40px);
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 11px;
    text-align: center;
  }

  .dialog-trend-stats {
    position: sticky;
    left: 0;
    width: 100vw;
    grid-template-columns: 1fr;
    background: var(--card);
  }

  .dialog-trend-stats span + span {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .metric-card {
    min-height: 145px;
  }

  .table-toolbar input {
    width: 100%;
  }

  .table-controls {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .export-menu {
    width: 100%;
  }

  .export-button {
    flex: 1;
  }

  .table-controls select {
    width: 100%;
  }
}
