@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;500;600;700&display=swap');

:root {
  --bg-primary: #14151b;
  --bg-panel: #1d1e26;
  --border: #2b2c36;
  --text-primary: #ffffff;
  --text-secondary: #8b8e9f;
  --chart-line: var(--green);
  --chart-line-glow: rgba(var(--green-rgb), 0.3);
  --green: #E63E88;
  --red: #964BFF;
  --green-rgb: 230, 62, 136;
  --red-rgb: 150, 75, 255;
  --font-ui: 'Noto Sans KR', -apple-system, sans-serif;
  --font-mono: 'Noto Sans KR', -apple-system, sans-serif;
}

body {
  background: #000;
  color: var(--text-primary);
  font-family: var(--font-ui);
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* Mobile First Layout (Centered on Desktop) */
.app-container {
  max-width: 440px;
  margin: 0 auto;
  position: relative;
  min-height: 100vh;
  padding-bottom: 140px;
  background: var(--bg-primary);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
  transition: transform 0.05s ease-out;
  /* For shake effect */
}

/* Shake Effect */
.shake-effect {
  animation: shake 0.3s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

.shake-effect-strong {
  animation: shakeStrong 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes shake {

  10%,
  90% {
    transform: translate3d(-1px, 0, 0);
  }

  20%,
  80% {
    transform: translate3d(2px, 0, 0);
  }

  30%,
  50%,
  70% {
    transform: translate3d(-3px, 0, 0);
  }

  40%,
  60% {
    transform: translate3d(3px, 0, 0);
  }
}

@keyframes shakeStrong {

  10%,
  90% {
    transform: translate3d(-4px, 2px, 0) rotate(-1deg);
  }

  20%,
  80% {
    transform: translate3d(6px, -2px, 0) rotate(1deg);
  }

  30%,
  50%,
  70% {
    transform: translate3d(-8px, 4px, 0) rotate(-2deg);
  }

  40%,
  60% {
    transform: translate3d(8px, -4px, 0) rotate(2deg);
  }
}

/* Floating Text Effect */
.floating-text {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-mono);
  font-size: 3.5rem;
  font-weight: 800;
  pointer-events: none;
  z-index: 500;
  animation: floatUpFade 1.2s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
}

.theme-selector {
  background: var(--bg-panel);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  outline: none;
  cursor: pointer;
}

.floating-text.float-profit {
  color: var(--green);
  text-shadow: 0 0 20px rgba(var(--green-rgb), 0.8), 0 4px 10px rgba(0, 0, 0, 0.8);
}

.floating-text.float-loss {
  color: var(--red);
  text-shadow: 0 0 20px rgba(var(--red-rgb), 0.8), 0 4px 10px rgba(0, 0, 0, 0.8);
}

.floating-text.strong {
  font-size: 5rem;
  font-weight: 900;
  animation: floatUpFadeStrong 1.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes floatUpFade {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%) scale(0.5);
  }

  15% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.2);
  }

  30% {
    transform: translate(-50%, -50%) scale(1);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -100%) scale(1);
  }
}

@keyframes floatUpFadeStrong {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%) scale(0.3);
  }

  15% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.4);
  }

  25% {
    transform: translate(-50%, -50%) scale(0.9);
  }

  35% {
    transform: translate(-50%, -50%) scale(1.1);
  }

  45% {
    transform: translate(-50%, -50%) scale(1);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -110%) scale(1.1);
  }
}

.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 20px 16px;
}

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

.logo-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-panel);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  border: 1px solid var(--border);
}

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

.duration-text {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  opacity: 0.6;
  outline: none;
}

.stock-name-title {
  color: var(--text-primary);
  font-size: 1.15rem;
  font-weight: 700;
  font-family: var(--font-ui);
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-source {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-secondary);
  background: var(--bg-panel);
  padding: 4px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.data-source.live {
  color: var(--green);
  border-color: rgba(0, 230, 118, 0.4);
}

.price-section {
  padding: 0 20px 16px;
  min-height: 100px;
}

.huge-price {
  font-family: var(--font-mono);
  font-size: 2.8rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text-primary);
  letter-spacing: -1.5px;
  display: flex;
  align-items: baseline;
}

.odometer-digit {
  display: inline-block;
  vertical-align: baseline;
  overflow: hidden;
  height: 1.1em;
  line-height: 1.1em;
}

.odometer-col {
  display: flex;
  flex-direction: column;
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.odometer-cell {
  height: 1.1em;
  display: flex;
  align-items: center;
  justify-content: center;
}

.odometer-char {
  display: inline-block;
  vertical-align: baseline;
}

.price-change {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.price-change.profit {
  color: var(--green);
}

.price-change.loss {
  color: var(--red);
}

.chart-wrapper {
  width: 100%;
  position: relative;
  height: 350px;
}

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

.progress-bar-container {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  height: 4px;
  background: var(--border);
  width: 100%;
  max-width: 440px;
  z-index: 9999;
}

.progress-bar {
  height: 100%;
  width: 100%;
  transform-origin: left;
  transform: scaleX(0);
  background: var(--text-primary);
  transition: transform 0.1s linear;
}

.speed-control-slider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}

.speed-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

.speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-primary);
  cursor: pointer;
}

.speed-value {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 440px;
  padding: 16px 20px 32px;
  background: var(--bg-primary);
  z-index: 100;
}

