@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Rubik:wght@400;500&display=swap");

:root {
  --bg: #f0f2f5;
  --panel: #ffffff;
  --card: #f1f4f8;
  --accent: #4f883d;
  --accent-strong: #4f883d;
  --text: #1f2a3d;
  --muted: #566577;
  --grid: #e6edf6;
  --grid-text: #0f1f2f;
  --shadow: 0 8px 24px rgba(15, 31, 47, 0.08);
  --border: #e0e4ef;
  --preview-bg: #e8eaf0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: "Space Grotesk", "Rubik", system-ui, sans-serif;
  padding: 0;
  overflow: hidden;
}

.backdrop {
  margin: 0;
  min-height: 100vh;
}

.frame {
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  min-height: 100vh;
}

.hero-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button {
  background: var(--accent);
  color: #ffffff;
  border: 1px solid var(--accent);
  padding: 12px 16px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  box-shadow: none;
}

button:hover {
  transform: none;
  box-shadow: none;
}

button:active {
  transform: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

button:disabled:hover {
  transform: none;
  box-shadow: none;
}

button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid #d6deeb;
  box-shadow: none;
}

button.ghost.secondary {
  color: var(--muted);
  border-color: #e1e7f0;
}

button.accent {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.primary {
  background: #4f883d;
  border-color: #4f883d;
  color: #ffffff;
}

.hero-badge {
  min-width: 180px;
  background: #f5f7fb;
  border: 1px solid #e3e8f0;
  border-radius: 12px;
  padding: 12px 14px;
  text-align: right;
  color: var(--text);
}

.hero-badge p {
  margin: 0;
  font-weight: 600;
}

.hero-badge span {
  color: var(--muted);
  font-size: 13px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 0;
  padding: 0;
  align-items: stretch;
  height: 100vh;
  min-height: 100vh;
}

.panel {
  background: var(--panel);
  border: none;
  border-radius: 0;
  padding: 18px;
  min-height: 0;
}

.panel h2 {
  margin: 0 0 8px;
  letter-spacing: -0.01em;
  font-size: 24px;
}

.settings-panel {
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.settings-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-bottom {
  margin-top: 2px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bottom-download {
  width: 100%;
}

.export-option {
  align-self: flex-start;
}

.preview {
  background: var(--preview-bg);
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.preview-surface {
  width: min(100%, 1080px);
  background: #ffffff;
  border: 1px solid #d8deea;
  border-radius: 18px;
  box-shadow: 0 14px 30px rgba(15, 31, 47, 0.14);
  padding: 20px 22px 24px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-controls {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.form-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
  gap: 6px;
}

.form-row.full {
  grid-column: 1 / -1;
}

label {
  color: var(--muted);
  font-size: 14px;
}

input[type="text"],
input[type="number"],
input[type="file"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #d6deeb;
  background: #ffffff;
  color: var(--text);
  font-size: 15px;
}

.gallery-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}

.gallery-controls select {
  flex: 1 1 auto;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #d6deeb;
  background: #ffffff;
  font-size: 14px;
  color: var(--text);
}

button.small {
  padding: 8px 10px;
  font-size: 13px;
  box-shadow: none;
}

.gallery-grid {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 6px;
  padding: 6px;
  border: 1px solid #e3e8f0;
  border-radius: 10px;
  background: #ffffff;
  max-height: 220px;
  overflow: auto;
}

.gallery-thumb {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid transparent;
  background: #f5f7fb;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.gallery-thumb img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
}

.gallery-thumb.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79, 136, 61, 0.25);
  background: #ffffff;
}

.selected-image {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.selected-image img {
  max-width: 100px;
  max-height: 100px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid #e3e8f0;
  background: #ffffff;
}

.gallery-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.gallery-chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid #dfe5ef;
  background: #f9fbfd;
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.gallery-chip:hover {
  border-color: #cfd7e3;
  color: var(--text);
}

.gallery-chip.active {
  border-color: var(--accent);
  background: #ffffff;
  color: var(--text);
}

.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.radio-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #dfe5ef;
  border-radius: 10px;
  padding: 6px 10px;
  background: #f9fbfd;
  cursor: pointer;
  color: var(--muted);
}

.radio-row input {
  margin: 0;
}

.radio-row label:hover {
  border-color: var(--accent);
  color: var(--text);
}

.word-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 760px;
}

.word-input-row input {
  flex: 1 1 0;
}

.image-trigger {
  width: 88px;
  height: 88px;
  border-radius: 16px;
  border: 1px solid #d6deeb;
  background: #ffffff url("images/photo.png") center/70% no-repeat;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: none;
}

.image-trigger img {
  max-width: 80%;
  max-height: 80%;
  object-fit: contain;
}

.image-trigger.has-image {
  border-color: var(--accent);
  box-shadow: none;
  background-color: #ffffff;
  background-image: none;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 40px;
  z-index: 20;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 31, 47, 0.35);
  backdrop-filter: blur(2px);
}

