:root {
  color-scheme: light;
  --bg: #fbfbfa;
  --panel: #ffffff;
  --text: #20201f;
  --muted: #70706d;
  --line: #e6e4df;
  --line-strong: #d6d3cb;
  --accent: #76b900;
  --accent-dark: #4f7f00;
  --accent-soft: #eef8dc;
  --red: #c4362e;
  --amber: #a76500;
  --soft: #f7f7f4;
  --shadow: 0 1px 2px rgba(15, 15, 15, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #11170b;
  cursor: pointer;
  font-weight: 600;
  padding: 9px 12px;
}

button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #ffffff;
}

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

button.secondary {
  background: #ffffff;
  border-color: var(--line-strong);
  color: var(--text);
}

button.secondary:hover {
  background: var(--soft);
  border-color: var(--line-strong);
  color: var(--text);
}

.app {
  display: grid;
  grid-template-columns: minmax(340px, 430px) minmax(0, 1fr);
  gap: 14px;
  height: 100vh;
  padding: 14px;
}

.panel {
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls {
  overflow: auto;
  padding: 18px;
}

.brand,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  justify-content: flex-start;
}

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

.ref-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #2f8fbc;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0 2px;
}

.ref-link svg {
  display: block;
  flex: 0 0 auto;
}

.ref-link:hover {
  color: #216f92;
}

.section-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  column-gap: 14px;
}

