:root {
  --green: #23845f;
  --green-dark: #17684a;
  --text: #1f292f;
  --muted: #6d797f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans",
    "Yu Gothic", "YuGothic", "Noto Sans JP", sans-serif;
  color: var(--text);
  background: #edf4ef;
}

button,
textarea {
  font: inherit;
}

.app {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
}


/* ==========================================
   BACKGROUND
========================================== */

.background {
  position: absolute;
  inset: 0;
  z-index: 0;

  background:
    url("assets/background/campus.webp")
    center center / cover no-repeat;

  filter:
    saturate(.56)
    contrast(.84)
    brightness(1.08);

  transition:
    filter .6s ease;
}

/* 初期状態でも背景は少し抑える */
.background::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(248, 251, 249, .40);
  transition: background .6s ease;
}

/* 会話が始まったらさらに背景化 */
.app.is-chatting .background {
  filter:
    saturate(.44)
    contrast(.80)
    brightness(1.12)
    blur(1.5px);
}

.app.is-chatting .background::after {
  background: rgba(248, 251, 249, .58);
}


/* ==========================================
   HEADER
========================================== */

.header {
  position: absolute;
  z-index: 30;
  top: 0;
  left: 0;
  right: 0;

  display: flex;
  align-items: center;
  justify-content: space-between;

  padding: 18px clamp(16px, 4vw, 54px);

  pointer-events: none;
}

.brand,
.header-actions {
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;

  padding: 6px 11px;

  border-radius: 14px;
  background: rgba(255,255,255,.90);

  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);

  box-shadow: 0 6px 22px rgba(30,50,40,.06);
}

.brand-logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.brand-text {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-name {
  font-size: clamp(15px, 1.4vw, 18px);
  font-weight: 750;
}

.brand-divider {
  width: 1px;
  height: 20px;
  background: rgba(20,30,35,.20);
}

.brand-service {
  font-size: clamp(13px, 1.2vw, 15px);
  font-weight: 700;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.header-button {
  display: flex;
  align-items: center;
  gap: 8px;

  padding: 11px 16px;

  border: 0;
  border-radius: 999px;

  background: rgba(255,255,255,.92);
  color: #344149;

  box-shadow: 0 6px 22px rgba(30,50,40,.07);

  font-size: 13px;
  font-weight: 600;

  cursor: pointer;
}

.header-button:hover {
  background: #fff;
}

.header-button:focus-visible {
  outline: 3px solid rgba(35, 132, 95, .35);
  outline-offset: 2px;
}


/* ==========================================
   PRIVACY / ATTRIBUTE DIALOG
========================================== */

.privacy-overlay[hidden] {
  display: none;
}

.privacy-overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(19, 32, 27, .58);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.privacy-dialog {
  width: min(680px, 100%);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  padding: clamp(22px, 4vw, 36px);
  border: 1px solid rgba(255, 255, 255, .8);
  border-radius: 24px;
  background: rgba(255, 255, 255, .97);
  box-shadow: 0 24px 80px rgba(11, 34, 25, .28);
}

.privacy-dialog h1 {
  margin: 0 0 14px;
  font-size: clamp(22px, 4vw, 30px);
}

.privacy-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.privacy-progress span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.privacy-progress b {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  background: #e5ece8;
  color: #64716b;
}

.privacy-progress i {
  flex: 1;
  height: 2px;
  background: #dce5e0;
}

.privacy-progress .is-current,
.privacy-progress .is-complete {
  color: var(--green-dark);
}

.privacy-progress .is-current b,
.privacy-progress .is-complete b {
  background: var(--green);
  color: #fff;
}

.privacy-step[hidden] {
  display: none;
}

.privacy-description {
  color: #3f4d53;
  font-size: 14px;
  line-height: 1.75;
}

.privacy-description p {
  margin: 0 0 10px;
}

.privacy-step-intro {
  margin: 0 0 10px;
  color: #3f4d53;
  font-size: 14px;
  line-height: 1.7;
}

.visitor-fieldset {
  margin-top: 0 !important;
}

.consent-scroll {
  max-height: min(180px, 26dvh);
  margin-top: 20px;
  padding: 16px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid rgba(35, 132, 95, .2);
  border-radius: 14px;
  background: #f8faf9;
  color: #36453e;
  font-size: 14px;
  line-height: 1.75;
}

.consent-scroll:focus-visible {
  outline: 3px solid rgba(35, 132, 95, .28);
  outline-offset: 2px;
}

.consent-scroll h2 {
  margin: 0 0 10px;
  font-size: 17px;
}

.consent-scroll p {
  margin: 0 0 14px;
}

.consent-scroll a {
  color: var(--green-dark);
  font-weight: 700;
}

.consent-confirmation {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 56px;
  margin-top: 14px;
  padding: 12px 16px;
  border: 1px solid rgba(35, 132, 95, .2);
  border-radius: 12px;
  background: #f4f7f5;
  color: #263c32;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.consent-confirmation input {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  margin: 0;
  accent-color: var(--green);
  cursor: pointer;
}

.privacy-dialog fieldset {
  margin: 22px 0 0;
  padding: 0;
  border: 0;
}

.privacy-dialog legend {
  margin-bottom: 10px;
  font-weight: 750;
}

.choice-row,
.visitor-grid label {
  cursor: pointer;
}

.choice-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 8px;
  padding: 12px 14px;
  border: 1px solid rgba(35, 132, 95, .18);
  border-radius: 14px;
  background: #f7fbf9;
}

.choice-row input,
.visitor-grid input {
  margin-top: 3px;
  accent-color: var(--green);
}

.choice-row span {
  display: grid;
  gap: 3px;
}

.choice-row small,
.privacy-note {
  color: var(--muted);
}

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

.visitor-grid label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f4f7f5;
}

