*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-assistant-bg: hsl(87, 63%, 95%);
  --color-assistant-fg: hsl(87, 63%, 15%);
  --color-bg: hsl(0, 0%, 100%);
  --color-bg-translucent: hsla(0, 0%, 100%, 0.8);
  --color-danger: hsl(6, 88%, 62%);
  --color-danger-alt: hsl(6, 88%, 50%);
  --color-fg: hsl(0, 0%, 19%);
  --color-fg-light: hsl(86, 4%, 35%);
  --color-grey-100: hsl(0, 0%, 95%);
  --color-grey-200: hsl(0, 0%, 85%);
  --color-link: hsl(221, 94%, 52%);
  --color-primary: hsl(87, 74%, 43%);
  --color-primary-alt: hsl(87, 77%, 37%);
  --color-primary-light: hsl(87, 74%, 56%);
  --color-tone-2: hsl(182, 80%, 34%);
  --color-tone-2-alt: hsl(182, 80%, 24%);
  --color-tone-3: hsl(126, 74%, 43%);
  --color-tone-3-alt: hsl(126, 74%, 33%);
  --color-user-bg: hsl(56, 93%, 94%);
  --color-user-fg: hsl(56, 93%, 15%);

  --color-brown-500: hsl(34, 41%, 97%);
  --color-brown-400: hsl(37, 94%, 94%);
  --color-brown-300: hsl(24, 42%, 87%);
  --color-brown-200: hsl(23, 87%, 81%);
  --color-brown-100: hsl(15, 31%, 26%);
  --color-blue-500: hsl(198, 99%, 72%);
  --color-blue-400: hsl(197, 78%, 63%);
  --color-blue-100: hsl(178, 38%, 87%);
  --color-green-500: hsl(79, 62%, 65%);
  --color-yellow-500: hsl(53, 95%, 74%);

  --font-bold: 900;
  --font-medium: 700;
  --font-normal: 500;
  --radius: 1rem;
  --size-2x: 1.5rem;
  --size-4x: 3rem;
  --size-base: 0.75rem;
  --size-half: 0.375rem;
  --size-quarter: 0.1875rem;
}

body {
  -webkit-overflow-scrolling: touch;
  background: var(--color-bg) url('assets/bg-dots.svg');
  color: var(--color-fg);
  font-family: 'Nunito', sans-serif;
  font-size: clamp(1.1rem, 2vw, 1.3rem);
  font-weight: 600;
  height: 100dvh;
  line-height: 1.5;
  overflow-y: auto;
  scroll-behavior: smooth;
  text-wrap: pretty;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

img,
svg {
  display: block;
  flex-shrink: 0;
  min-height: 100%;
}

input {
  border: 2px solid var(--color-grey-200);
  border-radius: var(--radius);
  flex: 1;
  font: inherit;
  padding: var(--size-half) var(--size-base);
  transition: border-color 0.15s ease-out;
  width: 100%;
}

input:focus {
  border-color: var(--color-fg);
  outline: transparent;
}

a {
  color: var(--color-link);
}

.button-wrapper {
  display: inline-block;
  position: relative;
  transform: rotateX(24deg);
}

button,
.button {
  --shadow-color: var(--color-grey-200);
  -webkit-tap-highlight-color: transparent;
  align-items: center;
  all: inherit;
  background: var(--color-grey-100);
  border-radius: var(--radius);
  box-shadow: 0 5px 0 0 var(--shadow-color);
  color: var(--color-fg);
  corner-shape: superellipse(1.333);
  cursor: pointer;
  display: flex;
  flex-shrink: 0;
  font-weight: var(--font-medium);
  justify-content: center;
  line-height: 1;
  max-width: fit-content;
  padding: calc(var(--size-base) - 2px) var(--size-base);
  transform: scale(1) translate3d(0, -3px, 0);
  transform-origin: center center;
  transition: all 0.15s ease-out;
}

.button-primary {
  --shadow-color: var(--color-primary-alt);
  background: var(--color-primary);
  color: white;
}

.button-secondary {
  --shadow-color: var(--color-tone-2-alt);
  background: var(--color-tone-2);
  color: white;
}

.button-tertiary {
  --shadow-color: var(--color-tone-3-alt);
  background: var(--color-tone-3);
  color: white;
}

.button-ghost {
  --shadow-color: transparent;
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--color-fg);
}

.button-outline {
  background: transparent;
  border: 2px solid var(--color-fg);
  box-shadow: none;
}

.button-destructive {
  --shadow-color: var(--color-danger-alt);
  background: transparent;
  background: var(--color-danger);
}

.button-square {
  aspect-ratio: 1 / 1;
  padding: var(--size-base);
}

.button-round {
  border-radius: 50%;
}

.button-large {
  font-size: 170%;
  height: 4rem;
}

.button-small {
  font-size: 100%;
  height: 2rem;
  padding: 0;
}

button svg,
.button svg {
  height: 1.15em;
  width: 1.15em;
}

button:not(:disabled):hover,
button:not(:disabled):focus {
  transform: scale(1.03) translate3d(0, -2px, 0);
}

