:root {
  --bg-0: #07090f;
  --bg-1: #0f1623;
  --panel: rgba(14, 20, 34, 0.92);
  --panel-soft: rgba(10, 16, 28, 0.72);
  --line: #2d415f;
  --line-bright: #5ee8ff;
  --text: #e6f7ff;
  --muted: #9bb4c9;
  --accent: #2de2c4;
  --accent-2: #5ee8ff;
  --warn: #ffd35f;
  --ok: #7dff7a;
  --danger: #ff6f91;
  --pixel: "Press Start 2P", "DungGeunMo", "Courier New", monospace;
  --body: "Pretendard", "Noto Sans KR", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 20% 10%, rgba(45, 226, 196, 0.13), transparent 38%),
    radial-gradient(circle at 80% 80%, rgba(94, 232, 255, 0.13), transparent 42%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
  color: var(--text);
  font-family: var(--body);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 28px 28px;
  opacity: 0.4;
}

.app {
  max-width: 1300px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 14px;
}

.start-scene {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 35%, rgba(26, 67, 102, 0.45), rgba(4, 8, 16, 0.94));
}

.start-scene.active {
  display: flex;
}

.start-card {
  width: min(520px, calc(100% - 24px));
  padding: 20px;
  text-align: center;
}

.start-card h1 {
  margin: 0 0 12px;
  font-family: var(--pixel);
  color: var(--accent-2);
}

.start-btn {
  margin-top: 10px;
  min-width: 180px;
  font-size: 1rem;
  font-weight: 700;
}

.contextual-hint {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(20px);
  z-index: 45;
  padding: 10px 14px;
  border: 1px solid #5ee8ff;
  border-radius: 8px;
  background: rgba(8, 18, 32, 0.92);
  color: #d7f6ff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.contextual-hint.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.story-scene {
  position: fixed;
  inset: 0;
  display: none;
  align-items: flex-end;
  z-index: 20;
}

.story-scene.active {
  display: flex;
}

.story-backdrop {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(5, 9, 17, 0.35), rgba(5, 9, 17, 0.88));
  animation: fadeIn 0.35s ease;
}

.story-art {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.story-bg-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 1;
  filter: saturate(1.1) contrast(1.08);
}

.story-portrait {
  position: absolute;
  bottom: 116px;
  width: clamp(150px, 16vw, 230px);
  image-rendering: pixelated;
  transform: translateY(0);
  transition: filter 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
  opacity: 0.78;
  filter: brightness(0.72) saturate(0.7);
}

.story-portrait.active {
  opacity: 1;
  filter: brightness(1) saturate(1.05) drop-shadow(0 0 12px rgba(94, 232, 255, 0.45));
  transform: translateY(-3px);
}

.portrait-left {
  left: clamp(12px, 4vw, 48px);
}

.portrait-right {
  right: clamp(12px, 4vw, 48px);
}

.story-card {
  position: relative;
  width: min(980px, calc(100% - 20px));
  margin: 0 auto 20px;
  background: rgba(9, 14, 26, 0.96);
  border: 2px solid var(--line-bright);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  padding: 14px;
  border-radius: 6px;
  animation: slideUp 0.35s ease;
}

.story-stage-label {
  margin: 0;
  color: var(--warn);
  font-size: 0.78rem;
  font-family: var(--pixel);
}

.story-speaker {
  margin: 8px 0 0;
  color: var(--accent);
  font-weight: 700;
}

.story-line {
  margin: 6px 0 0;
  line-height: 1.55;
  min-height: 46px;
}

.goal-keyword {
  font-weight: 800;
  color: var(--warn);
}

