:root { --bg: #061420; --panel: #0d2232; --line: #1c3a50; --text: #e6f4ff; --dim: #8fb0c4; --accent: #7be0c0; }
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif; }
body { display: flex; flex-direction: column; min-height: 100vh; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

#top { display: flex; align-items: center; gap: 18px; padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
h1 { margin: 0; font-size: 18px; letter-spacing: 2px; }
h1 span { color: var(--accent); }
.stats { display: flex; gap: 14px; font-size: 14px; color: var(--dim); flex-wrap: wrap; }
.stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.ctrl { margin-left: auto; display: flex; gap: 6px; }
.ctrl button { min-width: 44px; height: 36px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); font-weight: 700; }
.ctrl button.on { border-color: var(--accent); }

main { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 360px; min-height: 0; }
.stage { position: relative; min-height: 0; min-width: 0; padding: 12px; }
#tank { width: 100%; height: 100%; display: block; border-radius: 14px; border: 1px solid var(--line); touch-action: none; background: #04121c; }
.tools { position: absolute; top: 22px; left: 22px; display: flex; gap: 6px; }
.tools button { width: 52px; height: 52px; border-radius: 12px; background: rgba(6, 20, 32, 0.8); border: 1px solid var(--line); font-size: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.tools button small { font-size: 10.5px; margin-top: 3px; color: var(--dim); }
.tools button.on { border-color: var(--accent); background: rgba(123, 224, 192, 0.15); }
#empty { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); background: rgba(6, 20, 32, 0.9); border: 1px solid var(--line); padding: 14px 18px; border-radius: 14px; text-align: center; }

#info { position: absolute; left: 22px; bottom: 22px; width: min(330px, calc(100% - 44px)); background: rgba(6, 20, 32, 0.92); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; backdrop-filter: blur(6px); }
.ihead { display: flex; align-items: center; gap: 8px; }
.ihead b { font-size: 16px; flex: 1; }
.ihead button { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 3px 8px; font-size: 12.5px; }
.ihead button.on { border-color: #ffe066; color: #ffe066; }
#infoMeta, .parent { margin: 6px 0; font-size: 12.5px; color: var(--dim); }
.parent a { color: var(--accent); }

.gene { display: grid; grid-template-columns: 68px 1fr 44px; gap: 8px; align-items: center; font-size: 12px; margin: 3px 0; }
.gene label { color: var(--dim); }
.gb { height: 7px; background: #13324a; border-radius: 9px; overflow: hidden; }
.gb div { height: 100%; background: linear-gradient(90deg, #4fb3ff, var(--accent)); }
.gene span { text-align: right; font-variant-numeric: tabular-nums; }

#panel { border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: none; padding: 12px 4px; font-size: 13.5px; color: var(--dim); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.pane { display: none; padding: 14px 16px; overflow: auto; flex: 1; }
.pane.on { display: block; }
.slider { display: block; font-size: 14px; margin-top: 6px; }
.slider b { float: right; color: var(--accent); font-weight: 600; }
.slider input { width: 100%; accent-color: var(--accent); margin-top: 6px; }
.note { font-size: 12px; color: var(--dim); margin: 4px 0 12px; line-height: 1.5; }
.btns { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin: 8px 0; }
.btns button { font-size: 12.5px !important; white-space: nowrap; }
.btns button, .newtank button, .wide, .export { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 6px; font-size: 13px; }
.newtank { display: flex; gap: 6px; align-items: center; margin: 8px 0 14px; font-size: 13px; color: var(--dim); }
.newtank label { flex: 1; display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.newtank input { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
h3 { font-size: 13.5px; margin: 14px 0 6px; }
h3 small { color: var(--dim); font-weight: 400; }
textarea { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px; font-size: 12px; resize: vertical; }
.wide { width: 100%; margin-top: 6px; }

#speciesList, #goalList { list-style: none; margin: 0; padding: 0; }
#speciesList li { border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; margin-bottom: 7px; cursor: pointer; background: var(--panel); }
#speciesList li.extinct { opacity: 0.55; }
#speciesList li.open { border-color: var(--accent); }
#speciesList .row { display: flex; align-items: center; gap: 8px; }
#speciesList i { width: 14px; height: 14px; border-radius: 50%; flex: none; }
#speciesList b { flex: 1; font-size: 14px; }
#speciesList .st { font-size: 12.5px; color: var(--accent); }
#speciesList .sub { font-size: 11.5px; color: var(--dim); margin-top: 3px; }
#speciesList .genes { margin-top: 8px; }
.export { width: 100%; margin-top: 8px; }
#goalList li { display: flex; gap: 10px; align-items: center; padding: 8px 4px; opacity: 0.55; border-bottom: 1px solid var(--line); }
#goalList li.on { opacity: 1; }
#goalList span { font-size: 22px; }
#goalList b { font-size: 14px; }
#goalList small { display: block; font-size: 12px; color: var(--dim); margin-top: 2px; }
.chart { width: 100%; height: 130px; display: block; border-radius: 10px; }
.chart.tall { height: 240px; }
.chart.mid { height: 150px; }

.seg { display: flex; gap: 4px; margin: 6px 0 8px; flex-wrap: wrap; }
.seg button { flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 7px 4px; font-size: 12.5px; white-space: nowrap; }
.seg button.on { border-color: var(--accent); background: rgba(123, 224, 192, 0.15); }
#zoneInfo .zone { border: 1px solid var(--line); border-radius: 10px; padding: 7px 9px; margin: 5px 0; font-size: 12px; background: var(--panel); }
#zoneInfo .zone b { font-size: 12.5px; }
#zoneInfo .chips { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 4px; color: var(--dim); }
#zoneInfo i, .sw { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 3px; vertical-align: 0; }
#causes .cause { display: grid; grid-template-columns: 52px 1fr 38px; gap: 8px; align-items: center; font-size: 12px; margin: 3px 0; }
#causes .gb div { background: linear-gradient(90deg, #ff9a6b, #ff5c7a); }
#timeline { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow: auto; }
#timeline li { display: grid; grid-template-columns: 58px 20px 1fr; gap: 4px; font-size: 12px; padding: 5px 2px; border-bottom: 1px solid var(--line); cursor: pointer; }
#timeline li:hover { background: var(--panel); }
#timeline time { color: var(--dim); font-variant-numeric: tabular-nums; }
#timeline li.extinct span:last-child { color: #ff9a9a; }
#timeline li.challenge span:last-child { color: #ffd27a; }
#timeline li.species span:last-child { color: var(--accent); }
#replay { position: absolute; left: 22px; right: 22px; bottom: 22px; display: flex; align-items: center; gap: 8px; background: rgba(6, 20, 32, 0.92); border: 1px solid #ffd27a; border-radius: 14px; padding: 8px 12px; font-size: 13px; }
#replay input { flex: 1; accent-color: #ffd27a; min-width: 60px; }
#replay button { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 9px; }
#replay span { font-variant-numeric: tabular-nums; color: #ffe8a8; white-space: nowrap; }
body.replaying .tools, body.replaying #info { display: none; }
#toasts { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; z-index: 10; }
.toast { background: rgba(6, 20, 32, 0.94); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; font-size: 13.5px; animation: pop 0.3s ease-out; transition: opacity 0.4s; white-space: nowrap; }
.toast.gold { border-color: #ffd27a; color: #fff1c9; }
.toast.out { opacity: 0; }
@keyframes pop { from { opacity: 0; transform: translateY(-8px); } }

@media (max-width: 900px) {
  main { grid-template-columns: minmax(0, 1fr); align-content: start; flex: none; }
  .stage { min-height: auto; }
  .stage { height: auto; padding: 8px; }
  #tank { aspect-ratio: 10 / 7; height: auto; }
  .tools { top: 16px; left: 16px; }
  .tools button { width: 44px; height: 44px; font-size: 17px; }
  .tools button small { font-size: 9.5px; white-space: nowrap; }
  #panel { border-left: none; border-top: 1px solid var(--line); }
  .pane { overflow: visible; }
  #info { position: static; width: auto; margin: 8px 0 0; }
  #replay { position: static; margin-top: 8px; flex-wrap: wrap; }
  #replay b { display: none; }
}
@media (max-width: 520px) {
  #top { gap: 8px 12px; padding: 8px 10px; }
  h1 { font-size: 15px; }
  .stats { gap: 9px; font-size: 12.5px; order: 3; width: 100%; }
  .ctrl button { height: 32px; min-width: 40px; }
  .toast { white-space: normal; text-align: center; max-width: calc(100vw - 32px); }
}