.brand-mark img {
  width: 58px;
  height: 58px;
  object-fit: contain;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tagline {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-family: "Clash Display", "Arial Rounded MT Bold", "Arial Black", ui-rounded, system-ui, sans-serif;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1;
  white-space: nowrap;
  /* #2F8FBC → #6DBA44 → 薄いネイビー を滑らかに循環させるグラデーション。
     色を左右対称に並べ、位置を往復させることで継ぎ目のない自然な変化にする。 */
  background: linear-gradient(
    100deg,
    #2f8fbc 0%,
    #6dba44 38%,
    #4c5f86 50%,
    #6dba44 62%,
    #2f8fbc 100%
  );
  background-size: 220% 100%;
  background-position: 0% 50%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  animation: brand-gradient 16s ease-in-out infinite;
}

@keyframes brand-gradient {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

@media (prefers-reduced-motion: reduce) {
  h1 {
    animation: none;
    background-position: 25% 50%;
  }

  .thinking-box {
    animation: none;
    background-position: 50% 0;
  }
}

h2 {
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
}

p,
label,
.status {
  color: var(--muted);
  font-size: 13px;
}

.hint {
  margin-top: 10px;
  overflow-wrap: anywhere;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.status-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #a8a8a3;
}

.status-dot.ok {
  background: var(--accent);
}

.status-dot.fail {
  background: var(--red);
}

.section {
  border-top: 1px solid var(--line);
  margin-top: 6px;
  padding-top: 18px;
}

label {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  outline: none;
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(118, 185, 0, 0.18);
}

.icon-button {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  padding: 0;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 10px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.segmented button {
  min-width: 0;
  background: #ffffff;
  border: 0;
  border-right: 1px solid var(--line-strong);
  border-radius: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.2;
  min-height: 42px;
  padding: 9px 8px;
  white-space: nowrap;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: var(--accent);
  color: #11170b;
}

.grid-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 10px;
}

.compact-grid label {
  min-width: 0;
}

.toggles {
  display: grid;
  gap: 10px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
}

.toggle input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.chat {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  background: #ffffff;
}

.messages {
  overflow: auto;
  padding: 26px min(5vw, 56px) 18px;
}

.message {
  max-width: 860px;
  margin: 0 auto 22px;
}

.message.user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.meta {
  display: none;
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 5px 2px;
}

.bubble {
  border: 0;
  border-radius: 0;
  padding: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.75;
  font-size: 16px;
}

.user .bubble {
  max-width: min(78%, 560px);
  background: #f3f3f3;
  border-radius: 22px;
  color: var(--text);
  line-height: 1.55;
  padding: 11px 16px;
}

.message-image {
  display: block;
  max-width: min(100%, 360px);
  max-height: 260px;
  border-radius: 12px;
  margin-top: 10px;
  object-fit: contain;
}

.assistant .bubble {
  background: transparent;
  color: #101010;
  white-space: normal;
}

/* 本文（p/li）は送信メッセージと同じ 16px・濃色でくっきり出す。
   グローバルの `p { color: muted; font-size: 13px }`（左パネルのラベル用）が
   直接当たって薄く小さくなるのを、ここで明示的に上書きする。 */
.assistant .bubble p,
.assistant .bubble li {
  color: #0d0d0d;
  font-size: 16px;
}

/* Markdown 見出し（marked が出力する h1〜h6）。グローバルの h1 グラデーションを打ち消す。 */
.assistant .bubble h1,
.assistant .bubble h2,
.assistant .bubble h3,
.assistant .bubble h4,
.assistant .bubble h5,
.assistant .bubble h6 {
  color: #0d0d0d;
  font-family: inherit;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0;
  white-space: normal;
  margin: 18px 0 8px;
  background: none;
  -webkit-text-fill-color: currentColor;
  animation: none;
}
.assistant .bubble h1:first-child,
.assistant .bubble h2:first-child,
.assistant .bubble h3:first-child {
  margin-top: 0;
}
.assistant .bubble h1 { font-size: 20px; }
.assistant .bubble h2 { font-size: 18px; }
.assistant .bubble h3 { font-size: 16px; }
.assistant .bubble h4,
.assistant .bubble h5,
.assistant .bubble h6 { font-size: 15px; }

/* Markdown テーブル（GFM）。 */
.assistant .bubble table {
  border-collapse: collapse;
  margin: 0 0 16px;
  font-size: 14px;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}
.assistant .bubble th,
.assistant .bubble td {
  border: 1px solid var(--line-strong);
  padding: 7px 11px;
  text-align: left;
  color: #0d0d0d;
}
.assistant .bubble th {
  background: var(--soft);
  font-weight: 700;
}

.assistant .bubble p {
  margin: 0 0 14px;
}

.assistant .bubble p:last-child {
  margin-bottom: 0;
}

.assistant .bubble ul {
  margin: 0 0 18px;
  padding-left: 1.45em;
}

.assistant .bubble li {
  margin: 5px 0;
}

.assistant .bubble strong {
  font-weight: 700;
}

.assistant .bubble code {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  padding: 1px 5px;
}

.assistant.pending .bubble {
  min-height: 28px;
}

.assistant.pending .bubble::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: #8c8c89;
  box-shadow: 14px 0 0 #8c8c89, 28px 0 0 #8c8c89;
  animation: waiting-dots 0.9s infinite ease-in-out;
}

.thinking-box {
  max-width: 860px;
  font-size: 14px;
  margin: 0 auto 18px;
  overflow-wrap: anywhere;
  line-height: 1.6;
  /* 生成中に固まって見えないよう、明るい帯が文字上を流れるシマー。 */
  background: linear-gradient(
    90deg,
    #b0b0ac 0%,
    #b0b0ac 40%,
    #2f8fbc 50%,
    #b0b0ac 60%,
    #b0b0ac 100%
  );
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  animation: thinking-shimmer 1.5s linear infinite;
}

@keyframes thinking-shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: 0% 0;
  }
}

.usage-meta {
  max-width: 860px;
  color: var(--muted);
  font-size: 12px;
  margin: 10px auto 0;
}

.error .bubble {
  background: #fff1ef;
  border-color: #f2b5ae;
  color: #802019;
}

.composer {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 8px;
  width: min(100% - 36px, 900px);
  margin: 0 auto 16px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: #ffffff;
  box-shadow: 0 2px 10px rgba(15, 15, 15, 0.08);
  padding: 8px;
}

.attachment-preview {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 28px;
  align-items: center;
  gap: 10px;
  width: min(100% - 36px, 900px);
  margin: 0 auto 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
  padding: 8px 10px;
  box-shadow: var(--shadow);
}

.attachment-preview[hidden] {
  display: none;
}

.attachment-preview img {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
}

