/* ── Fonts ─────────────────────────────────────────────────────────────────── */

@font-face {
  font-family: 'Playfair Display';
  font-style: normal;
  font-weight: 700 900;
  font-display: swap;
  src: url('fonts/playfair-display.woff2') format('woff2');
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

/* ── Icons ─────────────────────────────────────────────────────────────────── */

.icon {
  width: 22px;
  height: 22px;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

[data-theme="light"] .icon-sun  { display: none; }
[data-theme="dark"]  .icon-moon { display: none; }

/* ── Design tokens ─────────────────────────────────────────────────────────── */

:root {
  color-scheme: dark;
  --bg:         #111;
  --surface:    #1c1c1c;
  --surface-2:  #252525;
  --border:     #2e2e2e;
  --text:       #e8e8e8;
  --text-muted: #999;
  --accent:     #1a8cff;
  --tag-bg:     #2a2a2a;
}

[data-theme="light"] {
  color-scheme: light;
  --bg:         #f4f4f2;
  --surface:    #ffffff;
  --surface-2:  #ebebea;
  --border:     #ddddd9;
  --text:       #1a1a1a;
  --text-muted: #666;
  --accent:     #1a8cff;
  --tag-bg:     #e4e4e2;
}

/* ── Base ──────────────────────────────────────────────────────────────────── */

html, body { height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

#app { height: 100%; }

/* Screen-reader-only utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */

#detail-view {
  display: flex;
  height: 100%;
}

#detail-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

/* ── Toolbar ───────────────────────────────────────────────────────────────── */

#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: 68px;
  min-height: 68px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#toolbar-select-wrap {
  position: relative;
}

#toolbar-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 10px 36px 10px 16px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  width: auto;
  max-width: 220px;
  outline: none;
}

#toolbar-select:focus { border-color: var(--accent); }

/* Shared chevron for selects */
.select-chevron {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  pointer-events: none;
}

/* Theme toggle */
/* Font size control */
#font-size-wrap {
  position: relative;
  margin-left: auto;
  flex-shrink: 0;
}

#font-size-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 11px;
  display: flex;
  align-items: center;
  border-radius: 50%;
  transition: color 0.2s, background 0.2s;
}

#font-size-btn:hover { color: var(--accent); background: var(--surface-2); }

#font-size-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 16px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  white-space: nowrap;
  z-index: 100;
}

.font-label-sm { font-size: 11px; color: var(--text-muted); font-weight: 700; line-height: 1; }
.font-label-lg { font-size: 20px; color: var(--text-muted); font-weight: 700; line-height: 1; }

#font-size-slider {
  width: 110px;
  cursor: pointer;
  accent-color: var(--accent);
}

#print-btn,
#theme-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 11px;
  display: flex;
  align-items: center;
  border-radius: 50%;
  transition: color 0.2s, background 0.2s;
  flex-shrink: 0;
}

#print-btn:hover                         { color: var(--accent); background: var(--surface-2); }
#theme-toggle:hover                      { color: var(--accent); background: var(--surface-2); }
[data-theme="dark"] #theme-toggle:hover  { color: #ffd600;       background: var(--surface-2); }

/* Only show the print button when a fabric is on screen. */
.is-empty #print-btn { display: none; }

/* ── Detail panel ──────────────────────────────────────────────────────────── */

#detail-panel {
  flex: 1;
  overflow-y: auto;
  padding: 28px 20px;
  -webkit-overflow-scrolling: touch;
}

#placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 12% 24px 24%;
  height: 100%;
  color: var(--text-muted);
  font-size: 13px;
}

#placeholder-logo {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: clamp(72px, 22vw, 140px);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: -0.02em;
  text-align: center;
  color: var(--text);
}

#placeholder p {
  max-width: 260px;
  text-align: center;
  line-height: 1.6;
}

/* ── Footer ────────────────────────────────────────────────────────────────── */

#detail-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 56px;
  padding: 14px 0 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

#contact-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
}

#contact-link:hover { text-decoration: underline; }

/* ── Mobile empty state background ────────────────────────────────────────── */

@media (max-width: 767px) {
  .is-empty #detail-panel {
    padding: 0;
    background-image: url('images/bg-dark.jpg');
    background-size: cover;
    background-position: center;
  }

  [data-theme="light"] .is-empty #detail-panel {
    background-image: url('images/bg-light.jpg');
  }

  .is-empty #placeholder {
    background: rgba(0, 0, 0, 0.45);
    color: rgba(255, 255, 255, 0.7);
  }

  .is-empty #placeholder-logo {
    color: #fff;
  }

  [data-theme="light"] .is-empty #placeholder {
    background: rgba(255, 255, 255, 0.3);
    color: rgba(0, 0, 0, 0.55);
  }

  [data-theme="light"] .is-empty #placeholder-logo {
    color: #1a1a1a;
    text-shadow: none;
  }
}

#fabric-detail:focus { outline: none; }

/* ── Fabric detail content ─────────────────────────────────────────────────── */

