/* Shared pixel workspace styles (converter + editor) */
.px-workspace {
  --px-gap: 1rem;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  gap: 0.65rem;
}

/* Action bar (edit mode only) */
.px-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 42px;
  padding: 0.25rem 0;
}

.px-action-bar[hidden] {
  display: none !important;
}

.px-action-left {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.px-btn-ghost {
  background: transparent;
  color: var(--app-text);
  border: 1px solid var(--app-border);
  padding: 0.45rem 0.75rem;
  font-size: 0.82rem;
}

.px-btn-ghost:hover:not(:disabled) {
  border-color: var(--app-primary);
  color: var(--app-primary);
}

.px-download-split {
  position: relative;
  display: flex;
  align-items: stretch;
  flex-shrink: 0;
}

.px-download-main {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px 0 0 8px;
  background: var(--app-primary);
  color: var(--app-bg);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.px-download-main:hover:not(:disabled) {
  background: var(--app-accent);
}

.px-download-main:disabled,
.px-download-caret:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.px-download-caret {
  padding: 0.5rem 0.55rem;
  border: none;
  border-left: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 0 8px 8px 0;
  background: var(--app-primary);
  color: var(--app-bg);
  font-size: 0.65rem;
  cursor: pointer;
  transition: background 0.2s;
}

.px-download-caret:hover:not(:disabled) {
  background: var(--app-accent);
}

.px-download-caret[aria-expanded="true"] {
  background: var(--app-accent);
}

.px-export-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  min-width: 260px;
  padding: 0.75rem;
  background: var(--app-secondary);
  border: 1px solid var(--app-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.px-export-popover[hidden] {
  display: none !important;
}

.px-export-popover-title {
  margin: 0 0 0.25rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--app-primary);
}

.px-mode-upload .px-panel-edit {
  display: none !important;
}

.px-mode-edit .px-panel-upload {
  display: none !important;
}

.px-panel-upload .px-guide-list {
  margin: 0.75rem 0;
  font-size: 0.95rem;
  color: var(--app-text);
  line-height: 1.55;
}

.px-panel-upload .px-guide-list p {
  margin-bottom: 0.45rem;
  font-family: "Press Start 2P", cursive;
  font-size: 0.7rem;
}

.px-link-center {
  display: block;
  text-align: center;
  color: var(--app-primary);
  text-decoration: none;
}

.px-link-center:hover {
  text-decoration: underline;
}

.px-btn-block {
  width: 100%;
}

/* Accordion sections */
.px-accordion {
  border-bottom: 1px solid var(--app-border);
}

.px-accordion:last-child {
  border-bottom: none;
}

.px-accordion-head {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.65rem 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--app-primary);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.px-accordion-head::-webkit-details-marker {
  display: none;
}

.px-accordion-head::before {
  content: '▸';
  flex-shrink: 0;
  display: block;
  line-height: 1;
  transition: transform 0.15s;
  font-size: 1.5rem;
}

.px-accordion[open] .px-accordion-head::before {
  transform: rotate(90deg);
}

.px-accordion-body {
  padding: 0 0 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.px-style-pane {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.px-style-pane[hidden] {
  display: none !important;
}

/* Underline tabs */
.px-tabs-underline {
  gap: 1rem;
  border-bottom: 1px solid var(--app-border);
  margin-bottom: 0.25rem;
}

.px-tabs-underline .px-tab {
  flex: 0 0 auto;
  padding: 0.4rem 0.15rem;
  border: none;
  border-radius: 0;
  background: transparent;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--app-disabled);
  font-size: 0.8rem;
}

.px-tabs-underline .px-tab:hover {
  color: var(--app-text);
}

.px-tabs-underline .px-tab.active {
  color: var(--app-primary);
  border-bottom-color: var(--app-primary);
  background: transparent;
}

.px-main {
  display: flex;
  flex-direction: column;
  gap: var(--px-gap);
  min-height: 0;
}

@media (min-width: 768px) {
  .px-main {
    flex-direction: row;
    align-items: stretch;
    min-height: 420px;
    height: calc(100vh - 360px);
  }
  .px-panel-upload .px-guide-list p {
    margin-bottom: 1.5rem;
  }
}

.px-canvas-wrap {
  flex: 1 1 auto;
  min-height: 280px;
  max-height: 65vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f0f0f;
  border: 2px dashed rgba(61, 217, 74, 0.35);
  border-radius: 10px;
  position: relative;
  overflow: hidden;
}

@media (min-width: 768px) {
  .px-canvas-wrap {
    flex: 1 1 58%;
    max-height: none;
    min-height: 380px;
  }
}

.px-canvas-wrap.has-image {
  border-style: solid;
  border-color: var(--app-border);
}

.px-canvas-wrap.highlight {
  border-color: var(--app-primary);
  background: rgba(61, 217, 74, 0.08);
}

.px-preview-canvas {
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.px-start-prompt {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1.5rem;
  color: var(--app-primary);
  cursor: pointer;
}

.px-start-prompt.hidden {
  display: none;
}

.px-panel {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--app-secondary);
  border: 1px solid var(--app-border);
  border-radius: 10px;
  padding: 1rem;
}

.px-panel::-webkit-scrollbar {
  width: 2px;
}
.px-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.4);
  border-radius: 3px;
}
.px-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.6);
}
.px-panel::-webkit-scrollbar-track {
  background: transparent;
}

