/* ═══════════════════════════════════════════════════════
   MyCrossPlay — Cross Stitch Pattern Maker
   Design: premium · minimal · calm · editorial
   Accent: warm linen / aged copper
   ═══════════════════════════════════════════════════════ */

:root {
  --bg:         #f8f6f2;
  --surface:    #ffffff;
  --surface-2:  #f2ede6;
  --border:     #ddd8cf;
  --border-2:   #c8c0b0;

  --text:       #2a2118;
  --text-2:     #6b5e50;
  --text-3:     #9c8e80;

  --accent:     #8b6248;
  --accent-lt:  #c4997a;
  --accent-bg:  #f5ece3;

  --canvas-bg:  #fafaf8;

  --radius:     6px;
  --radius-lg:  12px;
  --shadow:     0 1px 4px rgba(0,0,0,.07);
  --shadow-md:  0 4px 16px rgba(0,0,0,.10);

  --font-body:  'Georgia', 'Times New Roman', serif;
  --font-ui:    system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono:  'Courier New', Courier, monospace;

  --ctrl-h:     34px;
  --panel-w:    300px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Typography ─────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-family: var(--font-body);
  font-weight: normal;
  color: var(--text);
  line-height: 1.3;
}
h1 { font-size: 2.5rem; letter-spacing: -.02em; }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.2rem; }
h4 { font-size: 1rem; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ──────────────────────────────────────────────── */
.container      { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.container--wide{ max-width: 1440px; margin: 0 auto; padding: 0 24px; }

/* ── Nav ─────────────────────────────────────────────────── */
.site-nav {
  position: sticky; top: 0; z-index: 100;
  background: rgba(248,246,242,.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.site-nav__inner {
  display: flex; align-items: center;
  justify-content: space-between; height: 56px;
}
.site-nav__logo {
  font-family: var(--font-body); font-size: 1.25rem;
  color: var(--text); letter-spacing: -.01em;
  display: flex; align-items: center; gap: 8px;
}
.site-nav__logo .logo-mark {
  width: 28px; height: 28px;
  display: grid; grid-template-columns: repeat(4,1fr); gap: 2px;
}
.site-nav__logo .logo-mark span {
  background: var(--accent); border-radius: 1px; opacity: .7;
}
.site-nav__logo .logo-mark span:nth-child(2),
.site-nav__logo .logo-mark span:nth-child(7),
.site-nav__logo .logo-mark span:nth-child(10),
.site-nav__logo .logo-mark span:nth-child(15) { opacity: .2; }
.site-nav__links { display: flex; gap: 24px; }
.site-nav__links a { font-size: 13px; color: var(--text-2); transition: color .15s; }
.site-nav__links a:hover { color: var(--accent); }

/* ── Hero ────────────────────────────────────────────────── */
.hero {
  padding: 56px 0 40px; text-align: center;
  border-bottom: 1px solid var(--border);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20'%3E%3Ccircle cx='10' cy='10' r='1' fill='%23ddd8cf' opacity='.5'/%3E%3C/svg%3E");
}
.hero__eyebrow {
  font-size: 11px; letter-spacing: .15em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 12px;
}
.hero h1 { margin-bottom: 12px; }
.hero__sub {
  font-family: var(--font-body); font-size: 1.1rem;
  color: var(--text-2); max-width: 420px; margin: 0 auto 24px;
}
.hero__grid {
  display: inline-grid; grid-template-columns: repeat(8,16px);
  gap: 3px; margin-top: 20px; opacity: .35;
}
.hero__grid span { width: 16px; height: 16px; border-radius: 1px; }

/* ── Upload Section ──────────────────────────────────────── */
.upload-section {
  padding: 32px 0 28px;
  border-bottom: 1px solid var(--border);
  transition: padding .3s;
}
.upload-section.compact { padding: 12px 0; }
.upload-section.compact .upload-zone { display: none; }

.upload-section__inner {
  display: flex;
  justify-content: center;
}

/* Narrow tall upload zone */
.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 180px;
  min-height: 180px;
  border: 2px dashed var(--border-2);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  user-select: none;
  gap: 8px;
}
.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent); background: var(--accent-bg);
}
.upload-zone__icon  { font-size: 32px; opacity: .5; }
.upload-zone__title {
  font-family: var(--font-body); font-size: 1rem;
  color: var(--text);
}
.upload-zone__sub   { color: var(--text-2); font-size: 11px; line-height: 1.5; }

/* ── App Area ────────────────────────────────────────────── */
#app-area {
  display: none; gap: 0;
  min-height: calc(100vh - 56px);
}

