:root {
  color-scheme: light;
  --bg: #eef2ef;
  --surface: #fbfcfb;
  --surface-2: #f2f5f2;
  --text: #101816;
  --muted: #68726e;
  --line: #dfe6e1;
  --primary: #18211f;
  --primary-soft: #e8eeeb;
  --accent: #0f766e;
  --accent-soft: #e7f7f4;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(16, 24, 40, 0.12);
  --shadow-soft: 0 16px 38px rgba(17, 24, 19, 0.09);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}

html,
body,
#app {
  height: 100%;
}

body {
  overflow: hidden;
}

#app {
  min-height: 100dvh;
  display: grid;
}

button,
input,
textarea {
  font: inherit;
}

button,
input,
textarea,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease, transform 0.16s ease, opacity 0.16s ease;
  user-select: none;
  -webkit-user-select: none;
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

a {
  color: #155e75;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.boot,
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.boot {
  gap: 12px;
  text-align: center;
}

.boot-mark,
.login-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.boot-text {
  color: var(--muted);
}

.login-panel {
  width: min(360px, 100%);
  display: grid;
  gap: 16px;
  justify-items: center;
  text-align: center;
}

.login-panel h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.login-panel form,
.login-panel label {
  display: grid;
  gap: 10px;
}

.login-panel form {
  gap: 16px;
}

.login-panel span {
  color: var(--muted);
  font-size: 14px;
}

.member-grid {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.member-btn {
  min-height: 56px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 18px;
  font-weight: 760;
  border: 1px solid transparent;
}

.member-btn.selected {
  background: #ecfeff;
  border-color: #0891b2;
  color: #164e63;
}

.member-btn:active {
  transform: translateY(1px);
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
  font-size: 16px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
  -webkit-appearance: none;
  appearance: none;
}

input {
  height: 46px;
  padding: 0 13px;
}

textarea {
  min-height: 44px;
  max-height: 160px;
  resize: none;
  padding: 11px 52px 11px 76px;
  line-height: 1.55;
}

input:focus,
textarea:focus {
  border-color: #9ca3af;
  box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.08);
}

.primary-btn {
  height: 44px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 680;
}

.chat-shell {
  width: min(840px, calc(100vw - 56px));
  height: min(760px, calc(100vh - 56px));
  min-height: 520px;
  display: grid;
  grid-template-rows: 52px minmax(0, 1fr) auto;
  align-self: center;
  justify-self: center;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(223, 230, 225, 0.95);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(252, 253, 252, 0.98), rgba(246, 249, 247, 0.98));
  box-shadow: var(--shadow-soft);
}

.chat-shell.is-empty {
  grid-template-rows: 52px minmax(0, 1fr);
}

.chat-top {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid rgba(223, 230, 225, 0.88);
  background: rgba(251, 252, 251, 0.86);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  z-index: 5;
  user-select: none;
  -webkit-user-select: none;
}

