:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --muted: #94a3b8;
  --line: #334155;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --danger: #f87171;
  --warning: #fbbf24;
  --canvas-bg: #ffffff;
  --shadow: rgba(15, 23, 42, 0.18);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  background: linear-gradient(135deg, #0f172a 0%, #111827 100%);
  color: #e2e8f0;
}

body {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

button, input, select {
  font: inherit;
}

.app-shell {
  display: flex;
  width: 100%;
  min-height: 100vh;
  min-width: 0;
}

.toolbar {
  width: 340px;
  flex: 0 0 auto;
  min-width: 240px;
  max-width: 720px;
  padding: 20px 18px;
  background: rgba(15, 23, 42, 0.88);
  border-right: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: 8px 0 30px rgba(0, 0, 0, 0.12);
}

/* Make toolbar independently scrollable */
.toolbar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Resizer between toolbar and canvas */
.resizer {
  position: relative;
  width: 16px;
  flex: 0 0 16px;
  background: transparent;
  cursor: grab;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
  touch-action: none;
}

.resizer.dragging {
  cursor: grabbing;
}

.resizer::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 3px;
  border-radius: 999px;
  transform: translateX(-50%);
  background: rgba(148, 163, 184, 0.24);
  transition: background 0.18s ease, width 0.18s ease, opacity 0.18s ease;
  opacity: 0.8;
}

.resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 42px;
  border-radius: 999px;
  transform: translate(-50%, -50%);
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.9) 0 3px,
    rgba(148, 163, 184, 0.8) 3px 6px
  );
  box-shadow: 0 0 0 1px rgba(148, 163, 184, 0.25);
  opacity: 0.9;
  transition: transform 0.18s ease, opacity 0.18s ease, box-shadow 0.18s ease;
}

.resizer:hover::before,
.resizer:active::before,
.resizer:focus-visible::before,
.resizer:hover::after,
.resizer:active::after,
.resizer:focus-visible::after,
.resizer.dragging::after {
  width: 4px;
  background: rgba(56, 189, 248, 0.9);
  opacity: 1;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.65), 0 0 18px rgba(56, 189, 248, 0.45);
}

@media (pointer: coarse) {
  .resizer {
    width: 22px;
    flex-basis: 22px;
    cursor: grab;
  }

  .resizer::before {
    width: 4px;
  }

  .resizer::after {
    width: 12px;
    height: 52px;
  }
}

/* Prevent layout jump when resizing */
.app-shell { align-items: stretch; }

.brand-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.toolbar-logo {
  display: block;
  width: 120px;
  max-width: 100%;
  height: auto;
  filter: drop-shadow(0 6px 18px rgba(14, 165, 233, 0.2));
}

.brand-wrap h1 {
  margin: 0;
  font-size: 1.8rem;
  letter-spacing: 0.04em;
  text-align: center;
}

.tool-group {
  margin-bottom: 18px;
  padding: 12px 10px;
  background: rgba(31, 41, 55, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 12px;
}

.group-label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 0.72rem;
}

.button-row {
  display: flex;
  gap: 8px;
}

.wrap-row {
  flex-wrap: wrap;
}

.tool-button,
.line-button,
.icon-button,
.action-button,
#text-input,
#background-select,
#background-upload,
#post-title {
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.7);
  color: #e2e8f0;
  border-radius: 10px;
  transition: all 0.18s ease;
}

.tool-button,
.line-button,
.action-button {
  padding: 8px 12px;
  font-weight: 600;
  cursor: pointer;
}

.tool-button,
.line-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 42px;
  padding: 7px 10px;
  overflow: hidden;
}

.tool-button svg,
.tool-button img,
.line-button svg {
  width: 26px;
  height: 20px;
  display: block;
  object-fit: contain;
  max-width: 100%;
  max-height: 100%;
}

.tool-button img {
  max-width: 26px;
  max-height: 20px;
  filter: invert(100%);
}