.visitor-clear {
  margin-top: 8px;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--green-dark);
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
}

.privacy-error {
  margin: 14px 0 0;
  color: #a32727;
  font-size: 14px;
  font-weight: 700;
}

.privacy-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.privacy-submit,
.privacy-cancel {
  flex: 1;
  padding: 13px 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-weight: 750;
  cursor: pointer;
}

.privacy-submit {
  background: var(--green);
  color: #fff;
}

.privacy-cancel {
  border-color: rgba(35, 132, 95, .28);
  background: #fff;
  color: var(--green-dark);
}

.privacy-submit:hover {
  background: var(--green-dark);
}

.privacy-submit:disabled {
  background: #aeb8b3;
  color: #f2f4f3;
  cursor: not-allowed;
}

.privacy-submit:focus-visible {
  outline: 3px solid rgba(35, 132, 95, .35);
  outline-offset: 3px;
}

.privacy-cancel:focus-visible {
  outline: 3px solid rgba(35, 132, 95, .25);
  outline-offset: 3px;
}

.privacy-note {
  margin: 12px 0 0;
  font-size: 12px;
  line-height: 1.6;
}

@media (max-width: 560px) {
  .privacy-overlay {
    padding: 10px;
  }

  .privacy-dialog {
    max-height: calc(100dvh - 20px);
    border-radius: 18px;
  }

  .visitor-grid {
    grid-template-columns: 1fr;
  }

}


/* ==========================================
   CHAT AREA
========================================== */

.chat-zone {
  position: absolute;
  z-index: 10;

  top: 92px;
  bottom: 118px;
  left: 50%;

  width: min(820px, calc(100% - 28px));

  transform: translateX(-50%);

  padding: 14px 10px;

  border-radius: 30px;
  border: 1px solid rgba(255,255,255,.70);

  background: rgba(255,255,255,.74);

  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);

  box-shadow: 0 22px 60px rgba(20,45,35,.08);

  overflow: hidden;

  transition:
    background .45s ease,
    box-shadow .45s ease;
}

/* 最初は背景を少し見せる */
.app:not(.is-chatting) .chat-zone {
  background: rgba(255,255,255,.46);
  box-shadow: 0 18px 48px rgba(20,45,35,.05);
}

