:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #7a8496;
  --line: #e7ebf2;
  --primary: #2563eb;
  --primary-soft: #eff6ff;
  --red: #ef4444;
  --blue: #2563eb;
  --green: #10b981;
  --shadow: 0 18px 44px rgba(30, 41, 59, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: "Gowun Dodum", "Apple SD Gothic Neo", sans-serif;
  background:
    radial-gradient(circle at 12% -10%, rgba(37, 99, 235, 0.14), transparent 26rem),
    linear-gradient(180deg, #f9fbff 0%, var(--bg) 100%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(860px, calc(100% - 24px));
  margin: 0 auto;
  padding: 10px 0 28px;
}

.topbar {
  position: relative;
  overflow: hidden;
  min-height: 190px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.76);
  border-radius: 22px;
  background: #fff;
  box-shadow: var(--shadow);
  cursor: default;
}

.header-meme {
  display: block;
  width: 100%;
  height: 190px;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
}

.button,
.icon-button,
.delete-row {
  border: 0;
  transition:
    transform 140ms ease,
    background 140ms ease,
    box-shadow 140ms ease;
}

.button {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border-radius: 12px;
  font-size: 0.88rem;
  font-weight: 700;
}

.button-primary {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.18);
}

.button-soft {
  color: #334155;
  border: 1px solid var(--line);
  background: var(--surface);
}

.button:hover,
.icon-button:hover,
.delete-row:hover {
  transform: translateY(-1px);
}

.ranking-panel,
.modal {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.caption,
.meta-label,
.modal-desc,
.lookup-status {
  color: var(--muted);
  font-size: 0.78rem;
}

.ranking-panel {
  margin-top: 5px;
  overflow: hidden;
  border-radius: 22px;
  perspective: 1200px;
}

.ranking-view {
  transform-style: preserve-3d;
}

.ranking-row {
  transform-style: preserve-3d;
  backface-visibility: hidden;
  cursor: pointer;
}

.ranking-row.is-flipping {
  animation: flipRankingRow 420ms ease-in-out;
  pointer-events: none;
}

.ranking-row:focus-visible {
  position: relative;
  z-index: 1;
  outline: 2px solid var(--primary);
  outline-offset: -3px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px 8px;
}

.panel-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.panel-action-button {
  display: inline-flex;
  width: 30px;
  height: 30px;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: #475569;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  transition:
    color 140ms ease,
    border-color 140ms ease,
    background 140ms ease,
    transform 140ms ease,
    box-shadow 140ms ease;
}

.panel-action-button svg {
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.alarm-bell {
  width: 17px;
}

.panel-action-button .alarm-sound-waves {
  width: 0;
  margin-left: -1px;
  opacity: 0;
  transition:
    width 140ms ease,
    opacity 140ms ease;
}

.panel-action-button:hover {
  color: var(--primary);
  border-color: #bfdbfe;
  background: var(--primary-soft);
  transform: translateY(-1px);
}

.panel-action-button.is-active {
  width: 40px;
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
  box-shadow: 0 5px 12px rgba(37, 99, 235, 0.2);
}

.panel-action-button.is-active .alarm-sound-waves {
  width: 10px;
  opacity: 1;
}

.panel-action-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.panel-action-button.is-busy svg {
  animation: alarmPulse 700ms ease-in-out infinite alternate;
}

.panel-action-button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
  white-space: nowrap;
}

.caption {
  margin: 0 0 3px;
}

h2 {
  margin: 0;
  font-family: "Jua", sans-serif;
  font-size: 1.38rem;
  font-weight: 400;
}

.stock-table-head,
.stock-row {
  display: grid;
  grid-template-columns: 28px minmax(6em, 1.2fr) 1fr 1fr 0.9fr;
  column-gap: 8px;
  align-items: center;
}

.stock-table-head span:last-child,
.stock-row .profit-cell:last-child {
  padding-left: 12px;
}

.stock-table-head {
  padding: 7px 14px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: #f8fafc;
  font-size: 0.74rem;
}

.stock-table-head span:not(:first-child):not(:nth-child(2)) {
  text-align: right;
}

.stock-table-head span:first-child {
  text-align: center;
}

.stock-table-head span:nth-child(2) {
  text-align: center;
}

.stock-list {
  display: grid;
}

.stock-row {
  min-height: 72px;
  padding: 11px 16px;
  border-top: 1px solid var(--line);
  animation: rowIn 260ms ease both;
}

.rank-cell {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  color: #475569;
  border-radius: 8px;
  background: #f1f5f9;
  font-size: 0.78rem;
  font-weight: 800;
}

.stock-main {
  display: block;
  min-width: 0;
}

.stock-main strong {
  display: block;
  overflow: hidden;
  font-size: 1.08rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stock-main span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.leaderboard-head,
.leaderboard-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) minmax(112px, 0.7fr) minmax(96px, 0.55fr);
  gap: 14px;
  align-items: center;
}

