:root {
  --bg: #ffffff;
  --fg: #111111;
  --sub: #737373;
  --card: #efefef;
  --line: #dbdbdb;
  --pill: #efefef;
  --circle: #f2f2f2;
  --me-grad: linear-gradient(180deg, #9b30ff 0%, #5b51d8 60%, #3797f0 100%);
  --cam: #3797f0;
}

[data-theme="dark"] {
  --bg: #0b0c0e;
  --fg: #f5f5f5;
  --sub: #8e8e93;
  --card: #262629;
  --line: #1f2024;
  --pill: #1c1d21;
  --circle: #1e1f24;
  --me-grad: linear-gradient(180deg, #a334fa 0%, #6344f5 55%, #3b66f5 100%);
  --cam: #4c5df7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #18191c;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
}

#app {
  max-width: 430px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  color: var(--fg);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 0;
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
}

button.primary {
  background: #3797f0;
  color: #fff;
  font-weight: 600;
}

/* ホーム画面ヘッダー・リスト */
#top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

#top b {
  font-size: 17px;
}

#top button {
  background: none;
  font-size: 18px;
  padding: 4px 8px;
}

.screen {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

#home {
  overflow-y: auto;
}

.note {
  font-size: 11.5px;
  color: var(--sub);
  padding: 10px 16px;
  margin: 0;
  line-height: 1.5;
  border-bottom: 1px solid var(--line);
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 16px;
  cursor: pointer;
}

.row:hover {
  background: var(--card);
}

/* 丸型アバター画像の固定サイズ＆トリミング */
.av {
  width: 50px;
  height: 50px;
  min-width: 50px;
  min-height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  background: var(--card);
  overflow: hidden;
  flex: none;
}

.av img,
.mini-av img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.av.big {
  width: 80px;
  height: 80px;
  min-width: 80px;
  min-height: 80px;
  font-size: 40px;
  margin: 0 auto;
}

.row .info {
  flex: 1;
  min-width: 0;
}

.row .info b {
  font-size: 14.5px;
  display: block;
}

.row small {
  display: block;
  color: var(--sub);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.unread {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #3797f0;
  flex: none;
}

/* Instagram DM風チャットヘッダー */
.chead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 6px;
}

.circle-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--circle);
  display: grid;
  place-items: center;
  padding: 0;
  flex: none;
  color: var(--fg);
}

.circle-btn:active {
  opacity: 0.7;
}

.chead .av {
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  font-size: 18px;
}

.cid {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.cname-row {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  line-height: 1.2;
}

.cname-row .chev {
  color: var(--sub);
  font-size: 17px;
  font-weight: 400;
}

.csub {
  font-size: 12px;
  color: var(--sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

/* 極細下心・誘導意欲ゲージ */
.gauge-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px 8px;
  border-bottom: 1px solid var(--line);
}

.gauge {
  flex: 1;
  height: 4px;
  background: var(--card);
  border-radius: 4px;
  overflow: hidden;
}

.gauge i {
  display: block;
  height: 100%;
  width: 30%;
  background: linear-gradient(90deg, #fbbf24, #ef4444);
  transition: width 0.45s ease;
}

.gauge-label {
  font-size: 10.5px;
  color: var(--sub);
  white-space: nowrap;
}

.gauge-label b {
  color: var(--fg);
}

/* メッセージエリア・吹き出し（Instagram DM再現） */
#msgs {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.date-sep {
  align-self: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--sub);
  margin: 10px 0 8px;
  letter-spacing: 0.4px;
}

/* 相手メッセージ行（連続グループの最後の吹き出し左下にのみアバター表示） */
.them-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 82%;
  align-self: flex-start;
  margin-top: 2px;
}

.them-row.cont {
  margin-top: 0;
}

.mini-av {
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  background: var(--card);
  overflow: hidden;
  flex: none;
  visibility: hidden;
}

.them-row.last-in-group .mini-av {
  visibility: visible;
}

