:root {
  --ink: #2b2119;
  --muted: #736554;
  --panel: #fffaf0;
  --line: #dfcfb5;
  --moss: #516b3f;
  --sky: #e8ddc7;
  --soft: #f7efe0;
  --accent: #b78454;
  --danger: #a95f49;
  --clay: #c9825d;
  --shadow: rgba(68, 47, 28, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: "Inter", system-ui, sans-serif;
  background:
    linear-gradient(135deg, rgba(238, 225, 199, 0.98), rgba(250, 244, 232, 0.95) 46%),
    linear-gradient(45deg, rgba(165, 136, 95, 0.24), rgba(95, 122, 75, 0.2));
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.68;
}

.chat-app {
  width: min(1420px, 94vw);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) max(0px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(0px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: 300px minmax(360px, 1fr) minmax(340px, 420px);
  gap: 18px;
}

.companion-panel,
.dashboard-shell,
.chat-shell {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.88);
  box-shadow: 0 24px 70px var(--shadow);
}

.companion-panel {
  min-height: calc(100vh - 48px);
  display: grid;
  align-content: space-between;
  gap: 22px;
  padding: 22px;
  overflow: hidden;
}

.dashboard-shell {
  min-height: calc(100vh - 48px);
  min-height: calc(100dvh - 48px);
  display: grid;
  align-content: start;
  gap: 16px;
  padding: 20px;
  overflow: auto;
}

.dashboard-header {
  display: grid;
  gap: 8px;
  padding-bottom: 4px;
}

.dashboard-header p,
.tool-panel p,
.current-step-card p {
  color: var(--muted);
  line-height: 1.5;
}

h3 {
  margin: 0;
  font-size: 1.04rem;
  line-height: 1.2;
}

.tool-panel {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.76);
  padding: 16px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}

.panel-heading span {
  color: var(--moss);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: right;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.mood-grid,
.step-actions,
.activity-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mood-grid button,
.step-actions button,
.activity-list button,
.small-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sky);
  color: var(--ink);
  padding: 0 12px;
  font-weight: 800;
}

.mood-grid button {
  flex: 1 1 120px;
}

.small-button {
  min-height: 36px;
  color: var(--moss);
  background: var(--soft);
}

.current-step-card {
  display: grid;
  gap: 8px;
  min-height: 128px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fffaf0, #f0e3cf);
  padding: 16px;
  line-height: 1.5;
}

.current-step-card span {
  color: var(--moss);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.current-step-card strong {
  font-size: 1.1rem;
}

.activity-list button.is-active {
  background: var(--moss);
  border-color: var(--moss);
  color: #fff;
}

.helpline-list ul {
  margin: 0;
  padding-left: 18px;
  color: var(--ink);
  line-height: 1.5;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--moss);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14rem;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: clamp(4rem, 9vw, 7rem);
  line-height: 0.82;
  font-weight: 400;
}

h2 {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: clamp(2.1rem, 4vw, 3.6rem);
  line-height: 0.95;
  font-weight: 400;
}

.companion-panel p,
footer,
.profile-card p {
  color: var(--muted);
  line-height: 1.5;
}

.profile-card {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 14px;
}

.profile-card span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.profile-card strong {
  font-size: 1.08rem;
}

.activity-stage {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 184px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fffaf0, #eadcc6);
  padding: 14px;
  text-align: center;
}

.stage-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12rem;
  text-transform: uppercase;
}

.activity-stage strong {
  font-size: 1rem;
}

.stage-visual {
  position: relative;
  width: 112px;
  height: 96px;
}

.calm-spark span {
  position: absolute;
  border-radius: 999px;
  background: var(--accent);
  animation: spark-pulse 2.2s ease-in-out infinite;
}

.calm-spark span:nth-child(1) {
  inset: 34px 38px;
}

.calm-spark span:nth-child(2) {
  inset: 18px 24px;
  opacity: 0.4;
  animation-delay: 0.25s;
}