.leaderboard-head {
  padding-right: 20px;
  padding-left: 20px;
}

.leaderboard-head span:last-child {
  padding-left: 0;
  text-align: right;
}

.leaderboard-head span:nth-child(2) {
  text-align: center;
}

.leaderboard-row {
  min-height: 72px;
  padding: 10px 20px;
  border-top: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(248, 250, 252, 0.86), #fff 42%);
}

.leaderboard-rank {
  display: flex;
  justify-content: center;
}

.leaderboard-rank span {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  color: #475569;
  border: 1px solid #dbe2ec;
  border-radius: 10px;
  background: #f1f5f9;
  font-size: 0.88rem;
  font-weight: 900;
}

.rank-1 .leaderboard-rank span {
  position: relative;
  color: #fffdf0;
  border-color: #ffe99a;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.92), transparent 32%),
    linear-gradient(145deg, #ffe991 0%, #e6b638 42%, #a96d08 72%, #f2c94f 100%);
  box-shadow:
    0 0 0 2px rgba(178, 116, 9, 0.24),
    0 0 15px rgba(255, 211, 69, 0.7),
    0 6px 13px rgba(142, 88, 0, 0.28),
    inset 0 1px 1px rgba(255, 255, 255, 0.94);
  text-shadow: 0 1px 3px #8a5200;
  animation: championBadgeGlow 2.4s ease-in-out infinite;
}

.rank-1 .leaderboard-rank span::before {
  position: absolute;
  top: -17px;
  left: 50%;
  content: "♛";
  color: #e3a900;
  font-size: 1rem;
  line-height: 1;
  text-shadow:
    0 1px 0 #fff7c7,
    0 2px 3px rgba(120, 70, 0, 0.42),
    0 0 9px rgba(255, 210, 58, 0.78);
  transform: translateX(-50%);
}

.rank-2 .leaderboard-rank span {
  color: #475569;
  border-color: #cbd5e1;
  background: linear-gradient(145deg, #f8fafc, #e2e8f0);
}

.rank-3 .leaderboard-rank span {
  color: #9a3412;
  border-color: #fdba74;
  background: linear-gradient(145deg, #ffedd5, #fed7aa);
}

.rank-1.leaderboard-row {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border-top: 1px solid #f5ce55;
  border-bottom: 1px solid #c28a13;
  background:
    radial-gradient(ellipse at 12% 0%, rgba(255, 255, 255, 0.96), transparent 30%),
    radial-gradient(ellipse at 82% 110%, rgba(218, 153, 20, 0.38), transparent 36%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.12) 0 1px, transparent 1px 9px),
    linear-gradient(105deg, #fff8d9 0%, #f8df8a 25%, #dfad36 48%, #f5d873 68%, #fff6d2 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    inset 0 -1px 0 rgba(151, 93, 0, 0.2),
    0 5px 15px rgba(184, 120, 0, 0.22);
}

.rank-1.leaderboard-row::before {
  position: absolute;
  z-index: 0;
  top: -75%;
  bottom: -75%;
  left: -28%;
  width: 16%;
  content: "";
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.12),
    rgba(255, 255, 255, 0.96),
    rgba(255, 248, 213, 0.22),
    transparent
  );
  filter: blur(1px);
  transform: rotate(15deg);
  animation: championShine 3.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  pointer-events: none;
}

.rank-1.leaderboard-row::after {
  position: absolute;
  z-index: 0;
  inset: 3px 4px;
  content: "";
  border: 1px solid rgba(255, 249, 211, 0.84);
  border-radius: 8px;
  background:
    radial-gradient(circle at 14% 30%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 38% 78%, rgba(255, 255, 255, 0.92) 0 1px, transparent 2px),
    radial-gradient(circle at 72% 22%, #fffbe1 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 91% 68%, rgba(255, 255, 255, 0.9) 0 1px, transparent 2px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.28), transparent 9%, transparent 91%, rgba(255, 255, 255, 0.24));
  animation: championSparkle 1.7s ease-in-out infinite alternate;
  pointer-events: none;
}

.rank-1.leaderboard-row > * {
  position: relative;
  z-index: 1;
}

.rank-1 .leaderboard-name {
  color: #6e4100;
  font-size: 1.1rem;
  font-weight: 900;
  letter-spacing: 0.025em;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.92),
    0 0 10px rgba(255, 250, 211, 0.72);
}

.rank-1 .trend-value {
  color: #704400;
}

.rank-1 .trend-value.positive {
  color: #ff7b72;
}

.rank-1 .trend-value.negative {
  color: #82b3ff;
}

.leaderboard-name {
  overflow: hidden;
  justify-self: stretch;
  font-size: 1.08rem;
  font-weight: 800;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-amount,
.leaderboard-profit {
  overflow: hidden;
  font-size: 1.08rem;
  font-weight: 900;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.price-cell,
.profit-cell {
  min-width: 0;
  overflow: hidden;
  text-align: right;
  justify-self: stretch;
}

.price-cell strong,
.profit-cell strong {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 1.04rem;
  font-weight: 800;
  text-align: right;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  white-space: nowrap;
}

.price-cell > span,
.profit-cell > span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.74rem;
}

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

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

.trend-value.positive {
  color: var(--red);
}

.trend-value.negative {
  color: var(--blue);
}

.colored-value.positive {
  color: var(--red);
}

.colored-value.negative {
  color: var(--blue);
}

.trend-value {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  max-width: 100%;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.trend-icon {
  display: inline-block;
  width: 0;
  height: 0;
  vertical-align: 0.08em;
}

.trend-value.positive .trend-icon {
  border-right: 3px solid transparent;
  border-bottom: 6px solid var(--red);
  border-left: 3px solid transparent;
}

.trend-value.negative .trend-icon {
  border-top: 6px solid var(--blue);
  border-right: 3px solid transparent;
  border-left: 3px solid transparent;
}

.empty {
  margin: 0;
  padding: 48px 16px;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}

.modal {
  width: min(760px, calc(100% - 24px));
  padding: 0;
  overflow: hidden;
  border-radius: 22px;
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.44);
  backdrop-filter: blur(5px);
}

.modal form {
  padding: 0;
}

.crawl-logs {
  display: grid;
  max-height: min(62vh, 560px);
  overflow: auto;
  border-top: 1px solid var(--line);
}

.crawl-log {
  padding: 11px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.crawl-log:first-child {
  border-top: 0;
}

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

.log-summary strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-summary code,
.log-summary time {
  color: var(--muted);
  font-size: 0.75rem;
}

.log-summary time {
  margin-left: auto;
  white-space: nowrap;
}

.log-status {
  flex: 0 0 auto;
  padding: 2px 7px;
  color: #fff;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
}

.log-success .log-status {
  background: var(--green);
}

.log-failure .log-status {
  background: var(--red);
}

.log-market {
  flex: 0 0 auto;
  padding: 2px 7px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1.3;
}

.log-market-krx {
  color: #1d4ed8;
  border-color: #bfdbfe;
  background: #eff6ff;
}

.log-market-nxt {
  color: #7c3aed;
  border-color: #ddd6fe;
  background: #f5f3ff;
}

.log-market-unknown {
  color: var(--muted);
  border-color: var(--line);
  background: var(--surface-soft);
  font-weight: 600;
}

.crawl-log p {
  margin: 5px 0 0;
  overflow-wrap: anywhere;
  color: #475569;
  font-size: 0.82rem;
}

.log-message {
  margin: 0;
  padding: 36px 18px;
  color: var(--muted);
  text-align: center;
}

.log-message.log-failure {
  color: var(--red);
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head {
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, #f8fafc);
}

.modal-actions {
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.icon-button {
  width: 34px;
  height: 34px;
  color: #475569;
  border-radius: 12px;
  background: var(--surface-soft);
  font-size: 1.2rem;
}

.modal-desc {
  margin: 0;
  padding: 12px 18px 10px;
}

.edit-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px 88px 126px 30px;
  gap: 8px;
  align-items: center;
}

.edit-rows {
  display: grid;
  gap: 0;
  max-height: min(54vh, 440px);
  overflow: auto;
  padding: 0 18px 12px;
}

.edit-row {
  position: relative;
  min-height: 42px;
  padding: 5px 0;
  border-top: 1px solid var(--line);
  background: transparent;
}

.edit-row:first-child {
  border-top: 0;
}

.edit-field {
  min-width: 0;
}

.edit-row input {
  width: 100%;
  height: 32px;
  padding: 0 9px;
  color: var(--text);
  border: 1px solid #dbe2ec;
  border-radius: 10px;
  outline: none;
  background: var(--surface);
  font-size: 0.9rem;
}

.code-field input,
.buy-field input {
  text-align: right;
}

.edit-row input:focus {
  border-color: rgba(37, 99, 235, 0.72);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.lookup-status {
  position: absolute;
  left: 0;
  bottom: -11px;
  display: none;
}

.edit-row.is-looking .lookup-status,
.edit-row.has-lookup .lookup-status {
  display: block;
}

.delete-row {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  background: #ffffff;
  line-height: 1;
}

.delete-row span {
  position: relative;
  width: 12px;
  height: 12px;
}

.delete-row span::before,
.delete-row span::after {
  position: absolute;
  top: 5px;
  left: 0;
  width: 12px;
  height: 2px;
  content: "";
  border-radius: 999px;
  background: #ef4444;
}

.delete-row span::before {
  transform: rotate(45deg);
}

.delete-row span::after {
  transform: rotate(-45deg);
}

.delete-row:hover {
  border-color: #fecdd3;
  background: #fff1f2;
}

.form-error {
  min-height: 1.3em;
  margin: 10px 0 0;
  color: var(--red);
  font-size: 0.86rem;
}

@keyframes rowIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes flipRankingRow {
  0% {
    transform: rotateX(0deg);
  }

  49% {
    transform: rotateX(90deg);
  }

  50% {
    transform: rotateX(-90deg);
  }

  100% {
    transform: rotateX(0deg);
  }
}

@keyframes championShine {
  0%,
  28% {
    left: -28%;
    opacity: 0;
  }

  40% {
    opacity: 1;
  }

  62%,
  100% {
    left: 116%;
    opacity: 0;
  }
}

@keyframes championSparkle {
  from {
    opacity: 0.42;
  }

  to {
    opacity: 1;
  }
}

@keyframes championBadgeGlow {
  0%,
  100% {
    box-shadow:
      0 0 0 2px rgba(178, 116, 9, 0.24),
      0 0 12px rgba(255, 211, 69, 0.52),
      0 6px 13px rgba(142, 88, 0, 0.28),
      inset 0 1px 1px rgba(255, 255, 255, 0.94);
  }

  50% {
    box-shadow:
      0 0 0 2px rgba(194, 128, 8, 0.3),
      0 0 23px rgba(255, 216, 77, 0.92),
      0 7px 15px rgba(142, 88, 0, 0.34),
      inset 0 1px 1px rgba(255, 255, 255, 1);
  }
}

@keyframes alarmPulse {
  from {
    opacity: 0.4;
    transform: scale(0.88);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ranking-row.is-flipping {
    animation: none;
  }

  .panel-action-button.is-busy svg,
  .rank-1.leaderboard-row::before,
  .rank-1.leaderboard-row::after,
  .rank-1 .leaderboard-rank span {
    animation: none;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 18px, 860px);
  }

  .topbar {
    min-height: 164px;
  }

  .header-meme {
    height: 164px;
  }

  .stock-row {
    grid-template-columns: 24px minmax(6em, 1fr) repeat(3, minmax(0, 1fr));
    column-gap: 4px;
  }

  .stock-table-head {
    grid-template-columns: 24px minmax(6em, 1fr) repeat(3, minmax(0, 1fr));
    column-gap: 4px;
  }

  .stock-table-head span:last-child,
  .stock-row .profit-cell:last-child {
    padding-left: 2px;
  }

  .leaderboard-head,
  .leaderboard-row {
    grid-template-columns: 48px minmax(0, 1fr) minmax(96px, 0.8fr) minmax(88px, 0.7fr);
    gap: 8px;
  }

  .edit-row {
    grid-template-columns: minmax(0, 1fr) 92px 82px 108px 30px;
    gap: 6px;
  }

  .edit-row .code-field {
    grid-column: 3;
  }

  .edit-row .buy-field {
    grid-column: 4;
  }

  .delete-row {
    grid-column: 5;
    grid-row: 1;
    height: 30px;
    min-height: 30px;
  }
}

@media (max-width: 480px) {
  .topbar {
    min-height: 136px;
  }

  .header-meme {
    height: 136px;
  }

  .panel-head {
    align-items: center;
    flex-direction: row;
  }

  .stock-table-head,
  .stock-row {
    padding-right: 10px;
    padding-left: 10px;
  }

  .leaderboard-row {
    padding-right: 10px;
    padding-left: 10px;
  }

  .leaderboard-head,
  .leaderboard-row {
    grid-template-columns: 42px minmax(0, 1fr) minmax(76px, 0.9fr) minmax(70px, 0.75fr);
    gap: 4px;
  }

  .leaderboard-name,
  .leaderboard-amount,
  .leaderboard-profit {
    font-size: 0.9rem;
  }

  .stock-main strong,
  .price-cell strong,
  .profit-cell strong {
    font-size: 0.9rem;
  }

  .rank-cell {
    width: 22px;
    height: 22px;
    font-size: 0.7rem;
  }

  .stock-table-head {
    font-size: 0.66rem;
  }

  .price-cell > span,
  .profit-cell > span,
  .stock-main > span {
    display: none;
  }

  .edit-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 30px;
    align-items: start;
    row-gap: 10px;
    padding: 10px 0;
  }

  .edit-row .name-field {
    grid-column: 1;
    grid-row: 1;
  }

  .edit-row .owner-field {
    grid-column: 2;
    grid-row: 1;
  }

  .edit-row .code-field {
    grid-column: 1;
    grid-row: 2;
  }

  .edit-row .buy-field {
    grid-column: 2;
    grid-row: 2;
  }

  .delete-row {
    grid-column: 3;
    grid-row: 1;
  }
}
