@import "./ios-theme.css";

:root {
  --bg: var(--ios-bg-base);
  --panel: var(--ios-surface-2);
  --panel-soft: var(--ios-surface-1);
  --canvas: var(--ios-bg-canvas);
  --line: var(--ios-border-hairline);
  --line-strong: var(--ios-border-strong);
  --text: var(--ios-text-primary);
  --muted: var(--ios-text-secondary);
  --accent: var(--ios-accent);
  --accent-soft: var(--ios-accent-soft);
  --tool-active-square: #d9d9d9;
  --tool-active-square-size: 25px;
  --tool-active-square-radius: 0px;
  --glyph-header-bg: #ffffff;
  --glyph-header-text: rgba(0, 0, 0, 0.5);
  --glyph-header-divider: rgba(0, 0, 0, 0.16);
  --glyph-row-odd: #f9f8f9;
  --glyph-row-even: #fffeff;
  --glyph-row-hover-overlay: rgba(255, 255, 255, 0.42);
  --glyph-row-active-overlay: rgba(0, 0, 0, 0.05);
  --glyph-thumb-size: 36px;
  --cursor-hotspot-x: 12;
  --cursor-hotspot-y: 12;
  --move-preview-fill: rgba(0, 122, 255, 0.35);
  --move-preview-fill-invalid: rgba(0, 122, 255, 0.55);
  --move-preview-border: rgba(0, 122, 255, 0.9);
  --move-preview-border-invalid: rgba(0, 80, 180, 1);
  --paint-preview-fill: rgba(0, 255, 142, 0.55);
  --paint-preview-fill-invalid: rgba(0, 220, 140, 0.75);
  --paint-preview-border: rgba(0, 200, 120, 1);
  --paint-preview-border-invalid: rgba(0, 170, 100, 1);
  --tile: 58px;
  --sans: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", "Menlo", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
}

#app {
  height: 100%;
}

.editor-shell {
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
  display: grid;
  grid-template-rows: 48px 1fr 30px;
}

.topbar {
  display: grid;
  grid-template-columns: 228px 1fr 210px auto;
  align-items: stretch;
  border-bottom: 1px solid var(--line-strong);
  background: var(--panel-soft);
}

.topbar-col {
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-right: 1px solid var(--line);
}

.topbar-col-actions {
  justify-content: flex-start;
}

.topbar-col-brand {
  justify-content: flex-start;
}

.topbar-col-main {
  min-width: 0;
}

.project-title {
  font-size: 34px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.02em;
  transform: scale(0.48);
  transform-origin: left center;
  white-space: nowrap;
}

.map-name {
  font-size: 13px;
  color: var(--ios-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.topbar-action-btn {
  height: 28px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--ios-radius-sm);
  background: var(--ios-surface-0);
  color: var(--ios-text-primary);
  box-shadow: var(--ios-shadow-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: url("../assets/cursors/Pointer.svg") 4 4, pointer;
  transition: transform 120ms ease, border-color 120ms ease, background-color 120ms ease;
}

.topbar-action-btn:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: color-mix(in srgb, var(--ios-surface-0) 90%, var(--ios-accent-soft));
}

.topbar-action-btn:active {
  transform: translateY(0);
}

.mode-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.mode-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  height: 28px;
  padding: 0 10px;
  border-radius: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: url("../assets/cursors/Pointer.svg") 4 4, pointer;
  position: relative;
  transition: color 150ms ease;
}

.mode-btn::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 4px;
  width: 0;
  height: 2px;
  background: var(--ios-text-primary);
  transition: width 150ms ease-out;
}

.mode-btn:hover::after {
  width: 100%;
}

.mode-btn.active {
  color: var(--ios-text-primary);
}

.mode-btn.active::after {
  width: 100%;
}

.mode-btn:focus-visible,
.topbar-action-btn:focus-visible,
.tool-btn:focus-visible,
#sprite-search:focus-visible,
.sprite-item:focus-visible,
#raw-text:focus-visible,
.raw-sync-copy-btn:focus-visible,
.raw-sync-stage:focus-visible {
  outline: 2px solid var(--ios-focus-ring);
  outline-offset: 1px;
}

