:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1f2328;
  --text-sub: #6b7280;
  --accent: #2f7d4f;
  --accent-dark: #256340;
  --user-bubble: #2f7d4f;
  --user-text: #ffffff;
  --ai-bubble: #ffffff;
  --border: #e3e6ea;
  --danger: #c0392b;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---- アクセスコード画面 ---- */
.gate {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.gate-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
  text-align: center;
}
.gate-title { font-size: 22px; margin: 0 0 8px; }
.gate-desc { color: var(--text-sub); font-size: 14px; margin: 0 0 22px; line-height: 1.6; }
.code-input {
  width: 100%;
  padding: 13px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 14px;
  outline: none;
}
.code-input:focus { border-color: var(--accent); }
.turnstile { display: flex; justify-content: center; margin-bottom: 14px; min-height: 0; }
.btn-primary {
  width: 100%;
  padding: 13px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.gate-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 12px 0 0; }
.gate-note { color: var(--text-sub); font-size: 12px; margin: 18px 0 0; }

/* ---- チャット画面（全画面・中央カラム） ---- */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 760px;
  margin: 0 auto;
  background: var(--bg);
}
.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.app-title { font-weight: 700; font-size: 16px; }
.app-badge {
  font-size: 11px;
  color: var(--accent-dark);
  background: #e6f2ea;
  border-radius: 999px;
  padding: 2px 9px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg { display: flex; flex-direction: column; gap: 4px; max-width: 88%; }
.msg-role { font-size: 11px; color: var(--text-sub); padding: 0 4px; }
.msg-body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.7;
  padding: 11px 14px;
  border-radius: var(--radius);
  font-size: 15px;
}
.msg-user { align-self: flex-end; align-items: flex-end; }
.msg-user .msg-body { background: var(--user-bubble); color: var(--user-text); border-bottom-right-radius: 4px; }
.msg-ai { align-self: flex-start; }
.msg-ai .msg-body {
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg-sources {
  font-size: 12px;
  color: var(--text-sub);
  padding: 0 4px;
  margin-top: 2px;
}
.msg-sources b { color: var(--accent-dark); font-weight: 600; }
.msg-error .msg-body { background: #fdecea; border-color: #f5c6c2; color: var(--danger); }

.msg-feedback { display: flex; gap: 8px; padding: 2px 4px 0; }
.fb-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 9px;
  color: var(--text-sub);
}
.fb-btn:hover { border-color: var(--accent); }
.fb-btn.active { background: #e6f2ea; border-color: var(--accent); color: var(--accent-dark); }

.typing { display: inline-block; }
.typing::after { content: "▍"; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---- 入力欄 ---- */
.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
}
.chat-input {
  flex: 1;
  resize: none;
  max-height: 160px;
  padding: 11px 14px;
  font-size: 15px;
  line-height: 1.5;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  font-family: inherit;
}
.chat-input:focus { border-color: var(--accent); }
.btn-send {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
.btn-send:hover { background: var(--accent-dark); }
.btn-send:disabled { opacity: 0.5; cursor: default; }

@media (max-width: 600px) {
  .msg { max-width: 94%; }
}