/* 会話開始後は可読性優先 */
.app.is-chatting .chat-zone {
  background: rgba(255,255,255,.82);
}

.conversation {
  width: 100%;
  height: 100%;

  padding: 10px 12px 26px;

  overflow-y: auto;
  overscroll-behavior: contain;

  scrollbar-width: thin;
  scrollbar-color: rgba(70,90,80,.18) transparent;
}

.conversation::-webkit-scrollbar {
  width: 7px;
}

.conversation::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(80,100,90,.17);
}


/* ==========================================
   MESSAGE
========================================== */

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 11px;

  margin-bottom: 21px;

  animation: message-in .28s ease both;
}

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

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

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

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


/* ==========================================
   CHARACTER AVATAR
========================================== */

.avatar-wrap {
  position: relative;

  flex: 0 0 82px;

  width: 82px;

  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.message-avatar {
  display: block;

  width: 78px;
  height: auto;
  max-height: 96px;

  object-fit: contain;
  object-position: bottom;

  border: 0;
  border-radius: 0;

  background: transparent;

  filter: drop-shadow(0 6px 12px rgba(25,45,35,.12));

  transition:
    transform .2s ease,
    opacity .2s ease;
}


@keyframes thinking-float {
  0%, 100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-3px);
  }
}


/* 発話直後 */
.avatar-wrap.is-speaking .message-avatar {
  animation: speaking-pop .36s ease;
}

