:root {
  color-scheme: dark;
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1d242c;
  --line: #2e3844;
  --text: #eef3f8;
  --muted: #9ba9b7;
  --cyan: #5fd7d8;
  --green: #70e08f;
  --red: #ff6d7a;
  --amber: #ffc857;
  --blue: #79a8ff;
  --violet: #b18cff;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", "Noto Sans KR", system-ui, sans-serif;
  background:
    radial-gradient(circle at 18% 8%, rgba(95, 215, 216, 0.15), transparent 28rem),
    linear-gradient(145deg, #11161d 0%, #0c0f13 54%, #111820 100%);
  color: var(--text);
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  width: min(1560px, calc(100% - 28px));
  margin: 0 auto;
  padding: 16px 0 24px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 18px;
  min-height: 168px;
  padding: 22px 24px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background:
    linear-gradient(110deg, rgba(16, 20, 27, 0.9), rgba(25, 36, 43, 0.72)),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.035) 0 1px, transparent 1px 78px),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.025) 0 1px, transparent 1px 78px);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero h1 {
  width: min(900px, 100%);
  margin: 0;
  font-size: clamp(28px, 3.8vw, 52px);
  line-height: 1.06;
  letter-spacing: 0;
}

.hero p:last-child {
  width: min(700px, 100%);
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 1fr));
  gap: 8px;
  min-width: 330px;
}

.hero-stats div,
.control-panel,
.simulation-panel,
.insight-card {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(22, 27, 34, 0.88);
  border-radius: 8px;
}

.hero-stats div {
  padding: 12px;
}

.hero-stats span {
  display: block;
  color: var(--text);
  font-size: 24px;
  font-weight: 800;
}

.hero-stats small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.workspace {
  display: grid;
  grid-template-columns: 260px minmax(500px, 1fr) 330px;
  gap: 12px;
  margin-top: 12px;
}

.control-panel,
.simulation-panel,
.insight-panel {
  min-width: 0;
}

.control-panel {
  padding: 16px;
}

.panel-header,
.sim-topbar,
.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

h2,
h3 {
  margin: 0;
}

h2 {
  font-size: 16px;
}

h3 {
  font-size: 14px;
}

#modeBadge,
.card-title span {
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
}

.field {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

select {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10151b;
  color: var(--text);
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #202832;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: rgba(95, 215, 216, 0.6);
}

button.primary {
  background: linear-gradient(135deg, #42c8ce, #70e08f);
  color: #071013;
  border: 0;
}

.sliders {
  display: grid;
  gap: 13px;
  margin-top: 18px;
}

.sliders label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.sliders span {
  display: flex;
  justify-content: space-between;
}

.sliders b {
  color: var(--text);
}

input[type="range"] {
  accent-color: var(--cyan);
  width: 100%;
}

.legend {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.legend div {
  display: flex;
  align-items: center;
  gap: 9px;
}

.legend i {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  display: inline-block;
}

.legend .start { background: var(--blue); }
.legend .goal { background: var(--green); }
.legend .pit { background: var(--red); }
.legend .wall { background: #394554; }
.legend .agent { background: var(--amber); border-radius: 50%; }

.simulation-panel {
  padding: 16px;
}

.sim-topbar {
  align-items: flex-start;
}

.sim-topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.episode-meter {
  flex: 0 0 auto;
  min-width: 96px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10151b;
  text-align: right;
}

.episode-meter span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.episode-meter strong {
  color: var(--green);
  font-size: 20px;
}

.grid-wrap {
  margin-top: 12px;
  display: grid;
  place-items: center;
}

.grid-world {
  display: grid;
  grid-template-columns: repeat(8, minmax(42px, 1fr));
  grid-template-rows: repeat(8, minmax(42px, 1fr));
  width: min(100%, 640px);
  aspect-ratio: 1;
  gap: 4px;
}

.cell {
  position: relative;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 6px;
  background: linear-gradient(145deg, #182029, #11171e);
  overflow: hidden;
}

.cell.wall {
  background: repeating-linear-gradient(135deg, #2b3541 0 8px, #222a34 8px 16px);
}

.cell.goal {
  box-shadow: inset 0 0 0 2px rgba(112, 224, 143, 0.8);
}

.cell.pit {
  box-shadow: inset 0 0 0 2px rgba(255, 109, 122, 0.72);
}

.cell.start {
  box-shadow: inset 0 0 0 2px rgba(121, 168, 255, 0.76);
}

.cell.visited::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(95, 215, 216, 0.08);
}

.value {
  position: absolute;
  left: 6px;
  top: 5px;
  color: rgba(238, 243, 248, 0.86);
  font-size: clamp(9px, 0.95vw, 12px);
  font-weight: 800;
}

.arrow {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.74);
  font-size: clamp(17px, 2vw, 28px);
  font-weight: 900;
}

.reward-label {
  position: absolute;
  right: 6px;
  bottom: 5px;
  color: var(--muted);
  font-size: clamp(9px, 1vw, 12px);
  font-weight: 800;
}

.agent-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 36%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff2b4, var(--amber) 42%, #f08a3e 100%);
  box-shadow: 0 0 28px rgba(255, 200, 87, 0.55);
  z-index: 4;
}

.insight-panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.insight-card {
  padding: 14px;
}

canvas {
  display: block;
  width: 100%;
  margin-top: 8px;
}

.event-log {
  display: grid;
  gap: 8px;
  min-height: 128px;
  max-height: 170px;
  margin: 10px 0 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.event-log li {
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  background: #11171e;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.event-log b {
  color: var(--text);
}

.explanation p {
  color: var(--muted);
  line-height: 1.5;
  font-size: 13px;
}

.formula {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10151b;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
  overflow-x: auto;
}

@media (max-width: 1220px) {
  .workspace {
    grid-template-columns: 250px minmax(0, 1fr);
  }

  .insight-panel {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 18px, 720px);
    padding-top: 9px;
  }

  .hero {
    grid-template-columns: 1fr;
    padding: 18px;
  }

  .hero-stats,
  .workspace,
  .insight-panel {
    grid-template-columns: 1fr;
  }

  .hero-stats {
    min-width: 0;
  }

  .grid-world {
    gap: 2px;
  }

  .cell {
    border-radius: 6px;
  }
}
