/* Inkwell's pixel editor, styled after the game's green and cream windows. */
#pixel-editor {
  --pe-deep: #0d2219; --pe-panel: #173b2b; --pe-raise: #24563f; --pe-edge: #0a211b;
  --pe-trim: #d6c18a; --pe-text: #fff4d8; --pe-muted: #acbea7; --pe-accent: #7bce42; --pe-ink: #38291d;
  position: fixed; inset: 0; z-index: 30; display: grid; grid-template-rows: auto minmax(0, 1fr);
  background: var(--pe-deep); color: var(--pe-text); font: 14px/1.4 system-ui, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; outline: none;
}
#pixel-editor[hidden] { display: none; }
#pixel-editor button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 34px; min-height: 34px; padding: 0 8px; border: 2px solid var(--pe-edge); border-radius: 0;
  background: var(--pe-raise); color: var(--pe-text); box-shadow: 0 3px 0 var(--pe-edge);
  font: 18px Jersey, sans-serif; cursor: pointer; touch-action: manipulation;
}
#pixel-editor button:hover:not(:disabled) { background: #2d6a4d; }
#pixel-editor button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--pe-edge); }
#pixel-editor button:disabled { opacity: .4; cursor: default; }
#pixel-editor button[aria-pressed="true"] { background: var(--pe-accent); color: var(--pe-ink); }
#pixel-editor button:focus-visible, #pixel-editor input:focus-visible { outline: 2px solid var(--pe-trim); outline-offset: 2px; }
#pixel-editor .pe-icon { padding: 0; width: 34px; }
#pixel-editor .pe-primary { background: var(--pe-accent); color: var(--pe-ink); padding: 0 16px; font-size: 21px; }
#pixel-editor .pe-primary:hover:not(:disabled) { background: #93dc5e; }
#pixel-editor .pe-text { font-size: 17px; }
#pixel-editor .pe-wide { width: 100%; }
#pixel-editor.busy .pe-stage { opacity: .6; pointer-events: none; }

