:root {
  --portfolio-accent: #E5322D;
  --portfolio-scroll-thumb: #aaa;
  --portfolio-motion: 380ms cubic-bezier(0.4, 0, 0.2, 1);
}

:root:has(body.dark-mode) {
  --portfolio-scroll-thumb: #666;
}

html,
.portfolio-chat-log {
  scrollbar-width: thin;
  scrollbar-color: var(--portfolio-scroll-thumb) transparent;
}

.portfolio-chat-log {
  scrollbar-gutter: stable;
}

@supports selector(::-webkit-scrollbar) {
  html,
  .portfolio-chat-log {
    scrollbar-width: auto;
    scrollbar-color: auto;
  }

  :is(html, .portfolio-chat-log)::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }

  :is(html, .portfolio-chat-log)::-webkit-scrollbar-thumb {
    border: 2px solid transparent;
    border-radius: 8px;
    background: var(--portfolio-scroll-thumb) padding-box;
  }

  :is(html, .portfolio-chat-log)::-webkit-scrollbar-thumb:hover {
    background-color: var(--portfolio-accent);
  }
}

.portfolio-chat-launcher,
.portfolio-chat-panel {
  --chat-bg: #fff;
  --chat-border: #d0d0d0;
  --chat-muted: #646464;
  color: var(--text-color);
  background: var(--chat-bg);
  font-family: inherit;
}

body.dark-mode :is(.portfolio-chat-panel, .portfolio-chat-launcher) {
  --chat-bg: #141414;
  --chat-border: #3e3e3e;
  --chat-muted: #a7a7a7;
}

.portfolio-chat-launcher {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 5;
  padding: 8px 12px;
  border: 1px solid var(--chat-border);
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}

.portfolio-chat-launcher:hover {
  border-color: var(--portfolio-accent);
}

.portfolio-chat-panel {
  position: sticky;
  top: 24px;
  z-index: 4;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: min(560px, calc(100vh - 48px));
  height: min(560px, calc(100dvh - 48px));
  margin-top: 40px;
  box-sizing: border-box;
  border: 1px solid var(--chat-border);
  border-radius: 4px;
  box-shadow: 0 3px 14px #00000012;
  font-size: 13px;
  line-height: 1.6;
}

.portfolio-chat-panel[hidden],
.portfolio-chat-launcher[hidden],
.portfolio-chat-status[hidden],
.portfolio-chat-clear[hidden] {
  display: none;
}

body.portfolio-chat-open {
  display: grid;
  grid-template-columns: minmax(0, 650px) minmax(300px, 390px);
  gap: 32px;
  align-items: start;
  max-width: 1072px;
}

body.portfolio-chat-open #maincontent {
  min-width: 0;
}

html:is(.portfolio-chat-opening, .portfolio-chat-closing) #maincontent {
  view-transition-name: portfolio-content;
}

html:is(.portfolio-chat-opening, .portfolio-chat-closing) .portfolio-chat-panel {
  view-transition-name: portfolio-chat-panel;
}

html:is(.portfolio-chat-opening, .portfolio-chat-closing) .portfolio-chat-launcher {
  view-transition-name: portfolio-chat-launcher;
}

