*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --npc-safe-top: env(safe-area-inset-top, 0px);
  --npc-safe-right: env(safe-area-inset-right, 0px);
  --npc-safe-bottom: env(safe-area-inset-bottom, 0px);
  --npc-safe-left: env(safe-area-inset-left, 0px);
  --npc-accent: rgba(124, 247, 255, 0.95);
  --npc-mobile-canvas-h: clamp(220px, 42dvh, 360px);
}

html,
body {
  margin: 0;
  height: 100%;
  background: #070a15;
  color: #e8f0ff;
  font-family: "Outfit", system-ui, sans-serif;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

#npc-editor-app {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  grid-template-rows: 1fr;
  grid-template-areas: "panel canvas";
  height: 100%;
  height: 100dvh;
}

#npc-editor-panel {
  grid-area: panel;
  padding: 18px 20px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-right: 1px solid rgba(124, 247, 255, 0.14);
  background: linear-gradient(180deg, rgba(10, 14, 28, 0.98), rgba(6, 8, 18, 0.98));
}

#npc-editor-panel h1 {
  margin: 0 0 6px;
  font-size: 1.25rem;
  color: var(--npc-accent);
}

#npc-editor-panel p {
  margin: 0 0 14px;
  font-size: 0.86rem;
  line-height: 1.45;
  color: rgba(200, 214, 240, 0.78);
}

.npc-editor-mobile-banner {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 200, 120, 0.35);
  background: rgba(255, 180, 90, 0.1);
  color: rgba(255, 228, 190, 0.95) !important;
}

.npc-editor-platform-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.npc-editor-platform-tabs .npc-editor-tab--platform.is-active {
  border-color: rgba(255, 200, 120, 0.62);
  background: linear-gradient(180deg, rgba(255, 190, 100, 0.14) 0%, rgba(10, 16, 28, 0.9) 100%);
  box-shadow: 0 0 12px rgba(255, 180, 90, 0.14);
}

.npc-editor-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.npc-editor-tab {
  appearance: none;
  border: 1px solid rgba(124, 247, 255, 0.22);
  border-radius: 8px;
  padding: 9px 10px;
  min-height: 44px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: rgba(200, 214, 240, 0.88);
  background: rgba(10, 16, 28, 0.72);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.npc-editor-tab:hover,
.npc-editor-tab:focus-visible {
  border-color: rgba(124, 247, 255, 0.45);
  outline: none;
}

.npc-editor-tab.is-active {
  color: rgba(242, 254, 255, 0.96);
  border-color: rgba(124, 247, 255, 0.55);
  background: linear-gradient(180deg, rgba(124, 247, 255, 0.16) 0%, rgba(10, 16, 28, 0.9) 100%);
  box-shadow: 0 0 14px rgba(124, 247, 255, 0.12);
}

.npc-editor-drag-hint {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: rgba(210, 228, 255, 0.92);
  background: rgba(124, 247, 255, 0.06);
  border: 1px solid rgba(124, 247, 255, 0.18);
}

.npc-editor-tab-hint {
  margin: 0 0 14px !important;
  font-size: 0.8rem !important;
  color: rgba(160, 188, 220, 0.78) !important;
}

.npc-editor-field--npc-only.is-hidden,
.npc-editor-field--player-only.is-hidden,
.npc-editor-section.npc-editor-field--player-only.is-hidden {
  display: none;
}

.npc-editor-section {
  margin: 14px 0 10px;
  padding: 12px 0 4px;
  border-top: 1px solid rgba(124, 247, 255, 0.12);
}

.npc-editor-section-title {
  margin: 0 0 4px;
  font-size: 0.95rem;
  color: rgba(124, 247, 255, 0.92);
}

.npc-editor-section-hint {
  margin: 0 0 12px !important;
  font-size: 0.78rem !important;
}

.npc-editor-subsection h3 {
  margin: 0 0 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: rgba(200, 214, 240, 0.88);
}

.npc-editor-subsection {
  margin-bottom: 12px;
}

.npc-editor-row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.npc-editor-field select {
  width: 100%;
  padding: 10px 12px;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid rgba(124, 247, 255, 0.18);
  background: rgba(8, 12, 24, 0.9);
  color: #f2feff;
  font: inherit;
}

.npc-editor-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  cursor: pointer;
}

.npc-editor-check input {
  width: 18px;
  height: 18px;
}

.npc-editor-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.npc-editor-field span {
  font-size: 0.78rem;
  color: rgba(200, 214, 240, 0.82);
}

.npc-editor-field input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(124, 247, 255, 0.18);
  background: rgba(8, 12, 24, 0.9);
  color: #f2feff;
  font: inherit;
}

.npc-editor-row3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.npc-editor-axis {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.npc-editor-axis > span {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(124, 247, 255, 0.72);
}

.npc-editor-touch-save-row {
  margin-top: 14px;
}

.npc-editor-touch-save-row button {
  appearance: none;
  border: 1px solid rgba(124, 247, 255, 0.45);
  background: linear-gradient(180deg, rgba(36, 92, 120, 0.55), rgba(18, 44, 68, 0.85));
  color: #f2feff;
  border-radius: 10px;
  padding: 9px 14px;
  min-height: 44px;
  width: 100%;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.npc-editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 12px;
}

.npc-editor-actions button,
.npc-editor-back,
.npc-editor-mobile-savebar button {
  appearance: none;
  border: 1px solid rgba(124, 247, 255, 0.22);
  background: rgba(12, 20, 36, 0.92);
  color: #f2feff;
  border-radius: 10px;
  padding: 9px 14px;
  min-height: 44px;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.npc-editor-actions button.primary,
.npc-editor-mobile-savebar button.primary {
  border-color: rgba(124, 247, 255, 0.45);
  background: linear-gradient(180deg, rgba(36, 92, 120, 0.55), rgba(18, 44, 68, 0.85));
}

#npc-editor-status {
  font-size: 0.8rem;
  color: rgba(124, 247, 255, 0.85);
  min-height: 1.2em;
}

#npc-editor-canvas-wrap {
  grid-area: canvas;
  position: relative;
  min-height: 0;
  touch-action: none;
}