.story-controls {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.story-next {
  color: var(--muted);
  font-size: 0.84rem;
  margin-left: auto;
}

.lab-scene {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  display: grid;
  gap: 14px;
}

.lab-scene > section {
  position: relative;
  z-index: 3;
}

.world-bg {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.world-layer {
  position: absolute;
  inset: -3%;
  width: 106%;
  height: 106%;
  object-fit: cover;
  image-rendering: pixelated;
  transform: translate3d(0, 0, 0) scale(1.04);
}

.world-back {
  opacity: 0.36;
}

.world-mid {
  opacity: 0.44;
}

.world-front {
  opacity: 0.56;
}

.world-lamp {
  position: absolute;
  right: 11%;
  top: 10%;
  width: 14px;
  height: 14px;
  background: #ffd676;
  box-shadow: 0 0 12px #ffd676;
  image-rendering: pixelated;
  animation: lampBlink 2.6s steps(2) infinite;
}

.world-steam {
  position: absolute;
  left: 20%;
  bottom: 34%;
  width: 120px;
  height: 90px;
  background:
    radial-gradient(circle at 30% 80%, rgba(190, 230, 255, 0.2) 0 8px, transparent 9px),
    radial-gradient(circle at 50% 55%, rgba(190, 230, 255, 0.18) 0 7px, transparent 8px),
    radial-gradient(circle at 66% 30%, rgba(190, 230, 255, 0.14) 0 6px, transparent 7px);
  image-rendering: pixelated;
  animation: steamFloat 5s linear infinite;
}

.world-dust {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle, rgba(196, 235, 255, 0.15) 1px, transparent 1px),
    radial-gradient(circle, rgba(196, 235, 255, 0.11) 1px, transparent 1px);
  background-size: 46px 46px, 72px 72px;
  background-position: 0 0, 14px 18px;
  animation: dustDrift 12s linear infinite;
}

.pixel-panel {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03), 0 12px 30px rgba(0, 0, 0, 0.33);
}

.hud {
  display: grid;
  grid-template-columns: 2fr 3fr;
  gap: 12px;
  padding: 12px;
}

.hud-left h1 {
  margin: 0;
  font-family: var(--pixel);
  font-size: clamp(0.9rem, 2vw, 1.2rem);
  line-height: 1.5;
}

.story {
  margin-top: 8px;
  color: var(--muted);
  min-height: 40px;
}

.hud-right {
  display: grid;
  grid-template-columns: repeat(5, minmax(86px, 1fr));
  gap: 8px;
}

.metric {
  padding: 8px;
  border: 1px solid #314261;
  border-radius: 6px;
  background: var(--panel-soft);
}

.metric .label {
  font-size: 0.68rem;
  font-family: var(--pixel);
  color: var(--muted);
}

.metric .value {
  margin-top: 5px;
  font-weight: 700;
  font-size: 1.08rem;
}

.pixel-btn,
.action-btn {
  background: linear-gradient(180deg, rgba(18, 30, 47, 0.95), rgba(12, 21, 33, 0.95));
  color: var(--text);
  border: 2px solid #37507a;
  border-radius: 6px;
  font-family: var(--body);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.console-tools {
  margin-top: 10px;
  display: grid;
}
.notebook-hint {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.86rem;
}
.assistant-notebook {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  border: 1px solid #44618d;
  border-radius: 6px;
  background: rgba(8, 14, 26, 0.9);
  color: var(--text);
  padding: 10px;
  line-height: 1.45;
  font-family: "Consolas", "Courier New", monospace;
}

.assistant-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 10px;
}

.evidence-board {
  display: grid;
  gap: 8px;
}

.board-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.evidence-card {
  position: relative;
}

.evidence-card.selected {
  border-color: var(--line-bright);
  box-shadow: 0 0 0 1px rgba(94, 232, 255, 0.35);
}

.evidence-visual {
  margin-top: 6px;
  font-size: 0.75rem;
  color: #c9e9ff;
}

.principle-btn {
  margin-top: 6px;
  width: 100%;
}

.codex-wrap {
  margin-top: 8px;
}

.codex-wrap h3 {
  margin: 0 0 6px;
  font-size: 0.75rem;
  font-family: var(--pixel);
  color: var(--accent);
}

