/* =========================================================
   TOKENS
   ========================================================= */
:root {
  --ink:        #182420;
  --ink-soft:   #4A5850;
  --paper:      #EEF2EE;
  --paper-deep: #E2E8E1;
  --surface:    #FFFFFF;
  --line:       #D6DED5;

  --pine:       #21594A;
  --pine-deep:  #163D33;
  --pine-tint:  #E4EFE9;

  --amber:      #E3B341;
  --coral:      #D9534F;
  --sage:       #4C9A78;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body:    'Inter', -apple-system, sans-serif;
  --font-mono:    'JetBrains Mono', 'SFMono-Regular', monospace;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;

  --shadow-card: 0 1px 2px rgba(24,36,32,0.04), 0 12px 28px -8px rgba(24,36,32,0.10);
  --shadow-lift: 0 2px 4px rgba(24,36,32,0.06), 0 20px 40px -12px rgba(22,61,51,0.20);
}

* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 85% -10%, #F4F8F3 0%, transparent 55%),
    var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.5;
  position: relative;
}

.noise-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='90'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* =========================================================
   HEADER
   ========================================================= */
.site-header {
  padding: 64px 24px 32px;
  position: relative;
  z-index: 1;
}

.header-inner {
  max-width: 1180px;
  margin: 0 auto;
}

.eyebrow {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--pine);
  background: var(--pine-tint);
  padding: 5px 12px;
  border-radius: 100px;
  margin-bottom: 18px;
}

.title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(2.4rem, 5vw, 3.6rem);
  line-height: 1.05;
  margin: 0 0 14px;
  letter-spacing: -0.01em;
  color: var(--pine-deep);
}

.title em {
  font-style: italic;
  font-weight: 500;
  color: var(--pine);
}

.subtitle {
  max-width: 560px;
  font-size: 16px;
  color: var(--ink-soft);
  margin: 0;
}

/* =========================================================
   LAYOUT
   ========================================================= */
.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px 40px;
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 24px;
  align-items: start;
  position: relative;
  z-index: 1;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
}

.form-panel { padding: 8px 32px 32px; }

.result-panel {
  position: sticky;
  top: 24px;
  min-height: 520px;
  background: linear-gradient(165deg, var(--pine-deep) 0%, var(--pine) 100%);
  border: none;
  box-shadow: var(--shadow-lift);
  display: flex;
  color: #EAF3EE;
}

/* =========================================================
   FORM
   ========================================================= */
fieldset.group {
  border: none;
  margin: 0;
  padding: 28px 0;
  border-bottom: 1px solid var(--line);
}
fieldset.group:last-of-type { border-bottom: none; padding-bottom: 8px; }

legend {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  margin-bottom: 18px;
}

.legend-index {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--pine);
  background: var(--pine-tint);
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.grid {
  display: grid;
  gap: 18px;
}
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

.field { display: flex; flex-direction: column; gap: 6px; position: relative; }
.field-span { grid-column: 1 / -1; }

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}

input[type="text"],
input[type="number"],
select {
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  width: 100%;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9'%3E%3Cpath d='M1 1l6 6 6-6' stroke='%234A5850' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
  cursor: pointer;
}

input:hover, select:hover { border-color: #B9C6B7; }

input:focus, select:focus {
  outline: none;
  border-color: var(--pine);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--pine-tint);
}

input:invalid:not(:placeholder-shown):not(:focus) {
  border-color: var(--coral);
}

.field.field-error input,
.field.field-error select {
  border-color: var(--coral);
  background: #FBEEEE;
}

.unit-input { position: relative; }
.unit-input input { padding-right: 44px; }
.unit-input .unit {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  pointer-events: none;
}

.hint {
  font-size: 11.5px;
  color: #90A096;
}

.error-msg {
  font-size: 12px;
  color: var(--coral);
  min-height: 0;
  display: none;
}
.field.field-error .error-msg { display: block; }