.fabric-header {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.fabric-group {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

.fabric-name {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 12px;
  line-height: 1.15;
}

.tags { display: flex; flex-wrap: wrap; gap: 6px; }

.tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  background: var(--tag-bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  user-select: none;
}

/* Sections */
.section { margin-bottom: 28px; }

.section-title-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}

.section-title-row .section-title { margin-bottom: 0; }

.section-machine {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.section-machine::before {
  content: ":";
  margin-right: 10px;
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.kv-list { display: flex; flex-direction: column; gap: 6px; }
.kv-row  { display: flex; gap: 8px; font-size: var(--content-font-size, 13px); }
.kv-key  { color: var(--text-muted); min-width: 80px; flex-shrink: 0; }
.kv-val  { color: var(--text); }

/* Machine settings table */
.settings-table { border-collapse: collapse; width: 100%; }

.settings-table td {
  padding: 8px 10px;
  font-size: var(--content-font-size, 13px);
  border-bottom: 1px solid var(--border);
}

.settings-table td:first-child  { color: var(--text-muted); width: 130px; }
.settings-table td:last-child    { font-weight: 500; }
.settings-table tr:last-child td { border-bottom: none; }

/* Tips */
.tips-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tips-list li {
  font-size: var(--content-font-size, 13px);
  padding-left: 16px;
  position: relative;
  line-height: 1.5;
}

.tips-list li::before {
  content: "–";
  position: absolute;
  left: 0;
  color: var(--accent);
}

/* Thread */
.thread-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.thread-list li { font-size: var(--content-font-size, 13px); padding-left: 16px; position: relative; }

.thread-list li::before {
  content: "·";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-size: 18px;
  line-height: 1.1;
}

/* Detail paragraph */
.detail-text { font-size: var(--content-font-size, 13px); color: var(--text); line-height: 1.75; }

/* Scrollbar */
::-webkit-scrollbar       { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Reduced motion ────────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  #toolbar-title, #theme-toggle { transition: none; }
}

/* ── Desktop (≥ 768 px) ────────────────────────────────────────────────────── */

#detail-bg { display: none; }

@media (min-width: 768px) {
  /* Left content column */
  #detail-main { flex: 0 0 clamp(420px, 45%, 560px); border-right: 1px solid var(--border); }

  /* Right decorative column */
  #detail-bg {
    display: block;
    flex: 1;
    background-image: url('images/bg-dark.jpg');
    background-size: cover;
    background-position: center;
    position: relative;
  }

  [data-theme="light"] #detail-bg        { background-image: url('images/bg-light.jpg'); }
  [data-theme="light"] #detail-bg::after { background: rgba(255, 255, 255, 0.08); }

  #detail-bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
  }

  #detail-bg-logo {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
    font-family: 'Playfair Display', Georgia, serif;
    font-size: clamp(72px, 7.5vw, 110px);
    font-weight: 900;
    line-height: 0.95;
    letter-spacing: -0.02em;
    text-align: center;
    color: #fff;
    opacity: 0.5;
    max-width: 420px;
    width: 90%;
    pointer-events: none;
  }

  [data-theme="light"] #detail-bg-logo { color: #1a1a1a; opacity: 0.15; }

  .is-empty #detail-bg-logo { display: none; }

  #detail-panel { padding: 32px 28px; }

  .fabric-name    { font-size: 36px; }
  .settings-table { max-width: 420px; }
  .detail-text    { max-width: 560px; }
}

/* ── Print ─────────────────────────────────────────────────────────────────── */
/* A clean one- or two-page handout for the sewing machine. */

@media print {
  @page { margin: 0.5in; }

  :root,
  [data-theme="light"],
  [data-theme="dark"] {
    color-scheme: light;
    --bg:         #fff;
    --surface:    #fff;
    --surface-2: #fff;
    --border:     #bbb;
    --text:       #000;
    --text-muted: #333;
    --accent:     #000;
    --tag-bg:     #fff;
  }

  html, body {
    height: auto;
    overflow: visible;
    background: #fff;
    color: #000;
  }

  #toolbar,
  #detail-bg,
  #placeholder,
  #detail-footer { display: none !important; }

  #app,
  #detail-view,
  #detail-main,
  #detail-panel,
  #fabric-detail {
    display: block;
    flex: none;
    height: auto;
    min-height: 0;
    overflow: visible;
    padding: 0;
    margin: 0;
    border: none;
    max-width: 100%;
  }

  .fabric-header {
    border-bottom: 1px solid #000;
    padding-bottom: 8pt;
    margin-bottom: 14pt;
  }

  .fabric-group { color: #000;     font-size: 8pt;  letter-spacing: 0.1em; }
  .fabric-name  { font-size: 26pt; margin-bottom: 6pt; line-height: 1.1; }

  .tags { gap: 4pt; }
  .tag {
    background: transparent;
    border: 1px solid #999;
    color: #333;
    font-size: 8pt;
    padding: 1pt 5pt;
  }

  .section            { margin-bottom: 10pt; page-break-inside: avoid; }
  .section-title      { color: #000; font-size: 8pt; margin-bottom: 4pt; }
  .section-machine    { color: #333; font-size: 8pt; }
  .section-machine::before { content: ":"; margin-right: 8pt; }

  .kv-row,
  .thread-list li,
  .tips-list li,
  .settings-table td,
  .detail-text       { font-size: 10pt; line-height: 1.4; }

  .kv-key { color: #333; }

  .settings-table { border-collapse: collapse; width: 100%; max-width: 100%; }
  .settings-table td { padding: 3pt 6pt; border-bottom: 1px solid #ddd; }
  .settings-table td:first-child { color: #333; }

  .tips-list li::before,
  .thread-list li::before { color: #000; }

  .detail-text { color: #222; max-width: 100%; }

  /* The Detail prose is nice-to-have on paper; let it flow but keep settings on page one. */
  a[href]::after { content: ""; }
}
