/* ==========================================================================
   Grid Drawing Worksheet Maker — S002 Approved Design Styles
   ========================================================================== */

:root {
  --canvas: #f7f4ee;
  --paper: #fffdf8;
  --ink: #151515;
  --muted: #5d5b56;
  --line: #181818;
  --accent: #de522c;
  --accent-hover: #c4431e;
  --shadow: none;
}

body[data-page="grid-drawing-worksheet-maker"] {
  background:
    linear-gradient(90deg, rgba(21, 21, 21, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(21, 21, 21, 0.04) 1px, transparent 1px),
    #f7f4ee;
  background-size: 32px 32px;
  color: var(--ink);
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
}

/* Visibility helpers */
.desktop-only {
  display: inherit;
}
.mobile-only {
  display: none !important;
}

/* Header & Navigation */
.topbar {
  background: #fbf9f4;
  border-bottom: 1.5px solid var(--line);
}

.brand {
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 24px;
  height: 24px;
  border: 1.5px solid var(--line);
  background: linear-gradient(90deg, #fff 0 calc(50% - 0.75px), var(--line) calc(50% - 0.75px) calc(50% + 0.75px), #fff calc(50% + 0.75px) 100%);
  box-shadow: none;
  border-radius: 0;
}

nav a {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.88rem;
  color: #555;
  font-weight: 500;
  text-decoration: none;
}

nav a:hover {
  color: var(--ink);
}

.topbar nav a[aria-current="page"] {
  color: var(--ink);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 3px;
  text-underline-offset: 8px;
}

.nav-toggle {
  display: none;
}

/* Page Container */
.worksheet-page {
  padding-top: 16px;
  padding-bottom: 48px;
}

/* Full-width Intro */
.worksheet-header {
  margin-bottom: 24px;
}

.worksheet-heading {
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  font-size: clamp(2.1rem, 3.6vw, 3.1rem);
  font-weight: 800;
  line-height: 1.1;
  margin: 0 0 10px;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.worksheet-lede {
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  font-size: 1.15rem;
  line-height: 1.45;
  color: #444;
  margin: 0;
}

/* Two-column workspace on desktop */
.worksheet-workspace {
  display: grid;
  grid-template-columns: minmax(320px, 360px) minmax(0, 1fr);
  gap: 20px;
  align-items: stretch;
}

/* Left panel: Settings */
.worksheet-controls {
  background: var(--paper);
  border: 1.5px solid var(--line);
  box-shadow: none;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.worksheet-kicker {
  font-family: ui-monospace, "SF Mono", Monaco, "Cascadia Code", Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #666;
  margin: 0;
}

/* Upload button */
.worksheet-upload-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.worksheet-btn-upload {
  background: var(--accent);
  color: #fff;
  border: 1.5px solid var(--line);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 12px 18px;
  border-radius: 1px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: background 0.15s;
}

.worksheet-btn-upload:hover {
  background: var(--accent-hover);
}

.worksheet-upload-icon {
  width: 22px;
  height: 22px;
}

.worksheet-upload-desc {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.82rem;
  color: #666;
  line-height: 1.4;
  margin: 0;
}

.worksheet-browse-local {
  display: none;
}

.worksheet-upload-error {
  color: #b71c1c;
  background: #ffebee;
  border: 1px solid #ef9a9a;
  padding: 8px 12px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.82rem;
  margin-top: 8px;
  border-radius: 1px;
}

.worksheet-params-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Paper select */
.worksheet-select-wrap {
  position: relative;
  width: 100%;
}

.worksheet-select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1.5px solid var(--line);
  background: #ffffff;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink);
  border-radius: 1px;
  cursor: pointer;
}

.worksheet-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Toggle checkboxes */
.worksheet-toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
  margin-top: 4px;
}

.worksheet-toggle-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Row / Column controls */
.worksheet-param-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.worksheet-param-label {
  font-family: ui-monospace, "SF Mono", Monaco, "Cascadia Code", Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #555;
}

.worksheet-slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.worksheet-slider {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
  height: 6px;
}

.worksheet-stepper-btn {
  display: none;
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--line);
  background: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 1px;
}

.worksheet-stepper-btn:hover {
  background: #f0ece3;
}

.worksheet-num-box {
  min-width: 44px;
  height: 38px;
  border: 1.5px solid var(--line);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, "SF Mono", Monaco, monospace;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
}

/* Color swatches */
.worksheet-color-swatches {
  display: flex;
  gap: 10px;
  align-items: center;
}

.worksheet-color-swatch {
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--line);
  border-radius: 1px;
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform 0.1s;
}