/* segmented control for stress level */
.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.seg-btn {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.seg-btn:hover { border-color: #B9C6B7; color: var(--ink); }
.seg-btn.active {
  background: var(--pine);
  border-color: var(--pine);
  color: #fff;
}
.seg-btn[data-value="Very High"].active { background: var(--coral); border-color: var(--coral); }
.seg-btn[data-value="High"].active { background: #C97C3B; border-color: #C97C3B; }

/* footer / submit */
.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 20px;
}

.api-note {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: #90A096;
  margin: 0;
}
.api-note code {
  background: var(--paper-deep);
  padding: 2px 5px;
  border-radius: 4px;
}

.submit-btn {
  position: relative;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14.5px;
  color: #fff;
  background: var(--pine);
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 26px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}
.submit-btn:hover { background: var(--pine-deep); }
.submit-btn:active { transform: scale(0.98); }
.submit-btn:disabled { opacity: 0.75; cursor: progress; }

.btn-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
.submit-btn.loading .btn-label { opacity: 0.85; }
.submit-btn.loading .btn-spinner { display: inline-block; }

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

/* =========================================================
   RESULT PANEL
   ========================================================= */
.result-inner {
  width: 100%;
  padding: 40px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
}

.state { width: 100%; display: flex; flex-direction: column; align-items: center; }

/* gauge */
.gauge { width: 100%; max-width: 260px; overflow: visible; margin-bottom: 8px; }
.gauge-track {
  fill: none;
  stroke: rgba(255,255,255,0.14);
  stroke-width: 14;
  stroke-linecap: round;
}
.gauge-fill {
  fill: none;
  stroke: url(#gaugeGradient);
  stroke-width: 14;
  stroke-linecap: round;
  stroke-dasharray: 314;
  stroke-dashoffset: 314;
  transition: stroke-dashoffset 1.1s cubic-bezier(0.22, 1, 0.36, 1);
}
.gauge-needle-hub { fill: #fff; opacity: 0.9; }
.gauge-ticks line { stroke: rgba(255,255,255,0.3); stroke-width: 1.5; }

.idle-label {
  font-family: var(--font-display);
  font-size: 20px;
  font-style: italic;
  color: #EAF3EE;
  margin: 8px 0 4px;
}
.idle-copy {
  font-size: 13.5px;
  color: rgba(234,243,238,0.65);
  max-width: 230px;
  margin: 0;
}

/* loading */
.state-loading { padding: 40px 0; }
.pulse-ring {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25);
  position: relative;
  margin-bottom: 22px;
}
.pulse-ring::before, .pulse-ring::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(234,243,238,0.55);
  animation: pulse-out 1.8s ease-out infinite;
}
.pulse-ring::after { animation-delay: 0.6s; }
@keyframes pulse-out {
  0% { transform: scale(0.6); opacity: 0.9; }
  100% { transform: scale(1.9); opacity: 0; }
}
.loading-label {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 19px;
  margin: 0 0 4px;
}
.loading-copy { font-size: 13px; color: rgba(234,243,238,0.6); margin: 0; }

/* result */
.score-readout {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-top: -6px;
}
.score-number {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 52px;
  color: #fff;
  letter-spacing: -0.02em;
}
.score-max { font-family: var(--font-mono); font-size: 16px; color: rgba(234,243,238,0.55); }

.score-band {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 19px;
  margin: 2px 0 10px;
}
.score-context {
  font-size: 13px;
  color: rgba(234,243,238,0.7);
  max-width: 250px;
  margin: 0 0 22px;
}

.reset-btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13.5px;
  color: var(--pine-deep);
  background: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 22px;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}
.reset-btn:hover { box-shadow: 0 6px 16px rgba(0,0,0,0.18); }
.reset-btn:active { transform: scale(0.98); }

/* error state */
.state-error { padding: 28px 0; }
.error-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(217,83,79,0.18);
  color: #FF9B95;
  border: 1.5px solid rgba(255,155,149,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 18px;
  margin-bottom: 16px;
}
.error-label {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 19px;
  margin: 0 0 6px;
}
.error-copy {
  font-size: 13px;
  color: rgba(234,243,238,0.7);
  max-width: 250px;
  margin: 0 0 22px;
}

/* =========================================================
   FOOTER
   ========================================================= */
.site-footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px 48px;
  position: relative;
  z-index: 1;
}
.site-footer p {
  font-size: 12.5px;
  color: #90A096;
  text-align: center;
  margin: 0;
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; }
  .result-panel { position: static; min-height: 420px; }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
  .site-header { padding: 44px 16px 24px; }
  .layout { padding: 0 16px 32px; gap: 16px; }
  .form-panel { padding: 4px 20px 24px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .segmented { grid-template-columns: repeat(2, 1fr); }
  .form-footer { flex-direction: column; align-items: stretch; gap: 14px; }
  .submit-btn { justify-content: center; }
  .api-note { text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
