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

:root {
  --bg: #1a1a1a;
  --surface: #2a2a2a;
  --accent: #4a90d9;
  --accent-hover: #5aa0e9;
  --text: #e0e0e0;
  --text-muted: #888;
  --radius: 8px;
}

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  padding: 12px 16px;
  text-align: center;
  flex-shrink: 0;
}

.header__title {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* Workspace */
.workspace {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 8px;
  min-height: 0;
}

.canvas-container {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-touch-callout: none;
}

.canvas-container canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 140px);
  border-radius: var(--radius);
}

#overlay-canvas {
  position: absolute;
  top: 0;
  left: 0;
  touch-action: none;
  cursor: crosshair;
}

/* Placeholder */
.placeholder {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  pointer-events: none;
}

.placeholder__icon {
  font-size: 3rem;
}

.placeholder__text {
  font-size: 1rem;
}

.placeholder--hidden {
  display: none;
}

/* Toolbar */
.toolbar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  flex-shrink: 0;
  justify-content: center;
  flex-wrap: wrap;
}

.toolbar__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  min-height: 44px;
  min-width: 44px;
  border: 1px solid var(--surface);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
  -webkit-user-select: none;
}

.toolbar__btn:hover:not(:disabled) {
  background: #3a3a3a;
  border-color: #444;
}

.toolbar__btn:active:not(:disabled) {
  background: #333;
}

.toolbar__btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.toolbar__btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}

.toolbar__btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* Ratio bar */
.ratio-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  flex-shrink: 0;
}

.ratio-bar--hidden {
  display: none;
}

.ratio-bar__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  min-height: 36px;
  border: 1px solid var(--surface);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
  -webkit-user-select: none;
}

.ratio-bar__btn:hover {
  background: #3a3a3a;
  border-color: #444;
}

.ratio-bar__btn:active {
  background: #333;
}

.ratio-bar__btn--active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.ratio-bar__btn--active:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* Result canvas */
#result-canvas {
  border-radius: var(--radius);
}

/* Responsive */
@media (max-width: 480px) {
  .toolbar {
    padding: 8px 12px;
    gap: 6px;
  }

  .toolbar__btn {
    padding: 8px 14px;
    font-size: 0.85rem;
    flex: 1;
    min-width: 0;
  }

  .ratio-bar {
    padding: 6px 12px;
    flex-wrap: wrap;
  }

  .ratio-bar__btn {
    padding: 5px 10px;
    font-size: 0.8rem;
  }

  .header {
    padding: 8px 12px;
  }

  .header__title {
    font-size: 1rem;
  }
}