.worksheet-color-swatch:hover {
  transform: scale(1.05);
}

.worksheet-color-swatch[aria-pressed="true"] {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* Actions Desktop */
.worksheet-actions-desktop {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid rgba(21, 21, 21, 0.15);
}

.worksheet-btn-download {
  background: var(--accent);
  color: #fff;
  border: 1.5px solid var(--line);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 1.08rem;
  font-weight: 700;
  padding: 13px 18px;
  border-radius: 1px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: background 0.15s;
}

.worksheet-btn-download:hover {
  background: var(--accent-hover);
}

.worksheet-btn-secondary {
  background: #3b5a68;
  color: #fff;
  border: 1.5px solid var(--line);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.98rem;
  font-weight: 700;
  padding: 11px 16px;
  border-radius: 1px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s;
}

.worksheet-btn-secondary:hover {
  background: #2b4551;
}

.worksheet-btn-text {
  background: #fff;
  color: var(--ink);
  border: 1.5px solid var(--line);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 1px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s;
}

.worksheet-btn-text:hover {
  background: #f0ece3;
}

.worksheet-download-icon {
  width: 22px;
  height: 22px;
}

/* Matching note */
.worksheet-matching-note {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #444;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.88rem;
  line-height: 1.35;
}

.worksheet-info-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: ui-serif, Georgia, serif;
  font-weight: 700;
  font-style: italic;
  font-size: 13px;
  flex-shrink: 0;
}

/* Right preview panel */
.worksheet-previews-card {
  background: var(--paper);
  border: 1.5px solid var(--line);
  box-shadow: none;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
}

/* Preview Tabs */
.worksheet-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1.5px solid var(--line);
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.worksheet-tab {
  background: #fff;
  color: #555;
  border: 1.5px solid var(--line);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.88rem;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 1px;
  cursor: pointer;
  transition: all 0.15s;
}

.worksheet-tab:hover {
  color: var(--ink);
  background: #f3efe6;
}

.worksheet-tab.is-active {
  background: var(--ink);
  color: #fff;
}

.worksheet-tab-content {
  display: none;
  width: 100%;
}

.worksheet-tab-content.is-active {
  display: block;
}

.worksheet-mat {
  background: #ece7df;
  border: 1px solid #dcd6cd;
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 1px;
}

.worksheet-page-canvas {
  width: 100%;
  max-width: 900px;
  height: auto;
  aspect-ratio: 11 / 8.5;
  background: #ffffff;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.14), 0 2px 6px rgba(0, 0, 0, 0.08);
  display: block;
  box-sizing: border-box;
}

.worksheet-aspect-note {
  font-family: ui-monospace, "SF Mono", Monaco, monospace;
  font-size: 0.76rem;
  font-weight: 600;
  color: #555;
  background: #f3efe6;
  border: 1px solid rgba(21, 21, 21, 0.15);
  padding: 8px 12px;
  margin: 12px 0 0;
  line-height: 1.4;
  border-radius: 1px;
}

.worksheet-previews-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
  height: 100%;
}

.worksheet-preview-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.worksheet-preview-title {
  font-family: ui-monospace, "SF Mono", Monaco, "Cascadia Code", Consolas, monospace;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #555;
}

.worksheet-preview-frame {
  position: relative;
  background: #ffffff;
  border: 1.5px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  width: 100%;
}