html.portfolio-chat-opening::view-transition-group(portfolio-content),
html.portfolio-chat-opening::view-transition-group(portfolio-chat-panel),
html.portfolio-chat-opening::view-transition-group(portfolio-chat-launcher) {
  animation-duration: 380ms;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* On close: collapse the chat box FIRST, then glide the main resume content back to center. */
html.portfolio-chat-closing::view-transition-group(portfolio-chat-panel) {
  z-index: 2;
  animation-duration: 240ms;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

html.portfolio-chat-closing::view-transition-group(portfolio-content) {
  animation-delay: 210ms;
  animation-duration: 320ms;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
  animation-fill-mode: both;
}

html.portfolio-chat-closing::view-transition-group(portfolio-chat-launcher) {
  animation-delay: 220ms;
  animation-duration: 240ms;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  animation-fill-mode: both;
}

html:is(.portfolio-chat-opening, .portfolio-chat-closing)::view-transition-group(portfolio-chat-panel) {
  z-index: 2;
}

html:is(.portfolio-theme-dark, .portfolio-theme-light)::view-transition-old(root),
html:is(.portfolio-theme-dark, .portfolio-theme-light)::view-transition-new(root) {
  --portfolio-circle-origin: var(--portfolio-theme-origin, 50% 50%);
  animation: none;
  mix-blend-mode: normal;
}

html:is(.portfolio-theme-dark, .portfolio-theme-light) :is(a, .theme-toggle) {
  transition: none !important;
}

html.portfolio-theme-dark::view-transition-old(root) {
  z-index: 1;
  animation: portfolio-circle-reveal 520ms cubic-bezier(0.4, 0, 0.2, 1) reverse both;
}

html.portfolio-theme-light::view-transition-new(root) {
  z-index: 1;
  animation: portfolio-circle-reveal 520ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

html.portfolio-chat-closing::view-transition-old(portfolio-chat-panel) {
  z-index: 2;
  animation: portfolio-circle-reveal 240ms cubic-bezier(0.4, 0, 0.2, 1) reverse both;
}

html.portfolio-chat-opening::view-transition-new(portfolio-chat-panel) {
  z-index: 2;
  animation: portfolio-circle-reveal 380ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

@keyframes portfolio-circle-reveal {
  from { clip-path: circle(0% at var(--portfolio-circle-origin, 100% 100%)); }
  to { clip-path: circle(150% at var(--portfolio-circle-origin, 100% 100%)); }
}

.portfolio-chat-header,
.portfolio-chat-form {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 13px;
}

.portfolio-chat-header {
  justify-content: space-between;
  border-bottom: 1px solid var(--chat-border);
}

.portfolio-chat-header h2 {
  margin: 0;
  font-size: inherit;
  font-weight: 700;
}

.portfolio-chat-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.portfolio-chat-mark {
  color: var(--portfolio-accent);
  font-weight: 700;
}

.portfolio-chat-panel button {
  padding: 3px 5px;
  border: 0;
  color: inherit;
  background: transparent;
  font: inherit;
  cursor: pointer;
}

.portfolio-chat-clear {
  min-block-size: 26px;
  padding: 2px 6px !important;
  font-size: 11px !important;
  color: var(--chat-muted) !important;
  border-radius: 3px;
  transition: color 0.15s ease;
}

.portfolio-chat-clear:hover {
  color: var(--portfolio-accent) !important;
}

.portfolio-chat-close {
  min-width: 28px;
  min-height: 28px;
}

.portfolio-chat-panel button:disabled {
  opacity: 0.55;
  cursor: default;
}

.portfolio-chat-panel :is(button, a, input, textarea):focus-visible,
.portfolio-chat-launcher:focus-visible {
  outline: 1px solid var(--portfolio-accent);
  outline-offset: 2px;
}

.portfolio-chat-log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  min-height: 0;
  padding: 14px 15px;
  overflow-wrap: anywhere;
}

.portfolio-chat-log p {
  margin: 0 0 10px;
}

.portfolio-chat-intro,
.portfolio-chat-status,
.portfolio-chat-tool-status {
  color: var(--chat-muted);
}

.portfolio-chat-tool-status {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.portfolio-chat-tool-status::before {
  content: "•";
  content: "•" / "";
  color: var(--portfolio-accent);
  @media (prefers-reduced-motion: no-preference) {
    animation: portfolio-chat-blink 1s steps(2, start) infinite;
  }
}

.portfolio-chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 2px 0 12px;
}

.portfolio-chat-inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 10px;
}

.portfolio-chat-panel .portfolio-chat-chip {
  min-block-size: 28px;
  padding: 4px 9px;
  border: 1px solid var(--chat-border);
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.25;
  color: inherit;
  background: transparent;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.portfolio-chat-panel .portfolio-chat-chip:hover {
  border-color: var(--portfolio-accent);
  color: var(--portfolio-accent);
}

.portfolio-chat-answer {
  margin-bottom: 4px;
}

.portfolio-chat-streaming::after {
  content: "▍";
  content: "▍" / "";
  margin-left: 2px;
  color: var(--portfolio-accent);
  @media (prefers-reduced-motion: no-preference) {
    animation: portfolio-chat-blink 0.9s steps(2, start) infinite;
  }
}

@keyframes portfolio-chat-blink {
  to { visibility: hidden; }
}

@media (pointer: coarse) {
  .portfolio-chat-panel .portfolio-chat-chip {
    min-block-size: 44px;
    padding: 8px 12px;
  }

  .portfolio-chat-panel .a2ui-btn,
  .portfolio-chat-panel .a2ui-tab {
    min-block-size: 40px;
    padding: 6px 11px;
  }
}

.portfolio-chat-question {
  font-weight: 600;
  margin-top: 16px !important;
}

.portfolio-chat-question ~ .portfolio-chat-question {
  padding-top: 14px;
  border-top: 1px solid color-mix(in srgb, var(--chat-border) 55%, transparent);
}

.portfolio-chat-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 2px;
  font-size: 12px;
}

.portfolio-chat-sources a {
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.portfolio-chat-a2ui {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.portfolio-chat-a2ui-surface {
  min-width: 0;
}

.a2ui-card {
  border: 1px solid var(--chat-border);
  border-radius: 4px;
  padding: 11px 12px;
  background: var(--chat-bg);
}

.a2ui-column {
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-width: 0;
}

.a2ui-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.a2ui-row[data-justify="end"] {
  justify-content: flex-end;
}

.a2ui-row[data-justify="spaceBetween"] {
  justify-content: space-between;
}

.a2ui-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.a2ui-list[data-direction="horizontal"] {
  flex-direction: row;
  overflow-x: auto;
}

.a2ui-divider {
  border: 0;
  border-top: 1px solid color-mix(in srgb, var(--chat-border) 70%, transparent);
  margin: 2px 0;
}

.portfolio-chat-log .a2ui-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
}

.portfolio-chat-log .a2ui-text-h4,
.portfolio-chat-log .a2ui-text-h5 {
  font-size: 13px;
  font-weight: 700;
}

.portfolio-chat-log .a2ui-text-caption {
  font-size: 12px;
  color: var(--chat-muted);
}

.portfolio-chat-panel .a2ui-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-block-size: 29px;
  padding: 4px 10px;
  border: 1px solid var(--chat-border);
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 12px;
  line-height: 1.25;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.portfolio-chat-panel .a2ui-btn .a2ui-text {
  font-size: inherit;
  line-height: inherit;
  margin: 0;
}

.portfolio-chat-panel .a2ui-btn:hover {
  border-color: var(--portfolio-accent);
  color: var(--portfolio-accent);
}

.portfolio-chat-panel .a2ui-btn-primary {
  border-color: var(--portfolio-accent);
  color: var(--portfolio-accent);
  font-weight: 600;
}

.portfolio-chat-panel .a2ui-btn-primary:hover {
  background: var(--portfolio-accent);
  color: #fff;
}

.portfolio-chat-panel .a2ui-btn-borderless {
  min-block-size: auto;
  padding: 3px 4px;
  border-color: transparent;
  background: transparent;
  color: var(--chat-muted);
}

.portfolio-chat-panel .a2ui-btn-borderless:hover {
  border-color: transparent;
  color: var(--portfolio-accent);
}

.portfolio-chat-panel .a2ui-btn[aria-pressed="true"] {
  border-color: var(--portfolio-accent);
  color: var(--portfolio-accent);
}

.a2ui-tabs {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.a2ui-tablist {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 1px solid var(--chat-border);
  padding-bottom: 5px;
}

.portfolio-chat-panel .a2ui-tab {
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--chat-muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.portfolio-chat-panel .a2ui-tab[aria-selected="true"] {
  border-color: var(--chat-border);
  border-bottom-color: var(--portfolio-accent);
  color: inherit;
  font-weight: 600;
}

.a2ui-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.a2ui-field-label {
  font-size: 12px;
  color: var(--chat-muted);
}

.a2ui-input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid var(--chat-border);
  border-radius: 3px;
  background: var(--chat-bg);
  color: inherit;
  font: inherit;
  font-size: 13px;
  line-height: 1.45;
}

.a2ui-textarea {
  resize: vertical;
  min-height: 62px;
}

.a2ui-input:focus {
  outline: none;
  border-color: var(--portfolio-accent);
}

.a2ui-input[aria-invalid="true"] {
  border-color: var(--portfolio-accent);
}

.portfolio-chat-log .a2ui-field-error {
  margin: 0;
  font-size: 12px;
  color: var(--portfolio-accent);
}

.a2ui-field-error[hidden] {
  display: none;
}

.a2ui-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  cursor: pointer;
}

.a2ui-choice-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.portfolio-chat-status {
  margin: 0;
  padding: 5px 13px;
  font-size: 12px;
}

.portfolio-chat-form {
  border-top: 1px solid var(--chat-border);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Clean high-contrast focus indicator on the form bar instead of a double box inside the input */
.portfolio-chat-form:focus-within {
  border-top-color: var(--portfolio-accent);
  box-shadow: inset 0 1px 0 var(--portfolio-accent);
}

.portfolio-chat-form input {
  min-width: 0;
  flex: 1;
  padding: 2px 0;
  border: 0;
  border-radius: 0;
  color: inherit;
  background: transparent;
  font: inherit;
}

.portfolio-chat-form input:focus {
  outline: none;
}

@media (forced-colors: active) {
  .portfolio-chat-form input:focus-visible {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }
}

.portfolio-chat-form input::placeholder {
  color: var(--chat-muted);
}

@media (max-width: 820px), (max-height: 520px) and (pointer: coarse) {
  body.portfolio-chat-open {
    display: block;
    max-width: 650px;
    margin-top: 0;
  }

  body.portfolio-chat-open #maincontent {
    margin-top: 0;
    padding-top: 0;
  }

  body.portfolio-chat-open .header {
    position: sticky;
    top: var(--portfolio-visible-top, 0px);
    z-index: 2;
    flex-direction: row;
    align-items: center;
    min-height: 52px;
    margin-bottom: 14px;
    background: #fff;
  }

  body.dark-mode.portfolio-chat-open .header {
    background: #0f0f0f;
  }

  body.portfolio-chat-open .top-links {
    margin-top: 0;
  }

  body.portfolio-chat-open .top-links :is(a, .top-link-btn) {
    display: none;
  }

  body.portfolio-chat-open:has(.portfolio-chat-keyboard-open) #maincontent > :not(.header) {
    visibility: hidden;
  }

  body.portfolio-chat-open .header .theme-toggle {
    margin: 0;
  }

  .portfolio-chat-panel {
    --portfolio-phone-height: var(--portfolio-visible-height, 100vh);
    --portfolio-header-space: min(68px, calc(var(--portfolio-phone-height) * 0.22));
    position: fixed;
    inset: auto 0 var(--portfolio-keyboard-inset, 0px);
    z-index: 6;
    margin: 0;
    height: min(520px, calc(var(--portfolio-phone-height) * 0.55));
    max-height: calc(var(--portfolio-phone-height) - var(--portfolio-header-space));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    border-width: 1px 0 0;
    border-radius: 0;
    box-shadow: 0 -3px 14px #00000012;
  }

  .portfolio-chat-panel.portfolio-chat-keyboard-open {
    height: calc(var(--portfolio-phone-height) - var(--portfolio-header-space));
    padding-bottom: 0;
  }

  .portfolio-chat-header,
  .portfolio-chat-form {
    flex-shrink: 0;
    padding-block: 4px;
  }

  .portfolio-chat-close,
  .portfolio-chat-clear,
  .portfolio-chat-form button {
    min-width: 44px;
    min-height: 44px;
  }

  .portfolio-chat-form input,
  .a2ui-input {
    font-size: 16px;
  }
}
