:root {
  --bg: #f4f6f5;
  --bg-alt: #ffffff;
  --text: #13221c;
  --muted: #4a5a53;
  --line: #d5dfda;
  --primary: #188044;
  --primary-2: #0f5a30;
  --danger: #9e1f2b;
  --chip: #e9f6ee;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Avenir", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    linear-gradient(120deg, rgba(0, 146, 70, 0.18) 0%, rgba(255, 255, 255, 0.12) 35%, rgba(206, 43, 55, 0.16) 100%),
    linear-gradient(180deg, #f6faf8 0%, #f8f8f8 50%, #fcf5f6 100%);
  min-height: 100vh;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  display: grid;
  gap: 14px;
}

.hero h1 {
  margin: 0 0 6px;
  font-size: clamp(1.8rem, 2.5vw, 2.6rem);
}

.hero p {
  margin: 0;
  color: var(--muted);
}

.hero-top {
  display: grid;
  grid-template-columns: minmax(180px, 280px) 1fr;
  gap: 16px;
  align-items: center;
}

.hero-logo {
  width: 100%;
  max-width: 280px;
  height: auto;
  display: block;
}

.collapsible {
  padding: 0;
  overflow: hidden;
}

.collapsible > summary {
  cursor: pointer;
  list-style: none;
  padding: 14px 16px;
  font-weight: 700;
  user-select: none;
  border-bottom: 1px solid transparent;
}

.collapsible > summary::-webkit-details-marker {
  display: none;
}

.collapsible > summary::after {
  content: "▾";
  float: right;
  color: var(--muted);
}

.collapsible:not([open]) > summary::after {
  content: "▸";
}

.collapsible[open] > summary {
  border-bottom-color: var(--line);
}

.collapsible > .controls {
  padding: 16px;
}

.panel {
  background: color-mix(in srgb, var(--bg-alt), #ffffff 70%);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

.tabs-panel {
  padding: 10px;
}

.tabs {
  display: flex;
  gap: 8px;
}

.tab-btn {
  background: #e8f0ec;
  color: var(--primary-2);
}

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

.controls,
.save-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  align-items: end;
}

.field-group {
  display: grid;
  gap: 6px;
}

.checkbox-field label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.checkbox-field input[type="checkbox"] {
  width: auto;
}

label {
  font-weight: 600;
}

select,
textarea,
button,
input {
  font: inherit;
}

select,
textarea,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

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

button {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

#generateBtn,
#saveBtn,
#evaluateBtn {
  background: var(--primary);
  color: #fff;
}

.secondary {
  background: #edf4f0;
  color: var(--primary-2);
}

.danger {
  background: #f9e9eb;
  color: var(--danger);
}

.output-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.output-header h2 {
  margin: 0;
}

.output-header p {
  margin: 0;
  color: var(--muted);
}

.output-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.text-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 140px;
  padding: 12px;
  background: #fff;
  line-height: 1.7;
}

.hidden-text {
  filter: blur(7px);
  user-select: none;
  pointer-events: none;
}

.word {
  position: relative;
  display: inline-block;
  padding: 0 1px;
  border-radius: 4px;
}

.word[data-pos="verb"] {
  cursor: pointer;
}

.word[data-pos="substantiv"] {
  cursor: pointer;
}

.word:hover {
  background: #fff2cc;
}

.word[data-translation]:hover::after {
  content: attr(data-translation);
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(100% + 8px);
  background: #18202a;
  color: #fff;
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.82rem;
  z-index: 2;
}

.word[data-translation]:hover::before {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(100% + 2px);
  border: 6px solid transparent;
  border-top-color: #18202a;
  z-index: 2;
}

.badge {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 8px;
  background: var(--chip);
  border-radius: 999px;
  font-size: 0.84rem;
  color: #0e5f32;
}

.status {
  margin-top: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

.legend {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.legend-item {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.82rem;
  font-weight: 600;
  background: #fff;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.legend-item input {
  width: auto;
  margin: 0;
}

.word.pos-verb {
  box-shadow: inset 0 -2px 0 #ff6b6b;
  cursor: pointer;
}

.word.pos-substantiv {
  box-shadow: inset 0 -2px 0 #4dabf7;
}

.word.pos-adjektiv {
  box-shadow: inset 0 -2px 0 #ffd43b;
}

.word.pos-adverb {
  box-shadow: inset 0 -2px 0 #20c997;
}

.word.pos-pronomen {
  box-shadow: inset 0 -2px 0 #9775fa;
}

.word.pos-konjunktion {
  box-shadow: inset 0 -2px 0 #f783ac;
}

.word.pos-praeposition {
  box-shadow: inset 0 -2px 0 #ff922b;
}

.word.pos-artikel {
  box-shadow: inset 0 -2px 0 #69db7c;
}

.word.pos-andere {
  box-shadow: inset 0 -2px 0 #adb5bd;
}

.legend-item.pos-verb {
  border-color: #ff6b6b;
}

.legend-item.pos-substantiv {
  border-color: #4dabf7;
}

.legend-item.pos-adjektiv {
  border-color: #ffd43b;
}

.legend-item.pos-adverb {
  border-color: #20c997;
}

.legend-item.pos-pronomen {
  border-color: #9775fa;
}

.legend-item.pos-konjunktion {
  border-color: #f783ac;
}

.legend-item.pos-praeposition {
  border-color: #ff922b;
}

.legend-item.pos-artikel {
  border-color: #69db7c;
}

.legend-item.pos-andere {
  border-color: #adb5bd;
}

.story-image-box {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.quiz-box {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.quiz-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.quiz-option-btn {
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
}

.quiz-option-btn.correct {
  border-color: #2f9e44;
  background: #ebfbee;
}

.quiz-option-btn.wrong {
  border-color: #c92a2a;
  background: #fff5f5;
}

.story-image-box h3 {
  margin: 0 0 8px;
}

#storyImage {
  width: 100%;
  max-width: 640px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  display: block;
}

.gesture-toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 12px 0;
}

.sub-settings {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.75);
}

.sub-settings summary {
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 700;
  list-style: none;
}

.sub-settings summary::-webkit-details-marker {
  display: none;
}

.sub-settings-body {
  padding: 0 12px 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.gestures-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.gesture-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.gesture-card-head {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  align-items: center;
}

.gesture-card-head h3 {
  margin: 0;
  font-size: 1rem;
}

.gesture-italian {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.gesture-image-wrap {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  background: linear-gradient(135deg, #e8f5ea, #fff6f3);
  border: 1px solid var(--line);
  overflow: hidden;
}

.gesture-emoji {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 2rem;
}

.gesture-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #fff;
}

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

.gesture-tag {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  background: #f8faf8;
}

.gesture-meaning {
  margin: 0;
  font-weight: 700;
  color: var(--primary-2);
}

.gesture-section-title {
  margin: 0;
  font-weight: 700;
}

.gesture-usecases {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}

.gesture-note {
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  font-size: 0.9rem;
}

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

.word.gesture-inline {
  font-size: 1.08em;
  filter: saturate(1.1);
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow: hidden;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 20, 17, 0.45);
}

.modal-card {
  position: absolute;
  z-index: 51;
  top: 6vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(1100px, calc(100% - 24px));
  min-width: 340px;
  min-height: 240px;
  max-width: calc(100% - 24px);
  max-height: 88vh;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  resize: both;
  box-shadow: 0 28px 60px rgba(0, 0, 0, 0.18);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: move;
  user-select: none;
}

.modal-head h3 {
  margin: 0;
}

.modal-body {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.verb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.verb-table th,
.verb-table td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}

.verb-table .is-current {
  background: #e9f6ee;
  font-weight: 700;
}

.modal-body .is-current {
  background: #e9f6ee;
  border-radius: 6px;
  padding: 6px 8px;
}

@media (min-width: 860px) {
  .output-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 860px) {
  .hero-top {
    grid-template-columns: 1fr;
  }

  .hero-logo {
    max-width: 240px;
  }

  .modal-card {
    width: calc(100% - 16px);
    max-width: calc(100% - 16px);
    top: 8px;
    left: 8px;
    transform: none;
    max-height: calc(100vh - 16px);
    resize: none;
  }
}
