body {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100vh;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* ---- Toolbar ---- */
#toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--sz-color-button-shadow);
  flex-shrink: 0;
  flex-wrap: wrap;
}

#toolbar label {
  font-size: 11px;
  font-weight: bold;
}

#toolbar select {
  font-size: 11px;
  max-width: 180px;
}

#toolbar button {
  font-size: 11px;
  padding: 1px 8px;
  min-width: 24px;
}

#mag-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  padding: 1px 4px;
}

#toolbar button.toggled {
  font-weight: bold;
  outline: 2px solid var(--sz-color-highlight);
}

#drop-hint {
  font-size: 10px;
  color: var(--sz-color-gray-text);
  margin-left: auto;
}

/* ---- Main area ---- */
#main-area {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px;
  position: relative;
  background: repeating-conic-gradient(#e0e0e0 0% 25%, #f5f5f5 0% 50%) 0 0 / 16px 16px;
}

/* ---- Drop overlay ---- */
#drop-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 100;
  background: rgba(0, 100, 200, 0.2);
  border: 3px dashed var(--sz-color-highlight);
  font-size: 18px;
  font-weight: bold;
  color: var(--sz-color-highlight);
  justify-content: center;
  align-items: center;
}

#main-area.dragging #drop-overlay {
  display: flex;
}

/* ---- 9-piece frame grid ----
   Uses the same --sz-frame-* custom properties as the real window
   so that skin-css-generator.js output directly controls sizing. */
#frame-grid {
  display: grid;
  gap: 4px;
  grid-template-columns:
    var(--sz-frame-left-w, 40px)
    var(--sz-frame-nw-ext, 0px)
    1fr
    var(--sz-frame-ne-ext, 0px)
    var(--sz-frame-right-w, 40px);
  grid-template-rows:
    var(--sz-frame-top-h, 30px)
    minmax(200px, 1fr)
    var(--sz-frame-bottom-h, 10px);
  grid-template-areas:
    "nw nw n  ne ne"
    "w  c  c  c  e"
    "sw sw s  se se";
  min-width: 400px;
  min-height: 300px;
}

/* Override: the frame grid is not a floating window, so disable
   position/size rules that skin-css-generator sets on .sz-window. */
#frame-grid.sz-window {
  position: static;
  width: auto;
  height: auto;
  min-width: 400px;
  min-height: 300px;
  animation: none;
}

.frame-cell {
  position: relative;
  overflow: hidden;
  outline: 1px dashed rgba(255, 0, 0, 0.4);
}

.cell-label {
  position: absolute;
  top: 1px;
  left: 1px;
  font-size: 9px;
  font-weight: bold;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  padding: 0 3px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 1;
  white-space: nowrap;
}

#cell-nw  { grid-area: nw; }
#cell-n   { grid-area: n; }
#cell-ne  { grid-area: ne; }
#cell-w   { grid-area: w; }
#cell-content { grid-area: c; background: var(--sz-color-window, #fff); overflow: auto; }
#cell-e   { grid-area: e; }
#cell-sw  { grid-area: sw; }
#cell-s   { grid-area: s; }
#cell-se  { grid-area: se; }

/* ---- Sub-skin color overlay (mirrors window.css) ----
   Recolors frame BMP images via mix-blend-mode when a non-default sub-skin
   is active.  Toggled by adding .sz-subskin-tint to the frame grid. */
.sz-subskin-tint .sz-frame-nw::after,
.sz-subskin-tint .sz-frame-n::after,
.sz-subskin-tint .sz-frame-ne::after,
.sz-subskin-tint .sz-frame-w::after,
.sz-subskin-tint .sz-frame-e::after,
.sz-subskin-tint .sz-frame-sw::after,
.sz-subskin-tint .sz-frame-s::after,
.sz-subskin-tint .sz-frame-se::after {
  content: '';
  position: absolute;
  inset: 0;
  mix-blend-mode: color;
  pointer-events: none;
}

/* Title row — gradient tint */
.sz-window-active.sz-subskin-tint .sz-frame-nw::after,
.sz-window-active.sz-subskin-tint .sz-frame-n::after,
.sz-window-active.sz-subskin-tint .sz-frame-ne::after {
  background: linear-gradient(to right,
    var(--sz-color-active-title, transparent),
    var(--sz-color-gradient-active-title, transparent));
}

.sz-window:not(.sz-window-active).sz-subskin-tint .sz-frame-nw::after,
.sz-window:not(.sz-window-active).sz-subskin-tint .sz-frame-n::after,
.sz-window:not(.sz-window-active).sz-subskin-tint .sz-frame-ne::after {
  background: linear-gradient(to right,
    var(--sz-color-inactive-title, transparent),
    var(--sz-color-gradient-inactive-title, transparent));
}

