:root {
  --klonist-teal: #009688;
  --complementary-coral: #b85c5c;
  --ink-brown: #795548;
  --deep-ink-brown: #6d4c41;
  --parchment: #f2f6c1;
  --paper-line: #efcfad;
  --paper-border: #c3baaa;
  --sepia-text: #6a5f49;
  --muted-sepia: #84775c;
  --charcoal: #404040;
  --focus-ring: rgba(121, 85, 72, 0.16);
  --thai-ui-font: "Noto Sans Thai", "IBM Plex Sans Thai", "Sarabun", "Th Sarabun New", "Lucida Grande", Tahoma, Verdana, sans-serif;
  --thai-poetry-font: "Noto Serif Thai", "Sarabun", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font: 14px/1.7 var(--thai-ui-font);
  color: var(--charcoal);
  background: var(--klonist-teal);
}

.ai-page-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.ai-workspace {
  width: min(100%, 760px);
}

.ai-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  color: #fff;
}

.back-link,
.brand-mark {
  align-items: center;
  border-radius: 9999px;
  background: rgba(242, 246, 193, 0.94);
  color: var(--deep-ink-brown);
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  line-height: 1;
  min-height: 48px;
  padding: 8px 14px;
  text-decoration: none;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
  white-space: nowrap;
}

.back-link:hover {
  text-decoration: underline;
}

.brand-mark {
  font-family: var(--thai-poetry-font);
  text-align: center;
}

.ai-header,
.poetry-panel,
.results-card {
  border: 1px solid rgba(195, 186, 170, 0.9);
  background-color: var(--parchment);
  background-image: radial-gradient(
      circle at center,
      rgba(255, 255, 255, 0.68) 0%,
      rgba(255, 255, 255, 0.08) 88%
    ),
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 29px,
      rgba(239, 207, 173, 0.68) 29px,
      rgba(239, 207, 173, 0.68) 30px
    );
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.5),
    inset 0 0 5px rgba(136, 143, 48, 0.5), 0 12px 28px rgba(0, 0, 0, 0.16);
}

.ai-header {
  padding: 28px 30px 26px;
  position: relative;
}

.ai-header::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 28px;
  width: 2px;
  border-left: 1px solid rgba(239, 207, 173, 0.9);
  border-right: 1px solid rgba(239, 207, 173, 0.9);
}

.eyebrow {
  margin: 0 0 8px 28px;
  color: var(--muted-sepia);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.eyebrow-row {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 8px 28px;
}

.eyebrow-row .eyebrow {
  margin: 0;
}

.status-badge {
  align-items: center;
  background: rgba(184, 92, 92, 0.13);
  border: 1px solid rgba(184, 92, 92, 0.36);
  border-radius: 999px;
  color: var(--complementary-coral);
  display: inline-flex;
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1;
  min-height: 24px;
  padding: 5px 9px;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 10px 28px;
  color: var(--deep-ink-brown);
  font-family: var(--thai-poetry-font);
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1.1;
}

.intro {
  max-width: 560px;
  margin: 0 0 0 28px;
  color: var(--sepia-text);
  font-size: 1rem;
}

.launch-note {
  background: rgba(255, 255, 255, 0.56);
  border: 1px solid rgba(195, 186, 170, 0.75);
  border-radius: 8px;
  color: var(--sepia-text);
  font-size: 0.94rem;
  font-weight: 700;
  line-height: 1.7;
  margin: 16px 0 0 28px;
  max-width: 620px;
  padding: 12px 14px;
}

.poetry-panel,
.results-card {
  margin-top: 18px;
  padding: 24px;
}

.input-label,
.results-label {
  display: block;
  margin-bottom: 10px;
  color: var(--deep-ink-brown);
  font-weight: 700;
}

.poetry-input {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  border: 1px solid var(--paper-border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--sepia-text);
  font: 1.08rem/1.9 var(--thai-poetry-font);
  padding: 16px 18px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.poetry-input::placeholder {
  color: rgba(106, 95, 73, 0.64);
}

.poetry-input:focus {
  outline: none;
  border-color: var(--ink-brown);
  box-shadow: 0 0 0 4px var(--focus-ring);
}

.action-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.primary-action {
  border: none;
  border-radius: 9999px;
  background: var(--ink-brown);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 12px 22px;
  transition: background-color 0.2s ease, box-shadow 0.2s ease,
    transform 0.2s ease;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.18);
}

.primary-action:hover:not(:disabled) {
  background: var(--deep-ink-brown);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
  transform: translateY(-1px);
}

.primary-action:disabled {
  cursor: wait;
  opacity: 0.65;
}

.loading-spinner {
  width: 26px;
  height: 26px;
  display: none;
  border: 3px solid rgba(121, 85, 72, 0.18);
  border-top-color: var(--ink-brown);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

.message-box {
  display: none;
  margin-top: 16px;
  border-radius: 8px;
  border: 1px solid rgba(121, 85, 72, 0.3);
  background: rgba(255, 255, 255, 0.68);
  color: var(--deep-ink-brown);
  padding: 12px 14px;
  text-align: left;
}

.message-box.is-error {
  border-color: rgba(121, 85, 72, 0.42);
  background: rgba(239, 207, 173, 0.45);
  color: #5d2f24;
}

.message-box.is-info {
  border-color: rgba(239, 207, 173, 0.9);
  background: rgba(255, 255, 255, 0.56);
}

.results-card {
  color: var(--sepia-text);
}

.results-label {
  margin-bottom: 12px;
}

.results-text {
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--sepia-text);
  font-family: var(--thai-poetry-font);
  font-size: 1.08rem;
  line-height: 1.8;
  text-align: center;
}

.rhyme-word {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(195, 186, 170, 0.95);
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--deep-ink-brown);
  font-family: var(--thai-poetry-font);
  padding: 7px 13px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}

@media (max-width: 640px) {
  .ai-page-shell {
    align-items: flex-start;
    padding: 16px;
  }

  .ai-nav {
    align-items: center;
    display: grid;
    gap: 10px;
    grid-template-columns: max-content minmax(0, max-content);
    justify-content: start;
    max-width: 100%;
    width: 100%;
  }

  .back-link,
  .brand-mark {
    min-height: 44px;
    padding: 8px 12px;
  }

  .brand-mark {
    font-size: clamp(0.86rem, 3.4vw, 1rem);
    max-width: calc(100vw - 154px);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .ai-header,
  .poetry-panel,
  .results-card {
    padding: 20px;
  }

  h1,
  .intro,
  .eyebrow {
    margin-left: 20px;
  }
}