@media (min-width: 768px) {
  .px-panel {
    flex: 0 0 38%;
    max-width: 340px;
    overflow-y: auto;
    /* max-height: 600px; */
  }
}

.px-panel.disabled {
  opacity: 0.55;
  pointer-events: none;
}

.px-panel-step {
  display: none;
  flex-direction: column;
  gap: 0.75rem;
}

.px-panel-step.active {
  display: flex;
}

.px-panel-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--app-primary);
  margin: 0;
}

.px-control-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.px-control-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--app-text);
}

.px-value-badge {
  background: rgba(61, 217, 74, 0.25);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.75rem;
  color: var(--app-text);
  border: 1px solid transparent;
  width: 3.25rem;
  text-align: center;
  -moz-appearance: textfield;
}

.px-value-badge:focus {
  outline: none;
  border-color: var(--app-primary);
  background: rgba(61, 217, 74, 0.35);
}

.px-value-badge::-webkit-outer-spin-button,
.px-value-badge::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.px-tabs {
  display: flex;
  gap: 0.35rem;
}

.px-tab {
  flex: 1;
  padding: 0.45rem;
  border: 1px solid var(--app-border);
  border-radius: 6px;
  background: transparent;
  color: var(--app-text);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.2s;
}

.px-tab.active {
  border-color: var(--app-primary);
  background: rgba(61, 217, 74, 0.2);
  color: var(--app-primary);
}

.px-filter-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}

.px-filter-btn {
  padding: 0.35rem 0.2rem;
  border: 1px solid var(--app-border);
  border-radius: 6px;
  background: var(--app-bg);
  color: var(--app-primary);
  font-size: 0.72rem;
  cursor: pointer;
  text-align: center;
}

.px-filter-btn.active {
  border-color: var(--app-primary);
  background: rgba(61, 217, 74, 0.3);
}

.px-select,
.px-color-input {
  width: 100%;
  padding: 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--app-border);
  background: var(--app-bg);
  color: var(--app-text);
  font-size: 0.8rem;
}

.px-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.px-toggle-label {
  font-size: 0.82rem;
  color: var(--app-text);
  font-weight: 600;
}

.px-toggle-row + .px-toggle-row {
  margin-top: 0.5rem;
}

.px-row-action {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 32px;
  border: 0;
  background: transparent;
  color: var(--app-text);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.px-row-action:hover:not(:disabled) {
  border-color: var(--app-primary);
  color: var(--app-primary);
  background: rgba(61, 217, 74, 0.1);
}

.px-row-action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.px-row-action svg {
  width: 16px;
  height: 16px;
}

.px-switch {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.px-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.px-switch-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--app-border);
  transition: background 0.2s;
}

.px-switch-slider::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.px-switch input:checked + .px-switch-slider {
  background: var(--app-primary);
}

.px-switch input:checked + .px-switch-slider::before {
  transform: translateX(20px);
}

.px-switch input:disabled + .px-switch-slider {
  opacity: 0.45;
  cursor: not-allowed;
}

.px-switch:has(input:disabled) {
  cursor: not-allowed;
}

.px-checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--app-text);
}

.px-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--app-border);
}

.px-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.px-btn-primary {
  background: var(--app-primary);
  color: var(--app-bg);
}

.px-btn-primary:hover:not(:disabled) {
  background: var(--app-accent);
}