.worksheet-preview-img {
  width: 100%;
  height: auto;
  display: block;
}

.worksheet-grid-canvas {
  width: 100%;
  height: auto;
  display: block;
}

.worksheet-actions-mobile {
  display: none;
}

/* 3-Step Strip */
.worksheet-steps-panel {
  background: var(--paper);
  border: 1.5px solid var(--line);
  box-shadow: none;
  padding: 24px 32px;
  margin-top: 24px;
  margin-bottom: 28px;
}

.worksheet-steps-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.worksheet-step-item {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  flex: 1;
}

.worksheet-step-badge {
  width: 38px;
  height: 38px;
  background: var(--accent);
  color: #fff;
  border-radius: 1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: ui-serif, Georgia, serif;
  font-size: 1.35rem;
  font-weight: 700;
  flex-shrink: 0;
}

.worksheet-step-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.worksheet-step-title {
  font-family: ui-serif, Georgia, Cambria, serif;
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
  color: var(--ink);
  line-height: 1.2;
}

.worksheet-step-text {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--muted);
  margin: 0;
}

.worksheet-step-arrow {
  font-size: 1.6rem;
  color: var(--ink);
  font-weight: 300;
  padding: 0 10px;
  user-select: none;
  flex-shrink: 0;
}

/* Footer */
footer {
  border-top: 1.5px solid var(--line);
  background: #fbf9f4;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.82rem;
  padding: 16px 0;
}

/* ==========================================================================
   Mobile Responsive Adjustments
   ========================================================================== */