.science-check {
  margin-top: 8px;
  border: 1px solid #3d5a84;
  border-radius: 6px;
  padding: 8px;
  background: rgba(8, 14, 24, 0.82);
}

.science-question {
  margin: 0 0 8px;
  color: #d8ebff;
}

.science-options {
  display: grid;
  gap: 6px;
}

.pixel-btn:hover,
.action-btn:hover {
  transform: translateY(-1px);
  border-color: var(--line-bright);
  box-shadow: 0 0 0 1px rgba(94, 232, 255, 0.25);
}

.pixel-btn:active,
.action-btn:active {
  transform: translateY(1px);
}

.pixel-btn:disabled,
.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.main-grid {
  display: grid;
  grid-template-columns: 1fr 1.1fr 0.8fr;
  gap: 12px;
}

.panel {
  padding: 12px;
}

.panel h2 {
  margin: 0 0 10px;
  font-family: var(--pixel);
  color: var(--accent-2);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.actions {
  display: grid;
  gap: 8px;
}

.action-btn {
  text-align: left;
  padding: 10px;
}

.action-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.action-cost {
  color: var(--warn);
  font-family: var(--pixel);
  font-size: 0.68rem;
}

.action-desc {
  color: var(--muted);
  font-size: 0.83rem;
}

.result-stage {
  min-height: 248px;
  border: 2px solid #30425c;
  border-radius: 8px;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(8, 14, 24, 0.9) 0 6px,
      rgba(10, 16, 28, 0.92) 6px 12px
    );
  position: relative;
  overflow: hidden;
  image-rendering: pixelated;
}

.tube-visual {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.tube-visual::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 16%;
  width: 160px;
  height: 190px;
  transform: translateX(-50%);
  border: 2px solid rgba(125, 166, 206, 0.5);
  border-radius: 10px 10px 18px 18px;
  background: rgba(20, 40, 56, 0.2);
}

.tube-liquid {
  position: absolute;
  left: 50%;
  bottom: 43px;
  width: 140px;
  height: 70px;
  transform: translateX(-50%);
  border-radius: 2px;
  image-rendering: pixelated;
  background: rgba(64, 145, 205, 0.62);
  transition: background 0.35s ease, height 0.35s ease;
}

.tube-flame,
.tube-precipitate,
.tube-gas {
  position: absolute;
  opacity: 0;
}

.tube-flame.active {
  opacity: 1;
  left: 50%;
  top: 34px;
  width: 80px;
  height: 120px;
  transform: translateX(-50%);
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 247, 191, 0.96) 0 8px,
      rgba(255, 207, 85, 0.92) 8px 16px,
      rgba(255, 147, 51, 0.55) 16px 24px,
      rgba(255, 147, 51, 0) 24px 32px
    );
  filter: drop-shadow(0 0 14px rgba(255, 206, 99, 0.62));
  image-rendering: pixelated;
  animation: flameFlicker 0.2s steps(2) infinite alternate;
}

.tube-precipitate.active {
  opacity: 1;
  left: 50%;
  bottom: 38px;
  width: 136px;
  height: 36px;
  transform: translateX(-50%);
  border-radius: 0;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(211, 236, 255, 0.88) 0 6px,
      rgba(170, 206, 255, 0.86) 6px 12px
    );
  image-rendering: pixelated;
  animation: precipitateRise 0.35s ease;
}

.tube-gas.active {
  opacity: 1;
  left: 50%;
  top: 44px;
  width: 150px;
  height: 140px;
  transform: translateX(-50%);
}

.tube-gas.active::before,
.tube-gas.active::after {
  content: "";
  position: absolute;
  border-radius: 1px;
  background: rgba(201, 255, 242, 0.8);
  image-rendering: pixelated;
  animation: bubbleRise 1.1s steps(3) infinite;
}

.tube-gas.active::before {
  width: 16px;
  height: 16px;
  left: 34px;
  bottom: 0;
}