.main-layout {
  display: grid;
  grid-template-columns: 296px 1fr;
  min-height: 0;
  height: 100%;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  min-height: 0;
  overflow: hidden;
  padding: 14px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.tool-section {
  background: transparent;
  border: 0;
  padding: 0;
  margin-bottom: 16px;
}

.tool-section h2 {
  margin: 0 0 -12px;
  font-size: 31px;
  line-height: 1;
  font-weight: 500;
  transform: scale(0.46);
  transform-origin: left top;
  letter-spacing: 0.01em;
}

.tool-row {
  display: flex;
  gap: 8px;
  padding-bottom: 28px;
}

#tool-collider::after,
#tool-move::after,
#tool-paint::after,
#tool-rubber::after {
  position: absolute;
  bottom: -28px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--ios-text-tertiary);
  text-align: center;
  line-height: 1.3;
  text-transform: uppercase;
}

#tool-collider::after {
  content: "Collider\A(C)";
  white-space: pre;
}

#tool-move::after {
  content: "Move\A(M)";
  white-space: pre;
}

#tool-paint::after {
  content: "Paint\A(P)";
  white-space: pre;
}

#tool-rubber::after {
  content: "Delete\A(D)";
  white-space: pre;
}

.tool-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ios-text-primary);
  cursor: url("../assets/cursors/Pointer.svg") 4 4, pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.tool-btn.icon-only {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  position: relative;
}

.tool-btn.icon-only::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc((100% - var(--tool-active-square-size)) / 2);
  width: var(--tool-active-square-size);
  height: 0;
  border-radius: var(--tool-active-square-radius);
  transform: translateX(-50%);
  background: var(--tool-active-square);
  z-index: 0;
  transition: height 150ms ease-out;
}

.tool-btn.icon-only:hover::before {
  height: var(--tool-active-square-size);
}

.tool-btn.icon-only img {
  width: 24px;
  height: 24px;
  display: block;
  filter: grayscale(1) contrast(1.08);
  position: relative;
  z-index: 1;
  transition: transform 150ms ease-out;
}

.tool-btn.icon-only:hover img {
  transform: scale(1.15);
}

.rubber-btn span {
  font-size: 50px;
  line-height: 1;
  transform: scale(0.46);
  transform-origin: center;
  font-weight: 600;
  position: relative;
  z-index: 1;
  transition: transform 150ms ease-out;
}

.rubber-btn:hover span {
  transform: scale(0.53);
}

.tool-btn.icon-only:hover {
  border-color: transparent;
  background: transparent;
}

.tool-btn.active {
  border-color: transparent;
  background: transparent;
}

.tool-btn.icon-only.active::before {
  height: var(--tool-active-square-size);
}

.paint-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-left: -14px;
  margin-right: -14px;
}

.paint-panel.hidden {
  display: none;
}

.paint-panel h3 {
  margin: 0 14px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ios-text-secondary);
  text-transform: uppercase;
}

#sprite-search {
  width: calc(100% - 28px);
  height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--ios-radius-sm);
  background: var(--ios-surface-0);
  padding: 0 10px;
  margin: 0 14px 8px;
  font-size: 12px;
  color: var(--ios-text-primary);
  box-shadow: var(--ios-shadow-inset);
}

#sprite-search::placeholder {
  color: var(--ios-text-tertiary);
}

.sprite-meta {
  display: none;
}

.sprite-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 0;
  background: transparent;
  padding: 0;
}

.sprite-group-label {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 7px 14px;
  margin-top: 0;
  border-bottom: 1px solid var(--glyph-header-divider);
  background: var(--glyph-header-bg);
  color: var(--glyph-header-text);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sprite-item {
  width: 100%;
  border: 0;
  background: var(--glyph-row-odd);
  display: grid;
  grid-template-columns: 42px 36px 1fr;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 8px 14px;
  cursor: url("../assets/cursors/Pointer.svg") 4 4, pointer;
  color: var(--ios-text-primary);
  margin: 0;
  position: relative;
  transition: transform 120ms ease-out, box-shadow 120ms ease-out;
}

.sprite-item:hover {
  transform: scale(1.02);
  transform-origin: left center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  z-index: 1;
}

.sprite-item:nth-of-type(even) {
  background: var(--glyph-row-even);
}

.sprite-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 4px;
  height: 100%;
  background-color: transparent;
  z-index: 10;
  transition: background-color 120ms ease-out;
  pointer-events: none;
}