.modal-dialog {
  position: relative;
  width: min(640px, 90vw);
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid #dce3ee;
  box-shadow: 0 16px 40px rgba(15, 31, 47, 0.15);
  padding: 16px;
  z-index: 1;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.icon-close {
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

@media (max-width: 760px) {
  .word-entry {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .word-input-row {
    flex-direction: column;
    align-items: stretch;
  }

  .word-input-row input {
    width: 100%;
  }

  .image-trigger {
    width: 100%;
    height: 120px;
  }
}

input:focus {
  outline: 2px solid rgba(47, 111, 235, 0.35);
  border-color: rgba(47, 111, 235, 0.55);
}

.actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin: 10px 0;
  flex-wrap: wrap;
}

.actions-left {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex: 1 1 220px;
}

.actions-right,
.ai-row {
  margin-left: 0;
  width: 100%;
}

.ghost.ai {
  font-weight: 700;
}

.ai-btn {
  background: #3f7a36;
  color: #ffffff;
  border: 1px solid #3f7a36;
  border-radius: 8px;
  padding: 14px 22px;
  font-weight: 600;
  font-size: 17px;
  line-height: 1.1;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: none;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  width: 100%;
}

.ai-btn:hover {
  transform: none;
  box-shadow: none;
}

.ai-btn:active {
  transform: none;
}

.inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}

.inline input {
  width: auto;
}

.word-list {
  background: var(--card);
  border: 1px solid #e3e8f0;
  border-radius: 8px;
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.word-entry {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.image-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 90px;
}

.image-label {
  font-size: 13px;
  color: var(--muted);
}

.image-column .small {
  width: 100%;
}

.word-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
  flex: 1 1 auto;
  min-width: 0;
}

.word-entry .hint {
  margin: 0;
}

.word-chip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid #e3e8f0;
}

.chip-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.chip-thumb {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid #e3e8f0;
  background: #f8fafc;
  flex: 0 0 auto;
}

.chip-thumb.placeholder {
  opacity: 0.6;
  background: #f1f4f8;
}

.chip-word {
  cursor: pointer;
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.chip-edit {
  display: grid;
  gap: 5px;
  min-width: 0;
  flex: 1 1 auto;
}

.chip-edit input {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
}

.chip-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  flex-shrink: 0;
  width: 52px;
}

.word-chip strong {
  letter-spacing: 0.02em;
}

.word-chip small {
  color: var(--muted);
}

.remove {
  background: transparent;
  color: #b83a3a;
  border: none;
  padding: 4px 2px;
  cursor: pointer;
  font-size: 12px;
  box-shadow: none;
  text-align: center;
}

.edit {
  background: transparent;
  color: var(--accent);
  border: none;
  padding: 4px 2px;
  cursor: pointer;
  font-size: 12px;
  box-shadow: none;
  text-align: center;
}

.edit:hover {
  color: var(--accent-strong);
}

.remove:hover {
  color: #8f2424;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  margin: 6px 0 0;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}

.preview-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

#shuffleGrid {
  background: #3f7a36;
  border-color: #3f7a36;
  color: #ffffff;
}

#shuffleGrid:hover {
  background: #356a2f;
  border-color: #356a2f;
}

.panel.preview h2 {
  font-size: 20px;
}

.preview-title {
  margin: 8px 0 14px;
  text-align: center;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0.01em;
}

.status {
  font-size: 13px;
  color: var(--muted);
  text-align: right;
}

.grid {
  margin: 14px 0 18px;
  background: #f7f9fc;
  border: 1px solid #dde3ef;
  border-radius: 14px;
  padding: 10px;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  min-height: 300px;
}

.grid-inner {
  display: inline-grid;
  gap: 2px;
  --cell-size: 64px;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid #d6deeb;
  position: relative;
  font-weight: 700;
  color: var(--grid-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell-size) * 0.45);
}

.cell.empty {
  background: transparent;
  border: none;
}

.cell .number {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: clamp(9px, calc(var(--cell-size) * 0.2), 12px);
  color: #6b7788;
  font-weight: 600;
}

.clues {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  background: #f8fafd;
  border: 1px solid #e3e8f0;
  border-radius: 14px;
  padding: 14px;
}

.clues h3 {
  margin: 0 0 8px;
}

.clues ul {
  margin: 0;
  padding-left: 0;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
  list-style: none;
}

.clue-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.clue-text {
  flex: 1 1 auto;
}

.clue-image {
  max-width: 80px;
  max-height: 80px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid #e3e8f0;
  background: #ffffff;
}

.clue-image.solo {
  max-width: 120px;
  max-height: 120px;
}

.cell.multiword::after {
  content: "+";
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 13px;
  color: #3f7a36;
  font-weight: 800;
}

@media (max-width: 1024px) {
  .layout {
    grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  }

  .panel.preview .clues {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: auto;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .hero {
    flex-direction: column;
    align-items: flex-start;
  }

  .grid {
    min-height: 260px;
  }

  .preview-header {
    align-items: flex-start;
  }

  .preview-meta {
    width: 100%;
    justify-content: flex-start;
  }

  .status {
    text-align: left;
  }

  .settings-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .panel-bottom {
    margin-top: 2px;
  }

  .preview {
    padding: 14px;
  }

  .preview-surface {
    border-radius: 14px;
    padding: 14px;
  }
}