.tube-gas.active::after {
  width: 12px;
  height: 12px;
  right: 28px;
  bottom: 14px;
  animation-delay: 0.3s;
}

.result-text {
  margin-top: 10px;
  line-height: 1.5;
}

.log {
  margin-top: 10px;
  max-height: 160px;
  overflow: auto;
  border-top: 1px dashed #385074;
  padding-top: 8px;
}

.log-item {
  color: var(--muted);
  font-size: 0.84rem;
  border-bottom: 1px dashed rgba(88, 114, 155, 0.35);
  padding: 6px 0;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.drop-zone {
  min-height: 190px;
  border: 2px dashed #3a5072;
  border-radius: 8px;
  padding: 8px;
  background: rgba(10, 16, 30, 0.66);
}

.drop-zone h3 {
  margin: 0 0 8px;
  font-size: 0.8rem;
  font-family: var(--pixel);
  color: var(--accent);
}

.evidence-card {
  background: rgba(12, 23, 40, 0.95);
  border: 1px solid #456089;
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 8px;
  cursor: grab;
  animation: fadeIn 0.25s ease;
}

.evidence-card img {
  width: 100%;
  height: 64px;
  object-fit: cover;
  border-radius: 4px;
  margin-top: 5px;
}

.evidence-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: #a8d8ff;
  font-size: 0.8rem;
}

.tag-select,
.player-tools input {
  width: 100%;
  padding: 7px;
  border-radius: 6px;
  border: 1px solid #44618d;
  background: rgba(6, 13, 25, 0.95);
  color: var(--text);
}

.connect-tools,
.controls {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 6px;
}

.controls {
  grid-template-columns: 1fr 1fr;
}

.connections {
  margin-top: 8px;
  border-top: 1px dashed #3e5882;
  padding-top: 8px;
  color: var(--muted);
  max-height: 110px;
  overflow: auto;
  font-size: 0.84rem;
}

.deduce-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.ion-option {
  border: 1px solid #365176;
  border-radius: 6px;
  padding: 6px;
  display: flex;
  gap: 8px;
  background: rgba(8, 14, 26, 0.8);
}

.player-tools {
  margin-top: 8px;
  display: grid;
  gap: 6px;
}

.status {
  margin-top: 8px;
  min-height: 24px;
}

.status.ok {
  color: var(--ok);
}

.status.error {
  color: var(--danger);
}

.badge {
  border: 1px solid rgba(255, 211, 95, 0.6);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--warn);
  font-size: 0.68rem;
  font-family: var(--pixel);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes flameFlicker {
  from {
    transform: translateX(-50%) scale(0.96) rotate(-2deg);
  }
  to {
    transform: translateX(-50%) scale(1.05) rotate(2deg);
  }
}

@keyframes precipitateRise {
  from {
    height: 4px;
    opacity: 0.4;
  }
  to {
    height: 36px;
    opacity: 1;
  }
}

@keyframes bubbleRise {
  from {
    transform: translateY(0);
    opacity: 0.9;
  }
  to {
    transform: translateY(-95px);
    opacity: 0;
  }
}

@keyframes lampBlink {
  0%,
  100% {
    opacity: 0.86;
  }
  45% {
    opacity: 0.58;
  }
}

@keyframes steamFloat {
  from {
    transform: translateY(0);
    opacity: 0.42;
  }
  to {
    transform: translateY(-24px);
    opacity: 0.15;
  }
}

@keyframes dustDrift {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(-24px);
  }
}

@media (max-width: 1080px) {
  .hud,
  .main-grid {
    grid-template-columns: 1fr;
  }

  .hud-right {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

}

@media (max-width: 740px) {
  .assistant-grid,
  .board-grid,
  .deduce-grid,
  .connect-tools,
  .controls {
    grid-template-columns: 1fr;
  }

  .story-card {
    margin: 0 10px 14px;
    width: auto;
  }

  .story-portrait {
    bottom: 140px;
    width: 126px;
  }

}