.calm-spark span:nth-child(3) {
  inset: 4px 10px;
  opacity: 0.18;
  animation-delay: 0.5s;
}

.dancer .head {
  position: absolute;
  left: 45px;
  top: 4px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--moss);
  animation: dancer-bob 0.8s ease-in-out infinite;
}

.dancer .body {
  position: absolute;
  left: 53px;
  top: 30px;
  width: 10px;
  height: 38px;
  border-radius: 999px;
  background: var(--moss);
  transform-origin: top center;
  animation: dancer-body 0.8s ease-in-out infinite;
}

.dancer .arm,
.dancer .leg {
  position: absolute;
  width: 9px;
  border-radius: 999px;
  background: var(--moss);
  transform-origin: top center;
}

.dancer .arm {
  top: 34px;
  height: 36px;
}

.dancer .arm.left {
  left: 48px;
  animation: dancer-left-arm 0.8s ease-in-out infinite;
}

.dancer .arm.right {
  left: 58px;
  animation: dancer-right-arm 0.8s ease-in-out infinite;
}

.dancer .leg {
  top: 64px;
  height: 34px;
}

.dancer .leg.left {
  left: 50px;
  animation: dancer-left-leg 0.8s ease-in-out infinite;
}

.dancer .leg.right {
  left: 58px;
  animation: dancer-right-leg 0.8s ease-in-out infinite;
}

.dancer .note {
  position: absolute;
  color: var(--clay);
  font-size: 1.4rem;
  font-weight: 800;
  animation: note-float 1.4s ease-in-out infinite;
}

.dancer .note::before {
  content: "\266A";
}

.dancer .note.one {
  left: 12px;
  top: 22px;
}

.dancer .note.two {
  right: 10px;
  top: 12px;
  animation-delay: 0.35s;
}

.drawing-motion .paper {
  position: absolute;
  left: 20px;
  top: 18px;
  width: 72px;
  height: 58px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
}

.drawing-motion .pencil {
  position: absolute;
  left: 48px;
  top: 28px;
  width: 10px;
  height: 54px;
  border-radius: 999px;
  background: var(--moss);
  transform: rotate(42deg);
  animation: pencil-draw 1.6s ease-in-out infinite;
}

.drawing-motion .line {
  position: absolute;
  left: 37px;
  top: 57px;
  width: 42px;
  height: 3px;
  border-radius: 999px;
  background: var(--accent);
  animation: line-grow 1.6s ease-in-out infinite;
}

.music-motion span {
  position: absolute;
  bottom: 16px;
  width: 16px;
  border-radius: 999px 999px 4px 4px;
  background: linear-gradient(180deg, var(--accent), var(--moss));
  animation: music-bar 0.9s ease-in-out infinite;
}

.music-motion span:nth-child(1) {
  left: 24px;
  height: 36px;
}

.music-motion span:nth-child(2) {
  left: 48px;
  height: 58px;
  animation-delay: 0.15s;
}

.music-motion span:nth-child(3) {
  left: 72px;
  height: 44px;
  animation-delay: 0.3s;
}

.ghost-button,
.primary-button,
.quick-actions button {
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 800;
}

.ghost-button {
  min-height: 42px;
  background: var(--soft);
  color: var(--moss);
}

.primary-button {
  min-height: 46px;
  background: var(--moss);
  color: #fff;
  border-color: var(--moss);
}

.primary-button:disabled {
  background: var(--muted);
  border-color: var(--muted);
}

.chat-shell {
  min-height: calc(100vh - 48px);
  min-height: calc(100dvh - 48px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  overflow: hidden;
}

.chat-shell h2 {
  font-size: clamp(2rem, 3vw, 2.8rem);
}

.chat-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.privacy-pill {
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--sky);
  color: var(--moss);
  padding: 8px 10px;
  font-size: 0.78rem;
  font-weight: 800;
}

