:root {
  --bg: #0f0f0f;
  --bg-toolbar: #1a1a1a;
  --bg-toolbar-border: #2a2a2a;
  --text: #f0f0f0;
  --text-muted: #888;
  --accent: #007AFF;
  --btn-bg: #2a2a2a;
  --btn-active: #3a3a3a;
  --crop-line: rgba(255,255,255,0.9);
  --crop-shade: rgba(0,0,0,0.55);
  --toolbar-h: 72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: none;
}

/* Screens */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.screen.active {
  opacity: 1;
  pointer-events: all;
}

/* Gallery */
.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
  flex-shrink: 0;
}

.app-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.folder-label-wrap {
  padding: 0 16px 10px;
}

.folder-label {
  font-size: 13px;
  color: var(--text-muted);
}

.gallery-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 0 3px;
  overscroll-behavior: contain;
}

.gallery-grid::-webkit-scrollbar { display: none; }

.thumb-wrap {
  aspect-ratio: 1;
  overflow: hidden;
  background: #1a1a1a;
  cursor: pointer;
}

.thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.1s;
}

.load-more-wrap {
  padding: 12px;
  text-align: center;
  flex-shrink: 0;
}

.load-more-btn {
  background: var(--btn-bg);
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 10px 28px;
  font-size: 14px;
  cursor: pointer;
}

/* Editor */
.canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

#canvas-image,
#canvas-marks {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  touch-action: none;
}

#canvas-marks {
  pointer-events: none;
}

/* Crop overlay */
.crop-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.crop-edge {
  position: absolute;
  background: var(--crop-line);
  pointer-events: all;
  z-index: 10;
}

.crop-edge--top,
.crop-edge--bottom {
  left: 0; right: 0;
  height: 3px;
  cursor: ns-resize;
}

.crop-edge--left,
.crop-edge--right {
  top: 0; bottom: 0;
  width: 3px;
  cursor: ew-resize;
}

.crop-edge--top { top: 0; }
.crop-edge--bottom { bottom: 0; }
.crop-edge--left { left: 0; }
.crop-edge--right { right: 0; }

.crop-shade {
  position: absolute;
  background: var(--crop-shade);
  pointer-events: none;
}

/* Toolbar */
.toolbar {
  flex-shrink: 0;
  background: var(--bg-toolbar);
  border-top: 1px solid var(--bg-toolbar-border);
  min-height: var(--toolbar-h);
  padding-bottom: var(--safe-bottom);
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.toolbar-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
}

.toolbar-colors {
  padding: 8px 12px 4px;
  gap: 12px;
}

.tool-btn {
  background: var(--btn-bg);
  color: var(--text);
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
}

.tool-btn:active {
  background: var(--btn-active);
}

.tool-btn--icon {
  padding: 10px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
}

.tool-btn--icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--text);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.tool-btn--primary:active {
  background: #005ecb;
}

.tool-btn--active {
  background: var(--accent);
}

.tool-btn--active svg {
  stroke: #fff;
}

.tool-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* Color dots */
.color-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}

.color-dot.selected {
  border-color: #fff;
  transform: scale(1.2);
}

/* Toast */
.toast {
  position: absolute;
  bottom: calc(var(--toolbar-h) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(8px);
  color: #fff;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.toast.show {
  opacity: 1;
}

/* Dialog */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.dialog {
  background: #1e1e1e;
  border-radius: 16px;
  padding: 24px;
  width: 280px;
  text-align: center;
}

.dialog p {
  font-size: 16px;
  margin-bottom: 20px;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* Utilities */
.hidden {
  display: none !important;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: var(--text);
  stroke: none;
}
