:root {
  color-scheme: dark;
  --bg: #05060c;
  --panel: rgba(14, 16, 28, 0.84);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f4f2ff;
  --muted: #9b9caf;
  --violet: #9f7cff;
  --cyan: #6ee7ff;
  --warm: #ffd28d;
  --danger: #ff7b91;
  --ok: #7ee2a8;
  --radius: 22px;
  font-family: Inter, Pretendard, "Noto Sans KR", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  background:
    radial-gradient(circle at 12% 8%, rgba(96, 76, 180, .16), transparent 34%),
    radial-gradient(circle at 84% 8%, rgba(54, 146, 170, .13), transparent 31%),
    linear-gradient(150deg, #05060c, #080913 48%, #04050a);
  overflow-x: hidden;
}
button, input, select { font: inherit; }
button { color: inherit; }
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }

.app-shell { min-height: 100vh; max-width: 1800px; margin: 0 auto; padding: 20px 24px 14px; }
.topbar { display: flex; justify-content: space-between; align-items: end; gap: 18px; margin-bottom: 16px; }
.eyebrow { margin: 0 0 5px; color: var(--cyan); letter-spacing: .18em; font-size: 11px; font-weight: 800; }
h1 { margin: 0; font-size: clamp(28px, 4vw, 47px); letter-spacing: -.055em; line-height: .95; }
.top-actions { display: flex; gap: 8px; }
.icon-button, .secondary-button {
  border: 1px solid var(--line-strong); background: rgba(255,255,255,.045); border-radius: 12px; padding: 10px 13px; cursor: pointer;
  transition: .2s ease;
}
.icon-button:hover, .secondary-button:hover { border-color: rgba(159,124,255,.55); background: rgba(159,124,255,.09); transform: translateY(-1px); }