.sprite-item:hover::before {
  background-color: #ffcc00;
}

.sprite-item.active::before {
  background-color: #34c759;
}

.sprite-item::after {
  content: "";
  position: absolute;
  inset: 0;
  background: transparent;
  pointer-events: none;
}

.sprite-item:hover::after {
  background: transparent;
}

.sprite-item.active::after {
  background: transparent;
}

.sprite-item.highlighted {
  transform: scale(1.02);
  transform-origin: left center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  z-index: 1;
}

.sprite-item.highlighted::before {
  background-color: #ffcc00;
}

.sprite-thumb {
  width: var(--glyph-thumb-size);
  height: var(--glyph-thumb-size);
  image-rendering: pixelated;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #fff;
}

.sprite-glyph {
  font-family: var(--mono);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 18px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.03);
  font-size: 10px;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.48);
  letter-spacing: 0.03em;
}

.sprite-details {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sprite-label {
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: rgba(0, 0, 0, 0.8);
}

.sprite-row-meta {
  font-size: 10px;
  color: rgba(0, 0, 0, 0.52);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.workspace {
  display: grid;
  grid-template-rows: 40px 1fr;
  min-height: 0;
  height: 100%;
  position: relative;
  overflow: hidden;
  background: var(--canvas);
}

.workspace-panels {
  min-height: 0;
  height: 100%;
  position: relative;
  overflow: hidden;
  background: var(--canvas);
}

.panel {
  display: none;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.panel.active {
  display: block;
}

.visual-panel {
  min-height: 0;
}

.visual-panel.active {
  display: block;
}

.visual-toolbar {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  color: var(--ios-text-secondary);
  background: var(--panel-soft);
  font-size: 11px;
  letter-spacing: 0.01em;
}

.visual-toolbar-hints {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.visual-toolbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.sync-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: url("../assets/cursors/Pointer.svg") 4 4, pointer;
  user-select: none;
  color: var(--ios-text-primary);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  flex: 0 0 auto;
}

.sync-toggle-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.sync-toggle-track {
  position: relative;
  width: 36px;
  height: 22px;
  border-radius: var(--ios-radius-pill);
  background: var(--ios-border-strong);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
  transition: background-color 140ms ease, border-color 140ms ease;
}

.sync-toggle-track::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow:
    0 1px 1px rgba(0, 0, 0, 0.18),
    0 2px 4px rgba(0, 0, 0, 0.12);
  transition: transform 140ms ease;
}

.sync-toggle-input:checked + .sync-toggle-track {
  background: #34c759;
  border-color: rgba(27, 140, 62, 0.45);
}

.sync-toggle-input:checked + .sync-toggle-track::after {
  transform: translateX(14px);
}

.sync-toggle-input:focus-visible + .sync-toggle-track {
  outline: 2px solid var(--ios-focus-ring);
  outline-offset: 2px;
}

.sync-toggle-text {
  color: var(--ios-text-secondary);
}

.sync-toggle-key {
  color: var(--ios-text-tertiary);
}

.visual-stage {
  position: relative;
  min-height: 0;
  height: 100%;
  overflow: auto;
  cursor: url("../assets/cursors/Arrow.svg") 2 2, default;
  background: var(--canvas);
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  scrollbar-gutter: stable both-edges;
}

.visual-stage[data-tool="move"] {
  cursor: url("../assets/cursors/Move.svg") var(--cursor-hotspot-x) var(--cursor-hotspot-y), move;
}

.visual-stage[data-tool="paint"] {
  cursor: url("../assets/cursors/Pointer.svg") 4 4, crosshair;
}

.visual-stage[data-tool="collider"] {
  cursor: url("../assets/cursors/collider.svg") var(--cursor-hotspot-x) var(--cursor-hotspot-y),
    crosshair;
}

.visual-stage[data-tool="rubber"] {
  cursor: url("../assets/cursors/Not-allowed.svg") var(--cursor-hotspot-x) var(--cursor-hotspot-y),
    not-allowed;
}

.visual-stage.is-panning {
  cursor: url("../assets/cursors/Grab.svg") var(--cursor-hotspot-x) var(--cursor-hotspot-y), grab;
}

.visual-stage.is-grabbing {
  cursor: url("../assets/cursors/Grabbed.svg") var(--cursor-hotspot-x) var(--cursor-hotspot-y),
    grabbing;
}

.visual-stage.is-zoom-key {
  cursor: url("../assets/cursors/ZoomIn.svg") var(--cursor-hotspot-x) var(--cursor-hotspot-y), zoom-in;
}

.visual-stage.is-action-blocked {
  cursor: url("../assets/cursors/Not-allowed.svg") var(--cursor-hotspot-x) var(--cursor-hotspot-y),
    not-allowed;
}

.visual-grid,
.visual-overlay {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

.visual-overlay {
  pointer-events: none;
}

.overlay-selection-layer,
.overlay-preview-layer {
  position: absolute;
  inset: 0;
}

.tile-cell {
  position: absolute;
  border: 1px solid #d6d6dc;
  background: #f4f4f7;
  overflow: hidden;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

.tile-cell::after {
  content: "+";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -52%);
  color: #a2a7b1;
  font-size: 20px;
  line-height: 1;
  font-weight: 500;
  pointer-events: none;
  z-index: 1;
}

.tile-floor-img,
.tile-entity-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  pointer-events: none;
}

.tile-floor-img {
  z-index: 2;
}

.tile-entity-img {
  z-index: 3;
}

.tile-collider-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  display: none;
  background: rgba(220, 38, 38, 0.3);
  box-shadow: inset 0 0 0 1px rgba(220, 38, 38, 0.9);
}

.tile-floor-glyph,
.tile-entity-glyph {
  display: none;
}

.selection-rect {
  position: absolute;
  border: 1px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

.move-preview {
  position: absolute;
  overflow: hidden;
  border: 2px solid var(--move-preview-border);
  background: var(--move-preview-fill);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.35) inset,
    0 0 0 1px rgba(0, 122, 255, 0.75),
    0 0 14px rgba(0, 122, 255, 0.4);
  z-index: 8;
}

.move-preview::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 122, 255, 0.15);
  pointer-events: none;
  z-index: 3;
}