/* Side borders — border color tint */
.sz-window-active.sz-subskin-tint .sz-frame-w::after,
.sz-window-active.sz-subskin-tint .sz-frame-e::after {
  background: var(--sz-color-active-border, transparent);
}

.sz-window:not(.sz-window-active).sz-subskin-tint .sz-frame-w::after,
.sz-window:not(.sz-window-active).sz-subskin-tint .sz-frame-e::after {
  background: var(--sz-color-inactive-border, transparent);
}

/* Bottom row — border color tint */
.sz-window-active.sz-subskin-tint .sz-frame-sw::after,
.sz-window-active.sz-subskin-tint .sz-frame-s::after,
.sz-window-active.sz-subskin-tint .sz-frame-se::after {
  background: var(--sz-color-active-border, transparent);
}

.sz-window:not(.sz-window-active).sz-subskin-tint .sz-frame-sw::after,
.sz-window:not(.sz-window-active).sz-subskin-tint .sz-frame-s::after,
.sz-window:not(.sz-window-active).sz-subskin-tint .sz-frame-se::after {
  background: var(--sz-color-inactive-border, transparent);
}

/* Disable animations when toggled off */
.sz-anim-off [class^="sz-frame-"] {
  animation-duration: 0s !important;
}

/* ---- Content area controls ---- */
#controls-area {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#controls-area fieldset {
  border: 1px solid var(--sz-color-button-shadow);
  padding: 6px 8px;
}

#controls-area legend {
  font-size: 11px;
  font-weight: bold;
  padding: 0 4px;
}

.ctrl-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.ctrl-row label {
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 3px;
}

#scroll-test {
  height: 60px;
  overflow-y: scroll;
  border: 1px solid var(--sz-color-button-shadow);
  background: var(--sz-color-window, #fff);
  font-size: 11px;
  padding: 2px;
}

/* ---- Info panel ---- */
#info-panel {
  flex-shrink: 0;
  max-height: 180px;
  overflow-y: auto;
  border-top: 1px solid var(--sz-color-button-shadow);
  font-size: 10px;
  font-family: 'Consolas', 'Lucida Console', monospace;
  background: var(--sz-color-window, #fff);
  user-select: text;
  -webkit-user-select: text;
}

#info-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 8px;
  border-bottom: 1px solid var(--sz-color-button-shadow, #808080);
  background: var(--sz-color-button-face, #d4d0c8);
  font-weight: bold;
  font-size: 10px;
  position: sticky;
  top: 0;
  z-index: 1;
  user-select: none;
  -webkit-user-select: none;
}

#copy-info-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid var(--sz-color-button-shadow, #808080);
  background: var(--sz-color-button-face, #d4d0c8);
  cursor: default;
  color: var(--sz-color-button-text, #000);
}

#copy-info-btn:hover {
  filter: brightness(1.1);
}

#copy-info-btn:active {
  border-style: inset;
}

#copy-info-btn.copied {
  color: #080;
}

#info-content {
  white-space: pre-wrap;
  line-height: 1.5;
  padding: 4px 8px;
}

.info-section {
  margin-bottom: 4px;
}

.info-section b {
  color: var(--sz-color-button-text, #000);
}

.info-warn {
  color: #c00;
  font-weight: bold;
}

.info-ok {
  color: #080;
}

/* ---- Magnifier ---- */
#magnifier {
  display: none;
  position: absolute;
  width: 180px;
  height: 180px;
  border: 2px solid #333;
  border-radius: 50%;
  overflow: hidden;
  pointer-events: none;
  z-index: 50;
  background: #000;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

#magnifier.active {
  display: block;
}

#magnifier-clone-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

#magnifier-clone-wrap > * {
  image-rendering: pixelated;
  -ms-interpolation-mode: nearest-neighbor;
}

#magnifier-crosshair-h,
#magnifier-crosshair-v {
  position: absolute;
  pointer-events: none;
  background: rgba(255, 0, 0, 0.5);
  z-index: 1;
}

#magnifier-crosshair-h {
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
}

#magnifier-crosshair-v {
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
}

#magnifier-info {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 9px;
  color: #fff;
  text-shadow: 0 0 3px #000, 0 0 3px #000;
  pointer-events: none;
  z-index: 2;
}

#mag-zoom-label {
  font-weight: normal;
}

#mag-zoom {
  font-size: 11px;
}