/* ── Control Panel ───────────────────────────────────────── */
.control-panel {
  width: var(--panel-w); min-width: 240px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  height: calc(100vh - 56px);
  position: sticky; top: 56px;
  display: flex;
  flex-direction: column;
}

/* ── Sticky PDF download bar ────────────────────────────── */
.pdf-download-bar {
  position: sticky; top: 0; z-index: 20;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 2px solid var(--accent-lt);
  box-shadow: 0 2px 8px rgba(139,98,72,.12);
}

/* ── Image bar (thumbnail + actions) ────────────────────── */
.image-bar {
  display: flex; align-items: center;
  gap: 10px; padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.original-preview {
  display: none;
  width: 48px; height: 48px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.image-bar__actions {
  display: flex; gap: 6px; flex-wrap: wrap;
}

/* ── Size Info ───────────────────────────────────────────── */
.size-info {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--accent-bg);
  font-size: 10px;
  color: var(--accent);
  font-family: var(--font-mono);
  line-height: 1.6;
}

/* ── Preview Area ────────────────────────────────────────── */
.preview-area {
  flex: 1;
  background: var(--canvas-bg);
  overflow: hidden;
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ── Collapsible ─────────────────────────────────────────── */
.collapsible-section { border-bottom: 1px solid var(--border); }
.collapsible-header {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 11px 16px; cursor: pointer;
  user-select: none; transition: background .1s;
}
.collapsible-header:hover { background: var(--surface-2); }
.collapsible-header__title {
  font-size: 11px; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-2);
}
.collapsible-header__arrow {
  font-size: 10px; color: var(--text-3);
  transition: transform .2s;
}
.collapsible-section.open .collapsible-header__arrow { transform: rotate(180deg); }
.collapsible-body { display: none; padding: 10px 16px 14px; }
.collapsible-section.open .collapsible-body { display: block; }

/* ── Controls ────────────────────────────────────────────── */
.ctrl-row {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 10px; gap: 8px;
}
.ctrl-label {
  font-size: 11px; color: var(--text-2);
  white-space: nowrap; flex-shrink: 0;
}
.ctrl-value {
  font-size: 11px; font-family: var(--font-mono);
  color: var(--accent); min-width: 28px;
  text-align: right; flex-shrink: 0;
}

/* Slider */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px;
  background: var(--border); border-radius: 2px;
  outline: none; flex: 1;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border: none;
  border-radius: 50%; background: var(--accent); cursor: pointer;
}

/* Select */
select {
  appearance: none;
  background: var(--surface)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239c8e80' fill='none' stroke-width='1.5'/%3E%3C/svg%3E")
    no-repeat right 8px center;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 0 28px 0 8px; height: var(--ctrl-h);
  font-size: 12px; color: var(--text); width: 100%; cursor: pointer;
}
select:focus { outline: none; border-color: var(--accent); }

/* Checkbox */
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
input[type="checkbox"] {
  width: 14px; height: 14px;
  accent-color: var(--accent); cursor: pointer; flex-shrink: 0;
}
.checkbox-row label { font-size: 11px; color: var(--text-2); cursor: pointer; }

