/* ==========================================================================
   🐷 ลูกหมู 3 ตัว: นักคราฟต์สายโค้ด (Coding & Crafting)
   Dark RPG Glassmorphism Theme — Nisit Zombie Visual Standard
   ========================================================================== */

:root {
  --bg-deep: #080c16;
  --bg-surface: #0f172a;
  --bg-card: rgba(18, 26, 44, 0.92);
  --bg-card-hover: rgba(26, 38, 64, 0.95);
  --border-card: rgba(251, 191, 36, 0.28);
  --border-card-hover: rgba(251, 191, 36, 0.65);
  --glow-gold: rgba(245, 158, 11, 0.28);
  --glow-emerald: rgba(16, 185, 129, 0.35);

  --gold-300: #fde68a;
  --gold-400: #fbbf24;
  --gold-500: #f59e0b;
  --gold-600: #d97706;

  --emerald-400: #34d399;
  --emerald-500: #10b981;
  --emerald-600: #059669;

  --cyan-400: #38bdf8;
  --purple-400: #c084fc;
  --rose-400: #fb7185;
  --rose-500: #f43f5e;

  --text-main: #f8fafc;
  --text-body: #cbd5e1;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --border-radius: 16px;
  --font-thai: 'Kanit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Fira Code', ui-monospace, SFMono-Regular, Menlo, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-thai);
  background-color: var(--bg-deep);
  background-image: 
    radial-gradient(ellipse at 50% 0%, rgba(16, 185, 129, 0.22) 0%, transparent 60%),
    radial-gradient(ellipse at 85% 80%, rgba(245, 158, 11, 0.12) 0%, transparent 50%),
    radial-gradient(circle at 15% 75%, rgba(56, 189, 248, 0.08) 0%, transparent 40%);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  max-width: 1320px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header */