.move-preview.invalid {
  background: var(--move-preview-fill-invalid);
  border-color: var(--move-preview-border-invalid);
}

.move-preview.paint-preview {
  border-color: var(--paint-preview-border);
  background: var(--paint-preview-fill);
}

.move-preview.paint-preview.invalid {
  background: var(--paint-preview-fill-invalid);
  border-color: var(--paint-preview-border-invalid);
}

.move-preview-floor,
.move-preview-entity {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  pointer-events: none;
  opacity: 0.95;
}

.move-preview-floor {
  z-index: 1;
}

.move-preview-entity {
  z-index: 2;
}

.move-preview-tile {
  position: absolute;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.raw-panel {
  height: 100%;
  padding: 12px;
  background: var(--canvas);
}

.raw-panel.active {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 8px;
}

.raw-panel.active.raw-sync-active {
  display: block;
  padding: 0;
}

.raw-sync-shell {
  display: none;
  height: 100%;
}

.raw-sync-shell.active {
  display: block;
  height: 100%;
}

.raw-sync-copy-btn {
  min-width: 88px;
}

.raw-sync-stage {
  position: relative;
  min-height: 0;
  height: 100%;
  overflow: auto;
  background: var(--canvas);
  cursor: url("../assets/cursors/Arrow.svg") 2 2, default;
  scrollbar-gutter: stable both-edges;
}

.raw-sync-stage.is-panning {
  cursor: url("../assets/cursors/Grab.svg") var(--cursor-hotspot-x) var(--cursor-hotspot-y), grab;
}

.raw-sync-stage.is-grabbing {
  cursor: url("../assets/cursors/Grabbed.svg") var(--cursor-hotspot-x) var(--cursor-hotspot-y), grabbing;
}

.raw-sync-stage.is-zoom-key {
  cursor: url("../assets/cursors/ZoomIn.svg") var(--cursor-hotspot-x) var(--cursor-hotspot-y), zoom-in;
}

.raw-sync-world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}

.raw-sync-content {
  position: relative;
  border: 1px solid color-mix(in srgb, var(--line-strong) 70%, transparent);
  background: color-mix(in srgb, var(--ios-surface-0) 94%, var(--ios-bg-canvas));
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.12),
    0 1px 0 rgba(255, 255, 255, 0.7) inset;
}