/* Radio group */
.radio-group { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 10px; }
.radio-group label {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--text-2); cursor: pointer;
  padding: 3px 9px;
  border: 1px solid var(--border-2); border-radius: 20px;
  transition: all .15s;
}
.radio-group label:hover { border-color: var(--accent); }
.radio-group input[type="radio"] { display: none; }
.radio-group label:has(input:checked) {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

/* Number input */
input[type="number"] {
  border: 1px solid var(--border-2); border-radius: var(--radius);
  padding: 4px 6px; font-size: 12px;
  width: 70px; height: 30px;
  color: var(--text); background: var(--surface);
}
input[type="number"]:focus { outline: none; border-color: var(--accent); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center;
  justify-content: center; gap: 6px;
  height: var(--ctrl-h); padding: 0 14px;
  border: 1px solid var(--border-2); border-radius: var(--radius);
  font-size: 12px; cursor: pointer;
  background: var(--surface); color: var(--text-2);
  transition: all .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: #7a5438; border-color: #7a5438; color: #fff; }
.btn--sm   { height: 28px; padding: 0 10px; font-size: 11px; }
.btn--lg   { height: 40px; padding: 0 18px; font-size: 13px; font-weight: 600; }
.btn--block{ width: 100%; }
.btn--primary:disabled { background: var(--text-3); border-color: var(--text-3); cursor: wait; }

/* Divider */
.ctrl-divider { height: 1px; background: var(--border); margin: 10px 0; }

/* Margins grid */
.margins-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.margins-grid .ctrl-row { margin-bottom: 0; }

/* ── Preview Header ──────────────────────────────────────── */
.preview-header {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface); gap: 10px; flex-wrap: wrap;
}
.preview-header__title {
  font-size: 10px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--text-3);
}
.preview-controls { display: flex; align-items: center; gap: 5px; }
.preview-tabs     { display: flex; gap: 4px; }
.preview-tab {
  padding: 4px 12px; font-size: 11px;
  border: 1px solid var(--border-2); border-radius: 20px;
  cursor: pointer; background: transparent; color: var(--text-2);
  transition: all .15s;
}
.preview-tab.active,
.preview-tab:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Chart Layout (chart + inline legend) ────────────────── */
.chart-layout {
  display: flex;
  flex-direction: row;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
.chart-layout.legend-left    { flex-direction: row-reverse; }
.chart-layout.legend-bottom  { flex-direction: column; }

/* ── Chart Container & Canvas ────────────────────────────── */
.chart-container {
  position: relative; overflow: hidden;
  padding: 16px;
  flex: 1;
  min-width: 0;
  min-height: 300px;
}
#chart-canvas {
  display: block; cursor: grab;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-width: 100%;
}
#chart-canvas:active { cursor: grabbing; }

.chart-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-3); gap: 12px;
  pointer-events: none;
}
.chart-empty__icon { font-size: 48px; opacity: .3; }
.chart-empty__text { font-family: var(--font-body); font-size: 1.1rem; opacity: .6; }

.preview-status {
  position: absolute; inset: 0;
  background: rgba(248,246,242,.88);
  display: none;
  align-items: center; justify-content: center;
  font-family: var(--font-body); color: var(--text-2);
  font-size: 1rem; z-index: 20;
}

.stitch-stats {
  position: absolute; bottom: 12px; left: 16px;
  font-size: 10px; color: var(--text-3);
  font-family: var(--font-mono);
  background: rgba(255,255,255,.88); padding: 3px 10px;
  border-radius: 20px; border: 1px solid var(--border);
  pointer-events: none;
}

/* ── Preview Panel ───────────────────────────────────────── */
.preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
#chart-panel-wrap {
  position: relative;
}