button:not(:disabled):active,
button.pressed {
  box-shadow: 0 2px 0 0 var(--shadow-color);
  transform: scale(0.98) translate3d(0, 3px, 0);
}

button:disabled,
.button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.full-width {
  min-width: 100%;
}

/* Inline and Stack layout */
[class^='inline'],
[class*=' inline'],
[class^='stack'],
[class*=' stack'] {
  --gap: var(--size-base);
  display: flex;
  gap: var(--gap);
}

ul[class] {
  list-style: none;
  margin: 0;
  padding: 0;
}

[class^='inline'],
[class*=' inline'] {
  align-items: center;
  justify-content: flex-start;
}

[class^='stack'],
[class*=' stack'] {
  flex-direction: column;
}

[class^='inline'] > [class^='stack'] {
  flex: 1;
}

.inline-zero,
.stack-zero {
  display: inline-flex;
  gap: 0;
}

.inline-quarter,
.stack-quarter {
  --gap: var(--size-quarter);
}

.inline-half,
.stack-half {
  --gap: var(--size-half);
}

.inline-2x,
.stack-2x {
  --gap: var(--size-2x);
}

.inline-4x,
.stack-4x {
  --gap: var(--size-4x);
}

.inline-between {
  justify-content: space-between;
}

.inline-wrap {
  flex-wrap: wrap;
}

.hidden,
[hidden] {
  display: none !important;
}

h1,
h2,
h3 {
  font-weight: var(--font-bold);
  line-height: 1.2;
}

#app {
  margin: 0 auto;
  max-width: 50ch;
  min-height: 100dvh;
  padding-bottom: 5rem;
}

#app > header {
  padding: var(--size-half) var(--size-base);
  position: sticky;
  top: 0;
  z-index: 80;
}

#app > header .button-ghost {
  backdrop-filter: blur(10px);
  background: var(--color-bg-translucent);
}

#app > footer {
  backdrop-filter: blur(10px);
  background: var(--color-bg-translucent);
  bottom: 0;
  left: 0;
  position: fixed;
  right: 0;
  z-index: 80;
}

#app > footer > div {
  margin: 0 auto;
  max-width: 50ch;
  padding: var(--size-half) var(--size-base);
}

#app > header h1 {
  background: var(--color-bg);
  border-radius: var(--radius);
  color: var(--color-primary);
  corner-shape: superellipse(1.333);
  font-size: 120%;
  margin-left: -0.25rem;
  padding: var(--size-half) var(--size-base);
  transform: rotate(-2deg);
  transform-origin: center center;
}

#sidebar-overlay {
  background: rgba(0, 0, 0, 0.2);
  inset: 0;
  position: fixed;
  z-index: 90;
}

.sidebar {
  background: var(--color-bg);
  bottom: 0;
  max-width: 80vw;
  position: fixed;
  right: 0;
  top: 0;
  transform: translateX(100%);
  transition: transform 0.15s ease-out;
  width: 17rem;
  z-index: 100;
}

.sidebar.open {
  transform: translateX(0%);
}

.sidebar > header {
  padding: var(--size-half) var(--size-base);
}

.sidebar > header h2 {
  font-size: inherit;
}

.sidebar nav {
  flex: 1;
}

.sidebar ul {
  -webkit-overflow-scrolling: touch;
  overflow-y: auto;
  width: 100%;
}

.sidebar ul li {
  align-items: center;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  gap: 0.25rem;
  overflow: hidden;
  padding: 0;
}

#session-list .session-info {
  cursor: pointer;
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
}

.session-delete {
  color: var(--color-fg-light);
  flex-shrink: 0;
  opacity: 0;
  padding: 0.5rem;
  transition:
    opacity 0.15s,
    color 0.15s;
}

#session-list li:hover .session-delete,
#session-list li:focus .session-delete {
  opacity: 1;
}

#session-list .session-preview {
  color: var(--color-fg);
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#session-list .session-date {
  color: var(--color-fg-light);
  font-size: 0.875rem;
}

.sidebar footer {
  align-items: center;
  border-top: 1px solid #eee;
  display: flex;
  flex-shrink: 0;
  gap: 0.25rem;
  padding: 0.75rem 1rem;
}

#session-list li:hover {
  background: var(--color-bg);
}

#session-list li.active {
  background: var(--color-assistant-bg);
  color: var(--color-assistant-fg);
}

#chat {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem;
}

.message {
  animation: fadeIn 0.2s ease;
  display: flex;
  max-width: 90%;
}

.message.user {
  align-self: flex-end;
  position: relative;
}

.message.user .me {
  background: hsl(56 90% 85% / 1);
  border-radius: 6px;
  font-size: 90%;
  left: -26px;
  line-height: 1;
  padding: 6px;
  position: absolute;
  top: -3px;
  transform: rotate(-10deg);
}

.message.assistant {
  align-items: center;
}

.bubble {
  border-radius: var(--radius);
  font-size: inherit;
  line-height: 1.5;
  padding: 1rem;
  white-space: pre-wrap;
}