.raw-sync-line {
  position: absolute;
  left: 0;
  display: flex;
}

.raw-sync-char {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  color: rgba(21, 26, 34, 0.72);
  user-select: none;
}

#raw-text {
  width: 100%;
  height: 100%;
  resize: none;
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--ios-surface-0);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.2;
  padding: 10px;
  color: var(--ios-text-primary);
  box-shadow: var(--ios-shadow-inset);
  white-space: pre;
  word-break: normal;
}

.hidden-by-sync {
  display: none !important;
}

#raw-text.raw-locked {
  background: color-mix(in srgb, var(--ios-surface-0) 84%, var(--ios-bg-canvas));
  color: color-mix(in srgb, var(--ios-text-primary) 86%, var(--ios-text-secondary));
  caret-color: transparent;
}

.raw-error {
  min-height: 18px;
  font-size: 12px;
  color: transparent;
}

.raw-error.visible {
  color: var(--ios-danger);
}

.statusbar {
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 10px;
  color: var(--ios-text-secondary);
  background: var(--panel-soft);
  font-size: 11px;
  font-family: var(--mono);
}

.status-success {
  color: #1f9d55;
}

.status-unsaved {
  color: #b58700;
}

.status-sep {
  color: var(--ios-text-tertiary);
}

/* Modal Base */
.modal-root {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-root.open {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(11, 15, 24, 0.35);
  backdrop-filter: blur(4px);
}

.modal-window {
  position: relative;
  width: 920px;
  height: 640px;
  min-width: 920px;
  max-width: 920px;
  min-height: 640px;
  max-height: 640px;
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--ios-surface-0);
  box-shadow:
    0 14px 40px rgba(0, 0, 0, 0.18),
    0 1px 0 rgba(255, 255, 255, 0.8) inset;
  overflow: hidden;
}

.modal-window.hide-header-close .modal-close {
  display: none;
}

.modal-window-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.modal-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ios-text-primary);
}

.modal-close {
  border: 0;
  background: transparent;
  color: var(--ios-text-secondary);
  height: 28px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  border-radius: var(--ios-radius-sm);
  cursor: url("../assets/cursors/Pointer.svg") 4 4, pointer;
}

.modal-close:hover {
  background: color-mix(in srgb, var(--ios-surface-0) 80%, var(--ios-accent-soft));
}

.modal-close:focus-visible,
.modal-btn:focus-visible,
.modal-input:focus-visible,
.library-search:focus-visible,
.sort-segment-btn:focus-visible {
  outline: 2px solid var(--ios-focus-ring);
  outline-offset: 1px;
}

.modal-body {
  overflow: auto;
  padding: 14px;
  background: var(--ios-surface-0);
}

/* Save/Rename/Confirm */
.save-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: start;
}

.save-form {
  min-width: 0;
}

.save-existing-pane {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-top: 2px;
}

.save-existing-title {
  margin: 0;
  padding: 0 0 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ios-text-secondary);
}

.save-existing-list {
  flex: 1;
  min-height: 0;
  max-height: 260px;
  overflow: auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

.save-existing-item.sprite-item::before {
  display: none;
}

.save-existing-item.sprite-item:hover::before,
.save-existing-item.sprite-item.active::before,
.save-existing-item.sprite-item.highlighted::before {
  background-color: transparent;
}

.save-existing-badge {
  width: var(--glyph-thumb-size);
  height: var(--glyph-thumb-size);
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: rgba(0, 0, 0, 0.52);
  font-family: var(--mono);
}

.save-existing-empty {
  border: 0;
  border-radius: 0;
  padding: 8px 2px;
  color: var(--ios-text-secondary);
  font-size: 12px;
  background: transparent;
}

.modal-form {
  display: grid;
  gap: 10px;
}

.modal-field-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ios-text-secondary);
}

.modal-input {
  width: 100%;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--ios-radius-sm);
  background: var(--ios-surface-0);
  color: var(--ios-text-primary);
  font-size: 13px;
  padding: 0 10px;
  box-shadow: var(--ios-shadow-inset);
}

.modal-help {
  margin: 0;
  color: var(--ios-text-tertiary);
  font-size: 12px;
}

.modal-help.error {
  color: var(--ios-danger);
}