.chat-setup-hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.chat-log {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(255, 250, 240, 0.94), rgba(238, 225, 199, 0.72)),
    var(--soft);
}

.message {
  width: min(78%, 680px);
  max-width: 100%;
  white-space: pre-line;
  overflow-wrap: anywhere;
  border-radius: 8px;
  padding: 12px 14px;
  line-height: 1.5;
  box-shadow: 0 10px 22px rgba(68, 47, 28, 0.08);
}

.message.bot {
  align-self: flex-start;
  background: #fffaf0;
  border: 1px solid var(--line);
}

.message.user {
  align-self: flex-end;
  background: var(--moss);
  color: #fff;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px 0;
  background: rgba(255, 250, 240, 0.78);
}

.quick-actions:empty {
  display: none;
}

.quick-actions button {
  min-height: 42px;
  background: var(--sky);
  color: var(--ink);
  padding: 0 12px;
  font-size: 0.84rem;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 10px;
  padding: 14px 20px 20px;
  background: rgba(255, 250, 240, 0.78);
}

.chat-form.is-loading input {
  background: #f4ead8;
}

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
  color: var(--ink);
  padding: 0 14px;
  font-size: 1rem;
}

footer {
  padding: 0 20px 18px;
  font-size: 0.78rem;
  background: rgba(255, 250, 240, 0.78);
}

button:hover,
button:focus-visible {
  border-color: var(--moss);
  box-shadow: 0 0 0 3px rgba(129, 107, 75, 0.22);
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(169, 95, 73, 0.32);
  outline-offset: 2px;
}

