* { box-sizing: border-box; }
[hidden] { display: none !important; }
:root {
  --bg: #0b1020; --card: rgba(22, 30, 54, 0.88); --line: rgba(148, 163, 184, 0.18); --text: #e2e8f0; --sub: #94a3b8;
  --c: #fbbf24; --d: #34d399; --money: #fde68a; --accent: #38bdf8; --bad: #f87171; --era: #94a3b8;
}
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif; }
body { overflow: hidden; }
button { font: inherit; color: inherit; }
.app { display: grid; grid-template-columns: minmax(340px, 1fr) minmax(360px, 460px); height: 100dvh; }

/* ---------- 작업실 ---------- */
.stage { position: relative; display: flex; flex-direction: column; gap: 10px; padding: 12px 14px 14px; overflow: hidden;
  background: radial-gradient(circle at 20% 0%, rgba(56, 189, 248, 0.12), transparent 50%), radial-gradient(circle at 90% 100%, rgba(167, 139, 250, 0.12), transparent 55%), var(--bg); }
.top { display: flex; align-items: center; gap: 8px; }
.top h1 { flex: 1; font-size: 16px; margin: 0; text-align: center; letter-spacing: -0.3px; }
.back-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 11px; border-radius: 10px; background: rgba(15, 23, 42, 0.8); border: 1px solid var(--line); color: var(--text); text-decoration: none; font-size: 12.5px; font-weight: 700; }
.back-btn:hover { border-color: var(--accent); }
.icon-btn { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: rgba(15, 23, 42, 0.8); cursor: pointer; font-size: 15px; }