.modal-error {
  min-height: 18px;
  color: var(--ios-danger);
  font-size: 12px;
}

.confirm-copy {
  margin: 0 0 12px;
  color: var(--ios-text-primary);
  font-size: 13px;
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-btn {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--ios-radius-sm);
  background: var(--ios-surface-0);
  color: var(--ios-text-primary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: url("../assets/cursors/Pointer.svg") 4 4, pointer;
  transition: transform 120ms ease, border-color 120ms ease, background-color 120ms ease;
}

.modal-btn:hover {
  transform: translateY(-1px);
}

.modal-btn:active {
  transform: translateY(0);
}

.modal-btn.primary {
  background: var(--ios-accent);
  border-color: color-mix(in srgb, var(--ios-accent) 74%, black);
  color: #fff;
}

.modal-btn.primary:hover {
  background: color-mix(in srgb, var(--ios-accent) 88%, white);
}

.modal-btn.danger {
  background: var(--ios-danger);
  border-color: color-mix(in srgb, var(--ios-danger) 74%, black);
  color: #fff;
}

.modal-btn.danger:hover {
  background: color-mix(in srgb, var(--ios-danger) 88%, white);
}

/* Load Modal */
.library-toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.library-search {
  width: 100%;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--ios-radius-sm);
  background: var(--ios-surface-0);
  color: var(--ios-text-primary);
  font-size: 13px;
  padding: 0 10px;
  box-shadow: var(--ios-shadow-inset);
}

.sort-segment {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--ios-radius-sm);
  overflow: hidden;
  background: var(--ios-surface-0);
}

.sort-segment-btn {
  border: 0;
  background: transparent;
  color: var(--ios-text-secondary);
  height: 32px;
  min-width: 76px;
  padding: 0 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: url("../assets/cursors/Pointer.svg") 4 4, pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.sort-segment-btn + .sort-segment-btn {
  border-left: 1px solid var(--line);
}

.sort-segment-btn.active {
  background: var(--ios-accent);
  color: #fff;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.level-empty {
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  padding: 18px;
  color: var(--ios-text-secondary);
  background: var(--ios-surface-1);
  font-size: 13px;
}

.level-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--ios-surface-0);
  overflow: hidden;
  display: grid;
  grid-template-rows: 144px auto;
  box-shadow: var(--ios-shadow-soft);
}

.level-card.current {
  border-color: var(--ios-accent);
}

.level-card.keyboard-selected {
  border-color: var(--ios-accent);
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--ios-accent) 40%, transparent),
    var(--ios-shadow-soft);
}

.level-preview-frame {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.8), rgba(228, 233, 240, 0.95)),
    repeating-linear-gradient(
      45deg,
      rgba(130, 145, 165, 0.08),
      rgba(130, 145, 165, 0.08) 5px,
      transparent 5px,
      transparent 10px
    );
}

.level-preview-world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}

.level-preview-tile {
  position: absolute;
  border: 1px solid rgba(122, 133, 150, 0.18);
  background: #f4f4f7;
  overflow: hidden;
}

.level-preview-floor,
.level-preview-entity {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  pointer-events: none;
}

.level-preview-floor {
  z-index: 1;
}

.level-preview-entity {
  z-index: 2;
}

.level-preview-invalid {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.22);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.level-card-content {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.level-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--ios-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.level-meta {
  font-size: 11px;
  color: var(--ios-text-secondary);
}

.level-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

@media (max-width: 980px) {
  .editor-shell {
    grid-template-rows: 56px 1fr 30px;
  }

  .topbar {
    grid-template-columns: 1fr 210px auto;
  }

  .topbar-actions {
    gap: 4px;
  }

  .topbar-action-btn {
    padding: 0 8px;
  }

  .topbar-col-main {
    display: none;
  }

  .main-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 42vh 58vh;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .library-toolbar {
    grid-template-columns: 1fr;
  }

  .save-layout {
    grid-template-columns: 1fr;
  }

  .save-existing-pane {
    min-height: 0;
  }

  .save-existing-list {
    max-height: 200px;
  }

  .sort-segment {
    width: 100%;
  }

  .sort-segment-btn {
    flex: 1;
  }

}
.move-preview.paint-preview::before {
  background: rgba(0, 255, 142, 0.35);
}