.message.user .bubble {
  background: var(--color-user-bg);
  border-bottom-right-radius: 0.25rem;
  color: var(--color-user-fg);
}

.message.assistant .bubble {
  background: var(--color-assistant-bg);
  border-bottom-left-radius: 0.25rem;
  color: var(--color-assistant-fg);
}

.bubble-image-wrapper {
  display: block;
  line-height: 0;
  margin: -1rem -1rem 0.75rem -1rem;
  text-decoration: none;
}

.bubble-image {
  border-radius: var(--radius) var(--radius) 0 0;
  margin: 0 auto;
  max-width: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.bubble-image.loaded {
  opacity: 1;
}

.message.assistant .bubble-image {
  border-bottom-left-radius: 0;
}

.replay {
  bottom: -0.5rem;
  display: inline-flex;
  margin-top: -1rem;
  position: relative;
}

.replay.playing {
  --shadow-color: var(--color-danger-alt);
  background: var(--color-danger);
}

.hl-number {
  color: var(--color-link);
  font-weight: var(--font-normal);
}

.hl-big {
  font-size: 1.2em;
  font-weight: var(--font-bold);
  letter-spacing: 0.01em;
}

.hl-small {
  font-size: 0.78em;
}

.hl-loud {
  font-style: italic;
  font-weight: var(--font-bold);
}

.hl-wow {
  color: var(--color-link);
  font-weight: var(--font-bold);
}

.chat-divider {
  align-items: center;
  color: var(--color-fg-light);
  display: flex;
  font-size: 0.875rem;
  gap: 1rem;
  padding: 1rem 0;
  text-align: center;
}

.chat-divider::before,
.chat-divider::after {
  background: #ddd;
  content: '';
  flex: 1;
  height: 1px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(0.25rem);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Quick actions */

#quick-actions {
  margin-top: auto;
}

.quick-btn {
  --shadow-color: var(--color-primary-alt);
  background-color: var(--color-primary);
  color: white;
  min-width: 7ch;
}

.quick-btn:nth-child(2n) {
  --shadow-color: var(--color-tone-2-alt);
  background-color: var(--color-tone-2);
}

.quick-btn:nth-child(3n) {
  --shadow-color: var(--color-tone-3-alt);
  background-color: var(--color-tone-3);
}

/* Topic picker (onboarding multi-select) */

.topic-picker {
  gap: 0.4rem;
}

button.topic-btn {
  --shadow-color: var(--color-primary-alt) !important;
  background-color: transparent !important;
  border: 2px solid var(--color-primary);
  color: var(--color-primary);
}

.topic-btn:hover,
.topic-btn:active {
  background-color: var(--color-bg);
  color: var(--color-primary);
}

.topic-btn.selected {
  background-color: var(--color-primary) !important;
  border-color: var(--color-primary);
  color: white;
}

.topic-btn.selected:hover,
.topic-btn.selected:active {
  background-color: var(--color-primary-alt);
  color: white;
}

.done-btn {
  --shadow-color: var(--color-tone-2-alt);
  background-color: var(--color-tone-2);
  border: 2px solid var(--color-tone-2);
  color: white;
}

.mic-wrapper {
  position: relative;
}

#mic-ring {
  border: 3px solid transparent;
  border-radius: 50%;
  corner-shape: superellipse(1.333);
  height: 4.5rem;
  left: 50%;
  pointer-events: none;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  transition:
    width 0.1s,
    height 0.1s,
    border-color 0.1s;
  width: 4.5rem;
}

#mic-ring.active {
  border-color: var(--color-danger);
}

#mic-btn svg {
  transform: rotate(-5deg);
}

#mic-btn.recording {
  animation: pulse 1.5s ease-in-out infinite;
  background: var(--color-danger);
}

#mic-label {
  color: var(--color-fg-light);
  display: none;
  font-size: 12px;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4);
  }

  50% {
    transform: scale(1.05);
    box-shadow: 0 0 0 12px rgba(231, 76, 60, 0);
  }
}

#status {
  color: var(--color-fg-light);
  font-size: 14px;
  padding: 8px;
  text-align: center;
}

#auth-gate {
  align-items: center;
  display: flex;
  height: 100dvh;
  justify-content: center;
  padding: 1rem;
}

#auth-box {
  background: var(--color-bg);
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 20rem;
  padding: 2rem;
  text-align: center;
  width: 100%;
}

#auth-box h2 {
  color: var(--color-primary);
  font-size: 1.3rem;
}

#auth-error {
  color: var(--color-danger);
  font-size: 0.875rem;
}

.cooldown-timer {
  color: var(--color-tone-2);
}

.cooldown-countdown {
  font-variant-numeric: tabular-nums;
  font-weight: var(--font-bold);
}

.thinking .bubble::after {
  animation: dot 1.4s infinite ease-in-out both;
  background: var(--color-primary);
  border-radius: 50%;
  content: '';
  display: inline-block;
  height: 6px;
  margin-left: 4px;
  width: 6px;
}

@keyframes dot {
  0%,
  80%,
  100% {
    transform: scale(0);
  }

  40% {
    transform: scale(1);
  }
}