.pe-top {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: var(--pe-panel); border-bottom: 3px solid var(--pe-edge); min-width: 0;
}
.pe-kind { font: 22px Jersey, sans-serif; color: var(--pe-trim); white-space: nowrap; }
.pe-name {
  width: min(260px, 30vw); min-width: 110px; height: 34px; padding: 0 10px; border: 2px solid var(--pe-trim); border-radius: 0;
  background: var(--pe-text); color: var(--pe-ink); font: 16px system-ui, sans-serif; user-select: text;
}
.pe-status { color: var(--pe-muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pe-spacer { flex: 1; }

.pe-body { display: grid; grid-template-columns: auto minmax(0, 1fr) 272px; min-height: 0; }
.pe-tools {
  display: flex; flex-direction: column; gap: 6px; padding: 10px 8px; overflow-y: auto;
  background: var(--pe-panel); border-right: 3px solid var(--pe-edge);
}
.pe-tools hr { width: 100%; border: 0; border-top: 2px solid var(--pe-edge); margin: 4px 0; }
.pe-stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.pe-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.pe-zoom { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 6px; }
.pe-notice {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); margin: 0; max-width: calc(100% - 24px);
  padding: 6px 12px; background: var(--pe-panel); border: 2px solid var(--pe-trim); font-size: 13px; pointer-events: none;
}
.pe-notice:empty { display: none; }

.pe-side {
  display: flex; flex-direction: column; gap: 14px; padding: 10px 12px 16px; overflow-y: auto; overflow-x: hidden;
  background: var(--pe-panel); border-left: 3px solid var(--pe-edge); min-width: 0;
}
.pe-section { min-width: 0; }
.pe-section[hidden] { display: none; }
.pe-section h2 { margin: 0 0 6px; font: 20px Jersey, sans-serif; color: var(--pe-trim); font-weight: 400; }
.pe-section h3 { margin: 8px 0 4px; font-size: 11px; font-weight: 600; color: var(--pe-muted); text-transform: uppercase; letter-spacing: .06em; }
.pe-chips { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pe-chip-stack { position: relative; width: 50px; height: 42px; flex: none; }
#pixel-editor .pe-chip { position: absolute; width: 32px; height: 32px; min-width: 0; min-height: 0; padding: 0; border: 3px solid var(--pe-text); box-shadow: 0 0 0 2px var(--pe-edge); }
#pixel-editor .pe-chip:active:not(:disabled) { transform: none; box-shadow: 0 0 0 2px var(--pe-edge); }
.pe-chip { left: 0; top: 0; z-index: 1; }
.pe-chip-back { left: 16px !important; top: 10px !important; z-index: 0 !important; }
.pe-hex-label { display: flex; align-items: center; gap: 2px; color: var(--pe-muted); }
.pe-hex { width: 74px; height: 30px; padding: 0 6px; border: 2px solid var(--pe-edge); border-radius: 0; background: var(--pe-text); color: var(--pe-ink); font: 14px ui-monospace, monospace; text-transform: lowercase; user-select: text; }
.pe-color-input { width: 34px; height: 34px; padding: 0; border: 2px solid var(--pe-edge); background: var(--pe-raise); cursor: pointer; }
.pe-palette { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; }
#pixel-editor .pe-swatch { min-width: 0; min-height: 0; width: 100%; aspect-ratio: 1; padding: 0; border: 2px solid var(--pe-edge); box-shadow: none; }
#pixel-editor .pe-swatch:active:not(:disabled) { transform: none; box-shadow: none; }
#pixel-editor .pe-swatch[aria-pressed="true"] { outline: 2px solid var(--pe-text); outline-offset: -4px; }
#pixel-editor .pe-add { background: var(--pe-raise); color: var(--pe-muted); }
#pixel-editor .pe-add svg { width: 8px; height: 6px; }

.pe-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; margin: 6px 0; font-size: 13px; }
.pe-row input[type=range] { width: 100%; accent-color: var(--pe-accent); }
.pe-value { color: var(--pe-muted); font-size: 12px; min-width: 34px; text-align: right; }
.pe-check { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: 13px; }
.pe-check[hidden], .pe-row[hidden] { display: none; }
.pe-recent { min-height: 26px; }
/* A fixed height keeps the layers panel still when tools change. */
.pe-options { min-height: 62px; }
.pe-check input { width: 16px; height: 16px; accent-color: var(--pe-accent); }

.pe-layers { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; }
.pe-layer {
  display: grid; grid-template-columns: 34px 36px minmax(0, 1fr) 34px; align-items: center; gap: 6px;
  padding: 3px; background: var(--pe-deep); border: 2px solid var(--pe-edge); cursor: pointer;
}
.pe-layer.active { border-color: var(--pe-trim); background: #1f4a37; }
.pe-thumb {
  width: 36px; height: 30px; object-fit: contain; image-rendering: pixelated;
  background: repeating-conic-gradient(#f4eee4 0 25%, #e4dccd 0 50%) 0 0 / 8px 8px;
}
.pe-layer-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pe-layer-input { width: 100%; height: 28px; padding: 0 6px; border: 2px solid var(--pe-trim); border-radius: 0; background: var(--pe-text); color: var(--pe-ink); font: 13px system-ui, sans-serif; user-select: text; }
.pe-layer-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }

.pe-preview-frame {
  display: grid; place-items: center; min-height: 72px; padding: 10px;
  background: repeating-conic-gradient(#f4eee4 0 25%, #e4dccd 0 50%) 0 0 / 12px 12px; border: 2px solid var(--pe-edge);
}
.pe-preview { image-rendering: pixelated; max-width: 100%; }
.pe-tip { margin: 6px 0 0; color: var(--pe-muted); font-size: 12px; }

@media (max-width: 980px), (max-height: 560px) {
  .pe-body { grid-template-columns: auto minmax(0, 1fr) 228px; }
  .pe-side { gap: 10px; padding: 8px; }
  .pe-tools { gap: 4px; padding: 6px; }
  #pixel-editor button { min-width: 30px; min-height: 30px; }
  #pixel-editor .pe-icon { width: 30px; }
  .pe-layer { grid-template-columns: 30px 30px minmax(0, 1fr) 30px; }
  .pe-top { padding: 5px 8px; gap: 6px; }
  .pe-name { height: 30px; }
}
@media (max-height: 430px) {
  .pe-tools { display: grid; grid-template-columns: repeat(2, 30px); align-content: start; }
  .pe-tools hr { grid-column: 1 / -1; }
  .pe-status { display: none; }
}

/* Scale items: dinos and owned items at their in-game size. */
.pe-guides { margin-bottom: 6px; }
.pe-guide {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) 34px 34px 34px; align-items: center; gap: 4px;
  padding: 3px; background: var(--pe-deep); border: 2px solid var(--pe-edge);
}
.pe-guide-add { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
.pe-select {
  min-width: 0; height: 34px; padding: 0 6px; border: 2px solid var(--pe-edge); border-radius: 0;
  background: var(--pe-text); color: var(--pe-ink); font: 13px system-ui, sans-serif;
}
#pixel-editor.loading .pe-body { visibility: hidden; }
@media (max-width: 980px), (max-height: 560px) {
  .pe-guide { grid-template-columns: 30px minmax(0, 1fr) 30px 30px 30px; }
  .pe-select { height: 30px; }
}

/* Animation timeline under the canvas (hats, suits and pets). */
.pe-center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pe-center .pe-stage { flex: 1; }
.pe-timeline {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; overflow-x: auto;
  background: var(--pe-panel); border-top: 3px solid var(--pe-edge);
}
.pe-timeline[hidden] { display: none; }
.pe-frames { display: flex; gap: 4px; }
#pixel-editor .pe-frame {
  position: relative; width: 44px; height: 40px; padding: 2px; background: var(--pe-deep); box-shadow: none;
}
#pixel-editor .pe-frame[aria-pressed="true"] { background: var(--pe-deep); outline: 2px solid var(--pe-trim); outline-offset: -2px; }
.pe-frame .pe-thumb { width: 100%; height: 100%; }
.pe-frame span { position: absolute; right: 2px; bottom: 0; font-size: 13px; color: var(--pe-text); text-shadow: 0 1px 0 var(--pe-edge); }
.pe-duration { width: 64px; height: 30px; padding: 0 6px; border: 2px solid var(--pe-edge); border-radius: 0; background: var(--pe-text); color: var(--pe-ink); font: 13px system-ui, sans-serif; user-select: text; }
.pe-duration-row { display: flex; margin: 0; white-space: nowrap; }
@media (max-height: 430px) {
  #pixel-editor .pe-frame { width: 34px; height: 30px; }
  .pe-timeline { padding: 4px 6px; }
}

/* Phones: the side panel slides over the canvas; full screen keeps only the canvas and tools. */
#pixel-editor .pe-panel-toggle, .pe-focusbar { display: none; }
.pe-panel-chip { width: 20px; height: 20px; border: 3px solid var(--pe-text); box-shadow: 0 0 0 2px var(--pe-edge); }
#pixel-editor.pe-drawer .pe-panel-toggle { display: inline-flex; }
#pixel-editor.pe-drawer .pe-panel-toggle[aria-expanded="true"] { background: var(--pe-accent); }
#pixel-editor.pe-drawer .pe-body { grid-template-columns: auto minmax(0, 1fr); position: relative; }
#pixel-editor.pe-drawer .pe-side {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 2; width: min(300px, 86vw);
  box-shadow: -4px 0 0 rgba(0, 0, 0, .3); visibility: hidden; transform: translateX(100%);
  transition: transform .15s ease, visibility .15s; overscroll-behavior: contain;
}
#pixel-editor.pe-panel-open .pe-side { visibility: visible; transform: none; }
#pixel-editor.pe-focus { grid-template-rows: minmax(0, 1fr); }
#pixel-editor.pe-focus .pe-top, #pixel-editor.pe-focus .pe-timeline { display: none; }
#pixel-editor.pe-focus .pe-focusbar { position: absolute; left: 10px; top: 10px; display: flex; gap: 6px; }
#pixel-editor.pe-focus .pe-tools { padding-top: max(6px, env(safe-area-inset-top)); padding-left: max(6px, env(safe-area-inset-left)); }
#pixel-editor.pe-focus .pe-zoom { right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); }
@media (pointer: coarse) {
  #pixel-editor button { min-width: 38px; min-height: 38px; }
  #pixel-editor .pe-icon { width: 38px; }
  #pixel-editor .pe-swatch, #pixel-editor .pe-chip, #pixel-editor .pe-frame { min-width: 0; min-height: 0; }
  #pixel-editor .pe-frame { width: 44px; }
  .pe-tools { display: grid; grid-template-columns: repeat(2, 38px); align-content: start; }
  .pe-tools hr { grid-column: 1 / -1; }
}
@media (pointer: coarse) and (min-height: 700px) {
  .pe-tools { display: flex; }
}
/* Portrait phones: tools run along the bottom. */
@media (max-width: 600px) {
  .pe-top { flex-wrap: wrap; }
  .pe-kind, .pe-status, .pe-back span { display: none; }
  .pe-name { flex: 1; width: auto; min-width: 60px; }
  #pixel-editor.pe-drawer .pe-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .pe-center { grid-row: 1; }
  #pixel-editor .pe-tools {
    grid-row: 2; display: flex; flex-direction: row; overflow-x: auto; overflow-y: hidden;
    border-right: 0; border-top: 3px solid var(--pe-edge); padding: 6px 8px max(6px, env(safe-area-inset-bottom));
  }
  #pixel-editor .pe-tools button { flex: none; }
  .pe-tools hr { width: auto; margin: 0 2px; border-top: 0; border-left: 2px solid var(--pe-edge); }
  #pixel-editor.pe-drawer .pe-side { width: min(300px, 92vw); }
}
