:root {
  --ink: #16243a;
  --muted: #5a687f;
  --bg: #f3f6fa;
  --surface: #ffffff;
  --line: #d8e1ec;
  --navy: #1f3a5f;
  --teal: #1f8a7e;
  --shamrock: #10b981;
  --sun: #f4a261;
  --coral: #d9603f;
  --rail: #b8743c;
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: "Lexend", system-ui, sans-serif;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 4px 12px rgba(31, 58, 95, 0.06);
  --shadow-md: 0 10px 25px rgba(31, 58, 95, 0.1);
  --shadow-hover: 0 14px 35px rgba(31, 58, 95, 0.16);
}

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

body {
  font-family: var(--body);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  user-select: none;
}

/* Header */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0.75rem 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--navy);
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #f43f5e, #e11d48);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: 0 4px 10px rgba(225, 29, 72, 0.25);
  flex-shrink: 0;
}

.brand h1 {
  font-family: var(--display);
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--navy);
  line-height: 1.15;
}

.brand p {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.controls-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.template-selector-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--line);
}

.selector-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--navy);
}

#template-select {
  font-family: var(--body);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--navy);
  background: transparent;
  border: none;
  cursor: pointer;
  outline: none;
  max-width: 330px;
}

.btn-header {
  font-family: var(--body);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--navy);
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.2s;
}

.btn-header:hover {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.btn-highlight {
  background: linear-gradient(135deg, var(--teal), #0d9488);
  color: #fff;
  border-color: var(--teal);
}

.btn-highlight:hover {
  background: linear-gradient(135deg, #0f766e, var(--navy));
  border-color: #0f766e;
}

/* Studio Layout */
.studio-layout {
  display: grid;
  grid-template-columns: 240px 1fr 220px;
  gap: 1.2rem;
  padding: 1.2rem;
  flex: 1;
  max-width: 1540px;
  margin: 0 auto;
  width: 100%;
}

/* Sidebar Sections */
.sidebar-tools, .sidebar-palette {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.1rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  height: fit-content;
}

.section-title, .palette-header h3 {
  font-family: var(--display);
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--navy);
  margin-bottom: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Tools Grid */
.tools-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}

.tool-btn {
  font-family: var(--body);
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-md);
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--navy);
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
  transition: all 0.18s ease;
  width: 100%;
  text-align: left;
}

.tool-btn .tool-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.tool-btn:hover {
  border-color: var(--teal);
  background: #f0fdfa;
}

.tool-btn.active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
  box-shadow: 0 4px 12px rgba(31, 58, 95, 0.2);
}

/* Brush Sizes */
.size-selector {
  display: flex;
  gap: 0.4rem;
}

.size-btn {
  flex: 1;
  font-family: var(--body);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.3rem;
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}

.dot-preview {
  display: inline-block;
  background: var(--navy);
  border-radius: 50%;
}

.size-btn.active {
  background: #f0fdfa;
  border-color: var(--teal);
  color: var(--teal);
}

.size-btn.active .dot-preview {
  background: var(--teal);
}

/* Action Buttons */
.action-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.45rem;
}

.action-btn {
  font-family: var(--body);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--navy);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.84rem;
  transition: all 0.15s;
}

.action-btn:hover {
  background: var(--bg);
  border-color: var(--navy);
}

/* Focloir Card (Irish Colour Pronunciation) */
.focloir-card {
  background: linear-gradient(135deg, #f0fdf4, #dcfce7);
  border: 1.5px solid #86efac;
  border-radius: var(--radius-md);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.focloir-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.focloir-badge {
  font-size: 0.72rem;
  font-weight: 800;
  color: #166534;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.focloir-speaker {
  background: #15803d;
  color: #fff;
  border: none;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  transition: background 0.15s;
}

.focloir-speaker:hover {
  background: #14532d;
}

.focloir-irish {
  font-family: var(--display);
  font-size: 1.4rem;
  font-weight: 800;
  color: #14532d;
  line-height: 1.1;
}

.focloir-english {
  font-size: 0.84rem;
  color: #166534;
  font-weight: 600;
}

/* Canvas Stage */
.canvas-stage {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
  justify-content: flex-start;
  min-width: 0;
}

.worksheet-print-header {
  display: none; /* Only visible in print */
}

.artboard-container {
  width: 100%;
  max-width: 860px;
  aspect-ratio: 4 / 3;
  background: #ffffff;
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.svg-art-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
}

.svg-art-layer svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Style SVG line-art elements */
.svg-art-layer svg path,
.svg-art-layer svg circle,
.svg-art-layer svg rect,
.svg-art-layer svg polygon,
.svg-art-layer svg ellipse {
  cursor: pointer;
  transition: fill 0.15s ease, filter 0.15s ease;
}

.svg-art-layer svg path:hover,
.svg-art-layer svg polygon:hover,
.svg-art-layer svg circle:hover {
  filter: brightness(0.95);
}

/* Canvas for Brush overlay */
#brush-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 20;
  pointer-events: none; /* Default to pass clicks to SVG */
  touch-action: none;
}

/* When brush or eraser mode is active, canvas captures pointer */
.brush-active #brush-canvas {
  pointer-events: auto;
  cursor: crosshair;
}

