:root {
  color-scheme: light;
  --paper: #f8f3ea;
  --surface: #fffaf1;
  --ink: #1f2623;
  --muted: #69716d;
  --line: #dacdbb;
  --teal: #1f766c;
  --teal-dark: #15534d;
  --gold: #b98528;
  --coral: #b85645;
  --focus: #247f77;
  --shadow: 0 18px 46px rgba(40, 34, 24, 0.13);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(31, 118, 108, 0.08), transparent 32%),
    linear-gradient(260deg, rgba(184, 86, 69, 0.08), transparent 36%),
    var(--paper);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: max(18px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.workspace {
  width: min(1120px, 100%);
  margin: 0 auto;
}

.brand-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-weight: 800;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 7vw, 54px);
  line-height: 1.02;
  letter-spacing: 0;
  max-width: 620px;
}

.language-control {
  display: grid;
  grid-template-columns: repeat(4, 42px);
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.82);
}

.lang-button {
  width: 42px;
  height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.lang-button.is-active {
  background: var(--ink);
  color: var(--surface);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.04fr) minmax(340px, 0.86fr);
  gap: 18px;
  align-items: stretch;
}

.ask-form,
.result-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.88);
  box-shadow: var(--shadow);
}

.ask-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field.wide {
  grid-column: 1 / -1;
}

.field > span,
.check-row,
.answer-label,
.result-copy p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid #c8b9a6;
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  outline: none;
}

input {
  height: 48px;
  padding: 0 12px;
}

textarea {
  min-height: 118px;
  resize: vertical;
  padding: 12px;
  line-height: 1.45;
}

input:focus,
textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(36, 127, 119, 0.16);
}

.time-field {
  grid-template-columns: 1fr;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.submit-button {
  grid-column: 1 / -1;
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.submit-button:hover {
  background: var(--teal-dark);
}

.submit-button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.result-panel {
  position: relative;
  overflow: hidden;
  min-height: 570px;
  padding: 18px;
}

#chart-canvas {
  display: block;
  width: min(100%, 360px);
  aspect-ratio: 1;
  height: auto;
  margin: 0 auto 8px;
}

.result-copy h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.18;
  letter-spacing: 0;
}

.result-copy p,
.answer-label {
  margin: 0 0 8px;
}

.loading {
  display: grid;
  gap: 12px;
  margin-top: 10px;
}

.loading p {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.meter {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #eadfce;
}

.meter span {
  display: block;
  width: 38%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold), var(--coral));
  animation: meter 1.15s ease-in-out infinite alternate;
}

.answer {
  display: grid;
  gap: 14px;
}

#answer-text {
  max-height: 340px;
  overflow: auto;
  color: #29312e;
  line-height: 1.58;
  white-space: pre-wrap;
}

.report-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  text-decoration: none;
  font-weight: 800;
}

.error-message {
  margin: 14px 0 0;
  padding: 12px;
  border: 1px solid rgba(184, 86, 69, 0.35);
  border-radius: 8px;
  background: rgba(184, 86, 69, 0.08);
  color: #7a2f22;
  line-height: 1.45;
}

@keyframes meter {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(164%);
  }
}

@media (max-width: 820px) {
  .brand-row,
  .content-grid {
    display: grid;
  }

  .brand-row {
    gap: 12px;
  }

  .language-control {
    justify-self: start;
  }

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

  .ask-form {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .result-panel {
    min-height: 420px;
  }
}

@media (max-width: 390px) {
  .language-control {
    grid-template-columns: repeat(4, 38px);
  }

  .lang-button {
    width: 38px;
  }
}