.bear-scene {
  justify-self: center;
  width: 190px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.bear {
  position: relative;
  width: 128px;
  height: 138px;
  animation: bear-float 3s ease-in-out infinite;
}

.bear .face {
  position: absolute;
  inset: 18px 8px 10px;
  border-radius: 46% 46% 42% 42%;
  background: #b9845f;
  box-shadow: inset 0 -10px 0 rgba(91, 55, 37, 0.12);
}

.bear .ear {
  position: absolute;
  top: 10px;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: #a87351;
}

.bear .ear.left {
  left: 14px;
}

.bear .ear.right {
  right: 14px;
}

.bear .eye {
  position: absolute;
  top: 60px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #2f1d16;
}

.bear .eye.left {
  left: 45px;
}

.bear .eye.right {
  right: 45px;
}

.bear .nose {
  position: absolute;
  top: 74px;
  left: 50%;
  width: 18px;
  height: 13px;
  border-radius: 999px;
  background: #3a251d;
  transform: translateX(-50%);
}

.bear .arm {
  position: absolute;
  top: 82px;
  width: 34px;
  height: 18px;
  border-radius: 999px;
  background: #9b6649;
  z-index: 2;
}

.bear .arm.left {
  left: 20px;
  transform: rotate(24deg);
}

.bear .arm.right {
  right: 20px;
  transform: rotate(-24deg);
}

.bear .heart {
  position: absolute;
  left: 50%;
  top: 86px;
  width: 36px;
  height: 36px;
  background: #f06f88;
  transform: translateX(-50%) rotate(45deg);
  animation: heart-beat 1.4s ease-in-out infinite;
}

.bear .heart::before,
.bear .heart::after {
  content: "";
  position: absolute;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: #f06f88;
}

.bear .heart::before {
  left: -18px;
}

.bear .heart::after {
  top: -18px;
}

@keyframes bear-float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

@keyframes heart-beat {
  0%,
  100% {
    transform: translateX(-50%) rotate(45deg) scale(1);
  }
  45% {
    transform: translateX(-50%) rotate(45deg) scale(1.12);
  }
}

@keyframes spark-pulse {
  0%,
  100% {
    transform: scale(0.85);
  }
  50% {
    transform: scale(1.08);
  }
}

@keyframes dancer-bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

@keyframes dancer-body {
  0%,
  100% {
    transform: rotate(-8deg);
  }
  50% {
    transform: rotate(8deg);
  }
}

@keyframes dancer-left-arm {
  0%,
  100% {
    transform: rotate(66deg);
  }
  50% {
    transform: rotate(-88deg);
  }
}

@keyframes dancer-right-arm {
  0%,
  100% {
    transform: rotate(-70deg);
  }
  50% {
    transform: rotate(86deg);
  }
}

@keyframes dancer-left-leg {
  0%,
  100% {
    transform: rotate(24deg);
  }
  50% {
    transform: rotate(-34deg);
  }
}

@keyframes dancer-right-leg {
  0%,
  100% {
    transform: rotate(-24deg);
  }
  50% {
    transform: rotate(38deg);
  }
}

@keyframes note-float {
  0%,
  100% {
    transform: translateY(6px);
    opacity: 0.45;
  }
  50% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

@keyframes pencil-draw {
  0%,
  100% {
    transform: translateX(-10px) rotate(42deg);
  }
  50% {
    transform: translateX(18px) rotate(42deg);
  }
}

@keyframes line-grow {
  0%,
  100% {
    width: 10px;
  }
  50% {
    width: 42px;
  }
}

@keyframes music-bar {
  0%,
  100% {
    transform: scaleY(0.65);
  }
  50% {
    transform: scaleY(1.12);
  }
}

@media (max-width: 1180px) {
  .chat-app {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .chat-shell {
    grid-column: 1 / -1;
    min-height: 560px;
  }
}

@media (max-width: 860px) {
  .chat-app {
    width: min(760px, 100vw);
    grid-template-columns: 1fr;
    gap: 0;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }

  .companion-panel {
    min-height: auto;
    border-radius: 0;
    box-shadow: none;
  }

  .dashboard-shell {
    min-height: auto;
    border-radius: 0;
    box-shadow: none;
  }

  .bear-scene {
    display: none;
  }

  .chat-shell {
    grid-column: auto;
    min-height: 72vh;
    min-height: 72dvh;
    border-radius: 0;
    box-shadow: none;
  }

  .message {
    width: min(92%, 620px);
  }
}

@media (max-width: 560px) {
  body {
    background: var(--soft);
  }

  .chat-app {
    width: min(100%, 100vw);
    padding: 0;
    min-height: 100svh;
    min-height: 100dvh;
  }

  .companion-panel,
  .dashboard-shell,
  .chat-shell {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .companion-panel {
    gap: 14px;
    padding: max(16px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 14px max(14px, env(safe-area-inset-left));
  }

  h1 {
    font-size: clamp(3.4rem, 22vw, 5rem);
  }

  h2 {
    font-size: clamp(2rem, 13vw, 2.8rem);
  }

  .activity-stage {
    min-height: 138px;
  }

  .dashboard-shell {
    padding: 16px 14px;
    gap: 12px;
  }

  .tool-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .tool-panel {
    padding: 14px;
  }

  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-heading span {
    text-align: left;
  }

  .stage-visual {
    width: 88px;
    height: 76px;
    transform: scale(0.86);
  }

  .chat-header,
  .chat-form {
    grid-template-columns: 1fr;
  }

  .chat-header {
    flex-direction: column;
    padding: 16px 14px;
  }

  .privacy-pill {
    white-space: normal;
  }

  .chat-log {
    gap: 10px;
    padding: 14px;
  }

  .message {
    width: 94%;
    padding: 11px 12px;
    font-size: 0.96rem;
  }

  .quick-actions {
    padding: 10px 14px 0;
  }

  .quick-actions button {
    min-height: 44px;
    padding: 0 14px;
  }

  .chat-form {
    position: sticky;
    bottom: 0;
    padding: 12px max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }

  .primary-button,
  input {
    min-height: 50px;
  }

  footer {
    padding: 0 max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
}
