
:root {
  --ivory: #F7F8F5;
  --white: #FFFFFF;
  --charcoal: #1d2726;
  --slate: #52615B;
  --sage: #B7C9BE;
  --sage-dark: #126b48;
  --pale-sage: #E8F0EB;
  --quiet-blue: #DDE9E8;
  --border: #D9E2DB;
  --rose: #974146;
  --rose-pale: #F9EBEB;
  --shadow: 0 12px 36px rgba(28, 51, 49, 0.055);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--ivory);
  color: var(--charcoal);
  font-family: "Segoe UI", Arial, sans-serif;
  line-height: 1.55;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.53;
}

:focus-visible {
  outline: 3px solid var(--sage-dark);
  outline-offset: 3px;
}

.page-shell {
  width: 100%;
  min-height: 100vh;
  padding: clamp(20px, 4vw, 48px) 20px 36px;
}

.completion-page {
  display: grid;
  place-items: center;
}

.completion-card {
  width: min(100%, 600px);
  padding: clamp(32px, 7vw, 64px);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  text-align: center;
}

.completion-card h1 {
  margin: 0;
}

.page-header {
  width: min(100%, 760px);
  margin: 0 auto 26px;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--sage-dark);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  line-height: 1.2;
  letter-spacing: -0.035em;
}

.intro {
  max-width: 52ch;
  margin: 10px 0 0;
  color: var(--slate);
}

.chat-card {
  width: min(100%, 760px);
  margin: 0 auto;
  overflow: hidden;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.chat-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  color: var(--slate);
  font-size: 0.9rem;
}

.status-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--sage-dark);
}

.chat-messages {
  height: clamp(280px, 46vw, 420px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 26px 24px;
}

.empty-state {
  max-width: 370px;
  margin: 64px auto 0;
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.empty-state p {
  margin: 0;
  color: var(--slate);
}

.starter-area {
  margin-top: 22px;
  text-align: left;
}

.starter-label {
  margin-bottom: 9px !important;
  font-size: 0.85rem;
  font-weight: 650;
}

.starter-prompts {
  display: grid;
  gap: 8px;
}

.starter-button {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--slate);
  font-size: 0.86rem;
  line-height: 1.4;
  text-align: left;
  transition: background-color 0.18s ease,
              border-color 0.18s ease,
              color 0.18s ease;
}

.starter-button:hover {
  background: var(--ivory);
  border-color: var(--sage);
  color: var(--charcoal);
}

.message {
  display: flex;
  margin-bottom: 18px;
}

.message-user {
  justify-content: flex-end;
}

.message-assistant {
  justify-content: flex-start;
}

.message-bubble {
  max-width: min(83%, 540px);
  padding: 12px 16px;
  border-radius: 17px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-height: 1.55;
}

.message-user .message-bubble {
  background: var(--quiet-blue);
  border-bottom-right-radius: 5px;
}

.message-assistant .message-bubble {
  background: var(--pale-sage);
  border-bottom-left-radius: 5px;
}

.error-message {
  margin: 0 24px 16px;
  padding: 12px 14px;
  background: var(--rose-pale);
  border-radius: 10px;
  color: var(--rose);
  font-size: 0.9rem;
}

.chat-composer {
  padding: 17px 24px 20px;
  border-top: 1px solid var(--border);
}

.composer-label {
  display: block;
  margin-bottom: 9px;
  font-size: 0.88rem;
  font-weight: 650;
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.message-input {
  width: 100%;
  min-height: 50px;
  max-height: 160px;
  resize: vertical;
  padding: 12px 14px;
  border: 1px solid #AEBEB4;
  border-radius: 12px;
  background: var(--white);
  color: var(--charcoal);
}

.message-input::placeholder {
  color: #63726B;
}

.message-input:disabled {
  background: var(--ivory);
}

.send-button,
.consent-button {
  min-height: 48px;
  padding: 11px 20px;
  border: 0;
  border-radius: 12px;
  background: var(--sage-dark);
  color: var(--white);
  font-weight: 650;
  transition: background-color 0.18s ease,
              transform 0.18s ease;
}

.send-button:not(:disabled):hover,
.consent-button:not(:disabled):hover {
  background: #304F43;
  transform: translateY(-1px);
}

.composer-hint {
  margin: 9px 0 0;
  color: var(--slate);
  font-size: 0.78rem;
}

/* Lopeta keskustelu -painike */
.chat-end-row {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

.end-chat-button,
.feedback-skip {
    background: transparent;
    color: var(--slate);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 16px;
    cursor: pointer;
}

.end-chat-button:hover,
.feedback-skip:hover {
    background: var(--pale-sage);
}

/* Kyselyn taustapeite */
.feedback-modal[hidden] {
    display: none !important;
}

.feedback-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgb(25 35 29 / 60%);
    overflow-y: auto;
}

.feedback-card {
    width: min(100%, 600px);
    max-height: 90vh;
    overflow-y: auto;
    padding: 28px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
}

.feedback-card h2 {
    margin: 0 0 10px;
}

.feedback-intro,
.feedback-scale {
    color: var(--slate);
    font-size: 0.9rem;
}

.feedback-question {
    min-width: 0;
    margin: 22px 0;
    padding: 0;
    border: 0;
}

.feedback-question legend {
    margin-bottom: 12px;
    font-weight: 600;
    line-height: 1.5;
}

.likert-options {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 9px;
}

.likert-options label {
    position: relative;
    cursor: pointer;
}

.likert-options input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.likert-options span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--ivory);
}

