*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 2rem 1rem;
  background: #f5f0e8;
  font-family: Georgia, "Times New Roman", serif;
  color: #2c2418;
  line-height: 1.5;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(circle, #a89880 0.7px, transparent 0.7px);
  background-size: 18px 18px;
  z-index: -2;
  pointer-events: none;
}

/* Block entrance animation */

@keyframes block-enter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.block, .block-review, .context-bubble {
  animation: block-enter 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.container {
  max-width: 44rem;
  margin: 0 auto;
  padding-top: calc(50vh - 8rem);
  padding-bottom: calc(50vh - 8rem);
}

/* Model picker */

.model-picker {
  position: fixed;
  top: 1rem;
  right: 1.5rem;
  background: #fff;
  border: 1px solid #ddd5c8;
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
  box-shadow: 0 1px 4px rgba(80, 60, 40, 0.1);
  z-index: 10;
  transition: box-shadow 0.2s ease;
}

.model-picker:hover {
  box-shadow: 0 2px 8px rgba(80, 60, 40, 0.16);
}

.model-icon {
  width: 16px;
  height: 16px;
  stroke: #a89880;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.model-picker {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.model-picker select {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.9rem;
  color: #2c2418;
  background: transparent;
  border: none;
  outline: none;
  cursor: pointer;
  padding-right: 0.2rem;
}

.logo {
  position: fixed;
  left: -0.3rem;
  top: 1.8rem;
  margin: 0;
  font-family: "Special Elite", Georgia, serif;
  font-size: 10rem;
  font-weight: 400;
  font-style: normal;
  color: #7a9e7e;
  letter-spacing: -0.02em;
  line-height: 1;
  transform: rotate(-6deg);
  transform-origin: top left;
  user-select: none;
  pointer-events: none;
  z-index: -1;
  text-shadow: 2px 3px 0 rgba(44, 36, 24, 0.06);
}

.logo::after {
  content: "";
  position: absolute;
  left: 0.05em;
  right: 0.02em;
  top: 0.52em;
  height: 0.06em;
  background: #2d5a3a;
  opacity: 0.25;
  border-radius: 1px;
  transform: rotate(-1deg);
  pointer-events: none;
}

@media (max-width: 60rem) {
  .logo {
    font-size: 6rem;
    left: 0.3rem;
    top: 0.5rem;
  }
}

/* Blocks */

.block {
  background: #fff;
  border: 1px solid #ddd5c8;
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow:
    0 1px 2px rgba(80, 60, 40, 0.08),
    0 4px 12px rgba(80, 60, 40, 0.10),
    0 12px 28px rgba(80, 60, 40, 0.06);
  transition: box-shadow 0.25s ease;
}

.block:hover {
  box-shadow:
    0 1px 2px rgba(80, 60, 40, 0.10),
    0 6px 16px rgba(80, 60, 40, 0.12),
    0 16px 36px rgba(80, 60, 40, 0.08);
}

.subtitle {
  font-style: italic;
  color: #5a8a60;
  font-size: 1.8rem;
  margin: 0 0 1.5rem 0;
  text-align: center;
  letter-spacing: 0.01em;
  text-wrap: balance;
}

.subtitle-short {
  display: none;
}

.free-notice {
  text-align: center;
  font-size: 0.85rem;
  color: #8a7e6e;
  margin: -1rem 0 1.2rem 0;
}

.subtitle-short em {
  font-style: normal;
  font-weight: 600;
}

/* Context bubble */

.context-bubble {
  background: #fff;
  border: 1px solid #ddd5c8;
  border-radius: 10px;
  padding: 0.75rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 4px rgba(80, 60, 40, 0.08);
  border-top: 2px solid #2d5a3a;
}

/* Context bar */

.context-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.context-btn {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.1rem;
  padding: 0.55rem 1.2rem;
  border: 1px solid #7a9e7e;
  border-radius: 5px;
  background: #e8f0e9;
  color: #2d4a35;
  cursor: pointer;
  transition: background 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              color 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.15s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.context-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.context-btn {
  position: relative;
}

.context-btn::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.4rem 0.7rem;
  background: #e8f0e9;
  color: #2d4a35;
  font-size: 0.78rem;
  font-style: normal;
  line-height: 1.3;
  white-space: nowrap;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
}

.context-btn:hover::after {
  opacity: 1;
}

.context-btn:hover {
  background: #c8dccb;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(45, 90, 58, 0.15);
}

.context-btn:active {
  transform: translateY(0);
}

.context-btn.active {
  background: #2d5a3a;
  color: #f0f5f1;
  border-color: #2d5a3a;
  box-shadow: 0 2px 8px rgba(45, 90, 58, 0.25);
}

/* Textareas */

textarea {
  display: block;
  width: 100%;
  padding: 0.85rem 1rem;
  font-family: Menlo, Consolas, "Courier New", monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  color: #2c2418;
  background:
    repeating-linear-gradient(
      transparent,
      transparent 1.37rem,
      #f3efe9 1.37rem,
      #f3efe9 calc(1.37rem + 1px)
    );
  background-position-y: 0.82rem;
  border: 1px solid #d0c7b8;
  border-radius: 6px;
  resize: none;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

textarea:focus {
  outline: none;
  border-color: #8b7355;
  box-shadow: 0 0 0 3px rgba(139, 115, 85, 0.12);
}

textarea[readonly] {
  opacity: 0.7;
  cursor: default;
}

textarea::placeholder {
  color: #a89880;
  font-style: italic;
}

/* Directive buttons */

.directives {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.directive-btn {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid #8b7355;
  border-radius: 3px;
  background: #fff;
  color: #8b7355;
  cursor: pointer;
  transition: background 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              color 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

.directive-btn:hover:not(:disabled) {
  background: #8b7355;
  color: #fff;
  transform: translateY(-1px);
}

.directive-btn:active:not(:disabled) {
  transform: translateY(0);
}

.directive-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.directive-btn.chosen {
  opacity: 1;
  background: #8b7355;
  color: #fff;
  border-color: #8b7355;
}

.directive-btn[data-directive="accept"] {
  border-color: #2d5a3a;
  color: #2d5a3a;
  background: #e8f0e9;
  font-weight: 600;
}

.directive-btn[data-directive="accept"]:hover:not(:disabled) {
  background: #2d5a3a;
  color: #fff;
  box-shadow: 0 2px 8px rgba(45, 90, 58, 0.25);
}

.directive-btn[data-directive="accept"].chosen {
  background: #2d5a3a;
  color: #fff;
  border-color: #2d5a3a;
}

/* More dropdown (styled as button) */

.directive-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 1.2rem !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238b7355'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.4rem center;
  cursor: pointer;
}

.directive-select.chosen {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23fff'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.4rem center;
}

/* Custom directive */

.custom-directive {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin-left: auto;
}

.custom-input {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  padding: 0 0.6rem;
  border: 1px solid #8b7355;
  border-right: none;
  border-radius: 3px 0 0 3px;
  background: #fff;
  color: #2c2418;
  width: 10rem;
  outline: none;
  transition: border-color 0.15s;
}

.custom-input:focus {
  border-color: #6b5540;
}

.custom-input:disabled {
  opacity: 0.35;
}

.custom-input.chosen {
  opacity: 1;
  background: #f5f0e8;
  color: #5a4a36;
}

.custom-go {
  border-radius: 0 3px 3px 0;
  padding-top: 0;
  padding-bottom: 0;
}

/* Review group (review + edit as one scroll unit) */

.review-group {
  margin-bottom: 1rem;
}

.review-group .block {
  margin-bottom: 0.5rem;
}

.review-group .block:last-child {
  margin-bottom: 0;
}

/* Review bubble */

.block-review {
  background: #faf8f4;
  border-left: 3px solid #c0463a;
}

.review-prose {
  font-size: 1.05rem;
  line-height: 1.6;
}

.review-prose p {
  margin: 0 0 0.5rem 0;
}

.review-prose p:last-child {
  margin-bottom: 0;
}

.review-prose ul, .review-prose ol {
  margin: 0 0 0.5rem 0;
  padding-left: 1.4rem;
}

.review-prose li {
  margin-bottom: 0.3rem;
}

.review-prose strong {
  color: #2c2418;
}

.review-prose code {
  font-family: inherit;
  font-size: inherit;
  background: #a8e6b4;
  padding: 0.1rem 0.25rem;
  border-radius: 3px;
}

.review-prose li::marker {
  color: #c0463a;
}
/* Textarea wrapper (for inset copy button) */

.textarea-wrap {
  position: relative;
}

/* Copy button */

.copy-btn {
  position: absolute;
  bottom: 7px;
  right: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: #a89880;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.copy-btn:hover {
  color: #5a4a36;
  background: rgba(139, 115, 85, 0.1);
}

.copy-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.copy-btn.copied {
  color: #2d5a3a;
  animation: copy-flash 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes copy-flash {
  0% { transform: scale(1); }
  50% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.speak-btn {
  right: 39px;
}

.speak-btn.speaking {
  color: #8b7355;
}

/* Spinner */

.spinner-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2.5rem 0;
  color: #8b7355;
  font-style: italic;
  font-size: 1.1rem;
  animation: block-enter 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.spinner-wrap span {
  animation: pulse-text 1.8s ease-in-out infinite;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #d4c9b8;
  border-top-color: #8b7355;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse-text {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Reset button */

.reset-btn {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  border: none;
  border-radius: 20px;
  padding: 0.45rem 1rem;
  gap: 0.35rem;
  background: rgba(255, 255, 255, 0.85);
  color: #a89880;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 6px rgba(80, 60, 40, 0.12);
  opacity: 0;
  transition: opacity 0.4s ease, color 0.2s, background 0.2s;
  z-index: 10;
}

.reset-btn.visible {
  opacity: 1;
}

.reset-btn:hover {
  color: #5a4a36;
  background: #fff;
}

.reset-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Error display */

.error-msg {
  background: #fdf0ed;
  border: 1px solid #d4a093;
  border-left: 3px solid #c0463a;
  border-radius: 3px;
  padding: 0.6rem 0.9rem;
  color: #8b3a2a;
  font-size: 0.88rem;
  margin-top: 0.5rem;
  animation: block-enter 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.limit-msg {
  background: #f0f5f1;
  border: 1px solid #7a9e7e;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  color: #2d4a35;
  font-size: 1rem;
  text-align: center;
  margin-top: 1rem;
  animation: block-enter 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Mobile */

@media (max-width: 480px) {
  body {
    padding: 1.5rem 0.5rem;
  }

  .subtitle-full {
    display: none;
  }

  .subtitle-short {
    display: inline;
  }

  .block {
    padding: 1rem;
    border-radius: 10px;
  }

  .context-bubble {
    padding: 0.6rem 0.75rem;
  }

  .context-btn {
    font-size: 0.95rem;
    padding: 0.45rem 0.8rem;
    gap: 0.3rem;
  }

  .context-btn svg {
    width: 15px;
    height: 15px;
  }

  .directives {
    flex-wrap: wrap;
  }

  .custom-directive {
    display: none;
  }

  .directive-select {
    flex: 1;
  }

  .model-picker {
    right: 0.5rem;
    top: 0.5rem;
  }

  .logo {
    font-size: 3.5rem;
    left: 0.2rem;
    top: 0.3rem;
  }

  .review-group .block {
    margin-bottom: 0.4rem;
  }
}