.app-header {
  background: var(--bg-card);
  padding: 12px 22px;
  border-radius: var(--border-radius);
  border: 1.5px solid var(--border-card);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(14px);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.game-logo {
  font-size: 2rem;
  background: linear-gradient(135deg, rgba(244, 63, 94, 0.25), rgba(245, 158, 11, 0.25));
  border: 1.5px solid var(--rose-400);
  border-radius: 12px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(244, 63, 94, 0.35);
}

.header-titles h1 {
  font-size: 1.35rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.2px;
}

.subtitle {
  font-size: 0.86rem;
  color: var(--text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-home {
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.35);
  color: var(--gold-300);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.88rem;
  padding: 8px 14px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.btn-home:hover {
  background: rgba(251, 191, 36, 0.22);
  color: #fff;
  transform: translateY(-1px);
}

.level-badge {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(217, 119, 6, 0.3));
  color: var(--gold-300);
  font-weight: 700;
  font-size: 0.88rem;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--gold-400);
  box-shadow: 0 2px 8px var(--glow-gold);
}

.btn-icon {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn-secondary {
  background: rgba(168, 85, 247, 0.15);
  color: #e9d5ff;
  border: 1px solid rgba(168, 85, 247, 0.35);
  padding: 8px 14px;
  border-radius: 10px;
  font-family: var(--font-thai);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-secondary:hover {
  background: rgba(168, 85, 247, 0.25);
  color: #fff;
  transform: translateY(-1px);
}

/* Main Content Dual Pane */
.main-content {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(360px, 0.95fr);
  gap: 18px;
  align-items: start;
}

/* Left Section: Game Arena */
.game-section {
  background: var(--bg-card);
  padding: 16px;
  border-radius: var(--border-radius);
  border: 1.5px solid var(--border-card);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stage-info-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(10, 15, 28, 0.75);
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid rgba(251, 191, 36, 0.25);
}

.mission-box {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  color: var(--gold-300);
}

.mission-tag {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.74rem;
  padding: 3px 8px;
  border-radius: 6px;
}

.lives-box {
  font-weight: 700;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #fff;
}

/* Canvas Viewport */
.canvas-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 600 / 460;
  border-radius: 14px;
  overflow: hidden;
  background: #090e18;
  border: 2px solid rgba(251, 191, 36, 0.3);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.8), 0 8px 24px rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

.game-banner {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--gold-400);
  color: #fff;
  padding: 8px 20px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.92rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  animation: fadeInDown 0.25s ease;
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Controls Bar */
.controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(10, 15, 28, 0.65);
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.hint-text {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.hint-text strong {
  color: var(--gold-300);
}

.btn-action {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 6px 14px;
  border-radius: 8px;
  font-family: var(--font-thai);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-action:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

/* D-Pad Controls for Mobile */
.dpad-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
}

.dpad-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.dpad-btn {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.9), rgba(15, 23, 42, 0.9));
  border: 1.5px solid rgba(251, 191, 36, 0.3);
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.dpad-btn:active {
  transform: translateY(2px);
  border-color: var(--gold-400);
  background: rgba(245, 158, 11, 0.25);
}

.dpad-center {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

/* Right Section: Inspector Cards */
.coding-inspector {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.inspector-card {
  background: var(--bg-card);
  padding: 16px;
  border-radius: var(--border-radius);
  border: 1.5px solid var(--border-card);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h3 {
  font-size: 0.98rem;
  font-weight: 700;
  color: #fff;
}

.badge-tag {
  background: rgba(16, 185, 129, 0.2);
  border: 1px solid var(--emerald-400);
  color: var(--emerald-400);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
}

.card-desc {
  font-size: 0.84rem;
  color: var(--text-muted);
}

/* Variables Grid (Nisit Zombie inventory slot aesthetic) */
.variables-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.var-card {
  background: rgba(10, 15, 26, 0.75);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: all 0.2s ease;
}

.var-card.just-updated {
  border-color: var(--gold-400);
  box-shadow: 0 0 16px var(--glow-gold);
  transform: scale(1.03);
}

.var-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
}

.pixel-hud-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
}

.var-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.var-name {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 700;
  color: #fff;
}

.var-code-formula {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--gold-400);
}

.var-value {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--gold-300);
  background: rgba(0, 0, 0, 0.4);
  padding: 2px 10px;
  border-radius: 8px;
  border: 1px solid rgba(251, 191, 36, 0.2);
}

/* Conditional If-Then Block */
.condition-status-pill {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid var(--rose-400);
  color: #fca5a5;
  transition: all 0.2s ease;
}

.condition-status-pill.is-true {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--emerald-400);
  color: var(--emerald-400);
  box-shadow: 0 0 12px var(--glow-emerald);
}

.scratch-block-container {
  display: flex;
  flex-direction: column;
}

.scratch-block.if-block {
  background: rgba(10, 15, 26, 0.8);
  border: 1.5px solid rgba(245, 158, 11, 0.4);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  transition: all 0.2s ease;
}

.scratch-block.if-block.is-true {
  border-color: var(--emerald-400);
  box-shadow: 0 0 16px var(--glow-emerald);
}

.block-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.block-keyword {
  color: var(--rose-400);
  font-weight: 700;
}

.block-condition {
  background: rgba(251, 191, 36, 0.15);
  border: 1px solid rgba(251, 191, 36, 0.35);
  color: var(--gold-300);
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 600;
}

.block-body {
  padding-left: 18px;
  border-left: 3px solid var(--gold-500);
  margin-left: 6px;
}

.block-action {
  color: var(--emerald-400);
  font-weight: 600;
}

.block-end {
  color: var(--text-dim);
}

/* Crafting Trigger Button (Tactile 3D RPG Button) */
.crafting-action-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-craft {
  width: 100%;
  padding: 12px 18px;
  border-radius: 12px;
  font-family: var(--font-thai);
  font-size: 1.05rem;
  font-weight: 800;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  cursor: not-allowed;
  opacity: 0.5;
  transition: all 0.2s ease;
}