.likert-options input:checked + span {
    background: var(--pale-sage);
    border-color: var(--sage-dark);
    font-weight: 700;
}

.likert-options input:focus-visible + span {
    outline: 2px solid var(--sage-dark);
    outline-offset: 3px;
}

.feedback-open-label {
    display: block;
    margin: 24px 0 10px;
    font-weight: 600;
    line-height: 1.5;
}

#feedback-comment {
    width: 100%;
    box-sizing: border-box;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font: inherit;
    resize: vertical;
}

.feedback-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
}

.feedback-actions button[type="submit"] {
    flex: 1;
    min-height: 44px;
    padding: 10px 16px;
    background: var(--sage-dark);
    color: white;
    border: 0;
    border-radius: 10px;
    cursor: pointer;
}

.feedback-actions button:disabled {
    opacity: 0.6;
    cursor: wait;
}

.feedback-error {
    color: #a12626;
    font-size: 0.9rem;
}

@media (max-width: 480px) {
    .feedback-modal {
        padding: 10px;
    }

    .feedback-card {
        padding: 20px 16px;
        max-height: 95vh;
    }

    .feedback-actions {
        flex-direction: column;
    }
}

@media (max-width: 560px) {
  .page-shell {
    padding: 24px 12px;
  }

  .page-header {
    padding: 0 6px;
  }

  .chat-card {
    border-radius: 17px;
  }

  .chat-status,
  .chat-composer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .chat-messages {
    height: 340px;
    padding: 20px 16px;
  }

  .error-message {
    margin-left: 16px;
    margin-right: 16px;
  }

  .send-button {
    padding-left: 15px;
    padding-right: 15px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

.consent-overlay {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 2.5vw, 32px);
  background: var(--ivory);
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.consent-screen {
  width: min(1200px, 100%);
  margin: auto;
}

.consent-heading {
  margin: 0 auto 20px;
  text-align: center;
}

.consent-heading p {
  margin: 8px 0 0;
  color: var(--slate);
}

.consent-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  gap: clamp(16px, 2.5vw, 28px);
}

.consent-content {
  display: flex;
  min-width: 0;
  height: min(68vh, 720px);
  max-height: calc(100vh - 180px);
  min-height: 390px;
  flex-direction: column;
  overflow: hidden;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.consent-card-body {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(20px, 3vw, 32px);
}

.consent-card-body h2 {
  margin: 0 0 12px;
  font-size: 1.4rem;
}

.consent-card-body h3 {
  margin: 20px 0 8px;
  font-size: 1.05rem;
}

.consent-card-body > p,
.consent-card-body > ul {
  color: var(--slate);
  font-size: 0.94rem;
}

.consent-card-body > p {
  margin: 0 0 16px;
}

.consent-card-body > ul {
  padding-left: 22px;
}

.consent-card-body > ul li {
  margin-bottom: 7px;
}

.consent-card-body > .participation-reminder {
  margin-bottom: 20px;
  padding: 14px 16px;
  color: var(--slate);
  background: var(--pale-sage);
  border: 2px solid var(--sage-dark);
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 700;
}

.consent-card-actions {
  padding: 16px clamp(20px, 3vw, 32px);
  border-top: 1px solid var(--border);
}

.consent-card-actions .consent-button {
  width: 100%;
  min-height: 56px;
  line-height: 1.35;
}

.consent-error {
  width: min(100%, 800px);
  margin: 14px auto 0;
}

.consent-retry {
  display: block;
  margin: 12px auto 0;
}

/* The existing [hidden] rule ensures the panel disappears after consent */
.consent-overlay[hidden] {
  display: none !important;
}

@media (max-width: 760px) {
  .consent-overlay {
    align-items: flex-start;
  }

  .consent-cards {
    grid-template-columns: minmax(0, 1fr);
  }

  .consent-content {
    height: min(48vh, 480px);
    max-height: 48vh;
    min-height: 260px;
  }
}

/* Completion page — literary quotation */

.completion-page {
  min-height: 85vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.completion-card {
  width: min(100%, 760px);
  box-sizing: border-box;
  padding: clamp(36px, 8vw, 84px) clamp(24px, 7vw, 72px);
  text-align: center;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.quote-mark {
  height: 62px;
  margin-bottom: 12px;
  color: var(--sage-dark);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 6rem;
  line-height: 1;
  opacity: 0.8;
}

.completion-quote {
  margin: 0;
}

.completion-quote h1 {
  max-width: 620px;
  margin: 0 auto;
  color: var(--charcoal);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 5vw, 3.4rem);
  font-weight: 400;
  line-height: 1.35;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.quote-source {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  margin-top: 34px;
  color: var(--slate);
  font-size: 0.88rem;
  line-height: 1.6;
}

.quote-author {
  color: var(--sage-dark);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

.quote-source cite {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  font-style: italic;
}

.quote-year {
  font-size: 0.8rem;
  opacity: 0.8;
}

.quote-ornament {
  width: 44px;
  height: 1px;
  margin: 36px auto 0;
  background: var(--sage-dark);
  opacity: 0.65;
}

@media (max-width: 480px) {
  .completion-card {
    padding: 36px 22px;
    border-radius: 18px;
  }

  .quote-mark {
    font-size: 5rem;
    height: 52px;
  }

  .desktop-break {
    display: none;
  }

  .quote-source {
    margin-top: 28px;
  }
}