:root {
  --bg: #1a1d23;
  --bg-elevated: #22262e;
  --border: #2f3540;
  --text: #e8eaef;
  --muted: #8b93a7;
  --accent: #3d8bfd;
  --accent-dim: #2a5fad;
  --danger: #e85d5d;
  --radius: 8px;
  --header-h: 48px;
}

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

.hidden {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.workspace {
  display: grid;
  grid-template-columns: 200px 1fr 240px;
  flex: 1;
  height: auto;
  min-height: 0;
  min-width: 0;
}

.app-header {
  min-height: var(--header-h);
  height: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 8px;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.doc-size {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.doc-size input {
  width: 60px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.logo {
  color: var(--accent);
  font-size: 14px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

.btn:hover {
  border-color: var(--muted);
}

.btn-ghost {
  background: transparent;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
}

.btn.small {
  padding: 6px 10px;
  font-size: 11px;
}

.btn.full {
  width: 100%;
  margin-top: 10px;
}

.workspace {
  display: grid;
  grid-template-columns: 200px 1fr 240px;
  flex: 1;
  height: auto;
  min-height: 0;
}

.panel {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 12px;
  overflow: auto;
  min-height: 0;
  height: 100%;
}

.right-stack {
  border-right: none;
  border-left: 1px solid var(--border);
  display: block;
  overflow-y: auto !important;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #4b5568 #1a1d23;
  min-height: 0;
  height: 100%;
}

.right-stack::-webkit-scrollbar {
  width: 10px;
}

.right-stack::-webkit-scrollbar-track {
  background: #1a1d23;
}

.right-stack::-webkit-scrollbar-thumb {
  background: #4b5568;
  border-radius: 999px;
  border: 2px solid #1a1d23;
}

.right-stack::-webkit-scrollbar-thumb:hover {
  background: #5d6a82;
}

.panel-block:last-child {
  overflow: hidden;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.tool-groups {
  display: grid;
  gap: 14px;
}

.tool-group {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: #191c23;
}

.tool-group-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-bottom: 8px;
}

.tool-group-items {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.tool-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  background: #14171f;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  padding: 0;
  text-align: center;
  line-height: 1;
}

.tool-btn i {
  font-size: 16px;
}

.tool-btn:hover {
  border-color: var(--muted);
}

.tool-btn.active {
  border-color: var(--accent);
  background: #1f2634;
  box-shadow: 0 0 0 1px var(--accent);
}

.sub-tools {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.tool-hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  white-space: pre-wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}

.field input[type="range"] {
  width: 100%;
}

.color-field input[type="color"] {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
}

.canvas-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #12141a;
}

.canvas-scroll {
  flex: 1;
  overflow: auto;
  padding: 24px;
  background: repeating-conic-gradient(#1e2128 0% 25%, #181b22 0% 50%) 50% / 16px 16px;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.canvas-toolbar input[type="range"] {
  width: 120px;
}

#cursor-pos {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

.canvas-scroll {
  flex: 1;
  overflow: auto;
  padding: 24px;
  background: repeating-conic-gradient(#1e2128 0% 25%, #181b22 0% 50%) 50% / 16px 16px;
}

.stage {
  position: relative;
  margin: auto;
  min-width: 200px;
  min-height: 150px;
  overflow: visible;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.stage.tool-move {
  cursor: grab;
}

.stage.tool-move:active {
  cursor: grabbing;
}

.stage.tool-hand {
  cursor: grab;
}

.stage.tool-zoom {
  cursor: zoom-in;
}

.stage.tool-zoom:active {
  cursor: zoom-in;
}

.stage.tool-hand:active {
  cursor: grabbing;
}

.layers-stack {
  position: relative;
}

.layer-view {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}

.layer-view canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.layer-view.interactive {
  pointer-events: auto;
}

.selection-overlay {
  position: absolute;
  border: 1px dashed var(--accent);
  background: rgba(61, 139, 253, 0.12);
  pointer-events: none;
}

.crop-overlay {
  position: absolute;
  border: 2px solid #ffb020;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.panel-block {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  min-height: 0;
}

.action-grid {
  display: grid;
  gap: 8px;
}

.panel-block:last-child {
  border-bottom: none;
  overflow: visible;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}

.tab {
  flex: 1;
  padding: 6px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}

.tab.active {
  color: var(--text);
  border-color: var(--accent);
}

.adj-pane.hidden {
  display: none;
}

.hint {
  font-size: 11px;
  color: var(--muted);
  margin: 10px 0 0;
  line-height: 1.45;
}

.layer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: visible;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  margin-bottom: 4px;
  background: var(--bg);
}

.layer-item:hover {
  border-color: var(--border);
}

.layer-item.active {
  border-color: var(--accent);
}

.layer-item .thumb {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  border: 1px solid var(--border);
  object-fit: cover;
  background: repeating-conic-gradient(#2a2f3a 0% 25%, #232833 0% 50%) 50% / 8px 8px;
}

.layer-meta {
  flex: 1;
  min-width: 0;
}

.layer-name {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-item input[type="range"] {
  width: 100%;
}

.layer-ops {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.layer-ops button {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 2px;
  font-size: 12px;
}

.layer-ops button:hover {
  color: var(--text);
}

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 0;
  min-width: 280px;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.dialog-form {
  padding: 16px;
}

.dialog-form h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.new-project-form {
  max-width: 480px;
}

.project-presets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.preset-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 12px;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #161820;
  color: var(--text);
  cursor: pointer;
}

.preset-card:hover,
.preset-card.active {
  border-color: var(--accent);
  background: #1f2430;
}

.preset-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.preset-size {
  font-size: 11px;
  color: var(--muted);
}

.project-size-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.field label input[type="checkbox"] {
  margin: 0;
}