.btn-craft.ready {
  opacity: 1;
  cursor: pointer;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border-color: var(--emerald-400);
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  animation: pulseButton 1.5s infinite;
}

@keyframes pulseButton {
  0%, 100% { box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4); }
  50% { box-shadow: 0 6px 22px rgba(16, 185, 129, 0.7); }
}

.btn-craft.ready:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

.btn-craft.ready:active {
  transform: translateY(1px);
}

.craft-hint-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

/* Level Stepper Progression */
.level-stepper {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(10, 15, 26, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.86rem;
  color: var(--text-muted);
  transition: all 0.2s ease;
}

.step-item.active {
  background: linear-gradient(135deg, rgba(26, 38, 66, 0.95), rgba(40, 24, 60, 0.85));
  border-color: var(--gold-400);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 2px 10px var(--glow-gold);
}

.step-num {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.8rem;
}

.step-item.active .step-num {
  background: var(--gold-500);
  color: #000;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 14, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-card {
  background: var(--bg-card);
  border: 2px solid var(--gold-400);
  border-radius: 20px;
  max-width: 520px;
  width: 100%;
  padding: 28px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 0 50px rgba(245, 158, 11, 0.35), 0 20px 40px rgba(0, 0, 0, 0.7);
}

.modal-icon {
  font-size: 2.8rem;
  filter: drop-shadow(0 4px 12px rgba(251, 191, 36, 0.5));
}

.pixel-modal-icon {
  width: 64px;
  height: 64px;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.7));
}

.modal-card h2 {
  font-size: 1.45rem;
  font-weight: 800;
  color: #fff;
}

.modal-summary {
  font-size: 0.95rem;
  color: var(--text-body);
  line-height: 1.5;
}

.modal-code-snippet {
  background: #090e18;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 10px 14px;
  width: 100%;
  text-align: left;
}

.code-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--gold-400);
  margin-bottom: 4px;
}

.modal-code-snippet pre {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: #7dd3fc;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-top: 6px;
}

.btn-primary {
  flex: 1;
  padding: 12px 18px;
  border-radius: 12px;
  font-family: var(--font-thai);
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  border: 1px solid var(--emerald-400);
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
  transition: all 0.15s ease;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #34d399 0%, #10b981 100%);
  transform: translateY(-2px);
}

/* Victory Modal Specifics */
.congrats-sub {
  font-size: 0.92rem;
  color: var(--text-muted);
}

.knowledge-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  width: 100%;
  text-align: left;
}

.k-card {
  background: rgba(10, 15, 26, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 8px 12px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.k-icon {
  font-size: 1.2rem;
}

.k-card h4 {
  font-size: 0.88rem;
  color: var(--gold-300);
}

.k-card p {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Code Viewer Modal */
.code-viewer-card {
  max-width: 620px;
  text-align: left;
  align-items: stretch;
}

.code-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  cursor: pointer;
}

.btn-close:hover {
  color: #fff;
}

.code-tabs {
  display: flex;
  gap: 8px;
}

.code-tab-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 8px;
  font-family: var(--font-thai);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.code-tab-btn.active {
  background: rgba(251, 191, 36, 0.15);
  border-color: var(--gold-400);
  color: #fff;
}

.tab-explainer {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.code-block-display {
  background: #090e18;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: #7dd3fc;
  overflow-x: auto;
  line-height: 1.6;
}

.scratch-simulation-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scratch-code-box {
  background: #090e18;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.sc-tag {
  color: var(--gold-400);
  font-weight: 700;
  display: block;
  margin-bottom: 6px;
}

.sc-line { margin: 3px 0; }
.sc-yellow { color: #facc15; }
.sc-orange { color: #fb923c; }
.sc-darkorange { color: #f97316; }
.sc-purple { color: #c084fc; }
.sc-pink { color: #f43f5e; }
.pad-1 { padding-left: 14px; }
.pad-2 { padding-left: 28px; }

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .main-content {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .header-right {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  .variables-grid {
    grid-template-columns: 1fr;
  }
}
