/* ── Custom Properties (set per-theme by app.js) ── */
:root {
  --color-primary: #2c3e50;
  --color-accent: #bdc3c7;
  --font-title: 'Playfair Display', serif;
  --font-body: 'Libre Baskerville', serif;
}

/* ── Reset ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Base ── */
body {
  font-family: system-ui, sans-serif;
  background: #f0f0ec;
  min-height: 100vh;
}

body.grayscale {
  filter: grayscale(1) contrast(1.2);
}

/* ── Layout ── */
.layout {
  display: flex;
  gap: 2rem;
  padding: 1.5rem;
  max-width: 1280px;
  margin: 0 auto;
}

/* ── Controls Sidebar ── */
.controls {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.app-title {
  font-family: system-ui, sans-serif;
  font-size: 1.6rem;
  line-height: 1.2;
  color: #2c3e50;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.sticky-note {
  position: fixed;
  bottom: 1.5rem;
  background: #fef08a;
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  color: #555;
  line-height: 1.5;
  transform: rotate(-1.5deg);
  box-shadow: 2px 3px 8px rgba(0,0,0,0.15);
  z-index: 10;
}

.family-safe-note {
  font-size: 0.7rem;
  color: #999;
  margin-top: 0.2rem;
}

.control-group--inline {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #555;
}

input[type="text"],
select {
  padding: 0.5rem 0.6rem;
  border: 2px solid #ccc;
  border-radius: 4px;
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  background: white;
}

input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
}

input[type="checkbox"] {
  width: 1.2rem;
  height: 1.2rem;
  cursor: pointer;
}

button {
  padding: 0.65rem 1rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: system-ui, sans-serif;
  transition: opacity 0.15s;
}

button:hover { opacity: 0.85; }

#generate-btn {
  background: var(--color-primary);
  color: white;
}

#print-btn {
  background: #ecf0f1;
  color: #1a1a1a;
  border: 2px solid #ccc;
}

/* ── Puzzle Area ── */
.puzzle-area {
  flex: 1;
  min-width: 0;
}

.puzzle-scale-wrapper {
  width: 100%;
  position: relative;
  /* height set by JS to match scaled puzzle height */
}

.loading,
.error-msg,
.empty-state {
  padding: 2rem;
  text-align: center;
  font-size: 1.1rem;
  color: #666;
}

.error-msg { color: #c0392b; }

/* ── Puzzle Card ── */
.puzzle {
  width: 720px;
  aspect-ratio: 8.5 / 11;
  overflow: hidden;
  position: relative;
  background: white;
  border: 3px solid var(--color-accent);
  padding: 24px;
  box-sizing: border-box;
  transform-origin: top left;
  transform: scale(var(--puzzle-scale, 1));
}

.puzzle-decorations {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  overflow: hidden;
}

.puzzle-scatter-item {
  position: absolute;
  opacity: 0.2;
  user-select: none;
  line-height: 1;
}

.puzzle-title {
  font-family: var(--font-title);
  font-size: 32px;
  text-align: center;
  color: var(--color-primary);
  text-transform: capitalize;
  margin: 2px 0 8px;
  position: relative;
  z-index: 2;
}

.emoji-border {
  text-align: center;
  font-size: 18px;
  letter-spacing: 3px;
  padding: 2px 0;
  line-height: 1.4;
}

#emoji-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1;
  padding: 2px 0;
}

.puzzle-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  z-index: 2;
}

/* ── Grid ── */
.grid-wrapper {
  container-type: inline-size;
  width: 100%;
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 15), 1fr);
  font-family: 'Source Code Pro', monospace;
  font-weight: 600;
  width: 100%;
}

.grid div {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  font-size: calc(55cqw / var(--grid-cols));
  color: #000;
  background: #fff;
}

.grid.grid--lines div {
  border-color: #ddd;
}

/* ── Word List ── */
.word-list {
  width: 100%;
}

.word-list h3 {
  font-family: 'Source Code Pro', monospace;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 7px;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.word-list ul {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 5px 10px;
}

.word-list li {
  font-family: 'Source Code Pro', monospace;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #000;
  overflow-wrap: break-word;
  hyphens: auto;
}

/* ── Puzzle Toolbar ── */
.puzzle-toolbar {
  display: flex;
  gap: 0.4rem;
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 20;
}

body.modal-open .puzzle-toolbar {
  display: none;
}

.toolbar-btn {
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.1rem;
  font-weight: 700;
  background: white;
  border: 2px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: border-color 0.15s, color 0.15s;
}

.toolbar-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* ── Modal ── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 99;
  cursor: pointer;
}

body.modal-open {
  overflow: hidden;
}

body.modal-open .modal-backdrop {
  display: block;
}

body.modal-open .puzzle-scale-wrapper {
  position: fixed;
  inset: 0;
  z-index: 100;
  height: 100dvh !important;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

body.modal-open .puzzle {
  transform: scale(var(--modal-scale, 1)) !important;
  transform-origin: center center;
  aspect-ratio: 8.5 / 11;
  cursor: default;
  pointer-events: auto;
}

.modal-close-btn {
  display: none;
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 101;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  border: none;
  background: white;
  font-size: 1.1rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

body.modal-open .modal-close-btn {
  display: flex;
}

.puzzle:not(body.modal-open .puzzle) {
  cursor: zoom-in;
}

/* ── Mobile Layout ── */
@media (max-width: 700px) {
  .layout {
    flex-direction: column;
    padding: 1rem;
    gap: 1rem;
  }

  .controls {
    width: 100%;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .app-title,
  .control-group,
  #generate-btn,
  #print-btn {
    width: 100%;
  }

  .control-group--inline {
    width: auto;
    flex: 1;
  }

  .sticky-note {
    position: static;
    width: 100%;
    transform: none;
    box-shadow: 2px 3px 8px rgba(0,0,0,0.15);
  }
}

/* ── Print ── */
@media print {
  .controls,
  .loading,
  .error-msg,
  .empty-state,
  .puzzle-toolbar,
  .modal-backdrop,
  .modal-close-btn,
  .sticky-note,
  ins.adsbygoogle,
  .adsbygoogle {
    display: none !important;
  }

  body {
    background: white;
    filter: none !important;
    overflow: visible !important;
  }

  body.grayscale .puzzle {
    filter: grayscale(1);
  }

  .layout {
    display: block;
    padding: 0;
  }

  /* Reset any modal state for print */
  .puzzle-scale-wrapper {
    position: static !important;
    height: auto !important;
    display: block !important;
  }

  .puzzle {
    transform: none !important;
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 8.5 / 11 !important;
    overflow: hidden !important;
    page-break-inside: avoid;
  }
}

@page {
  size: letter portrait;
  margin: 0.5in;
}