.app-name {
  font-size: 15px;
  font-weight: 760;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.app-name::before {
  content: "AI";
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

.member-name {
  min-width: 48px;
  min-height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 15px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.album-link,
.portal-link {
  min-height: 36px;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #0f766e;
  background: rgba(231, 247, 244, 0.9);
  font-size: 14px;
  font-weight: 720;
  text-decoration: none;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.album-link {
  padding: 0 12px;
}

.portal-link {
  width: 100%;
  margin-top: 4px;
}

.album-link:hover,
.portal-link:hover {
  background: #d6f3ee;
  border-color: rgba(15, 118, 110, 0.32);
  transform: translateY(-1px);
}

.quiet-btn {
  min-width: 48px;
  height: 36px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.quiet-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.messages {
  width: min(720px, 100%);
  min-height: 0;
  justify-self: center;
  overflow: auto;
  padding: 24px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.empty-chat {
  min-height: 100%;
  display: grid;
  place-items: center;
  color: var(--text);
}

.empty-title {
  max-width: min(520px, 92%);
  text-align: center;
  font-size: clamp(22px, 4vw, 30px);
  font-weight: 760;
}

.message {
  display: flex;
}

.message.user {
  justify-content: flex-end;
}

.message.assistant {
  justify-content: flex-start;
}

.message-body {
  max-width: min(620px, 88%);
  border-radius: 8px;
  padding: 12px 14px;
  line-height: 1.66;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}

.message.user .message-body {
  background: var(--primary);
  color: #fff;
}

.message.assistant .message-body {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(223, 230, 225, 0.96);
  color: var(--text);
}

.composer {
  width: min(720px, calc(100% - 36px));
  justify-self: center;
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 8px;
  padding: 8px;
  margin-bottom: max(10px, env(safe-area-inset-bottom));
  position: relative;
  border: 1px solid rgba(223, 230, 225, 0.96);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 30px rgba(17, 24, 19, 0.1);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.chat-shell.is-empty .messages {
  width: min(720px, calc(100% - 36px));
  padding: 0 0 132px;
  align-self: center;
  overflow: hidden;
}

.chat-shell.is-empty .empty-chat {
  min-height: 0;
}

.chat-shell.is-empty .empty-title {
  text-align: center;
}

.chat-shell.is-empty .composer {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(660px, calc(100% - 56px));
  margin-bottom: 0;
  transform: translate(-50%, 36px);
}

.composer textarea {
  display: block;
  grid-column: 2;
  min-height: 42px;
  padding: 9px 0;
  border: 0;
  box-shadow: none;
  background: transparent;
}

.composer textarea:focus {
  box-shadow: none;
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  touch-action: manipulation;
}

.voice-btn {
  width: 70px;
  height: 42px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--primary-soft);
  color: #34413d;
  font-size: 15px;
  line-height: 1;
  white-space: nowrap;
  z-index: 2;
  touch-action: manipulation;
}

.voice-mode-label {
  font-size: 12px;
  font-weight: 720;
}

.voice-btn:hover:not(:disabled) {
  background: #dfe8e3;
  transform: translateY(-1px);
}

.voice-btn.is-active {
  background: var(--primary);
  color: #fff;
}

.voice-btn.is-active:hover:not(:disabled) {
  background: var(--primary);
}

.voice-btn.is-recording {
  background: #b42318;
  color: #fff;
}

.voice-btn.is-recording:hover:not(:disabled) {
  background: #b42318;
}

.voice-btn.is-transcribing {
  background: var(--accent);
  color: #fff;
}

.voice-btn.is-transcribing:hover:not(:disabled) {
  background: var(--accent);
}

.hold-voice-btn {
  display: none;
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  box-shadow: none;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.composer.is-voice-mode textarea,
.composer.is-voice-mode .send-btn {
  display: none;
}

.composer.is-voice-mode .hold-voice-btn {
  grid-column: 2 / 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 8px;
}

.hold-label {
  font-size: 16px;
  font-weight: 760;
}

.hold-hint {
  font-size: 12px;
  color: var(--muted);
}

.hold-voice-btn.is-recording {
  background: #b42318;
  border-color: #b42318;
  color: #fff;
  transform: translateY(1px);
}

.hold-voice-btn.is-recording .hold-hint,
.hold-voice-btn.is-transcribing .hold-hint {
  color: rgba(255, 255, 255, 0.82);
}

.hold-voice-btn.is-transcribing {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.send-btn span {
  transform: translateY(-1px);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  background: #111827;
  color: #fff;
  border-radius: 8px;
  padding: 11px 14px;
  box-shadow: var(--shadow);
  z-index: 20;
}

@media (prefers-reduced-motion: no-preference) {
  .message {
    animation: message-in 0.18s ease-out both;
  }

  .toast {
    animation: toast-in 0.18s ease-out both;
  }
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@media (max-width: 640px) {
  #app {
    display: block;
    min-height: 100dvh;
  }

  .chat-shell {
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    grid-template-rows: calc(54px + env(safe-area-inset-top)) minmax(0, 1fr) auto;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: #f6f8f6;
  }

  .chat-top {
    height: auto;
    min-height: calc(54px + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }

  .app-name {
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .top-actions {
    gap: 6px;
    min-width: 0;
  }

  .album-link {
    min-width: 64px;
    padding: 0 9px;
    font-size: 13px;
  }

  .messages {
    width: 100%;
    padding: 18px 12px 14px;
    gap: 14px;
  }

  .message-body {
    max-width: 92%;
    padding: 11px 12px;
  }

  .composer {
    width: calc(100% - 16px);
    grid-template-columns: 72px minmax(0, 1fr) 42px;
    padding: 8px;
    margin-bottom: max(8px, calc(env(safe-area-inset-bottom) + 6px));
    box-shadow: 0 -2px 22px rgba(17, 24, 19, 0.1);
  }

  .chat-shell.is-empty {
    grid-template-rows: calc(54px + env(safe-area-inset-top)) minmax(0, 1fr);
  }

  .chat-shell.is-empty .messages {
    width: calc(100% - 24px);
    padding: 0 0 126px;
  }

  .chat-shell.is-empty .composer {
    top: 52%;
    width: calc(100% - 20px);
    transform: translate(-50%, 32px);
  }

  .voice-btn {
    width: 72px;
    font-size: 14px;
  }

  .quiet-btn,
  .member-name {
    min-width: 40px;
    font-size: 14px;
  }

  .hold-label {
    font-size: 15px;
  }

  .hold-hint {
    max-width: 100%;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .composer.is-voice-mode .hold-voice-btn {
    padding-left: 6px;
    padding-right: 6px;
  }
}