@keyframes speaking-pop {
  0% {
    transform: scale(.94);
  }

  55% {
    transform: scale(1.07);
  }

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


/* ==========================================
   MESSAGE CONTENT
========================================== */

.message-content {
  max-width: min(76%, 590px);
}

.message-name {
  margin: 0 0 5px 5px;

  font-size: 12px;
  font-weight: 700;

  color: rgba(32,42,47,.76);
}

.message-bubble {
  position: relative;

  padding: 14px 17px;

  border-radius: 7px 21px 21px 21px;

  background: rgba(255,255,255,.99);

  color: var(--text);

  box-shadow: 0 8px 24px rgba(25,45,35,.10);

  font-size: 15px;
  line-height: 1.75;

  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-row.assistant .message-bubble::before {
  content: "";

  position: absolute;

  top: 12px;
  left: -7px;

  width: 14px;
  height: 14px;

  border-radius: 2px;

  background: rgba(255,255,255,.99);

  transform: rotate(45deg);
}



/* ==========================================
   USER
========================================== */

.message-row.user .message-content {
  display: flex;
  justify-content: flex-end;

  max-width: min(74%, 560px);
}

.message-row.user .message-bubble {
  border-radius: 21px 7px 21px 21px;

  background: rgba(39,137,99,.97);

  color: white;

  box-shadow: 0 9px 26px rgba(25,95,68,.18);
}

.message-row.user .message-bubble::before {
  content: "";

  position: absolute;

  top: 12px;
  right: -7px;

  width: 14px;
  height: 14px;

  border-radius: 2px;

  background: rgba(39,137,99,.97);

  transform: rotate(45deg);
}


/* ==========================================
   SHARED THINKING
========================================== */

.shared-thinking {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;

  padding: 10px 0 18px;
}

/* 回答が出るまでどちらが話すか分からないので、2人一緒の1枚絵を出す */
.shared-thinking-image {
  display: block;

  width: 156px;
  height: auto;

  filter: drop-shadow(0 6px 12px rgba(25,45,35,.12));

  animation: thinking-float 1.6s ease-in-out infinite;
}

.thinking-dots {
  display: flex;
  gap: 4px;
}

.thinking-dots span {
  width: 5px;
  height: 5px;

  border-radius: 50%;

  background: #71817a;

  animation: typing-dot 1.1s infinite;
}

.thinking-dots span:nth-child(2) {
  animation-delay: .15s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: .3s;
}

@keyframes typing-dot {
  0%, 70%, 100% {
    opacity: .25;
    transform: translateY(0);
  }

  35% {
    opacity: 1;
    transform: translateY(-3px);
  }
}


/* ==========================================
   SOURCES
========================================== */

/* キャラクターの吹き出しと左端を揃える（アバター幅 + gap） */
.message-sources {
  max-width: min(76%, 590px);

  margin: -9px 0 21px 93px;
  padding: 10px 14px 11px;

  border: 1px solid rgba(35,132,95,.16);
  border-radius: 14px;

  background: rgba(247,251,249,.92);

  font-size: 12.5px;
  line-height: 1.6;

  animation: message-in .28s ease both;
}

.sources-label {
  margin: 0 0 4px;

  font-size: 11.5px;
  font-weight: 700;

  color: var(--muted);
}

.sources-list {
  margin: 0;
  padding: 0;

  list-style: none;
}

.sources-list li + li {
  margin-top: 3px;
}

.sources-list a {
  color: var(--green-dark);

  text-decoration: underline;
  text-decoration-color: rgba(23,104,74,.35);
  text-underline-offset: 2px;

  overflow-wrap: anywhere;
}

.sources-list a:hover {
  text-decoration-color: currentColor;
}

.source-pages {
  margin-left: 6px;

  color: var(--muted);

  white-space: nowrap;
}

.message-map {
  width: min(560px, calc(100% - 93px));
  margin: -9px 0 16px 93px;
  overflow: hidden;
  border: 1px solid rgba(35,132,95,.2);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(25,54,42,.08);
  animation: message-in .28s ease both;
}

.message-map-header {
  padding: 13px 15px 11px;
  border-bottom: 1px solid rgba(35,132,95,.14);
}

.message-map-title {
  margin: 0;
  color: var(--green-dark);
  font-size: 14px;
  font-weight: 800;
}

.message-map-names {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.message-map-link {
  display: block;
  max-height: 430px;
  overflow: auto;
  background: #edf1ee;
}

.message-map-stage {
  position: relative;
  width: 100%;
  line-height: 0;
}

.message-map-stage img {
  display: block;
  width: 100%;
  height: auto;
}

.message-map-marker {
  position: absolute;
  z-index: 2;
  display: block;
  pointer-events: none;
}

.message-map-stage .message-map-marker-aki {
  width: 36px;
  height: auto;
  transform: translate(-96.9%, -93.2%);
  border-radius: 46%;
  background: rgba(255,255,255,.92);
  box-shadow:
    0 0 0 2px rgba(214,95,45,.92),
    0 2px 5px rgba(0,0,0,.38);
}

.message-map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin: 0;
  padding: 11px 15px 13px;
  list-style: none;
}

.message-map-legend li {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #34473e;
  font-size: 12px;
  font-weight: 700;
}

.message-map-legend li > span {
  display: block;
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
}

.message-map-legend-aki {
  border-radius: 46%;
  background: rgba(255,255,255,.92) url("assets/characters/aki/pointing.webp") center / contain no-repeat;
  box-shadow: 0 0 0 1px rgba(214,95,45,.92);
}

.message-map-link:focus-visible {
  outline: 3px solid rgba(35,132,95,.3);
  outline-offset: -3px;
}

.visually-hidden {
  position: absolute;

  width: 1px;
  height: 1px;

  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}


/* ==========================================
   FOCUS
========================================== */

.reset-button:focus-visible,
.send-button:focus-visible,
.sources-list a:focus-visible {
  outline: 3px solid rgba(35,132,95,.55);
  outline-offset: 2px;
}


/* ==========================================
   COMPOSER
========================================== */

.composer-area {
  position: absolute;
  z-index: 40;

  left: 50%;
  bottom: 34px;

  width: min(760px, calc(100% - 28px));

  transform: translateX(-50%);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 12px;

  padding: 12px 13px 12px 18px;

  border: 1px solid rgba(35,132,95,.20);
  border-radius: 25px;

  background: rgba(255,255,255,.98);

  box-shadow: 0 18px 54px rgba(18,45,34,.19);

  transition:
    transform .2s ease,
    box-shadow .2s ease;
}

.composer:focus-within {
  transform: translateY(-2px);

  box-shadow:
    0 21px 58px rgba(18,45,34,.22),
    0 0 0 3px rgba(35,132,95,.08);
}

#message-input {
  flex: 1;

  width: 100%;

  min-height: 46px;
  max-height: 145px;

  padding: 10px 2px 7px;

  border: 0;
  outline: none;

  resize: none;

  overflow-y: auto;

  background: transparent;

  color: var(--text);

  font-size: 16px;
  line-height: 1.5;
}

#message-input::placeholder {
  color: #87938f;
}

