/* ==========================================================================
   著者チャット(黒川蒼)- LINE風UI
   ARG「さわぬら」村サイトのフォント方針(Zen Kaku Gothic New + Noto Sans JP)
   を踏襲しつつ、配色だけLINE風のグリーンに変更している。
   ========================================================================== */

:root {
  --line-green: #06c755;
  --line-green-deep: #05a648;
  --bubble-mine: #9bE39c;
  --bubble-mine-2: #a9e9a6;
  --bubble-other: #ffffff;
  --chat-bg: #e5ede6;
  --text-main: #1c1c1a;
  --text-soft: #6b6f6a;
  --border-soft: #dfe6df;
  --font-sans: "Noto Sans JP", "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "Meiryo", "Noto Sans CJK JP", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--chat-bg);
  color: var(--text-main);
  font-family: var(--font-sans);
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------------- ヘッダー ---------------- */

.chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--line-green);
  color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  position: sticky;
  top: 0;
  z-index: 20;
}

.chat-header__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  flex: 0 0 auto;
  background: #fff;
}
.chat-header__avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.chat-header__name {
  font-size: 15px;
  font-weight: 700;
}
.chat-header__status {
  font-size: 11px;
  opacity: 0.85;
}

/* テスト用。URLに ?debug を付けた時だけ表示する(誤って進行を消さないため) */
.chat-header__reset { display: none; }
body.debug-mode .chat-header__reset { display: inline-block; }

.chat-header__reset {
  margin-left: auto;
  flex: 0 0 auto;
  color: #fff;
  opacity: 0.85;
  text-decoration: none;
  font-size: 12px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  padding: 5px 10px;
}
.chat-header__reset:active { opacity: 1; }

.chat-header__back {
  color: #fff;
  text-decoration: none;
  font-size: 20px;
  line-height: 1;
  padding: 4px 6px;
  margin-right: 2px;
  flex: 0 0 auto;
}

/* ---------------- スレッド本体 ---------------- */

.chat-thread {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 100%;
  margin: 3px 0;
}
.chat-row--kuro { justify-content: flex-start; }
.chat-row--player { justify-content: flex-end; }

.chat-row__avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  overflow: hidden;
  flex: 0 0 auto;
  background: #fff;
  /* 連投の1通目に出るので、吹き出しの先頭に合わせる(名前ラベルの分だけ下げる) */
  align-self: flex-start;
  margin-top: 16px;
}
.chat-row__avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-row__avatar-spacer { width: 30px; flex: 0 0 auto; }

.chat-bubble-col {
  display: flex;
  flex-direction: column;
  max-width: 74%;
}
.chat-row--player .chat-bubble-col { align-items: flex-end; }
.chat-row--kuro .chat-bubble-col { align-items: flex-start; }

.chat-name-label {
  font-size: 11px;
  color: var(--text-soft);
  margin: 0 0 2px 2px;
}

/*
 * 同じ人が続けて送ったメッセージ(2通目以降)。
 * 実際のLINEと同じく、名前とアイコンは連続の1通目にだけ出し、
 * 2通目以降はアイコン幅の余白だけ空けて揃える。
 */
.chat-row--cont { margin-top: 1px; }
.chat-row--cont .chat-name-label { display: none; }

.chat-bubble {
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}

.chat-row--kuro .chat-bubble {
  background: var(--bubble-other);
  border-bottom-left-radius: 4px;
  color: var(--text-main);
}
.chat-row--player .chat-bubble {
  background: var(--bubble-mine);
  border-bottom-right-radius: 4px;
  color: #10331a;
}

.chat-bubble--image {
  padding: 4px;
  overflow: hidden;
}
.chat-bubble--image img {
  display: block;
  max-width: 220px;
  width: 100%;
  border-radius: 12px;
  cursor: zoom-in;
}
.chat-bubble__caption {
  font-size: 12.5px;
  color: var(--text-soft);
  padding: 4px 6px 2px;
}
.chat-bubble__copylink {
  margin-top: 6px;
  padding: 6px 8px 2px;
}
.chat-bubble__copylink button {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-green);
  background: #fff;
  color: var(--line-green-deep);
  cursor: pointer;
}
.chat-bubble__copylink .copy-feedback {
  display: none;
  font-size: 11.5px;
  color: var(--line-green-deep);
  margin-left: 6px;
}
.chat-bubble__copylink .copy-feedback.show { display: inline; }

.chat-notice {
  align-self: center;
  font-size: 11.5px;
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  padding: 3px 12px;
  margin: 8px auto;
}

.chat-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 3px 0 3px 36px;
}
.chat-typing__bubble {
  background: var(--bubble-other);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 10px 14px;
  display: inline-flex;
  gap: 4px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}
.chat-typing__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9aa39a;
  animation: chatTypingBounce 1.1s infinite ease-in-out;
}
.chat-typing__dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing__dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatTypingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-row--new .chat-bubble,
.chat-notice--new {
  animation: chatPopIn 0.22s ease-out;
}
@keyframes chatPopIn {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------------- 入力エリア ---------------- */

.chat-inputbar {
  flex: 0 0 auto;
  border-top: 1px solid var(--border-soft);
  background: #fff;
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.chat-quickreplies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 2px 10px;
}
.chat-quickreply-btn {
  border: 1px solid var(--line-green);
  color: var(--line-green-deep);
  background: #fff;
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.chat-quickreply-btn:active { background: #eafaf0; }

.chat-form {
  display: flex;
  gap: 8px;
  align-items: center;
}
.chat-form input[type="text"] {
  flex: 1 1 auto;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 15px;
  font-family: inherit;
  background: #f4f6f4;
}
.chat-form input[type="text"]:focus { outline: 2px solid var(--line-green); outline-offset: 1px; }

.chat-form button {
  flex: 0 0 auto;
  background: var(--line-green);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14.5px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
}
.chat-form button:disabled { opacity: 0.5; }

.chat-editable-hint {
  font-size: 11.5px;
  color: var(--text-soft);
  padding: 0 2px 6px;
}

.chat-form-disabled-note {
  font-size: 12px;
  color: var(--text-soft);
  text-align: center;
  padding: 6px 0 2px;
}

/* ---------------- 画像拡大モーダル(村サイトと共通) ---------------- */

.img-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 12, 0.86);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.img-modal.open { display: flex; }
.img-modal img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: 6px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}
.img-modal__close {
  position: absolute;
  top: 16px;
  right: 18px;
  background: none;
  border: none;
  color: #fff;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
}

@media (min-width: 560px) {
  body { max-width: 480px; margin: 0 auto; box-shadow: 0 0 0 1px var(--border-soft); }
}
