:root {
  --content-width: 660px;
  --page-gutter: clamp(16px, 4vw, 26px);
  --header-height: 78px;
  --footer-height: 108px;
  --content-breathing-room: clamp(18px, 3vh, 32px);
  --visual-viewport-height: 100dvh;
}

html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  min-width: 280px;
  min-height: 100svh;
  height: 100dvh;
  overflow: hidden;
}

header {
  flex: 0 0 auto;
  min-height: var(--header-height);
  height: auto;
  padding-inline: var(--page-gutter);
}

main {
  flex: 1 1 auto;
  min-height: 0;
  overscroll-behavior-y: contain;
  scroll-padding-block-end: calc(var(--footer-height) + var(--content-breathing-room));
}

.wrap, footer { padding-inline: var(--page-gutter); }
.wrap, .composer, .hint { width: min(100%, var(--content-width)); }
.wrap {
  padding-block-end: calc(var(--footer-height) + var(--content-breathing-room));
}

.conversation-empty .wrap {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

footer { flex: 0 0 auto; }
textarea, select, button, input { max-width: 100%; }

.invocation {
  padding-block: clamp(46px, 7vh, 74px) clamp(26px, 4.5vh, 48px);
}

.rule { margin-top: clamp(28px, 4.5vh, 46px); }

.starters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  gap: 10px;
  margin: clamp(18px, 3vh, 34px) auto 8px;
}

.starters button {
  width: 100%;
  min-height: 48px;
  text-align: left;
  line-height: 1.45;
  border-radius: 16px;
}

@media (max-width: 1024px) {
  .pill, .selwrap select { min-height: 44px; height: 44px; }
  .pill.ico { width: 44px; min-width: 44px; padding: 0; }

  .invocation {
    padding-block: clamp(42px, 6vh, 58px) clamp(22px, 3.5vh, 34px);
  }

  .rule { margin-top: clamp(24px, 3.5vh, 34px); }
  .starters { margin-top: clamp(16px, 2.5vh, 24px); }
}

@media (max-width: 760px) {
  :root {
    --header-height: 0px;
    --content-breathing-room: clamp(16px, 2.5vh, 24px);
  }

  header {
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 8px;
    padding:
      max(8px, env(safe-area-inset-top))
      max(14px, env(safe-area-inset-right))
      8px
      max(14px, env(safe-area-inset-left));
  }

  .brand {
    flex: 1 1 auto;
    min-width: 120px;
    margin: 0;
    gap: 4px;
  }

  .mark, .mark svg { width: 48px; height: 48px; }
  .mark { margin: -3px -4px -3px -7px; flex: 0 0 48px; }

  .title { font-size: clamp(20px, 6vw, 24px); line-height: 1; }
  .title small { display: none; }

  .hgroup {
    flex: 1 0 100%;
    width: 100%;
    margin-left: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    min-width: 0;
  }

  .selwrap { margin-right: auto; min-width: 0; }
  .selwrap select {
    width: auto;
    max-width: 120px;
    min-height: 44px;
    padding-inline: 11px 28px;
    font-size: 12px;
    text-overflow: ellipsis;
  }
  .selwrap::after { right: 11px; }

  .pill, .pill.ico, #clear {
    min-width: 44px;
    min-height: 44px;
    height: 44px;
  }
  .pill { padding-inline: 11px; font-size: 12px; }
  .pill.ico { width: 44px; padding: 0; }
  #clear { justify-content: center; }

  .wrap {
    width: 100%;
    padding-inline: clamp(16px, 5vw, 26px);
  }

  .invocation { padding-block: clamp(30px, 5.5vh, 44px) clamp(18px, 3vh, 28px); }
  .invocation .deva { font-size: clamp(16px, 4.5vw, 19px); line-height: 1.9; }
  .invocation .tr { font-size: clamp(14px, 4vw, 15.5px); padding-inline: 4px; margin-top: 16px; }
  .invocation .ref { font-size: 9px; letter-spacing: 2px; margin-top: 16px; }
  .rule { margin-top: clamp(22px, 3.5vh, 30px); }

  .msg.user { max-width: 88%; }
  .msg.krishna .body { font-size: 17.5px; line-height: 1.75; }

  footer {
    width: 100%;
    padding:
      8px
      max(14px, env(safe-area-inset-right))
      max(12px, calc(env(safe-area-inset-bottom) + 8px))
      max(14px, env(safe-area-inset-left));
  }

  .composer { width: 100%; padding-left: 16px; }
  #input { min-width: 0; font-size: 16px; }
  .hint {
    padding-inline: 6px;
    font-size: 10px;
    line-height: 1.5;
    overflow-wrap: anywhere;
  }

  .card { padding: 24px 18px 20px; }
  .cardrow { flex-wrap: wrap; }
}

@media (max-width: 620px) {
  .starters { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .starters button { min-height: 46px; }
}

@media (max-width: 430px) {
  header { padding-inline: 10px; }
  .mark, .mark svg { width: 43px; height: 43px; }
  .mark { flex-basis: 43px; }
  .title { font-size: 20px; }
  .hgroup { gap: 2px; }
  .selwrap select { max-width: 108px; font-size: 11.5px; }
  .wrap { padding-inline: 14px; }
  .invocation { padding-top: clamp(24px, 4.5vh, 34px); }
  .starters button { font-size: 12.5px; }
  .hint { font-size: 9.75px; }
}

@media (max-width: 360px) {
  .title { font-size: 18px; }
  .mark, .mark svg { width: 40px; height: 40px; }
  .mark { flex-basis: 40px; }
  .selwrap select { max-width: 92px; font-size: 11px; }
  #clear { width: 44px; padding: 0; font-size: 0; }
  #clear::after { content: "+"; font-size: 20px; line-height: 1; }
  .wrap { padding-inline: 12px; }
  .invocation .deva { font-size: 15.5px; }
}

html[data-keyboard="open"] body {
  min-height: var(--visual-viewport-height);
  height: var(--visual-viewport-height);
}
html[data-keyboard="open"] .wrap {
  padding-block-end: calc(var(--footer-height) + 14px);
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