/* ── Inline Legend (next to chart) ──────────────────────── */
.inline-legend {
  width: 220px; min-width: 180px; max-width: 280px;
  border-left: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.chart-layout.legend-bottom .inline-legend {
  width: 100%; max-width: none;
  height: 180px; min-height: 120px; max-height: 220px;
  border-left: none; border-top: 1px solid var(--border);
  flex-direction: row; flex-wrap: wrap;
  overflow-x: auto;
}
.inline-legend__panel {
  display: grid; gap: 1px; padding: 8px;
}
.chart-layout.legend-bottom .inline-legend__panel {
  display: flex; flex-direction: row; flex-wrap: wrap; gap: 4px; padding: 6px;
}

/* ── Page Thumbnail Previews ─────────────────────────────── */
.page-previews {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  min-height: 0;
}
.page-previews:empty { display: none; }

.page-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.page-thumb canvas {
  display: block;
  border: 1px solid var(--border-2);
  border-radius: 3px;
  box-shadow: 0 1px 4px rgba(0,0,0,.10);
}
.page-thumb__label {
  font-size: 10px;
  color: var(--text-3);
  font-family: var(--font-mono);
}

/* ── Legend Panel (tab) ──────────────────────────────────── */
#legend-panel-wrap { padding: 12px 16px; overflow-y: auto; max-height: calc(100vh - 120px); }
#legend-canvas { display: block; max-width: 100%; border-radius: var(--radius); border: 1px solid var(--border); }

.legend-panel { display: grid; gap: 2px; margin-top: 10px; }
.legend-row {
  display: grid; grid-template-columns: 32px 1fr auto;
  align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: var(--radius);
  cursor: pointer; transition: background .1s;
  border: 1px solid transparent;
}
.legend-row:hover { background: var(--surface-2); }
.legend-row.active { background: var(--accent-bg); border-color: var(--accent-lt); }
.legend-swatch {
  width: 28px; height: 28px; border-radius: 4px;
  border: 1px solid rgba(0,0,0,.1);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.legend-info   { min-width: 0; }
.legend-code   { display: block; font-size: 10px; font-weight: 600; color: var(--text); }
.legend-name   { display: block; font-size: 9px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend-count  { font-size: 10px; font-family: var(--font-mono); color: var(--text-3); flex-shrink: 0; white-space: nowrap; }

/* ── How It Works ────────────────────────────────────────── */
.how-it-works { padding: 72px 0; border-top: 1px solid var(--border); }
.section-label {
  font-size: 11px; letter-spacing: .15em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 12px;
}
.section-title { margin-bottom: 48px; }
.steps-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(220px,1fr)); gap: 32px; }
.step { display: flex; flex-direction: column; gap: 12px; }
.step__num {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent-bg); border: 1px solid var(--accent-lt);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-body); font-size: 1.1rem; color: var(--accent);
}
.step h4 { font-family: var(--font-body); font-size: 1.05rem; }
.step p  { font-size: 13px; color: var(--text-2); line-height: 1.7; }

/* ── Features ────────────────────────────────────────────── */
.features-section {
  padding: 72px 0; background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.features-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(260px,1fr)); gap: 28px; margin-top: 48px; }
.feature-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px 24px;
  transition: box-shadow .2s;
}
.feature-card:hover     { box-shadow: var(--shadow-md); }
.feature-card__icon     { font-size: 24px; margin-bottom: 12px; }
.feature-card__title    { font-family: var(--font-body); font-size: 1rem; margin-bottom: 8px; }
.feature-card__text     { font-size: 13px; color: var(--text-2); line-height: 1.7; }

/* ── FAQ ─────────────────────────────────────────────────── */
.faq-section { padding: 72px 0; border-top: 1px solid var(--border); }
.faq-grid    { display: grid; grid-template-columns: repeat(auto-fit,minmax(300px,1fr)); gap: 32px; margin-top: 48px; }
.faq-item h4 { font-family: var(--font-body); font-size: 1rem; margin-bottom: 8px; color: var(--text); }
.faq-item p  { font-size: 13px; color: var(--text-2); line-height: 1.7; }

/* ── Footer ──────────────────────────────────────────────── */
.site-footer { border-top: 1px solid var(--border); padding: 32px 0; background: var(--surface); }
.site-footer__inner {
  display: flex; align-items: center;
  justify-content: space-between; flex-wrap: wrap; gap: 16px;
}
.site-footer__links { display: flex; gap: 20px; flex-wrap: wrap; }
.site-footer__links a { font-size: 12px; color: var(--text-3); }
.site-footer__links a:hover { color: var(--accent); }
.site-footer__copy    { font-size: 12px; color: var(--text-3); }
.site-footer__contact { font-size: 12px; color: var(--text-3); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  #app-area { flex-direction: column; }
  .control-panel {
    width: 100%; height: auto;
    position: static; border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 55vh;
  }
  .preview-area { min-height: 50vh; }
  h1 { font-size: 1.9rem; }
  .hero { padding: 36px 0 28px; }
}
@media (max-width: 600px) {
  :root { --panel-w: 100%; }
  .site-nav__links  { display: none; }
  .container        { padding: 0 16px; }
  .steps-grid, .features-grid, .faq-grid { grid-template-columns: 1fr; }
  .inline-legend    { width: 160px; }
}

@media print {
  .site-nav, .control-panel, .preview-header, .upload-section { display: none; }
  .preview-area { margin: 0; padding: 0; }
}