@media (max-width: 860px) {
  .desktop-only {
    display: none !important;
  }
  .mobile-only {
    display: block !important;
  }

  .topbar-inner {
    position: relative;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .nav-toggle {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 38px;
    height: 38px;
    padding: 6px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--ink);
    z-index: 1001;
  }

  .nav-toggle:focus-visible {
    outline: none;
  }

  .nav-toggle-bar {
    display: block;
    width: 22px;
    height: 2.5px;
    background: currentColor;
    border-radius: 1px;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  .nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(1) {
    transform: translateY(7.5px) rotate(45deg);
  }

  .nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(2) {
    opacity: 0;
  }

  .nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(3) {
    transform: translateY(-7.5px) rotate(-45deg);
  }

  .nav-links {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 200px;
    background: var(--paper);
    border: 1.5px solid var(--line);
    box-shadow: 4px 4px 0 rgba(21, 21, 21, 0.15);
    padding: 12px 16px;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
  }

  .nav-links.is-open {
    display: flex;
  }

  .nav-links a {
    display: block;
    padding: 6px 4px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink);
    text-decoration: none;
  }

  .nav-links a:hover,
  .nav-links a:focus-visible {
    color: var(--accent);
    text-decoration: underline;
  }

  .worksheet-heading {
    font-size: 2.2rem;
    line-height: 1.15;
  }

  .worksheet-lede {
    font-size: 1rem;
    line-height: 1.4;
  }

  .worksheet-workspace {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .worksheet-controls {
    background: transparent;
    border: none;
    padding: 0;
    box-shadow: none;
    gap: 14px;
  }

  .worksheet-kicker {
    display: none;
  }

  .worksheet-upload-card {
    background: var(--paper);
    border: 1.5px dashed #888;
    padding: 24px 16px;
    align-items: center;
    text-align: center;
    border-radius: 1px;
    gap: 12px;
  }

  .worksheet-upload-icon.mobile-only {
    display: block !important;
    width: 44px;
    height: 44px;
    color: var(--ink);
  }

  .worksheet-btn-upload {
    width: auto;
    padding: 10px 24px;
    font-size: 0.95rem;
  }

  .worksheet-browse-local.mobile-only {
    display: block !important;
    font-family: ui-monospace, "SF Mono", Monaco, monospace;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #666;
  }

  .worksheet-params-card {
    background: var(--paper);
    border: 1.5px solid var(--line);
    padding: 14px 16px;
    border-radius: 1px;
    gap: 12px;
  }

  .worksheet-param-group {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .worksheet-param-label {
    font-size: 0.95rem;
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-weight: 700;
    color: var(--ink);
    text-transform: none;
    letter-spacing: 0;
  }

  .worksheet-slider {
    display: none;
  }

  .worksheet-slider-row {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .worksheet-stepper-btn {
    display: inline-flex;
    width: 36px;
    height: 36px;
    border: 1.5px solid var(--line);
    background: #fff;
    font-size: 1.2rem;
    font-weight: 700;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 1px;
  }

  .worksheet-stepper-plus {
    background: var(--accent);
    color: #fff;
    border-color: var(--line);
  }

  .worksheet-stepper-plus:hover {
    background: var(--accent-hover);
  }

  .worksheet-num-box {
    min-width: 44px;
    height: 36px;
  }

  .worksheet-color-swatches {
    gap: 8px;
  }

  .worksheet-color-swatch {
    width: 30px;
    height: 30px;
  }

  .worksheet-previews-card {
    background: transparent;
    border: none;
    padding: 0;
    box-shadow: none;
  }

  .worksheet-previews-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .worksheet-preview-column {
    background: var(--paper);
    border: 1.5px solid var(--line);
    padding: 14px 16px;
    border-radius: 1px;
    gap: 10px;
  }

  .worksheet-preview-title {
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ink);
    text-transform: none;
    letter-spacing: 0;
  }

  .worksheet-preview-frame {
    border: none;
  }

  .worksheet-actions-desktop {
    display: none;
  }

  .worksheet-actions-mobile {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
    text-align: center;
    margin-top: 4px;
  }

  .worksheet-actions-mobile .worksheet-btn-download {
    width: 100%;
    padding: 14px 18px;
    font-size: 1.05rem;
  }

  .worksheet-actions-mobile .worksheet-btn-secondary {
    width: 100%;
    padding: 13px 18px;
    font-size: 1rem;
  }

  .worksheet-actions-mobile .worksheet-btn-text {
    width: 100%;
    padding: 11px 18px;
    font-size: 0.95rem;
  }

  .worksheet-matching-note {
    justify-content: center;
    font-size: 0.88rem;
  }

  .worksheet-steps-panel {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    margin-top: 14px;
    margin-bottom: 24px;
  }

  .worksheet-steps-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .worksheet-step-arrow {
    display: none;
  }

  .worksheet-step-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
    padding: 14px 4px;
    border: 1.5px solid var(--line);
    background: var(--paper);
    border-radius: 1px;
  }

  .worksheet-step-badge {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
  }

  .worksheet-step-title {
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1.25;
    margin: 0;
  }

  .worksheet-step-text {
    display: none;
  }
}

/* ==========================================================================
   Print Stylesheet — Exact Physical Landscape Worksheet
   ========================================================================== */
@media print {
  @page {
    size: 11in 8.5in;
    margin: 0;
  }

  html, body {
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    overflow: hidden !important;
  }

  /* Completely remove all document flow except worksheet canvas */
  header,
  footer,
  aside,
  .topbar,
  .worksheet-header,
  .worksheet-kicker,
  .worksheet-heading,
  .worksheet-lede,
  .worksheet-trust-note,
  .worksheet-upload-card,
  .worksheet-params-card,
  .worksheet-actions-desktop,
  .worksheet-actions-mobile,
  .worksheet-tabs,
  .worksheet-aspect-note,
  .worksheet-steps-panel,
  .worksheet-upload-error,
  #viewReference {
    display: none !important;
  }

  .worksheet-page,
  .worksheet-workspace,
  .worksheet-previews-card,
  #viewWorksheet,
  .worksheet-mat {
    display: block !important;
    position: static !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: #ffffff !important;
    box-shadow: none !important;
    max-width: none !important;
    max-height: none !important;
    overflow: hidden !important;
  }

  #worksheetCanvas {
    display: block !important;
    position: static !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: fill !important;
  }
}