#npc-editor-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.npc-editor-canvas-hint {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.72rem;
  color: rgba(220, 236, 255, 0.88);
  background: rgba(6, 10, 20, 0.72);
  border: 1px solid rgba(124, 247, 255, 0.2);
  pointer-events: none;
  white-space: nowrap;
}

.npc-editor-mobile-toggle {
  display: none;
}

.npc-editor-mobile-savebar {
  display: none;
}

/* —— Mobile layout —— */
@media (max-width: 860px) {
  #npc-editor-app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--npc-mobile-canvas-h) auto 1fr auto;
    grid-template-areas:
      "canvas"
      "toggle"
      "panel"
      "savebar";
  }

  #npc-editor-canvas-wrap {
    min-height: var(--npc-mobile-canvas-h);
    border-bottom: 1px solid rgba(124, 247, 255, 0.12);
  }

  #npc-editor-panel {
    border-right: none;
    padding: 14px max(14px, var(--npc-safe-left)) calc(18px + var(--npc-safe-bottom)) max(14px, var(--npc-safe-right));
    max-height: none;
    overflow-y: visible;
  }

  #npc-editor-panel h1 {
    font-size: 1.15rem;
  }

  .npc-editor-field input {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 16px;
  }

  .npc-editor-actions button,
  .npc-editor-back {
    flex: 1 1 calc(50% - 4px);
    min-width: calc(50% - 4px);
  }

  .npc-editor-actions .npc-editor-save-btn {
    flex: 1 1 100%;
    min-width: 100%;
    font-weight: 700;
  }
}

/* Phone / touch editor mode (class toggled from JS) */
html.npc-editor--mobile #npc-editor-app {
  grid-template-columns: 1fr;
  grid-template-rows: var(--npc-mobile-canvas-h) auto 1fr auto;
  grid-template-areas:
    "canvas"
    "toggle"
    "panel"
    "savebar";
}

html.npc-editor--mobile #npc-editor-canvas-wrap {
  min-height: var(--npc-mobile-canvas-h);
  padding-top: var(--npc-safe-top);
}

html.npc-editor--mobile .npc-editor-mobile-toggle {
  grid-area: toggle;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 8px max(12px, var(--npc-safe-right)) 8px max(12px, var(--npc-safe-left));
  background: rgba(8, 12, 24, 0.96);
  border-bottom: 1px solid rgba(124, 247, 255, 0.1);
}

html.npc-editor--mobile .npc-editor-mobile-toggle-btn {
  appearance: none;
  border: 1px solid rgba(124, 247, 255, 0.22);
  border-radius: 10px;
  min-height: 44px;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: rgba(200, 214, 240, 0.9);
  background: rgba(10, 16, 28, 0.82);
  cursor: pointer;
}

html.npc-editor--mobile .npc-editor-mobile-toggle-btn.is-active {
  color: #f2feff;
  border-color: rgba(124, 247, 255, 0.5);
  background: linear-gradient(180deg, rgba(124, 247, 255, 0.16), rgba(10, 16, 28, 0.92));
}

html.npc-editor--mobile .npc-editor-mobile-savebar {
  grid-area: savebar;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  bottom: 0;
  z-index: 4;
  padding: 10px max(12px, var(--npc-safe-right)) calc(10px + var(--npc-safe-bottom)) max(12px, var(--npc-safe-left));
  background: linear-gradient(180deg, rgba(6, 8, 18, 0.4), rgba(6, 8, 18, 0.98) 28%);
  border-top: 1px solid rgba(124, 247, 255, 0.14);
  backdrop-filter: blur(8px);
}

html.npc-editor--mobile .npc-editor-mobile-savebar button {
  width: 100%;
  font-weight: 700;
  font-size: 1rem;
}

html.npc-editor--mobile #npc-editor-intro {
  display: none;
}

html.npc-editor--mobile .npc-editor-canvas-hint {
  display: block;
}

/* Full-screen 3D preview on phone */
html.npc-editor--mobile.npc-editor-view-3d #npc-editor-app {
  grid-template-rows: 1fr auto auto;
  grid-template-areas:
    "canvas"
    "toggle"
    "savebar";
}

html.npc-editor--mobile.npc-editor-view-3d #npc-editor-canvas-wrap {
  min-height: 0;
  height: 100%;
}

html.npc-editor--mobile.npc-editor-view-3d #npc-editor-panel {
  display: none;
}

/* Full-screen controls on phone */
html.npc-editor--mobile.npc-editor-view-controls #npc-editor-app {
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas:
    "toggle"
    "panel"
    "panel"
    "savebar";
}

html.npc-editor--mobile.npc-editor-view-controls #npc-editor-canvas-wrap {
  display: none;
}

html.npc-editor--mobile.npc-editor-view-controls #npc-editor-panel {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-height: none;
  padding-bottom: calc(80px + var(--npc-safe-bottom));
}