.attachment-preview span {
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-remove {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: #ffffff;
  border-color: var(--line-strong);
  color: var(--text);
  padding: 0;
}

.composer textarea {
  height: 34px;
  min-height: 34px;
  max-height: calc(1.55em * 3 + 12px);
  border: 0;
  border-radius: 0;
  resize: none;
  line-height: 1.55;
  overflow-y: hidden;
  padding: 6px 4px;
}

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

.composer-tool,
.send-button {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  padding: 0;
}

.composer-tool svg,
.send-button svg {
  display: block;
}

/* 紙飛行機は視覚的に左に寄って見えるので、光学的に少し右へ寄せる。 */
.send-button svg {
  transform: translateX(1px);
}

.composer-tool {
  background: #ffffff;
  border-color: var(--line-strong);
  color: var(--text);
  font-size: 22px;
  font-weight: 400;
}

.send-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #11170b;
  font-size: 20px;
  line-height: 1;
}

.send-button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #ffffff;
}

@keyframes waiting-dots {
  0% {
    transform: translateY(0);
    box-shadow: 14px 0 0 #8c8c89, 28px 0 0 #8c8c89;
  }
  25% {
    transform: translateY(-4px);
    box-shadow: 14px 0 0 #8c8c89, 28px 0 0 #8c8c89;
  }
  50% {
    transform: translateY(0);
    box-shadow: 14px -4px 0 #8c8c89, 28px 0 0 #8c8c89;
  }
  75% {
    transform: translateY(0);
    box-shadow: 14px 0 0 #8c8c89, 28px -4px 0 #8c8c89;
  }
  100% {
    transform: translateY(0);
    box-shadow: 14px 0 0 #8c8c89, 28px 0 0 #8c8c89;
  }
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .messages {
    min-height: 48vh;
  }
}

@media (max-width: 540px) {
  .app {
    padding: 10px;
  }

  .brand {
    align-items: flex-start;
    flex-direction: column;
  }

  .grid-two,
  .composer {
    grid-template-columns: 1fr;
  }

  .composer {
    grid-template-columns: 34px minmax(0, 1fr) 38px;
    width: calc(100% - 20px);
  }

  .attachment-preview {
    width: calc(100% - 20px);
  }

  .button-row {
    width: 100%;
  }
}

/* ── コードブロック（ChatGPT風のダークブロック＋コピー） ───────────── */
.code-block {
  margin: 4px 0 16px;
  border: 1px solid #1f2430;
  border-radius: 10px;
  overflow: hidden;
  background: #0d1117;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px 6px 14px;
  background: #161b22;
  border-bottom: 1px solid #1f2430;
}

.code-lang {
  color: #9aa4b2;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  letter-spacing: 0.03em;
}

.code-copy {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid #2b3240;
  border-radius: 6px;
  background: transparent;
  color: #c9d1d9;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
}

.code-copy:hover {
  background: #22272e;
  border-color: #3a424f;
  color: #ffffff;
}

.code-copy.copied {
  color: #7fd25a;
  border-color: #3f7d33;
}

.code-copy svg {
  display: block;
}

.code-block pre {
  margin: 0;
  padding: 14px;
  overflow-x: auto;
}

/* 左パネル用の inline code スタイルより優先させて、ブロック内は素の等幅に戻す。 */
.assistant .bubble .code-block code {
  display: block;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  color: #e6edf3;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px;
  line-height: 1.6;
  white-space: pre;
}

/* トークンの配色は highlight.js のテーマCSS（github-dark）が付与する .hljs-* に任せる。 */

/* ── メッセージ操作ボタン（本文コピー／編集） ─────────────────────── */
.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}

.user .msg-actions {
  justify-content: flex-end;
}

.assistant.pending .msg-actions {
  display: none;
}

.msg-action {
  display: inline-flex;
  align-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 4px 6px;
}

.msg-action:hover {
  background: var(--soft);
  border-color: transparent;
  color: var(--text);
}

.msg-action.copied {
  color: var(--accent-dark);
}

.msg-action svg {
  display: block;
}

/* ── ユーザー発言の編集ボックス ─────────────────────────────────── */
.message.editing .bubble,
.message.editing .msg-actions {
  display: none;
}

.edit-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(78%, 560px);
}

.edit-input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 11px 15px;
  font-size: 16px;
  line-height: 1.5;
  resize: none;
  overflow: hidden;
}

.edit-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.edit-buttons button {
  font-size: 13px;
  padding: 6px 14px;
}