.hud { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.money { display: flex; align-items: center; gap: 8px; }
.money .ico { font-size: 28px; }
.money b { display: block; font-size: 26px; color: var(--money); font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.money small { color: var(--sub); font-size: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 9px; border-radius: 99px; background: rgba(15, 23, 42, 0.8); border: 1px solid var(--line); font-size: 12px; white-space: nowrap; }
.chip.c b { color: var(--c); } .chip.d b { color: var(--d); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.flag { display: flex; align-items: center; justify-content: space-between; gap: 10px; border-left: 3px solid var(--era); }
.flag-l { display: flex; align-items: center; gap: 10px; min-width: 0; }
.flag-l .mi { font-size: 28px; }
.flag-l small { display: block; color: var(--era); font-size: 11px; font-weight: 700; }
.flag-l b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flag-r { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.hype { font-weight: 900; font-size: 14px; color: #f0abfc; font-variant-numeric: tabular-nums; }
.hype.off { color: var(--sub); font-weight: 600; }
.buffs { display: flex; gap: 4px; }
.buff { font-size: 11px; padding: 2px 6px; border-radius: 6px; background: rgba(240, 171, 252, 0.15); color: #f5d0fe; }

.train-head { display: flex; justify-content: space-between; gap: 8px; }
.train-head small { color: var(--sub); font-size: 11px; }
.train-head b { display: block; font-size: 16px; margin: 1px 0; }
.train-head em { display: block; font-style: normal; font-size: 11.5px; color: #c4b5fd; }
#loss { width: 160px; height: 64px; flex-shrink: 0; border-radius: 8px; background: rgba(2, 6, 23, 0.6); border: 1px solid var(--line); }
.prog { position: relative; height: 20px; border-radius: 99px; background: rgba(2, 6, 23, 0.7); overflow: hidden; margin: 8px 0 6px; border: 1px solid var(--line); }
.prog i { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #6366f1, #38bdf8); transition: width 0.2s linear; }
.prog.ready i { background: linear-gradient(90deg, #22c55e, #a3e635); }
.prog span { position: relative; display: block; text-align: center; font-size: 12px; line-height: 20px; font-weight: 800; text-shadow: 0 1px 2px #000; }
.train-foot { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--sub); flex-wrap: wrap; }
.train-foot .need { flex: 1; }
.need .lack { color: var(--bad); font-weight: 800; }
.btn { padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); background: #1e293b; cursor: pointer; font-weight: 800; font-size: 13px; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: linear-gradient(135deg, #2563eb, #7c3aed); border-color: transparent; color: #fff; }
.btn.danger { background: #7f1d1d; border-color: #b91c1c; }
.release:not(:disabled) { background: linear-gradient(135deg, #16a34a, #65a30d); color: #fff; border-color: transparent; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(132, 204, 22, 0.25); } }

.code { position: relative; flex: 1; min-height: 120px; border-radius: 14px; border: 1px solid rgba(56, 189, 248, 0.35); background: #050a16; cursor: pointer; text-align: left; padding: 10px 12px; overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.code:active { border-color: #38bdf8; }
.code pre { margin: 0; font: 12.5px/1.45 ui-monospace, 'D2Coding', Consolas, monospace; color: #a5f3fc; white-space: pre-wrap; word-break: break-all; position: absolute; left: 12px; right: 12px; bottom: 34px; }
.code pre .kw { color: #f472b6; } .code pre .cm { color: #64748b; }
.code pre::after { content: '▋'; color: #38bdf8; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.code-hint { position: absolute; left: 0; right: 0; bottom: 8px; text-align: center; font-size: 12px; color: var(--sub); }
kbd { font-size: 10.5px; padding: 1px 5px; border-radius: 4px; border: 1px solid #475569; background: #0f172a; }
.pop { position: absolute; pointer-events: none; font-weight: 900; color: var(--money); font-size: 15px; text-shadow: 0 1px 3px #000; animation: up 0.9s ease-out forwards; }
@keyframes up { to { transform: translateY(-46px); opacity: 0; } }

.event { position: absolute; z-index: 5; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 10px; border-radius: 14px; border: 2px solid #fde047; background: rgba(30, 27, 75, 0.95); cursor: pointer; font-size: 26px; animation: bob 1s ease-in-out infinite; box-shadow: 0 0 22px rgba(253, 224, 71, 0.45); }
.event span { font-size: 11px; font-weight: 800; color: #fef08a; white-space: nowrap; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-3deg); } }
.log { position: absolute; left: 14px; right: 14px; bottom: 54px; margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; z-index: 4; }
.log li { font-size: 12.5px; padding: 5px 10px; border-radius: 8px; background: rgba(15, 23, 42, 0.92); border: 1px solid var(--line); animation: fadein 0.25s; text-align: center; }
.log li.good { border-color: rgba(52, 211, 153, 0.6); }
.log li.big { border-color: #fde047; color: #fef9c3; font-weight: 800; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }

/* ---------- 패널 ---------- */
.panel { display: flex; flex-direction: column; border-left: 1px solid var(--line); background: #0d1428; min-height: 0; }
.tabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs button { flex: 1 0 auto; padding: 10px 7px; border: 0; background: none; cursor: pointer; font-size: 12px; font-weight: 700; color: var(--sub); border-bottom: 2px solid transparent; white-space: nowrap; position: relative; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tabs button .dot { position: absolute; top: 6px; right: 3px; width: 7px; height: 7px; border-radius: 50%; background: #f43f5e; }
.amt { display: flex; align-items: center; gap: 4px; padding: 6px 10px; font-size: 12px; color: var(--sub); border-bottom: 1px solid var(--line); }
.amt span { margin-right: auto; }
.amt button { padding: 4px 9px; border-radius: 7px; border: 1px solid var(--line); background: #111a33; cursor: pointer; font-size: 12px; font-weight: 700; }
.amt button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.tab-body { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 7px; overscroll-behavior: contain; }
.tab-body h3 { margin: 8px 2px 2px; font-size: 13px; color: var(--sub); }
.tab-body p.note { margin: 0 2px; font-size: 12px; color: var(--sub); line-height: 1.5; }

.row { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.row .ri { font-size: 24px; width: 34px; text-align: center; flex-shrink: 0; }
.row .rb { flex: 1; min-width: 0; }
.row .rb b { font-size: 13.5px; }
.row .rb small { display: block; font-size: 11.5px; color: var(--sub); margin-top: 2px; }
.row .rb .ms { color: #c4b5fd; }
.row .cnt { font-size: 12px; font-weight: 900; color: var(--accent); margin-left: 4px; }
.buy { min-width: 92px; padding: 7px 8px; border-radius: 10px; border: 1px solid var(--line); background: #172036; cursor: pointer; font-size: 12px; font-weight: 800; text-align: center; line-height: 1.25; flex-shrink: 0; }
.buy small { display: block; font-size: 10.5px; color: var(--sub); font-weight: 600; }
.buy.ok { border-color: rgba(250, 204, 21, 0.6); background: #2a2410; color: var(--money); }
.buy:disabled { cursor: default; opacity: 0.55; }
.row.locked { opacity: 0.45; }
.row.bott { border-color: rgba(248, 113, 113, 0.55); }
.tagb { font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 6px; background: rgba(248, 113, 113, 0.18); color: #fecaca; margin-left: 4px; }

.models .row.done { border-left: 3px solid #22c55e; }
.models .row.cur { border-left: 3px solid #38bdf8; }
.era-h { display: flex; align-items: center; gap: 6px; }
.grid-ach { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.ach { padding: 8px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); font-size: 11.5px; }
.ach b { display: block; font-size: 12.5px; margin: 2px 0; }
.ach.off { opacity: 0.38; filter: grayscale(1); }
.stat { display: flex; justify-content: space-between; padding: 6px 4px; border-bottom: 1px dashed var(--line); font-size: 13px; }
.stat span:last-child { font-weight: 800; font-variant-numeric: tabular-nums; }
.big-btn { width: 100%; padding: 12px; font-size: 14px; }
.box { padding: 12px; border-radius: 12px; background: linear-gradient(135deg, rgba(99, 102, 241, 0.18), rgba(236, 72, 153, 0.12)); border: 1px solid rgba(167, 139, 250, 0.4); font-size: 13px; line-height: 1.55; }
.box b.k { color: #f0abfc; font-size: 18px; }
textarea { width: 100%; min-height: 70px; border-radius: 10px; background: #050a16; color: var(--text); border: 1px solid var(--line); padding: 8px; font-size: 11px; font-family: ui-monospace, monospace; }

/* ---------- 모달 ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(2, 6, 23, 0.72); }
.modal[hidden] { display: none; }
.modal-card { width: min(440px, 100%); max-height: 90dvh; overflow-y: auto; padding: 18px; border-radius: 18px; background: #111a33; border: 1px solid rgba(148, 163, 184, 0.3); box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6); font-size: 14px; line-height: 1.6; }
.modal-card h2 { margin: 0 0 8px; font-size: 18px; }
.modal-card ul { padding-left: 18px; margin: 6px 0; }
.modal-card .actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.choice button { padding: 12px 10px; border-radius: 12px; border: 1px solid var(--line); background: #172036; cursor: pointer; text-align: center; line-height: 1.4; }
.choice button:hover { border-color: var(--accent); }
.choice button b { display: block; font-size: 15px; color: var(--money); }
.choice button small { color: var(--sub); font-size: 11.5px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; z-index: 60; padding: 9px 14px; border-radius: 10px; background: #1e293b; border: 1px solid var(--line); font-size: 13px; transition: all 0.2s; pointer-events: none; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.fatal { position: fixed; inset: 0; z-index: 99; display: flex; align-items: center; justify-content: center; background: rgba(2, 6, 23, 0.94); padding: 16px; }
.fatal[hidden] { display: none; }
.fatal-card { max-width: 420px; padding: 20px; border-radius: 16px; background: #111a33; border: 1px solid #b91c1c; text-align: center; }
.fatal-card pre { white-space: pre-wrap; font-size: 11px; color: #fca5a5; }
.fatal-card button, .fatal-card a { display: inline-block; margin: 4px; padding: 8px 14px; border-radius: 10px; background: #1e293b; color: var(--text); border: 1px solid var(--line); text-decoration: none; cursor: pointer; }

/* ---------- 모바일 (세로) ---------- */
@media (max-width: 820px) {
  body { overflow: auto; }
  .app { display: flex; flex-direction: column; height: auto; min-height: 100dvh; }
  .stage { padding: 10px 12px 12px; gap: 8px; }
  .top h1 { font-size: 14px; }
  .money b { font-size: 22px; }
  .code { flex: none; height: 150px; }
  .log { bottom: 40px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); min-height: 60dvh; }
  .tabs { position: sticky; top: 0; z-index: 3; background: #0d1428; }
  .tab-body { overflow: visible; }
  #loss { width: 120px; height: 56px; }
  .tabs button { padding: 9px 4px; font-size: 11.5px; }
  .train-foot .need { order: 3; flex-basis: 100%; }
  .train-foot #tEta { flex: 1; }
}
@media (max-width: 380px) {
  .back-btn { padding: 6px 8px; font-size: 11.5px; }
  .top h1 { font-size: 13px; }
  .buy { min-width: 80px; }
}
