/* 주식으로 지구 사기. 우주 배경의 게임 화면이라 사이트의 공책 디자인 대신 어두운 화면을 쓴다 (DESIGN.md의 예외)
   색 약속: 금색 = 돈·주요 버튼, 빨강 = 내 땅·오름·매수, 파랑 = 내림·매도 (한국 증권 앱과 같게) */
:root {
  --bg: #05070f; --panel: #0d1322; --card: #131b2e; --line: rgba(170, 190, 230, .15); --line2: rgba(170, 190, 230, .28);
  --ink: #e9eef8; --muted: #93a0ba; --gold: #f5c542; --up: #ff5b5b; --down: #4c8dff; --ok: #3ecf8e; --own: #ff3b3b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font: 14px/1.5 "IBM Plex Sans KR", system-ui, sans-serif; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; opacity: .38; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.num, dd, .price { font-variant-numeric: tabular-nums; }
.up { color: var(--up); } .down { color: var(--down); }

#app { display: grid; grid-template-columns: 1fr 400px; grid-template-rows: auto 1fr; height: 100dvh; }
#hud { grid-column: 1 / -1; display: flex; align-items: center; gap: 18px; padding: 8px 14px 10px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--line); position: relative; flex-wrap: wrap; }
.home { color: var(--muted); text-decoration: none; font-size: 1.5rem; line-height: 1; padding: 0 2px; }
.when { display: flex; align-items: baseline; gap: 6px; min-width: 128px; }
.when b { font: 400 2rem/1 "Black Han Sans", sans-serif; letter-spacing: -.01em; }
.when span { font: 400 1.25rem/1 "Black Han Sans", sans-serif; color: var(--muted); }
.kpis { display: flex; gap: 22px; margin: 0; flex: 1; min-width: 0; }
.kpis div { min-width: 0; }
.kpis dt { font-size: .72rem; color: var(--muted); }
.kpis dd { margin: 0; font-weight: 700; font-size: 1.08rem; white-space: nowrap; }
.kpis .land dd { color: var(--own); }
.kpis small { color: var(--muted); font-size: .72rem; margin-left: 4px; }
.kpis .land dd, .kpis .land small { display: inline; }
.ctrl { display: flex; gap: 6px; }
.ctrl button { padding: 8px 12px; border: 1px solid var(--line2); border-radius: 6px; font-weight: 600; white-space: nowrap; }
.ctrl button[aria-pressed="true"] { background: rgba(245, 197, 66, .16); border-color: var(--gold); color: var(--gold); }
.go { background: var(--gold) !important; color: #1b1606 !important; border-color: var(--gold) !important; font-weight: 700; }
.go:hover:not(:disabled) { background: #ffd35e !important; }
.track { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255, 255, 255, .05); }
.track i { display: block; height: 100%; width: 0; background: var(--gold); transition: width .3s; }

#stage { position: relative; min-height: 0; overflow: hidden; }
#globe { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#globe:active { cursor: grabbing; }
.mapbar { position: absolute; right: 12px; top: 12px; display: flex; gap: 6px; }
.mapbar button { background: rgba(13, 19, 34, .8); border: 1px solid var(--line2); border-radius: 6px; padding: 6px 10px; font-weight: 600; min-width: 34px; }
.mapbar button[aria-pressed="false"] { color: var(--muted); }
.zoombar { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; }
.zoombar button { width: 38px; height: 38px; background: rgba(13, 19, 34, .8); border: 1px solid var(--line2); border-radius: 6px; font-size: 1.2rem; font-weight: 600; }
.speedbar { position: absolute; left: 12px; top: 12px; }
.seg { display: flex; background: rgba(13, 19, 34, .82); border: 1px solid var(--line2); border-radius: 6px; overflow: hidden; }
.seg button { padding: 6px 9px; font-weight: 600; font-size: .84rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--gold); color: #1b1606; }
.speedbar small { display: block; margin-top: 3px; font-size: .72rem; color: var(--muted); text-shadow: 0 1px 2px #000; }
.legend { position: absolute; left: 12px; bottom: 12px; display: flex; align-items: center; gap: 6px; font-size: .74rem; color: var(--muted); background: rgba(13, 19, 34, .75); padding: 5px 9px; border-radius: 6px; pointer-events: none; }
.legend i { width: 70px; height: 7px; border-radius: 4px; background: linear-gradient(90deg, rgb(92, 150, 78), rgb(176, 172, 84), rgb(206, 148, 70), rgb(136, 96, 158)); }
.legend em { font-style: normal; color: var(--own); font-weight: 700; margin-left: 6px; }
.legend.plain i, .legend.plain span { display: none; }
#toast { position: absolute; left: 50%; top: 62px; transform: translate(-50%, -8px); max-width: min(560px, calc(100% - 120px)); margin: 0; padding: 9px 14px; background: rgba(13, 19, 34, .94); border: 1px solid var(--line2); border-left: 3px solid var(--gold); border-radius: 6px; font-weight: 600; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#toast small { display: block; color: var(--muted); font-weight: 400; font-size: .74rem; }

#panel { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.tabs button { flex: 1; padding: 11px 6px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--gold); }
.tabs .fold { flex: none; width: 44px; display: none; }
.tab { overflow-y: auto; padding: 12px; flex: 1; min-height: 0; overscroll-behavior: contain; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: .9rem; color: var(--muted); font-weight: 600; }
.note, .fine { color: var(--muted); font-size: .74rem; margin: 10px 2px; }
.hint { color: var(--muted); margin: 4px 0; }

/* 주식 */
.shead { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.shead h2 { margin: 0; font-size: 1.15rem; }
.shead .sym { color: var(--muted); font-size: .78rem; }
.shead .price { text-align: right; font-weight: 700; font-size: 1.25rem; }
.shead .price small { display: block; font-size: .8rem; font-weight: 600; }
.chart { display: block; width: 100%; height: 130px; margin: 8px 0 4px; }
.hold { display: flex; justify-content: space-between; font-size: .84rem; color: var(--muted); margin: 6px 0 10px; gap: 8px; flex-wrap: wrap; }
.hold b { color: var(--ink); }
.trade { display: grid; grid-template-columns: 3.2em repeat(4, 1fr); gap: 5px; align-items: center; margin-top: 5px; }
.trade > span { font-size: .8rem; font-weight: 700; }
.trade button { padding: 7px 0; border-radius: 5px; font-weight: 600; font-size: .84rem; }
.trade.buy > span { color: var(--up); } .trade.buy button { background: rgba(255, 91, 91, .14); border: 1px solid rgba(255, 91, 91, .45); }
.trade.sell > span { color: var(--down); } .trade.sell button { background: rgba(76, 141, 255, .14); border: 1px solid rgba(76, 141, 255, .45); }
.trade button:hover:not(:disabled) { filter: brightness(1.3); }
.listhead, .slist li { display: grid; grid-template-columns: 1fr 5.4em 4.4em 5.2em; gap: 6px; align-items: center; }
.listhead { font-size: .72rem; color: var(--muted); padding: 0 8px 4px; }
.listhead span:not(:first-child), .slist li > span:not(:first-child) { text-align: right; }
.slist { list-style: none; margin: 0; padding: 0; }
.slist li { padding: 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; font-size: .86rem; }
.slist li:hover { background: rgba(255, 255, 255, .04); }
.slist li.on { border-color: var(--line2); background: rgba(255, 255, 255, .05); }
.slist li b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slist li small { color: var(--muted); font-size: .72rem; }
.slist li .mine { color: var(--gold); font-weight: 600; }
.slist li.soon { opacity: .4; cursor: default; }
.sfilter input { width: 100%; padding: 8px 11px; background: var(--card); border: 1px solid var(--line2); border-radius: 6px; }
.chips { display: flex; gap: 5px; flex-wrap: wrap; margin: 8px 0 4px; }
.chips button { padding: 4px 10px; border: 1px solid var(--line2); border-radius: 999px; font-size: .78rem; color: var(--muted); }
.chips button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 700; }
.sfilter .count { margin: 4px 2px 8px; font-size: .72rem; color: var(--muted); }
.sep { list-style: none; font-size: .72rem; color: var(--muted); padding: 10px 8px 4px; }

/* 땅 */
.search input { width: 100%; padding: 9px 11px; background: var(--card); border: 1px solid var(--line2); border-radius: 6px; margin-bottom: 12px; }
.cname { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.cname h2 { margin: 0; font: 400 1.5rem/1.2 "Black Han Sans", sans-serif; }
.cname span { color: var(--muted); font-size: .8rem; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin: 10px 0; }
.facts dt { font-size: .72rem; color: var(--muted); }
.facts dd { margin: 0; font-weight: 700; }
.facts .gold { color: var(--gold); }
.facts .own { color: var(--own); }
.bar { height: 6px; background: rgba(255, 255, 255, .08); border-radius: 3px; overflow: hidden; margin: 2px 0 10px; }
.bar i { display: block; height: 100%; background: var(--own); min-width: 2px; }
.buys { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.buys button { padding: 8px 6px; border-radius: 6px; border: 1px solid rgba(255, 59, 59, .55); background: rgba(255, 59, 59, .12); text-align: center; }
.buys button b { display: block; font-size: .92rem; }
.buys button small { display: block; color: var(--muted); font-size: .72rem; }
.buys button.max { background: var(--own); color: #fff; }
.buys button.max small { color: #ffe3e3; }
.sells { display: flex; gap: 6px; margin-top: 8px; }
.sells button { flex: 1; padding: 6px; border-radius: 6px; border: 1px solid var(--line2); color: var(--muted); font-size: .82rem; }
.blds { display: grid; gap: 6px; }
.bld { display: grid; grid-template-columns: 2em 1fr auto; gap: 8px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 6px; }
.bld .e { font-size: 1.4rem; text-align: center; }
.bld b { display: block; }
.bld small { color: var(--muted); font-size: .74rem; display: block; }
.bld button { padding: 7px 12px; border-radius: 6px; border: 1px solid var(--gold); color: var(--gold); font-weight: 700; }
.bld .cnt { color: var(--gold); font-size: .78rem; margin-left: 4px; }
.cheap { list-style: none; padding: 0; margin: 6px 0 0; }
.cheap li { display: flex; justify-content: space-between; padding: 7px 4px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: .86rem; }
.cheap li:hover { color: var(--gold); }
.cheap li span:last-child { color: var(--muted); }

/* 내 자산 */
.chartkey { display: flex; gap: 14px; font-size: .74rem; color: var(--muted); margin: 0 0 8px; flex-wrap: wrap; }
.chartkey span::before { content: ""; display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.chartkey .k1::before { background: var(--gold); } .chartkey .k2::before { background: #7f8aa3; }
.sum { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; margin: 0; }
.sum dt { color: var(--muted); }
.sum dd { margin: 0; text-align: right; font-weight: 700; }
.mini { list-style: none; margin: 0; padding: 0; }
.mini li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .86rem; }
.mini li:last-child { border: 0; }
.mini li.click { cursor: pointer; }
.mini li.click:hover { color: var(--gold); }
.mini li span:last-child { color: var(--muted); text-align: right; }
.mini .empty { color: var(--muted); }
.news { list-style: none; margin: 0; padding: 0; font-size: .84rem; }
.news li { padding: 5px 0; border-bottom: 1px solid var(--line); }
.news li span { color: var(--muted); margin-right: 6px; font-variant-numeric: tabular-nums; }
.ghost { border: 1px solid var(--line2); border-radius: 6px; padding: 10px 12px; color: var(--muted); font-weight: 600; }
.wide { display: block; width: 100%; margin-top: 8px; padding: 12px; border-radius: 6px; }

/* 시작·결과 화면 */
.over { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow: auto; background: rgba(3, 5, 12, .62); z-index: 10; }
.sheet { width: min(560px, 100%); background: rgba(13, 19, 34, .96); border: 1px solid var(--line2); border-radius: 10px; padding: 26px; }
.sheet h1 { font: 400 2.4rem/1.15 "Black Han Sans", sans-serif; margin: 0; letter-spacing: -.01em; }
.sheet .sub { color: var(--muted); margin: 8px 0 14px; }
.sheet .sub b { color: var(--ink); }
.sheet h2 { font-size: .82rem; color: var(--muted); font-weight: 600; margin: 16px 0 7px; }
.how { margin: 0; padding-left: 1.2em; color: var(--muted); font-size: .9rem; }
.how li { margin: 3px 0; }
.how b { color: var(--ink); }
.picks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.picks button { text-align: left; padding: 10px 12px; border: 1px solid var(--line2); border-radius: 6px; }
.picks b { display: block; font-size: 1.02rem; }
.picks span { font-size: .76rem; color: var(--muted); }
.picks button[aria-pressed="true"] { border-color: var(--gold); background: rgba(245, 197, 66, .12); }
#bStart { margin-top: 18px; font-size: 1.05rem; }
.eyebrow { color: var(--muted); margin: 0 0 4px; font-size: .84rem; }
.big { font: 400 2.7rem/1.1 "Black Han Sans", sans-serif; color: var(--gold); margin: 14px 0 0; word-break: break-all; }
#end .sum { margin: 14px 0; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row2 button { padding: 12px; border-radius: 6px; }

/* 랭킹 */
.rhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.rhead .ghost { padding: 6px 12px; }
#rank .seg { margin-bottom: 8px; }
#rank .seg button { flex: 1; padding: 8px 4px; }
#rank .seg.big button { font-size: .95rem; padding: 10px 4px; }
.rlist { list-style: none; margin: 8px 0 0; padding: 0; max-height: 52dvh; overflow-y: auto; }
.rlist li { display: grid; grid-template-columns: 2.2em 1fr auto; gap: 8px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.rlist li.empty { display: block; color: var(--muted); text-align: center; padding: 22px 0; border: 0; }
.rlist .no { font: 400 1.15rem/1 "Black Han Sans", sans-serif; color: var(--muted); text-align: center; }
.rlist li:nth-child(1) .no { color: #ffd34d; } .rlist li:nth-child(2) .no { color: #d6dde8; } .rlist li:nth-child(3) .no { color: #e09a5a; }
.rlist .who { min-width: 0; }
.rlist .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rlist small { display: block; color: var(--muted); font-size: .72rem; font-weight: 400; }
.rlist .val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.rlist li.me { background: rgba(255, 59, 59, .12); border-radius: 6px; }
.regist { display: flex; gap: 6px; margin-top: 12px; }
.regist input { flex: 1; min-width: 0; padding: 11px; background: var(--card); border: 1px solid var(--line2); border-radius: 6px; }
.regist .go { padding: 0 16px; border-radius: 6px; }
.rmsg { margin: 8px 0 4px; font-size: .9rem; color: var(--muted); }
.rmsg b { color: var(--gold); }

/* 휴대폰: 위 지구본, 아래 패널 */
@media (max-width: 860px) {
  html, body { font-size: 13.5px; }
  #app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr) auto; }
  #hud { gap: 6px 12px; padding: 6px 10px 9px; padding-top: max(6px, env(safe-area-inset-top)); }
  .when { min-width: 0; }
  .when b { font-size: 1.6rem; } .when span { font-size: 1.05rem; }
  .kpis { order: 3; flex-basis: 100%; gap: 14px; justify-content: space-between; }
  .kpis dd { font-size: .98rem; }
  .ctrl { margin-left: auto; }
  .ctrl button { padding: 7px 9px; }
  #panel { border-left: 0; border-top: 1px solid var(--line); height: 48dvh; padding-bottom: env(safe-area-inset-bottom); }
  #panel.folded { height: auto; }
  #panel.folded .tab { display: none; }
  .tabs .fold { display: block; }
  #panel.folded .fold { transform: rotate(180deg); }
  .legend { display: none; }
  #toast { max-width: calc(100% - 24px); top: 62px; font-size: .9rem; }
  .seg button { padding: 6px 7px; }
  .sheet { padding: 20px; }
  .sheet h1 { font-size: 2rem; }
}
@media (max-width: 380px) { .kpis small { display: none !important; } }