.stage-footer {
  width: 100%;
  max-width: 860px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  font-size: 0.84rem;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-weight: 500;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--shamrock);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.btn-subtle {
  font-family: var(--body);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--navy);
  cursor: pointer;
}

.btn-subtle:hover {
  background: var(--navy);
  color: #fff;
}

/* Palette Sidebar */
.palette-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.palette-count {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--teal);
  background: #f0fdfa;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid #99f6e4;
}

.palette-swatches {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  max-height: 520px;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.swatch-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  border-radius: var(--radius-md);
  border: 2px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}

.swatch-btn:hover {
  transform: scale(1.03);
  border-color: var(--teal);
}

.swatch-btn.active {
  border-color: var(--navy);
  box-shadow: 0 0 0 2px var(--navy);
  background: #f8fafc;
}

.swatch-circle {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.swatch-info {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.swatch-ga {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--navy);
}

.swatch-en {
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 500;
}

/* Colour by number legend card */
.cbn-card {
  background: #fffbeb;
  border: 1.5px solid #fde68a;
  border-radius: var(--radius-md);
  padding: 0.8rem;
}

.cbn-card h4 {
  font-family: var(--display);
  font-size: 0.85rem;
  font-weight: 800;
  color: #92400e;
  margin-bottom: 0.45rem;
}

.cbn-legend {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: #78350f;
  font-weight: 600;
}

/* Responsive adjustments */
@media (max-width: 1040px) {
  .studio-layout {
    grid-template-columns: 1fr;
  }
  .sidebar-tools {
    order: 2;
  }
  .canvas-stage {
    order: 1;
  }
  .sidebar-palette {
    order: 3;
  }
  .palette-swatches {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 680px) {
  header {
    flex-direction: column;
    align-items: flex-start;
  }
  .controls-bar {
    width: 100%;
    justify-content: space-between;
  }
  #template-select {
    max-width: 200px;
  }
  .palette-swatches {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* =========================================
   PRINT STYLES: High-res Classroom Printable
   ========================================= */
@media print {
  @page {
    size: A4 landscape;
    margin: 1cm;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  header,
  .sidebar-tools,
  .sidebar-palette,
  .stage-footer,
  .btn-header {
    display: none !important;
  }

  .studio-layout {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
  }

  .canvas-stage {
    width: 100% !important;
    margin: 0 auto !important;
  }

  .worksheet-print-header {
    display: flex !important;
    justify-content: space-between;
    align-items: flex-end;
    border-bottom: 2px solid #000000;
    padding-bottom: 0.5cm;
    margin-bottom: 0.5cm;
    width: 100%;
  }

  .print-title {
    font-family: var(--display);
    font-size: 1.3rem;
    font-weight: 800;
    color: #000000;
  }

  .print-theme {
    font-size: 1rem;
    color: #333333;
    font-weight: 600;
  }

  .print-fields {
    display: flex;
    gap: 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
  }

  .artboard-container {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    border: 2px solid #000000 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    aspect-ratio: 4 / 3 !important;
  }

  /* Ensure lines print sharp and black */
  .svg-art-layer svg path,
  .svg-art-layer svg polygon,
  .svg-art-layer svg circle,
  .svg-art-layer svg line {
    stroke: #000000 !important;
    stroke-width: 2.5px !important;
  }
}