.px-btn-secondary {
  background: transparent;
  color: var(--app-primary);
  border: 2px solid var(--app-primary);
}

.px-btn-secondary:hover:not(:disabled) {
  background: rgba(61, 217, 74, 0.1);
}

.px-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.px-btn-row {
  display: flex;
  gap: 0.5rem;
}

.px-btn-row .px-btn {
  flex: 1;
}

.px-hint {
  font-size: 0.72rem;
  color: var(--app-disabled);
  margin: 0;
}

.px-loading {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--app-primary);
  font-size: 0.85rem;
  z-index: 5;
}

.px-loading.show {
  display: flex;
}

.px-editor-layout {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  min-height: calc(100vh - 120px);
}

.px-editor-body {
  flex: 1;
  display: flex;
  min-height: 0;
  gap: 0;
  border: 2px solid var(--app-primary);
  border-radius: 12px;
  overflow: hidden;
  background: var(--app-secondary);
}

.px-tool-rail {
  flex: 0 0 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.25rem;
  background: var(--app-bg);
  border-right: 1px solid var(--app-border);
}

.px-tool-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--app-border);
  border-radius: 6px;
  background: var(--app-secondary);
  color: var(--app-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  transition: all 0.15s;
}

.px-tool-btn:hover {
  border-color: var(--app-primary);
  color: var(--app-primary);
}

.px-tool-btn.active {
  background: rgba(61, 217, 74, 0.25);
  border-color: var(--app-primary);
  color: var(--app-primary);
}

.px-tool-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.px-tool-sep {
  width: 28px;
  height: 1px;
  background: var(--app-border);
  margin: 0.15rem 0;
}

.px-editor-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #0a0a0a;
  touch-action: none;
  cursor: crosshair;
}

.px-viewport-tooltip {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 10;
  padding: 0.4rem 0.65rem;
  background: rgba(0, 0, 0, 0.82);
  color: var(--app-primary);
  font-size: 0.78rem;
  border-radius: 6px;
  border: 1px solid var(--app-border);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
  max-width: 85%;
}

.px-viewport-tooltip.show {
  opacity: 1;
}

.px-editor-viewport.pan-mode {
  cursor: grab;
}

.px-editor-viewport.pan-mode.panning {
  cursor: grabbing;
}

.px-editor-canvas {
  position: absolute;
  top: 0;
  left: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
}

.px-editor-bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--app-secondary);
  border-top: 1px solid var(--app-border);
  border-radius: 0 0 12px 12px;
}

.px-editor-bottom label {
  font-size: 0.78rem;
  color: var(--app-text);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.px-zoom-label {
  font-size: 0.75rem;
  color: var(--app-primary);
  min-width: 3rem;
  text-align: center;
}

.px-editor-actions {
  margin-left: auto;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.px-editor-actions .px-download-split {
  margin-left: auto;
}

/* Download success modal */
.px-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.px-modal-overlay[hidden] {
  display: none !important;
}

.px-modal {
  background: var(--app-secondary);
  border: 2px solid var(--app-primary);
  border-radius: 12px;
  padding: 1.25rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.px-modal-title {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  color: var(--app-primary);
  font-weight: 700;
}

.px-modal-preview-wrap {
  background: #0f0f0f;
  border: 1px solid var(--app-border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}

.px-modal-preview {
  max-width: 160px;
  max-height: 160px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.px-modal-text {
  margin: 0 0 1rem;
  font-size: 0.82rem;
  color: var(--app-text);
  line-height: 1.5;
}

.px-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.px-modal-actions-row {
  flex-direction: row;
}

.px-modal-actions .px-btn {
  width: 100%;
}

.px-modal-actions-row .px-btn {
  flex: 1;
}

@media (max-width: 767px) {
  .px-editor-bottom {
    flex-direction: column;
    align-items: stretch;
  }

  .px-editor-actions {
    margin-left: 0;
    width: 100%;
  }

  .px-editor-actions .px-btn {
    flex: 1;
  }
}

.px-export-advanced {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.px-export-advanced summary {
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--app-primary);
}

.px-checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--app-text);
}

.px-size-setup {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.px-size-setup input[type="number"] {
  width: 4rem;
  padding: 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--app-border);
  background: var(--app-bg);
  color: var(--app-text);
}

.px-color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: 1px solid var(--app-border);
  padding: 0;
  cursor: pointer;
}