.send-button {
  flex: 0 0 48px;

  display: grid;
  place-items: center;

  width: 48px;
  height: 48px;

  border: 0;
  border-radius: 50%;

  background: var(--green);

  color: white;

  font-size: 19px;

  cursor: pointer;

  box-shadow: 0 7px 18px rgba(20,100,70,.25);

  transition:
    transform .15s ease,
    background .15s ease;
}

.send-button:hover {
  transform: translateY(-1px);
  background: var(--green-dark);
}

.send-button:disabled {
  opacity: .55;
  cursor: default;
}


/* ==========================================
   DISCLAIMER
========================================== */

.disclaimer {
  position: absolute;
  z-index: 40;

  bottom: 9px;
  left: 50%;

  width: calc(100% - 24px);

  margin: 0;

  transform: translateX(-50%);

  color: rgba(45,55,58,.57);

  text-align: center;

  font-size: 10px;
  line-height: 1.4;
}


/* ==========================================
   MOBILE
========================================== */

@media (max-width: 700px) {
  .header {
    padding: 11px;
  }

  .brand {
    gap: 7px;
    padding: 5px 9px;
    border-radius: 13px;
  }

  .brand-logo {
    width: 28px;
    height: 28px;
  }

  .brand-text {
    gap: 7px;
  }

  .brand-name {
    font-size: 14px;
  }

  .brand-service {
    font-size: 12.5px;
  }

  .brand-divider {
    height: 16px;
  }

  .reset-button {
    width: 42px;
    height: 42px;
    padding: 0;

    justify-content: center;
  }

  .reset-label {
    display: none;
  }

  .chat-zone {
    top: 69px;
    bottom: 108px;

    width: calc(100% - 10px);

    padding: 8px 3px;

    border-radius: 22px;
  }

  .conversation {
    padding: 8px 8px 20px;
  }

  .message-row {
    gap: 8px;
    margin-bottom: 16px;
  }

  .avatar-wrap {
    flex-basis: 64px;

    width: 64px;
  }

  .message-avatar {
    width: 60px;
    max-height: 76px;
  }

  .shared-thinking-image {
    width: 128px;
  }

  .message-content {
    max-width: calc(100% - 72px);
  }

  .message-row.user .message-content {
    max-width: 82%;
  }

  .message-sources {
    max-width: calc(100% - 72px);

    margin: -7px 0 16px 72px;
    padding: 8px 12px 9px;
  }

  .message-map {
    width: calc(100% - 72px);
    margin: -7px 0 16px 72px;
  }

  .message-map-link {
    max-height: 56vh;
  }

  .message-bubble {
    padding: 11px 14px;

    font-size: 14px;
    line-height: 1.7;

    border-radius: 6px 18px 18px 18px;
  }

  .message-name {
    margin-left: 3px;
    font-size: 11px;
  }

  .composer-area {
    bottom: 30px;
    width: calc(100% - 16px);
  }

  .composer {
    gap: 8px;

    padding: 8px 8px 8px 13px;

    border-radius: 21px;
  }

  #message-input {
    min-height: 43px;
    padding: 9px 1px 6px;
  }

  .send-button {
    flex-basis: 43px;

    width: 43px;
    height: 43px;
  }

  .disclaimer {
    bottom: 5px;
    font-size: 9px;
  }
}

@media (max-width: 420px) {
  .brand-service,
  .brand-divider {
    display: none;
  }
}

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