.total-profit-wrap {
  text-align: center;
  margin-bottom: 12px;
}

.total-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-right: 6px;
  font-weight: 500;
}

.total-value {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
}

.total-value.profit {
  color: var(--green);
}

.total-value.loss {
  color: var(--red);
}

.btn-group {
  display: flex;
  gap: 12px;
  will-change: transform;
}

.btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 64px;
  border-radius: 16px;
  border: none;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  background: var(--bg-panel);
  outline: none;
}

.btn-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.btn-rate {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  margin-top: 4px;
  display: none;
}

/* Inactive default buttons styling text */
.btn-long {
  color: var(--green);
  background: rgba(var(--green-rgb), 0.1);
  border: none;
}

.btn-short {
  color: var(--red);
  background: rgba(var(--red-rgb), 0.1);
  border: none;
}

/* Active States */
.btn.active .btn-rate {
  display: block;
}

.btn-long.active .btn-title {
  font-size: 0.9rem;
  margin-bottom: 2px;
}

.btn-short.active .btn-title {
  font-size: 0.9rem;
  margin-bottom: 2px;
}

.btn-long.active {
  background: var(--green);
  color: #fff;
  border: none;
  box-shadow: 0 4px 16px rgba(var(--green-rgb), 0.4);
  transform: translateY(-2px);
}

.btn-short.active {
  background: var(--red);
  color: #fff;
  border: none;
  box-shadow: 0 4px 16px rgba(var(--red-rgb), 0.4);
  transform: translateY(-2px);
}

.btn:active {
  transform: scale(0.96) translateY(0);
}

/* ===== Loading Overlay ===== */
.loading-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(11, 14, 20, 0.95);
  z-index: 900;
  justify-content: center;
  align-items: center;
}

.loading-overlay.show {
  display: flex;
}

.loading-content {
  text-align: center;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 2px solid var(--border);
  border-top: 2px solid var(--text-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 12px;
}

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

.loading-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
  margin: 0;
  opacity: 0.8;
  transition: opacity 0.2s, transform 0.1s;
}

.btn-icon:hover {
  opacity: 1;
}

.btn-icon:active {
  transform: scale(0.9);
}

.btn-icon.muted {
  opacity: 0.4;
}

.version-badge {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.round-badge {
  background: rgba(var(--green-rgb), 0.2);
  color: var(--green);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  margin-right: 6px;
  border: 1px solid rgba(var(--green-rgb), 0.4);
}

/* ===== Game Over Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(6px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.show {
  display: flex;
  animation: fadeIn 0.3s ease;
}

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 24px;
  text-align: center;
  max-width: 340px;
  width: 90%;
  animation: modalPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal h2 {
  font-family: var(--font-ui);
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.modal .result-emoji {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

.modal .result-value {
  font-family: var(--font-mono);
  font-size: 2.2rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.modal .result-value.profit {
  color: var(--green);
}

.modal .result-value.loss {
  color: var(--red);
}

.modal .result-msg {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.modal-btn-group {
  display: flex;
  gap: 12px;
}

.btn-modal-secondary,
.btn-modal-primary {
  flex: 1;
  padding: 14px 0;
  border-radius: 12px;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-modal-secondary {
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-modal-primary {
  background: var(--text-primary);
  color: #0b0e14;
}

.btn-modal-primary:active,
.btn-modal-secondary:active {
  transform: scale(0.96);
}

/* Fullscreen Modals */
.modal.fullscreen {
  max-width: 440px;
  width: 100%;
  height: 100vh;
  margin: 0;
  border-radius: 0;
  border: none;
  padding: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.modal.fullscreen .image-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  min-height: 250px;
}

.modal.fullscreen .contain-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 12px;
}

.modal.fullscreen .bottom-content {
  background: transparent;
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  padding: 8px 24px 48px 24px;
  box-shadow: none;
  z-index: 2;
  flex-shrink: 0;
}

.modal:not(.fullscreen) .bottom-content {
  padding: 0;
  background: transparent;
  box-shadow: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes modalPop {
  from {
    transform: scale(0.85);
    opacity: 0;
  }

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

@media (max-height: 700px) {
  .chart-wrapper {
    height: 250px;
  }

  .huge-price {
    font-size: 2.4rem;
  }

  .bottom-bar {
    padding-bottom: 16px;
  }

  .app-container {
    padding-bottom: 120px;
  }
}

/* Leaderboard Styles */
.rank-item {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rank-item.top-rank {
  background: rgba(var(--green-rgb), 0.1);
  border-color: rgba(var(--green-rgb), 0.3);
}

.rank-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.rank-number {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text-secondary);
  width: 28px;
  text-align: center;
}

.rank-number.gold {
  color: #FFD700;
}

.rank-number.silver {
  color: #C0C0C0;
}

.rank-number.bronze {
  color: #CD7F32;
}

.rank-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.rank-date {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.rank-total {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 800;
}

.rank-total.profit {
  color: var(--green);
}

.rank-total.loss {
  color: var(--red);
}

.rank-details {
  border-top: 1px dashed rgba(255, 255, 255, 0.1);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  font-family: var(--font-mono);
}

.rank-round-item {
  display: flex;
  justify-content: space-between;
  color: var(--text-secondary);
}

.rank-round-profit {
  color: var(--green);
  font-weight: 600;
}

.rank-round-loss {
  color: var(--red);
  font-weight: 600;
}