:root {
  color-scheme: light;
  --dragon-black: #182026;
  --dragon-dark: #26313a;
  --gold: #e9a23b;
  --gold-light: #f4c66a;
  --cream: #f4e9db;
  --forest: #344a3d;
  --slate: #3e4a55;
  --bg: #f7f4ef;
  --surface: #ffffff;
  --surface-soft: #f5f2ec;
  --ink: #182026;
  --muted: #657078;
  --line: #ddd8ce;
  --success: #34734b;
  --danger: #b74735;
  --shadow: 0 12px 34px rgba(24, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

[hidden] {
  display: none !important;
}

button,
select,
input {
  font: inherit;
}

button,
select,
input,
dialog {
  letter-spacing: 0;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(233, 162, 59, 0.34);
  outline-offset: 2px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1,
h2,
h3 {
  line-height: 1.15;
}

h2 {
  font-size: 21px;
}

.eyebrow,
.stage-kicker {
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--dragon-black);
}

.auth-shell {
  width: min(1040px, 100%);
  min-height: 640px;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(380px, 0.85fr);
  overflow: hidden;
  border: 1px solid rgba(244, 198, 106, 0.2);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

.auth-visual {
  position: relative;
  min-height: 640px;
  overflow: hidden;
  background: var(--dragon-dark);
  color: var(--cream);
  padding: 38px 42px;
}

.brand-signature {
  width: max-content;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-signature > img {
  width: 58px;
  height: 58px;
  object-fit: contain;
}

.brand-signature > div {
  display: grid;
  gap: 2px;
}

.brand-signature strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 32px;
  font-weight: 500;
  line-height: 1;
}

.brand-signature span {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
}

.brand-signature-light strong {
  color: var(--cream);
}

.brand-signature-light span {
  color: var(--gold-light);
}

.brand-signature-dark strong {
  color: var(--dragon-black);
}

.brand-signature-dark span {
  color: var(--slate);
}

.auth-logo {
  position: relative;
  z-index: 2;
}

.auth-message {
  position: relative;
  z-index: 2;
  width: min(430px, 100%);
  margin-top: 66px;
}

.auth-message h1 {
  margin-top: 12px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 42px;
  font-weight: 500;
}

.auth-message > p:last-child {
  width: 370px;
  max-width: 100%;
  margin-top: 18px;
  color: #cfd4d5;
  font-size: 16px;
}

.auth-dragon {
  position: absolute;
  z-index: 1;
  right: -44px;
  bottom: -70px;
  width: 440px;
  height: 440px;
  object-fit: contain;
  pointer-events: none;
}

.auth-panel {
  align-self: center;
  padding: 54px 46px;
}

.auth-mark {
  width: 54px;
  height: 54px;
  margin-bottom: 24px;
}

.auth-panel .eyebrow {
  color: var(--forest);
}

.auth-panel h2 {
  margin-top: 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 34px;
  font-weight: 500;
}

.auth-panel > p:not(.eyebrow):not(.form-error) {
  margin: 12px 0 26px;
  color: var(--muted);
}

.auth-submit,
.auth-mode-button {
  width: 100%;
  min-height: 44px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 800;
}

.auth-submit {
  border: 1px solid var(--gold);
  background: var(--gold);
  color: var(--dragon-black);
}

.auth-submit:hover {
  background: var(--gold-light);
}

.auth-mode-button {
  margin-top: 9px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.shell {
  width: min(1200px, calc(100% - 36px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.topbar {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.dashboard-nav {
  display: flex;
  gap: 18px;
  margin: 0 0 14px;
  border-bottom: 1px solid var(--line);
}

.dashboard-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.dashboard-nav a:hover,
.dashboard-nav a[aria-current="page"] {
  color: var(--forest);
}

.dashboard-nav a[aria-current="page"] {
  border-bottom-color: var(--forest);
}

.brand-lockup {
  flex: 0 0 auto;
}

.brand-lockup > img {
  width: 52px;
  height: 52px;
}

.brand-lockup strong {
  font-size: 29px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 20px;
}

.account-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: end;
  min-width: 0;
}

.account-meta span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.account-meta strong {
  max-width: min(210px, 100%);
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
}

.toolbar button,
.icon-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--slate);
  cursor: pointer;
}

.toolbar button:hover,
.icon-button:hover {
  border-color: var(--gold);
  color: var(--dragon-black);
}

.toolbar button.toolbar-primary {
  border-color: var(--gold);
  background: var(--gold);
  color: var(--dragon-black);
}

.toolbar svg,
.icon-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.max-button-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: -0.4px;
}

.dragon-stage {
  position: relative;
  min-height: 348px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 440px;
  overflow: hidden;
  border: 1px solid #354049;
  border-top-color: var(--gold);
  border-radius: 8px;
  background: var(--dragon-black);
  color: var(--cream);
  box-shadow: 0 18px 50px rgba(24, 32, 38, 0.18);
}

.dragon-stage-copy {
  position: relative;
  z-index: 2;
  align-self: center;
  padding: 38px 10px 36px 40px;
}

.dragon-stage-copy h1 {
  max-width: 620px;
  margin-top: 10px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 38px;
  font-weight: 500;
}

.dragon-stage-copy > p:not(.stage-kicker):not(.dragon-note) {
  margin-top: 10px;
  color: #cdd2d3;
}

.dragon-progress-track {
  width: min(560px, 100%);
  height: 8px;
  overflow: hidden;
  margin-top: 28px;
  border-radius: 4px;
  background: #3b464f;
}

.dragon-progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--gold);
  transition: width 420ms ease;
}

.dragon-progress-meta {
  width: min(560px, 100%);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
  margin-top: 18px;
}

.dragon-progress-meta div {
  display: grid;
  gap: 3px;
}

.dragon-progress-meta span {
  color: #9ea8ad;
  font-size: 11px;
  text-transform: uppercase;
}

.dragon-progress-meta strong {
  overflow-wrap: anywhere;
  font-size: 15px;
}

.dragon-note {
  margin-top: 18px;
  color: #8f9a9f;
  font-size: 12px;
}

.dragon-art {
  position: relative;
  min-height: 348px;
}

.dragon-art::before {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 1px;
  background: var(--gold);
  opacity: 0.35;
}

.dragon-art img {
  position: absolute;
  right: -12px;
  bottom: -38px;
  width: 430px;
  height: 430px;
  object-fit: contain;
  filter: drop-shadow(0 14px 16px rgba(0, 0, 0, 0.34));
  transition: opacity 180ms ease, transform 300ms ease;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.stats article,
.panel,
.habit-card,
.empty {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stats article {
  min-height: 100px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-radius: 8px;
  padding: 16px;
}

.stats article > img {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  object-fit: contain;
}

.stats article > div {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.stats span,
.section-title p,
.habit-meta,
.empty p {
  color: var(--muted);
}

.stats article > div > span {
  font-size: 12px;
}

.stats strong {
  font-size: 27px;
  line-height: 1;
}

.panel {
  border-radius: 8px;
  padding: 20px;
}

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

.section-title p {
  margin-top: 5px;
  font-size: 14px;
}

.heatmap-tools {
  display: flex;
  align-items: center;
  gap: 14px;
}

.heatmap-tools select {
  height: 36px;
  min-width: 116px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 32px 0 10px;
}

.legend {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.legend i,
.day {
  display: block;
  width: 12px;
  height: 12px;
  border: 1px solid rgba(24, 32, 38, 0.09);
  border-radius: 3px;
}

[data-level="0"] { background: #ebe8e1; }
[data-level="1"] { background: #b9cbbd; }
[data-level="2"] { background: #7da088; }
[data-level="3"] { background: #4e785c; }
[data-level="4"] { background: #294c37; }

.heatmap-scroll {
  overflow-x: auto;
  padding: 8px 2px 8px;
  scrollbar-color: #c9c4bb transparent;
  scrollbar-width: thin;
}

.heatmap {
  width: max-content;
  min-height: 132px;
  display: flex;
  align-items: flex-start;
  gap: 18px;
}

.heatmap-month {
  display: grid;
  gap: 8px;
}

.month-grid {
  width: max-content;
  min-height: 108px;
  display: grid;
  grid-template-rows: repeat(7, 12px);
  grid-auto-flow: column;
  grid-auto-columns: 12px;
  gap: 4px;
}

.month-label {
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  text-transform: capitalize;
}

.day {
  position: relative;
}

.day.blank {
  visibility: hidden;
}

.day:hover::after {
  content: attr(aria-label);
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: calc(100% + 8px);
  width: max-content;
  transform: translateX(-50%);
  border-radius: 6px;
  background: var(--dragon-black);
  color: #fff;
  padding: 7px 9px;
  font-size: 12px;
  pointer-events: none;
}

.habits-layout {
  margin-top: 30px;
}

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

.habit-card {
  border-radius: 8px;
  padding: 18px;
}

.habit-card.is-completed-today {
  border-color: #c9dbcd;
  background: #edf5ee;
}

.habit-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.habit-title {
  min-width: 0;
}

.habit-header h3 {
  margin: 0 0 6px;
  overflow-wrap: anywhere;
  font-size: 19px;
}

.habit-actions {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.today-action {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
  margin-top: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.today-action.muted {
  justify-content: flex-start;
}

.completion-button {
  margin-inline-start: auto;
  min-height: 36px;
  border: 1px solid var(--forest);
  border-radius: 7px;
  padding: 0 13px;
  background: var(--forest);
  color: white;
  cursor: pointer;
  font-weight: 700;
}

.completion-button:hover:not(.is-completed):not(:disabled) {
  border-color: #283c30;
  background: #283c30;
}

.completion-button.is-completed {
  border-color: var(--line);
  background: var(--surface);
  color: var(--muted);
}

.completion-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.habit-progress {
  position: relative;
  display: grid;
  align-items: center;
  flex: none;
  width: 80px;
  min-height: 40px;
  border-radius: 4px;
}

.habit-progress:focus-visible {
  outline: 2px solid var(--forest);
  outline-offset: 2px;
}

.habit-progress-track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 3px;
  height: 9px;
}

.habit-progress-segment {
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface-soft);
}

.habit-progress-segment.is-complete {
  border-color: var(--forest);
  background: var(--forest);
}

.habit-progress-tooltip {
  position: absolute;
  z-index: 2;
  top: 100%;
  right: 0;
  width: max-content;
  padding: 5px 8px;
  border-radius: 4px;
  background: var(--dragon-black);
  color: white;
  font-size: 12px;
  visibility: hidden;
}

.habit-progress:hover .habit-progress-tooltip,
.habit-progress:focus .habit-progress-tooltip {
  visibility: visible;
}

.habit-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 14px;
}

.habit-grid.has-streak { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.mini-stat {
  min-height: 64px;
  border-radius: 7px;
  background: var(--surface-soft);
  padding: 10px;
}

.mini-stat span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
}

.mini-stat strong {
  font-size: 18px;
}

.habit-streak-flame {
  display: block;
  margin-bottom: 3px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.schedule-chips {
  margin-bottom: 12px;
}

.chip {
  border-radius: 999px;
  padding: 6px 10px;
  background: #ecefe9;
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
}

.empty {
  min-height: 210px;
  display: flex;
  align-items: center;
  gap: 28px;
  border-radius: 8px;
  padding: 24px 34px;
}

.empty > img {
  width: 150px;
  height: 150px;
  object-fit: contain;
}

.empty p {
  max-width: 560px;
  margin-top: 8px;
}

.dialog {
  width: min(680px, calc(100% - 24px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 22px 70px rgba(24, 32, 38, 0.25);
}

.dialog::backdrop {
  background: rgba(24, 32, 38, 0.58);
}

.profile-dialog { width: min(440px, calc(100% - 24px)); }
.profile-dialog .profile-dialog-actions { justify-content: flex-end; }

.dialog form {
  padding: 22px;
}

.dialog-header,
.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 18px;
}

.dialog-header {
  align-items: flex-start;
  margin-bottom: 18px;
}

.dialog-header p,
.compact p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field input,
.schedule-row select,
.schedule-row input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

.field input:read-only {
  background: var(--surface-soft);
}

.coach-setup,
.habit-coach {
  display: grid;
  justify-items: start;
  gap: 8px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.coach-setup {
  margin: 0 0 16px;
  padding: 12px 0;
  border-block: 1px solid var(--line);
}

.has-draft-chat .coach-setup { display: none; }

body:has(.has-draft-chat[open]) { overflow: hidden; }

.coach-notice,
.coach-status {
  font-size: 13px;
  color: var(--muted);
}

.coach-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  max-width: 100%;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  text-align: start;
}

.coach-button:hover:not(:disabled) {
  border-color: var(--gold);
}

.coach-button:disabled {
  opacity: 0.65;
  cursor: wait;
}

.coach-button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linejoin: round;
}

.habit-coach {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}

.habit-summary-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.habit-summary-header > div { min-width: 0; }

.dialog.has-draft-chat[open] {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  width: min(1050px, calc(100% - 24px));
  height: min(740px, calc(100dvh - 32px));
  overflow: hidden;
}

.has-draft-chat > #habitForm,
.draft-chat-slot {
  min-width: 0;
  min-height: 0;
}

.has-draft-chat > #habitForm {
  overflow: auto;
}

.draft-chat-slot {
  border-right: 1px solid var(--line);
}

.dashboard-workspace {
  display: grid;
  align-items: start;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.dashboard-content,
.coach-dock {
  min-width: 0;
}

.coach-nav-toggle {
  display: inline-flex;
  margin-inline-start: auto;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 4px 8px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--forest);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.coach-nav-toggle:hover,
.coach-nav-toggle[aria-expanded="true"] {
  border-bottom-color: var(--gold);
}

.coach-dock {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.coach-dock.has-thread {
  height: clamp(320px, 60dvh, 560px);
}

.coach-dock:not(.has-thread) .coach-chat-header {
  border-bottom: 0;
}

.coach-dock:not(.has-thread) .coach-chat-scroll {
  padding-top: 0;
  padding-bottom: 8px;
}

.coach-habit-picker {
  display: grid;
  grid-row: 2;
  gap: 8px;
  padding: 0 16px 14px;
}

.coach-dock.has-thread .coach-habit-picker {
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}

.coach-greeting {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.coach-greeting img {
  object-fit: contain;
}

.coach-today-note {
  color: var(--forest);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.coach-habit-picker select {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
}

.coach-habit-picker .coach-button {
  justify-self: start;
}

@media (min-width: 1150px) {
  .dashboard-workspace:has(.coach-dock:not([hidden])) {
    grid-template-columns: 320px minmax(0, 1fr);
    gap: 20px;
  }

  .coach-dock {
    position: sticky;
    top: 16px;
  }

  .coach-dock.has-thread {
    height: clamp(360px, calc(100dvh - 32px), 690px);
  }

  .dashboard-workspace:has(.coach-dock:not([hidden])) .dragon-stage {
    grid-template-columns: minmax(0, 1fr) 340px;
  }

  .dashboard-workspace:has(.coach-dock:not([hidden])) .dragon-art img {
    width: 340px;
    height: 340px;
    right: 0;
    bottom: 0;
  }
}

.coach-chat {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  height: 100%;
  min-width: 0;
  background: var(--surface);
}

.coach-chat-header { grid-row: 1; }
.coach-chat-scroll { grid-row: 4; }
.coach-chat-composer { grid-row: 5; }

.coach-goal-context {
  grid-row: 3;
  display: grid;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.coach-goal-context select {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

.coach-goal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.coach-goal-plan {
  display: grid;
  gap: 6px;
  border-top: 1px solid var(--line);
  padding-top: 7px;
  overflow-wrap: anywhere;
}

.coach-goal-plan ul {
  margin: 0;
  padding-left: 18px;
}

.coach-token-usage {
  color: var(--muted);
  font-size: 12px;
}

.coach-token-usage summary {
  cursor: pointer;
  width: fit-content;
  padding: 3px 0;
}

.coach-token-usage ul {
  margin: 2px 0 0;
  padding-left: 18px;
}

.coach-chat-header,
.coach-chat .coach-chat-composer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
}

.coach-chat-header {
  border-bottom: 1px solid var(--line);
}

.coach-chat-identity {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.coach-chat-identity > div { min-width: 0; }

.coach-chat-header h2 { font-size: 17px; }

.coach-chat-header p {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.coach-chat-header .icon-button,
.coach-chat-composer .icon-button {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
}

.coach-chat-scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 16px;
}

.coach-load-older { margin-bottom: 12px; }

.coach-messages {
  display: grid;
  gap: 12px;
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
}

.coach-messages:empty {
  margin: 0;
}

.coach-message {
  display: grid;
  gap: 6px;
  justify-self: start;
  max-width: min(95%, 390px);
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  overflow-wrap: anywhere;
  font-size: 14px;
}

.coach-message-user {
  justify-self: end;
  background: #e8efe8;
}

.coach-message-day {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.coach-message-day::before,
.coach-message-day::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--line);
}

.coach-message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.coach-message-time {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.coach-message-author {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 6px;
  min-width: 0;
  min-height: 16px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.coach-message-author-name { min-width: 0; }

.coach-message-user .coach-message-author {
  color: var(--forest);
}

.coach-avatar {
  display: block;
  flex: none;
  object-fit: contain;
}

svg.coach-avatar {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.coach-message p { white-space: pre-wrap; }
.coach-message .coach-button { justify-self: start; }
.coach-chat-scroll > .coach-status { margin-top: 12px; }

.coach-chat .coach-chat-composer {
  border-top: 1px solid var(--line);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.coach-chat-composer input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  font-size: 16px;
}

.coach-chat-composer button:disabled { opacity: 0.55; }

@media (max-width: 760px) {
  .dialog.has-draft-chat[open] {
    position: fixed;
    inset: 0;
    display: block;
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .has-draft-chat > #habitForm { display: none; }
  .draft-chat-slot { height: 100%; border: 0; }
}

.schedule-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #faf9f6;
}

.section-title.compact {
  margin-bottom: 12px;
}

.section-title.compact h2 {
  font-size: 16px;
}

#addScheduleButton,
.dialog-actions button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  padding: 0 14px;
  font-weight: 750;
}

#addScheduleButton:hover,
.dialog-actions button:hover {
  border-color: var(--gold);
}

.schedule-rows {
  display: grid;
  gap: 8px;
}

.schedule-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(110px, 1fr) 40px;
  gap: 8px;
  align-items: center;
}

.form-error {
  margin-top: 12px;
  color: #9c3828;
  font-weight: 700;
}

.dialog-actions {
  align-items: center;
  margin-top: 18px;
}

.dialog-actions > div {
  display: flex;
  gap: 8px;
}

.dialog-actions .primary {
  border-color: var(--gold);
  background: var(--gold);
  color: var(--dragon-black);
}

.dialog-actions .danger {
  border-color: #e2bdb6;
  background: #fff4f1;
  color: #983425;
}

@media (max-width: 900px) {
  .auth-shell {
    grid-template-columns: minmax(0, 1fr) minmax(350px, 0.9fr);
  }

  .dragon-stage {
    grid-template-columns: minmax(0, 1fr) 350px;
  }

  .dragon-art img {
    right: -34px;
    width: 380px;
    height: 380px;
  }

  .stats,
  .habits-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .auth-gate {
    align-items: start;
    padding: 0;
    background: var(--surface);
  }

  .auth-shell {
    width: 100%;
    min-height: 100vh;
    grid-template-columns: 1fr;
    border: 0;
    box-shadow: none;
  }

  .auth-visual {
    min-height: 280px;
    padding: 24px;
  }

  .auth-logo {
    gap: 9px;
  }

  .auth-logo > img {
    width: 48px;
    height: 48px;
  }

  .auth-logo strong {
    font-size: 25px;
  }

  .auth-message {
    margin-top: 24px;
  }

  .auth-message h1 {
    font-size: 30px;
  }

  .auth-message > p:last-child {
    display: none;
  }

  .auth-dragon {
    right: -28px;
    bottom: -50px;
    width: 245px;
    height: 245px;
    opacity: 0.82;
  }

  .auth-panel {
    align-self: start;
    padding: 34px 24px 44px;
  }

  .auth-mark {
    width: 44px;
    height: 44px;
    margin-bottom: 16px;
  }

  .shell {
    width: min(100% - 20px, 1200px);
    padding-top: 12px;
  }

  .topbar {
    align-items: flex-start;
    gap: 12px;
  }

  .brand-lockup {
    gap: 8px;
  }

  .brand-lockup > img {
    width: 42px;
    height: 42px;
  }

  .brand-lockup strong {
    font-size: 24px;
  }

  .brand-lockup span {
    font-size: 7px;
  }

  .topbar-actions {
    align-items: flex-end;
    flex-direction: column;
    gap: 8px;
  }

  .account-meta {
    display: none;
  }

  .toolbar {
    gap: 6px;
  }

  .toolbar button {
    width: 38px;
    height: 38px;
  }

  .dragon-stage {
    min-height: 510px;
    grid-template-columns: 1fr;
  }

  .dragon-stage-copy {
    z-index: 3;
    align-self: start;
    padding: 26px 22px 0;
  }

  .dragon-stage-copy h1 {
    font-size: 30px;
  }

  .dragon-progress-meta {
    gap: 10px;
  }

  .dragon-progress-meta strong {
    font-size: 13px;
  }

  .dragon-art {
    min-height: 255px;
  }

  .dragon-art img {
    right: 50%;
    bottom: -44px;
    width: 330px;
    height: 330px;
    transform: translateX(50%);
  }

  .section-title,
  .habit-header {
    flex-direction: column;
    align-items: stretch;
  }

  .heatmap-tools {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .habit-progress {
    margin-inline-start: auto;
  }

  .empty {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 24px;
  }

  .empty > img {
    width: 112px;
    height: 112px;
  }
}

@media (max-width: 520px) {
  .topbar {
    align-items: center;
    min-height: 48px;
    margin-bottom: 10px;
  }

  .brand-lockup {
    gap: 6px;
  }

  .brand-lockup > img {
    width: 34px;
    height: 34px;
  }

  .brand-lockup strong {
    font-size: 19px;
  }

  .brand-lockup span {
    display: none;
  }

  .toolbar button:not(.toolbar-primary):not(#editProfileButton):not(#logoutButton) {
    display: none;
  }

  .habits-list {
    grid-template-columns: 1fr;
  }

  .stats article {
    min-height: 76px;
  }

  .dragon-stage {
    min-height: 0;
    display: block;
  }

  .dragon-stage-copy {
    padding: 18px 16px 4px;
  }

  .dragon-stage-copy h1 {
    font-size: 25px;
  }

  .dragon-progress-track {
    margin-top: 14px;
  }

  .dragon-note {
    margin-top: 8px;
  }

  .dragon-art {
    min-height: 154px;
  }

  .dragon-art img {
    width: 210px;
    height: 210px;
    bottom: -18px;
  }

  .dragon-progress-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dragon-progress-meta div:last-child {
    grid-column: 1 / -1;
  }

  .legend > span {
    display: none;
  }

  .panel {
    padding: 16px;
  }

  .dialog-actions,
  .dialog-actions > div {
    align-items: stretch;
    flex-direction: column;
  }

  .schedule-row {
    grid-template-columns: 1fr 1fr 40px;
  }
}

.goals-layout {
  margin-top: 20px;
  padding: 16px 0;
  border-block: 1px solid var(--line);
}

.goals-layout .section-title {
  align-items: center;
}

.goal-editor button, #goalFields button {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
}

.goal-agenda, .milestone-rows, #goalFields, #initialGoalFields {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.next-goal, .goal-habit-context {
  margin-top: 8px;
  overflow-wrap: anywhere;
}

.goal-habit-context {
  margin-bottom: 12px;
}

.habit-goals {
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.habit-goals h4 {
  margin: 0 0 6px;
  font-size: 13px;
}

.habit-goals ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.goal-muted {
  color: var(--muted);
  font-size: 13px;
}

.goal-title-button, .goal-agenda-entry {
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  color: var(--forest);
  font-weight: 650;
  overflow-wrap: anywhere;
}

.goal-title-button:hover {
  text-decoration: underline;
}

.goal-calendar {
  display: grid;
  grid-template-columns: minmax(260px, 420px) minmax(0, 1fr);
  gap: 24px 44px;
  margin-top: 18px;
}

.goal-calendar h3, .goal-editor h3, #goalFields h3 {
  font-size: 15px;
}

.goal-calendar .section-title {
  flex-wrap: wrap;
}

.goal-month-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.goal-month-controls strong {
  min-width: 120px;
  text-align: center;
  font-size: 13px;
}

.goal-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 3px;
}

.goal-days .weekday {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.goal-days button {
  position: relative;
  min-width: 0;
  min-height: 36px;
  padding: 2px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.goal-days button:hover:not([aria-pressed="true"]) {
  border-color: var(--line);
}

.goal-days .has-event::after {
  position: absolute;
  content: "";
  width: 5px;
  height: 5px;
  bottom: 2px;
  left: calc(50% - 2px);
  background: var(--gold);
  border-radius: 50%;
}

.goal-days .has-habit::before {
  position: absolute;
  content: "";
  width: 5px;
  height: 5px;
  bottom: 2px;
  left: calc(50% - 2px);
  background: var(--forest);
  border-radius: 50%;
}

.goal-days .has-habit.has-event::before { left: calc(50% - 6px); }
.goal-days .has-habit.has-event::after { left: calc(50% + 2px); }
.goal-days .has-habit[aria-pressed="true"]::before { background: white; }

.goal-days .is-today {
  border-color: var(--forest);
}

.goal-days [aria-pressed="true"] {
  background: var(--forest);
  color: white;
}

.goal-agenda {
  align-content: start;
  max-height: 400px;
  overflow-y: auto;
}

.goal-agenda-entry {
  display: grid;
  gap: 2px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.agenda-habit strong { color: var(--ink); }
.agenda-habit .completion-button {
  justify-self: start;
  margin-inline-start: 0;
}

.goal-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.goal-check input {
  width: 17px;
  height: 17px;
  accent-color: var(--forest);
}

.goal-milestone-editor {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.goal-milestone-editor legend {
  font-size: 13px;
  color: var(--muted);
}

#initialGoalFields {
  padding-top: 10px;
}

@media (max-width: 670px) {
  .goal-calendar { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .goal-milestone-editor { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