.m {
  padding: 9px 14px;
  border-radius: 20px;
  font-size: 14.5px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.m.them {
  background: var(--card);
  color: var(--fg);
  border-bottom-left-radius: 6px;
}

.them-row.cont .m.them {
  border-top-left-radius: 6px;
}

.them-row.last-in-group .m.them {
  border-bottom-left-radius: 20px;
}

/* 自分メッセージ（画面位置に応じて紫から青紫へ変化するグラデーション） */
.m.me {
  background: var(--me-grad);
  background-attachment: fixed;
  color: #fff;
  align-self: flex-end;
  max-width: 76%;
  border-bottom-right-radius: 6px;
  margin-top: 2px;
}

.m.me.cont {
  margin-top: 0;
  border-top-right-radius: 6px;
}

.m.me.last-in-group {
  border-bottom-right-radius: 20px;
}

.m.sys {
  align-self: center;
  background: none;
  color: var(--sub);
  font-size: 11.5px;
  text-align: center;
  max-width: 90%;
  margin: 6px 0;
}

/* 証拠保全バッジ＆警告ボタン */
.badge {
  margin: 4px 12px;
  padding: 6px 10px;
  text-align: center;
  border-radius: 10px;
  background: #16a34a;
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
}

.warn-wrap {
  padding: 4px 12px;
}

.warn {
  width: 100%;
  background: #dc2626 !important;
  color: #fff !important;
  font-size: 13px;
  font-weight: 600;
  padding: 8px;
  border-radius: 12px;
}

/* Instagram DM風カプセル入力バー */
.inp-wrap {
  padding: 6px 10px 10px;
  background: var(--bg);
}

.inp-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--pill);
  border-radius: 26px;
  padding: 4px 6px 4px 5px;
}

.cam-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--cam);
  display: grid;
  place-items: center;
  padding: 0;
  flex: none;
  transition: transform 0.12s;
}

.cam-btn:active {
  transform: scale(0.9);
}

.inp-pill input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--fg);
  padding: 7px 4px;
  font: inherit;
  font-size: 14.5px;
  outline: none;
}

.inp-pill input::placeholder {
  color: var(--sub);
}

.icon-in {
  background: none;
  padding: 4px 6px;
  font-size: 18px;
  line-height: 1;
}

.send-in {
  background: none;
  color: #3797f0;
  font-weight: 700;
  font-size: 14px;
  padding: 6px 10px;
}

.send-in:disabled {
  opacity: 0.4;
}

.hidden {
  display: none !important;
}

.pop {
  position: absolute;
  right: 12px;
  top: 56px;
  background: var(--card);
  border-radius: 14px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 8px 24px #0008;
  z-index: 10;
}

.modal {
  position: fixed;
  inset: 0;
  background: #000a;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}

.modal .box {
  background: var(--bg);
  color: var(--fg);
  width: 100%;
  max-width: 390px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 18px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--line);
}

.modal h3 {
  margin: 4px 0;
  text-align: center;
}

.modal small {
  color: var(--sub);
  line-height: 1.5;
}

.flags-title {
  margin: 6px 0 0;
  font-size: 13.5px;
}

#pFlags {
  margin: 0 0 6px;
  padding-left: 20px;
  font-size: 13.5px;
  line-height: 1.6;
}

.stats {
  display: flex;
  justify-content: space-around;
  text-align: center;
  font-size: 13px;
}

.hint {
  text-align: left;
  width: 100%;
  margin-bottom: 6px;
  line-height: 1.4;
}

#flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 30;
}

#flash.go {
  animation: fl 0.4s;
}

@keyframes fl {
  0% { opacity: 0.95; }
  100% { opacity: 0; }
}

body.rage #app {
  animation: rg 0.5s infinite alternate;
}

@keyframes rg {
  from { box-shadow: inset 0 0 0 0 #f000; }
  to { box-shadow: inset 0 0 70px 20px #f00a; }
}

#result {
  padding: 16px;
  overflow-y: auto;
  gap: 10px;
}

.rank {
  font-size: 64px;
  font-weight: 800;
  text-align: center;
}

.card {
  background: var(--card);
  border-radius: 14px;
  padding: 12px;
  font-size: 14px;
  line-height: 1.55;
}

.lesson {
  border-left: 4px solid #16a34a;
}

/* 入力中アニメーション：相手吹き出し内で滑らかに点滅する三点リーダー */
.typing-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  align-self: flex-start;
  margin-top: 4px;
}

.typing-row .mini-av {
  visibility: visible;
}

.typing {
  background: var(--card);
  color: var(--sub);
  padding: 12px 16px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
}

.typing::after {
  content: '';
  width: 20px;
  height: 6px;
  flex: none;
  background: radial-gradient(circle, currentColor 2.2px, transparent 2.7px) 0 50% / 7px 6px repeat-x;
  animation: pulse 1s infinite alternate;
}

@keyframes pulse {
  0% { opacity: 0.25; }
  100% { opacity: 1; }
}

#kMsg {
  font-size: 13px;
  min-height: 1.2em;
}