.tool-button.active,
.line-button.active,
.icon-button.active {
  background: rgba(56, 189, 248, 0.18);
  border-color: rgba(56, 189, 248, 0.8);
  color: #bae6fd;
}

.tool-button:hover,
.line-button:hover,
.icon-button:hover,
.action-button:hover {
  transform: translateY(-1px);
  border-color: rgba(148, 163, 184, 0.45);
}

.color-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#stroke-color {
  width: 56px;
  height: 36px;
  border: none;
  background: transparent;
}

#stroke-width {
  width: 100%;
  margin-top: 8px;
}

#stroke-width-value {
  display: inline-block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.text-size-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

#text-size {
  width: 100%;
}

#text-size-value {
  color: var(--muted);
  font-size: 0.85rem;
}

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

.preset-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin:10px;
}

.color-presets {
  display: flex;
  gap: 8px;
  align-items: center;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 2px solid rgba(255,255,255,0.06);
  cursor: pointer;
}

.size-presets {
  display: flex;
  gap: 8px;
  align-items: center;
}

.size-button {
  width: 36px;
  height: 28px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 600;
}

.size-button.active, .color-swatch.active {
  outline: 3px solid rgba(56,189,248,0.18);
}

.icon-button {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  overflow: hidden;
  font-size: 1.2rem;
  cursor: pointer;
  text-align: center;
  word-break: break-word;
}

.icon-button img,
.icon-button svg {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.input-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meta-field-stack {
  gap: 10px;
}

#text-input,
#background-select,
#background-upload,
#post-title {
  width: 100%;
  padding: 10px 12px;
}

#background-upload {
  padding: 8px;
}

.meta-radio-group {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.35);
}

.meta-radio-group legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.radio-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-right: 16px;
  color: #e2e8f0;
}

.radio-option input {
  accent-color: var(--accent);
}

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

.action-button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-color: transparent;
  color: #eff6ff;
}

.action-button.danger {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.5);
  color: #fecaca;
}

.action-button.secondary {
  background: rgba(15, 23, 42, 0.9);
}

.zoom-level {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.status-message {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(14, 116, 144, 0.2);
  color: #dbeafe;
  border: 1px solid rgba(56, 189, 248, 0.35);
  min-height: 42px;
}

.canvas-panel {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  align-items: flex-start; /* align to top */
  justify-content: center;
  padding: 26px;
}

.canvas-stage {
  width: 100%;
  height: 82vh;
  min-width: 0;
  max-width: none;
  max-height: none;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

#drawing-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: transparent;
  border-radius: 18px;
  cursor: default;
}

#drawing-canvas.grab-cursor {
  cursor: grab;
}

#drawing-canvas.grabbing-cursor {
  cursor: grabbing;
}

@media (max-width: 900px) {
  /*
   * Mobile/tablet layout:
   * Put the toolbar above the canvas, but do NOT let the toolbar
   * consume the entire viewport. The previous height: 100vh rule
   * caused the canvas to be pushed below the visible screen.
   */
  .app-shell {
    flex-direction: column;
    height: 100vh;
    min-height: 100vh;
    overflow: hidden;
  }

  .toolbar {
    width: 100%;
    height: 42vh;
    min-height: 220px;
    max-height: 42vh;
    flex: 0 0 42vh;
    border-right: none;
    border-bottom: 1px solid rgba(148, 163, 184, 0.2);
    position: relative;
    top: auto;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .resizer {
    width: 18px;
    flex-basis: 18px;
    display: block;
  }

  .canvas-panel {
    width: 100%;
    height: 58vh;
    min-height: 0;
    flex: 1 1 auto;
    padding: 10px;
    align-items: stretch;
    overflow: hidden;
  }

  .canvas-stage {
    width: 100%;
    height: 100%;
    min-height: 0;
    border-radius: 14px;
  }

  #drawing-canvas {
    width: 100%;
    height: 100%;
  }
}
