:root {
  --bg: #0a0d18;
  --panel: #131830;
  --panel2: #1b2142;
  --text: #eef1ff;
  --sub: #8b93b8;
  --accent: #ffd84d;
  --up: #ff4d4d;   /* 한국식: 상승 빨강 */
  --down: #4d7fff; /* 하락 파랑 */
  --radius: 16px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Pretendard", -apple-system, "Malgun Gothic", sans-serif;
  line-height: 1.5;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation; /* 모바일 더블탭 확대 방지 */
}
button { touch-action: manipulation; }
.wrap { max-width: 560px; margin: 0 auto; padding: 20px 14px 40px; }
.hidden { display: none !important; }

header { text-align: center; padding: 14px 0 6px; }
h1 { font-size: 30px; letter-spacing: -0.5px; }
.tagline { color: var(--sub); margin-top: 4px; font-size: 15px; }

.panel { background: var(--panel); border-radius: var(--radius); padding: 18px; margin-top: 14px; }
.rules .rule { font-size: 14px; padding: 6px 0; color: var(--text); }
.rules b { color: var(--accent); }

.challenge-banner {
  margin-top: 14px; background: linear-gradient(135deg, #3a1d5e, #1d2a5e);
  border: 1px solid #6f4dff; border-radius: 12px; padding: 12px 16px;
  font-size: 14px; text-align: center;
}
.challenge-banner b { color: var(--accent); }

.go-btn {
  width: 100%; margin-top: 16px; padding: 16px; border: none; border-radius: 14px;
  background: linear-gradient(135deg, #ffd84d, #ff9d2e); color: #221700;
  font-size: 18px; font-weight: 800; cursor: pointer; font-family: inherit;
}
.go-btn:active { transform: scale(.97); }

.dash h3 { font-size: 14px; color: var(--accent); margin-bottom: 8px; }
.dash .sum { display: flex; gap: 14px; font-size: 13px; color: var(--sub); margin-bottom: 8px; flex-wrap: wrap; }
.dash .sum b { color: var(--text); }
.dash .hist { font-size: 12px; color: var(--sub); padding: 3px 0; border-top: 1px solid #232a52; display: flex; justify-content: space-between; }

.ad-slot {
  height: 90px; margin: 16px 0 0; border: 1px dashed #2a3158; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #39406b; font-size: 12px; letter-spacing: 2px;
}

/* ── 게임 화면 ── */
.hud { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.sector-chip {
  background: var(--panel2); color: var(--accent); font-size: 13px; font-weight: 700;
  border-radius: 99px; padding: 5px 12px;
}
.day-count { color: var(--sub); font-size: 13px; flex: 1; }
.speed button {
  background: var(--panel2); color: var(--sub); border: none; border-radius: 8px;
  padding: 5px 10px; margin-left: 4px; cursor: pointer; font-family: inherit; font-size: 12px; font-weight: 700;
}
.speed button.on { background: var(--accent); color: #221700; }
#btn-restart {
  background: var(--panel2); border: 1px solid var(--accent); color: var(--accent);
  border-radius: 8px; padding: 5px 10px; font-family: inherit; font-weight: 700;
  cursor: pointer; font-size: 12px; margin-left: 4px; white-space: nowrap;
}
#btn-restart:active { background: var(--accent); color: #221700; }

.ma-legend { display: flex; gap: 12px; font-size: 11px; margin-top: 4px; }
.ma-legend .ma20 { color: #ffd84d; }
.ma-legend .ma60 { color: #b86bff; }
.ma-legend .ma120 { color: #2ec8a6; }

.start-hint {
  text-align: center; font-size: 13px; color: var(--accent);
  margin: 4px 0 8px; line-height: 1.5;
}
.start-hint b { color: #fff; }

.playback {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border-radius: 12px; padding: 8px 10px; margin-top: 8px;
}
.playback .speed { display: flex; gap: 4px; }
.playback button {
  font-family: inherit; cursor: pointer; border-radius: 8px; font-weight: 700;
}
/* 가운데 큰 재생/정지 버튼 (재생 = 1년 단타 시작) */
#btn-pause {
  flex: 1; background: var(--panel2); border: 1px solid #4a5278; color: var(--text);
  padding: 10px 14px; font-size: 14px; white-space: nowrap;
}
#btn-pause.paused { border-color: var(--accent); color: var(--accent); }
#btn-pause.start {
  background: linear-gradient(135deg, #ffd84d, #ff9d2e); color: #221700;
  border-color: transparent; font-weight: 900; font-size: 15px;
}
#btn-pause:disabled { opacity: .6; cursor: default; }
#btn-step {
  background: var(--panel2); border: 1px solid #4a5278; color: var(--text);
  padding: 10px 14px; font-size: 13px; white-space: nowrap;
}
#btn-step:disabled { opacity: .3; cursor: default; }
#btn-step:not(:disabled) { border-color: var(--accent); color: var(--accent); }
#btn-step:not(:disabled):active { background: var(--accent); color: #221700; }

.stat-row.two { grid-template-columns: repeat(2, 1fr); }
.stat-row.two .stat b { font-size: 20px; }

.big-ret {
  margin-top: 8px; background: var(--panel); border-radius: 12px; padding: 10px;
  text-align: center; border: 1px solid #2a3158;
}
.big-ret span { display: block; font-size: 12px; color: var(--sub); }
.big-ret b { font-size: 38px; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.15; }
.big-ret.plus b { color: var(--up); } .big-ret.minus b { color: var(--down); }

.trade-row.main { display: flex; gap: 8px; }
.trade-row.main button {
  flex: 1; padding: 14px 2px 16px; border: none; border-radius: 14px; cursor: pointer;
  font-family: inherit; font-size: 16px; font-weight: 900;
  position: relative; overflow: hidden;
}
.trade-row.main .gauge {
  position: absolute; left: 0; bottom: 0; height: 5px; width: 0%;
  background: currentColor; opacity: .55; transition: width .2s;
  pointer-events: none;
}
.trade-row.main .btn-buy { background: #ff4d4d26; color: var(--up); border: 2px solid #ff4d4d66; }
.trade-row.main .btn-buy:active { background: #ff4d4d55; }
.trade-row.main .btn-sell { background: #4d7fff26; color: var(--down); border: 2px solid #4d7fff66; }
.trade-row.main .btn-sell:active { background: #4d7fff55; }
.trade-row.main button:disabled { opacity: .35; cursor: default; }

#g-chart-full { width: 100%; height: auto; background: var(--panel); border-radius: 12px; margin-bottom: 6px; }
#g-chart { width: 100%; height: auto; background: var(--panel); border-radius: 12px; }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.stat {
  background: var(--panel); border-radius: 10px; padding: 8px 4px; text-align: center;
}
.stat span { display: block; font-size: 11px; color: var(--sub); }
.stat b { font-size: 16px; font-variant-numeric: tabular-nums; }
#g-ret.plus { color: var(--up); } #g-ret.minus { color: var(--down); }

.pos-bar {
  position: relative; height: 22px; background: var(--panel); border-radius: 8px;
  margin-top: 8px; overflow: hidden;
}
#g-posfill { height: 100%; width: 0%; background: #6f4dff66; transition: width .2s; }
#g-poslabel {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--sub);
}

.trade-rows { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.trade-row { display: flex; gap: 6px; align-items: stretch; }
.t-label {
  width: 44px; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; border-radius: 10px;
}
.trade-row.buy .t-label { background: #3d1420; color: var(--up); }
.trade-row.sell .t-label { background: #142036; color: var(--down); }
.trade-row button {
  flex: 1; padding: 14px 2px; border: none; border-radius: 10px; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 800;
}
.trade-row.buy button { background: #ff4d4d22; color: var(--up); border: 1px solid #ff4d4d44; }
.trade-row.buy button:active { background: #ff4d4d55; }
.trade-row.sell button { background: #4d7fff22; color: var(--down); border: 1px solid #4d7fff44; }
.trade-row.sell button:active { background: #4d7fff55; }

.toast { text-align: center; font-size: 12px; color: var(--accent); height: 18px; margin-top: 6px; }

/* ── 결과 화면 ── */
#scr-result { text-align: center; }
.reveal-pre { color: var(--sub); font-size: 15px; margin-top: 14px; }
.reveal-name { font-size: 32px; font-weight: 900; margin-top: 6px; }
.reveal-period { color: var(--sub); font-size: 13px; margin-top: 2px; }

.grade-box {
  margin: 18px auto 0; width: 130px; height: 130px; border-radius: 26px;
  background: var(--panel); border: 2px solid var(--accent);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.grade { font-size: 64px; font-weight: 900; color: var(--accent); line-height: 1; }
.grade-label { font-size: 12px; color: var(--sub); margin-top: 4px; }
.r-comment { margin-top: 12px; color: var(--accent); font-size: 15px; }

.vs-rows { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.vs-rows .row {
  display: flex; justify-content: space-between; background: var(--panel);
  border-radius: 10px; padding: 10px 14px; font-size: 14px;
}
.vs-rows .row.me { border: 1px solid var(--accent); }
.vs-rows .row b { font-variant-numeric: tabular-nums; }
.vs-rows .plus { color: var(--up); } .vs-rows .minus { color: var(--down); }

#r-chart { width: 100%; height: auto; background: var(--panel); border-radius: 12px; margin-top: 14px; }

.r-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.r-stats .stat { background: var(--panel); }

.challenge-result {
  margin-top: 12px; background: linear-gradient(135deg, #3a1d5e, #1d2a5e);
  border: 1px solid #6f4dff; border-radius: 12px; padding: 12px; font-size: 14px;
}

.challenge-cta {
  width: 100%; margin-top: 14px; padding: 17px; border: none; border-radius: 14px;
  background: linear-gradient(135deg, #8a4dff, #4d6bff); color: #fff;
  font-size: 18px; font-weight: 900; cursor: pointer; font-family: inherit;
}
.challenge-cta:active { transform: scale(.97); }
.challenge-desc { margin-top: 8px; font-size: 13px; color: var(--sub); line-height: 1.6; }
.challenge-desc b { color: var(--accent); }
.challenge-msg { margin-top: 8px; font-size: 14px; color: var(--accent); font-weight: 700; }
.challenge-copy { display: flex; gap: 6px; margin-top: 8px; }
.challenge-copy input {
  flex: 1; background: var(--panel2); color: var(--text); border: 1px solid #4a5278;
  border-radius: 10px; padding: 10px 12px; font-size: 13px; font-family: inherit;
}
.challenge-copy button {
  background: var(--accent); color: #221700; border: none; border-radius: 10px;
  padding: 10px 16px; font-weight: 800; cursor: pointer; font-family: inherit;
}

.r-actions { margin-top: 16px; display: flex; gap: 8px; }
.r-actions button {
  flex: 1; padding: 13px 4px; border: none; border-radius: 12px; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 700;
  background: var(--panel2); color: var(--text);
}
.r-actions #btn-card { background: var(--accent); color: #221700; }

footer { margin-top: 26px; color: #4a5278; font-size: 11px; text-align: center; }
footer p { margin-top: 4px; }

/* ── 결과 카드 팝업 ── */
.card-modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4, 6, 14, .82); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.card-modal-inner {
  background: var(--panel); border: 1px solid #2a3158; border-radius: 18px;
  padding: 16px; width: 100%; max-width: 400px; max-height: 92vh;
  overflow-y: auto; text-align: center;
}
.card-modal-title { font-size: 14px; color: var(--accent); font-weight: 700; margin-bottom: 10px; }
#card-preview { width: 100%; border-radius: 12px; display: block; }
.card-modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.card-modal-actions button {
  flex: 1; padding: 14px 4px; border: none; border-radius: 12px;
  font-family: inherit; font-size: 15px; font-weight: 800; cursor: pointer;
}
#btn-card-save { background: var(--accent); color: #221700; }
#btn-card-copy { background: var(--panel2); color: var(--text); border: 1px solid #4a5278; }
.card-modal-actions button:active { transform: scale(.97); }
.card-modal-msg { font-size: 13px; color: var(--accent); min-height: 18px; margin-top: 10px; }
.card-modal-close {
  margin-top: 6px; background: none; border: none; color: var(--sub);
  font-family: inherit; font-size: 14px; cursor: pointer; padding: 6px 12px;
}
.footer-links { display: flex; justify-content: center; gap: 14px; margin-top: 10px; }
.footer-links a { color: #8b93b8; }