.workspace { display: grid; grid-template-columns: minmax(0, 1.68fr) minmax(390px, .76fr); gap: 16px; min-height: calc(100vh - 132px); }
.stage-panel, .control-panel { border: 1px solid var(--line); background: var(--panel); box-shadow: 0 25px 70px rgba(0,0,0,.32); backdrop-filter: blur(18px); }
.stage-panel { position: sticky; top: 16px; align-self: start; height: calc(100vh - 118px); min-height: 620px; border-radius: var(--radius); overflow: hidden; }
#universeCanvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.stage-panel::after { content:""; position:absolute; inset:0; pointer-events:none; box-shadow: inset 0 0 120px rgba(0,0,0,.6), inset 0 0 20px rgba(120,100,255,.06); }
.stage-overlay { position: absolute; z-index: 3; display: flex; align-items: center; gap: 9px; color: #dcd9f0; font-size: 12px; letter-spacing: .02em; }
.top-left { top: 18px; left: 20px; }
.top-right { top: 18px; right: 20px; }
.compact-help { color: var(--muted); padding: 8px 10px; border: 1px solid var(--line); background: rgba(5,6,12,.54); border-radius: 10px; backdrop-filter: blur(8px); }
.status-dot { width: 8px; height: 8px; background: var(--cyan); border-radius: 50%; box-shadow: 0 0 14px var(--cyan); }
.status-dot.running { background: var(--warm); box-shadow: 0 0 18px var(--warm); animation: pulse 1.4s infinite; }
.status-dot.paused { background: var(--danger); box-shadow: 0 0 14px var(--danger); }
@keyframes pulse { 50% { opacity: .45; transform: scale(.75); } }
.impact-card { position: absolute; z-index: 3; left: 20px; bottom: 79px; display: grid; gap: 4px; padding: 11px 13px; border: 1px solid var(--line); background: rgba(5,6,12,.64); border-radius: 12px; backdrop-filter: blur(10px); }
.impact-card span { color: var(--muted); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
.impact-card strong { font-size: 12px; }
.timeline { position:absolute; z-index:3; left:20px; right:20px; bottom:19px; }
.timeline-copy { display:flex; justify-content:space-between; margin-bottom:8px; font-size:11px; color:var(--muted); }
.timeline-copy span:first-child { color:var(--text); font-weight:700; }
.timeline-track { height:4px; border-radius:99px; overflow:hidden; background:rgba(255,255,255,.09); }
.timeline-fill { height:100%; width:0; background:linear-gradient(90deg,var(--violet),var(--cyan),var(--warm)); box-shadow:0 0 14px rgba(110,231,255,.5); transition:width .25s linear; }

.control-panel { border-radius: var(--radius); overflow: hidden; }
.panel-section { padding: 20px; border-bottom: 1px solid var(--line); }
.panel-section:last-child { border-bottom: 0; }
.section-heading { display:flex; gap:12px; align-items:flex-start; margin-bottom:17px; }
.section-heading.small { margin-bottom:13px; }
.step-badge { display:grid; place-items:center; flex:0 0 auto; width:34px; height:34px; border:1px solid rgba(159,124,255,.38); border-radius:11px; color:#cfc0ff; font-size:11px; background:rgba(159,124,255,.08); }
.section-heading h2 { margin:0 0 4px; font-size:16px; letter-spacing:-.02em; }
.section-heading p { margin:0; color:var(--muted); font-size:11px; line-height:1.45; }

.condition-toolbar { display:grid; grid-template-columns:1fr auto; align-items:center; gap:9px; margin-bottom:7px; }
.randomize-button { border-color:rgba(110,231,255,.28); background:linear-gradient(110deg,rgba(159,124,255,.13),rgba(110,231,255,.08)); font-weight:700; }
.lock-summary { color:var(--muted); font-size:10px; white-space:nowrap; }
.impact-random-option { display:flex; align-items:center; gap:7px; color:var(--muted); font-size:10px; margin:0 0 12px; cursor:pointer; }
.impact-random-option input { accent-color:var(--violet); }
.preset-row { display:grid; grid-template-columns:auto 1fr; align-items:center; gap:8px; padding:10px 0 6px; border-top:1px solid rgba(255,255,255,.055); }
.preset-row label { color:var(--muted); font-size:11px; }

.control-row { position:relative; display:grid; grid-template-columns:1fr auto 31px; gap:3px 9px; padding:10px 0; }
.control-copy { display:grid; gap:2px; }
.control-row b { font-size:12px; font-weight:650; }
.control-row small { color:var(--muted); font-size:10px; line-height:1.35; }
.control-row output { align-self:start; padding-top:1px; font-size:11px; color:var(--cyan); font-variant-numeric:tabular-nums; }
.control-row input[type="range"] { grid-column:1 / -1; width:100%; accent-color:var(--violet); height:16px; }
.control-row.locked { opacity:.78; }
.control-row.locked output { color:var(--warm); }
.lock-button { width:29px; height:27px; display:grid; place-items:center; border:1px solid var(--line); border-radius:9px; background:rgba(255,255,255,.035); cursor:pointer; font-size:13px; line-height:1; transition:.18s ease; }
.lock-button:hover { border-color:rgba(159,124,255,.55); }
.lock-button[aria-pressed="true"] { border-color:rgba(255,210,141,.45); background:rgba(255,210,141,.08); box-shadow:0 0 14px rgba(255,210,141,.08); }
input[type="range"] { appearance:none; background:transparent; }
input[type="range"]::-webkit-slider-runnable-track { height:3px; background:linear-gradient(90deg,rgba(159,124,255,.55),rgba(110,231,255,.55)); border-radius:99px; }
input[type="range"]::-webkit-slider-thumb { appearance:none; width:14px; height:14px; border-radius:50%; background:#f5f2ff; margin-top:-5.5px; box-shadow:0 0 12px rgba(159,124,255,.7); }

.seed-row { display:grid; grid-template-columns:auto 1fr auto; align-items:center; gap:8px; margin:13px 0 5px; }
.seed-row label { color:var(--muted); font-size:11px; }
.seed-row input, select, .speed-number-wrap input { min-width:0; border:1px solid var(--line-strong); background:rgba(0,0,0,.24); color:var(--text); border-radius:10px; padding:9px 10px; outline:none; }
.seed-row input:focus, select:focus, .speed-number-wrap input:focus { border-color:rgba(110,231,255,.6); }
.field-help { margin:5px 0 11px; color:#77798c; font-size:9.5px; line-height:1.48; }
.condition-memory-row { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-bottom:10px; }

.primary-button { position:relative; isolation:isolate; width:100%; overflow:hidden; border:1px solid rgba(195,177,255,.65); border-radius:13px; background:linear-gradient(115deg,#6f52c9,#7c67dc 44%,#4a9bb0); padding:13px 16px; font-weight:800; letter-spacing:.02em; cursor:pointer; box-shadow:0 9px 28px rgba(91,67,174,.28); }
.primary-button:hover { filter:brightness(1.1); transform:translateY(-1px); }
.button-glow { position:absolute; z-index:-1; width:80px; height:150px; background:rgba(255,255,255,.28); filter:blur(18px); transform:rotate(25deg); top:-62px; left:-100px; transition:left .5s ease; }
.primary-button:hover .button-glow { left:115%; }
.transport-row { display:grid; grid-template-columns:1fr 1fr minmax(116px,.9fr); gap:8px; margin-top:9px; align-items:stretch; }
.secondary-button { font-size:11px; padding:9px 10px; }
.secondary-button:disabled { opacity:.4; cursor:not-allowed; transform:none; }
.secondary-button.danger:hover { border-color:rgba(255,123,145,.5); background:rgba(255,123,145,.08); }
.speed-control { display:grid; grid-template-columns:auto 1fr; align-items:center; gap:6px; color:var(--muted); font-size:10px; }
.speed-number-wrap { display:flex; align-items:center; border:1px solid var(--line-strong); background:rgba(0,0,0,.24); border-radius:10px; overflow:hidden; }
.speed-number-wrap b { padding-left:8px; color:var(--cyan); }
.speed-number-wrap input { width:68px; border:0; border-radius:0; padding:8px 7px 8px 3px; background:transparent; font-size:11px; }
.speed-presets { display:grid; grid-template-columns:repeat(9,1fr); gap:4px; margin-top:7px; }
.speed-presets button { padding:6px 2px; border:1px solid rgba(255,255,255,.08); border-radius:8px; background:rgba(255,255,255,.025); color:var(--muted); font-size:9px; cursor:pointer; }
.speed-presets button:hover, .speed-presets button.active { color:var(--text); border-color:rgba(110,231,255,.42); background:rgba(110,231,255,.07); }

.stats-grid { display:grid; grid-template-columns:repeat(3,1fr); border:1px solid var(--line); border-radius:14px; overflow:hidden; }
.stats-grid article { min-width:0; padding:11px 10px; border-right:1px solid var(--line); border-bottom:1px solid var(--line); background:rgba(255,255,255,.018); }
.stats-grid article:nth-child(3n) { border-right:0; }
.stats-grid article:nth-child(n+4) { border-bottom:0; }
.stats-grid span { display:block; color:var(--muted); font-size:9px; margin-bottom:5px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.stats-grid strong { display:block; font-size:15px; letter-spacing:-.02em; font-variant-numeric:tabular-nums; }
.stats-grid small { display:block; margin-top:5px; color:#6f7183; font-size:8px; line-height:1.35; }
.interpretation-card { display:grid; gap:5px; margin-top:12px; padding:12px 13px; border:1px solid rgba(110,231,255,.13); border-radius:13px; background:linear-gradient(115deg,rgba(110,231,255,.045),rgba(159,124,255,.045)); }
.interpretation-card > span { color:var(--cyan); font-size:9px; letter-spacing:.1em; }
.interpretation-card strong { font-size:12px; line-height:1.4; }
.interpretation-card p { margin:0; color:var(--muted); font-size:10px; line-height:1.5; }
.beginner-guide { margin-top:9px; border:1px solid var(--line); border-radius:12px; background:rgba(0,0,0,.12); }
.beginner-guide summary { padding:10px 12px; color:#c9c6d7; font-size:10px; cursor:pointer; }
.beginner-guide p { margin:0; padding:0 12px 10px; color:var(--muted); font-size:9.5px; line-height:1.55; }
.chart-wrap { position:relative; margin-top:12px; border:1px solid var(--line); background:rgba(0,0,0,.19); border-radius:14px; padding:8px; }
#historyCanvas { width:100%; height:96px; display:block; }
.chart-legend { display:flex; justify-content:flex-end; gap:11px; color:var(--muted); font-size:9px; padding:2px 5px 0; }
.chart-legend span { display:flex; align-items:center; gap:4px; }
.chart-legend i { width:9px; height:2px; display:block; }
.legend-temp { background:var(--warm); }
.legend-structure { background:var(--cyan); }
.log-section { min-height:160px; }
.event-log { list-style:none; margin:0; padding:0; display:grid; gap:8px; max-height:190px; overflow:auto; scrollbar-width:thin; }
.event-log li { display:grid; grid-template-columns:54px 1fr; gap:8px; padding:9px 10px; border-radius:10px; background:rgba(255,255,255,.025); border:1px solid rgba(255,255,255,.045); font-size:10px; line-height:1.4; }
.event-log time { color:var(--cyan); font-variant-numeric:tabular-nums; }
.event-log span { color:#c8c7d3; }
footer { display:flex; justify-content:space-between; gap:15px; padding:12px 4px 0; color:#666879; font-size:9px; letter-spacing:.03em; }

@media (max-width: 1120px) {
  .app-shell { padding:14px; }
  .workspace { grid-template-columns:1fr; }
  .stage-panel { position:relative; top:auto; height:min(72vh,720px); min-height:520px; }
  .control-panel { display:grid; grid-template-columns:1fr 1fr; }
  .intro-section { grid-row:span 2; }
  .log-section { border-bottom:0; }
}
@media (max-width: 760px) {
  .app-shell { padding:10px; }
  .topbar { align-items:center; margin:5px 2px 10px; }
  .eyebrow { font-size:9px; letter-spacing:.12em; }
  h1 { font-size:30px; }
  .icon-button { font-size:10px; padding:8px 9px; }
  .workspace { gap:10px; }
  .stage-panel { height:62vh; min-height:430px; border-radius:17px; }
  .compact-help { display:none; }
  .control-panel { display:block; border-radius:17px; }
  .panel-section { padding:17px; }
  .stats-grid strong { font-size:13px; }
  .speed-presets { grid-template-columns:repeat(5,1fr); }
  footer { display:grid; line-height:1.5; }
}
@media (max-width: 460px) {
  .top-actions { gap:5px; }
  .top-actions .icon-button { max-width:68px; white-space:normal; line-height:1.1; }
  .stage-panel { height:56vh; min-height:390px; }
  .top-left { left:13px; top:13px; }
  .impact-card { left:13px; bottom:68px; }
  .timeline { left:13px; right:13px; bottom:14px; }
  .transport-row { grid-template-columns:1fr 1fr; }
  .speed-control { grid-column:1 / -1; grid-template-columns:auto 1fr; }
  .speed-number-wrap input { width:100%; }
  .seed-row { grid-template-columns:auto 1fr; }
  .seed-row button { grid-column:1 / -1; }
  .stats-grid { grid-template-columns:repeat(2,1fr); }
  .stats-grid article:nth-child(3n) { border-right:1px solid var(--line); }
  .stats-grid article:nth-child(2n) { border-right:0; }
  .stats-grid article:nth-child(n+4) { border-bottom:1px solid var(--line); }
  .stats-grid article:nth-child(n+5) { border-bottom:0; }
}
