:root {
  --ink: #161412;
  --ink-soft: #2a2622;
  --paper: #f4ede0;
  --paper-strong: #fbf6ec;
  --paper-deep: #ede4d2;
  --muted: #6e6659;
  --line: #cdbea4;
  --red: #9a2a23;
  --red-dark: #6e1d18;
  --gold: #b48a42;
  --wine: #7d140f;
  --aqua: #40b8c8;
  --shadow: 0 22px 60px rgba(22, 20, 18, 0.16);
  --soft-shadow: 0 12px 28px rgba(84, 47, 24, 0.11);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(246, 240, 229, 0.94), rgba(246, 240, 229, 0.82)),
    url("/assets/chat-room-bg.png") center / cover fixed no-repeat,
    radial-gradient(circle at 86% 8%, rgba(64, 184, 200, 0.14), transparent 26%),
    radial-gradient(circle at 12% 84%, rgba(125, 20, 15, 0.12), transparent 30%),
    linear-gradient(90deg, rgba(180, 138, 66, 0.08) 1px, transparent 1px) 0 0 / 74px 74px,
    linear-gradient(0deg, rgba(180, 138, 66, 0.055) 1px, transparent 1px) 0 0 / 74px 74px,
    var(--paper);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  line-height: 1.7;
}

button,
input,
textarea {
  font: inherit;
}

.chat-shell {
  width: min(1360px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 0;
  display: grid;
  grid-template-columns: 126px minmax(0, 1fr) minmax(360px, 0.5fr);
  gap: 18px;
}

.ai-rail {
  min-height: calc(100vh - 56px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 22px;
  padding: 22px 14px;
  border: 1px solid rgba(180, 138, 66, 0.5);
  background:
    linear-gradient(180deg, rgba(104, 16, 13, 0.52), rgba(42, 13, 11, 0.78)),
    url("/assets/reception-rail-deep.png") center / cover no-repeat;
  color: var(--paper-strong);
  box-shadow: var(--shadow);
  border-radius: 28px;
}
.rail-orb {
  width: 64px; height: 64px;
  display: grid; place-items: center;
  margin: 0 auto;
  border-radius: 50%;
  border: 1px solid rgba(216, 184, 120, 0.78);
  background: radial-gradient(circle, rgba(64,184,200,0.32), rgba(22,20,18,0.28));
  backdrop-filter: blur(2px);
  font-family: Georgia, serif;
  font-size: 24px;
  font-weight: 800;
}
.ai-rail nav {
  display: grid;
  align-content: start;
  gap: 18px;
  margin-top: 12px;
}
.ai-rail nav span {
  writing-mode: vertical-rl;
  justify-self: center;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: rgba(251, 246, 236, 0.86);
}
.ai-rail p {
  margin: 0;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.8;
  color: rgba(251, 246, 236, 0.76);
  text-align: center;
}

.chat-panel,
.memo-panel,
.complete-dialog {
  border: 1px solid rgba(180, 138, 66, 0.64);
  border-radius: 28px;
  background:
    radial-gradient(circle at 84% 30%, rgba(64,184,200,0.12), transparent 28%),
    rgba(251, 246, 236, 0.94);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-panel {
  min-height: calc(100vh - 56px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.chat-header {
  padding: 24px 30px 30px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(circle at 92% 18%, rgba(64, 184, 200, 0.14), transparent 24%),
    linear-gradient(135deg, rgba(255, 250, 240, 0.96), rgba(246, 232, 206, 0.86));
}

.back-link {
  display: inline-block;
  margin-bottom: 16px;
  color: var(--red-dark);
  font-weight: 800;
  text-decoration: none;
}
.back-link::before {
  content: "< ";
}

.assistant-intro {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  align-items: center;
  gap: 20px;
}

.assistant-portrait {
  position: relative;
  width: 118px;
  height: 118px;
  margin: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 250, 240, 0.92) 0 55%, rgba(180, 138, 66, 0.24) 56% 100%);
}
.assistant-portrait::before {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 1px solid rgba(180, 138, 66, 0.46);
}
.assistant-portrait::after {
  content: "";
  position: absolute;
  right: 8px;
  bottom: 13px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--aqua);
  border: 3px solid var(--paper-strong);
  box-shadow: 0 0 0 4px rgba(64, 184, 200, 0.16);
}

.assistant-avatar {
  width: 108px;
  height: 108px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(180, 138, 66, 0.8);
  background: var(--paper-strong);
  box-shadow: 0 14px 30px rgba(125, 20, 15, 0.16);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--red-dark);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.16em;
}

h1,
h2 {
  margin: 0;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "HGSMinchoE", serif;
  line-height: 1.25;
}

h1 {
  font-size: clamp(29px, 3vw, 38px);
  max-width: none;
}
h2 { font-size: 26px; }

.chat-header p:last-child,
.memo-lead,
.policy-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.message-list {
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: min(760px, 96%);
}
.message-row.assistant {
  align-self: flex-start;
}
.message-row.user {
  align-self: flex-end;
  justify-content: flex-end;
}
.message-row.system {
  align-self: center;
  justify-content: center;
  width: 100%;
}
.message-avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(180, 138, 66, 0.6);
  background: var(--paper-strong);
  box-shadow: var(--soft-shadow);
}

.message {
  max-width: 100%;
  padding: 15px 17px;
  border: 1px solid rgba(180, 138, 66, 0.45);
  border-radius: 18px;
  background: var(--paper-strong);
  white-space: pre-wrap;
  font-size: 15px;
  font-weight: 650;
}

.message.assistant {
  border-color: rgba(64, 184, 200, 0.42);
  background:
    linear-gradient(180deg, rgba(255, 250, 240, 0.98), rgba(245, 239, 226, 0.96));
  box-shadow: 0 10px 24px rgba(64, 184, 200, 0.08);
}

.message.user {
  background: linear-gradient(180deg, #40231f, #17110f);
  color: var(--paper-strong);
  border-color: var(--ink);
}

.message.system {
  max-width: 96%;
  background: rgba(237, 228, 210, 0.76);
  color: var(--muted);
  font-size: 13px;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 12px;
  padding: 16px 18px 18px;
  border-top: 1px solid var(--line);
  background: rgba(237, 228, 210, 0.8);
}

.chat-form textarea,
.memo-form input,
.memo-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-strong);
  color: var(--ink);
  padding: 12px;
  resize: vertical;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.78);
}
.chat-form textarea:focus,
.memo-form input:focus,
.memo-form textarea:focus {
  outline: 2px solid rgba(64, 184, 200, 0.34);
  border-color: rgba(64, 184, 200, 0.72);
}

.chat-form button,
.submit-button,
.complete-dialog button {
  border: 1px solid var(--ink);
  border-radius: 10px;
  background: linear-gradient(180deg, #a93229, var(--wine));
  color: var(--paper-strong);
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(125, 20, 15, 0.24);
}

.chat-form button:hover,
.submit-button:hover,
.complete-dialog button:hover {
  background: var(--red-dark);
}

.chat-form button:disabled,
.submit-button:disabled,
.complete-dialog button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
  box-shadow: none;
}

.memo-panel {
  padding: 22px;
  align-self: start;
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 36px);
  overflow-y: auto;
}

.privacy-card {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  padding: 14px;
  border: 1px solid rgba(180, 138, 66, 0.48);
  border-radius: 18px;
  background: rgba(255, 250, 240, 0.84);
  box-shadow: var(--soft-shadow);
}
.privacy-card img {
  width: 46px;
  height: 46px;
  object-fit: contain;
  display: block;
}
.privacy-card strong {
  color: var(--red-dark);
  font-family: "Yu Mincho", serif;
  font-size: 17px;
}

.memo-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.memo-progress {
  min-width: 78px;
  padding: 8px 10px;
  border: 1px solid rgba(180, 138, 66, 0.48);
  border-radius: 14px;
  background: rgba(255, 250, 240, 0.9);
  text-align: center;
}
.memo-progress span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}
.memo-progress strong {
  display: block;
  color: var(--red-dark);
  font-family: Georgia, serif;
  font-size: 22px;
  line-height: 1.15;
}
.privacy-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.memo-form {
  display: grid;
  gap: 11px;
  margin-top: 18px;
}

.memo-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.04em;
}
.memo-form label::before {
  content: "";
  width: 8px;
  height: 8px;
  margin-right: 5px;
  display: inline-block;
  border-radius: 50%;
  background: rgba(180, 138, 66, 0.72);
}
.memo-form small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
}

.submit-button {
  width: 100%;
  min-height: 48px;
  margin-top: 18px;
  font-size: 15px;
}

.policy-note {
  font-size: 12px;
}

.endo-mini {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-top: 18px;
  padding: 12px;
  border: 1px solid rgba(180, 138, 66, 0.5);
  border-radius: 18px;
  background: rgba(255, 250, 240, 0.72);
  box-shadow: var(--soft-shadow);
}
.endo-mini img {
  width: 74px;
  height: 74px;
  border-radius: 14px;
  object-fit: cover;
  object-position: center 22%;
  border: 1px solid rgba(180, 138, 66, 0.58);
}
.endo-mini strong {
  display: block;
  color: var(--red-dark);
  font-family: "Yu Mincho", serif;
  font-size: 16px;
}
.endo-mini span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.complete-dialog {
  width: min(720px, calc(100% - 28px));
  padding: 28px;
}

.complete-dialog::backdrop {
  background: rgba(22, 20, 18, 0.42);
}

.complete-dialog pre,
.completion-summary {
  max-height: 360px;
  overflow: auto;
  padding: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  font-size: 13px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 920px) {
  .chat-shell {
    grid-template-columns: 1fr;
  }

  .ai-rail {
    min-height: 0;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto;
    align-items: center;
  }
  .ai-rail nav,
  .ai-rail p { display: none; }

  .memo-panel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 640px) {
  .chat-shell {
    width: min(100% - 20px, 1180px);
    padding: 10px 0;
  }

  .chat-panel {
    min-height: 78vh;
  }

  .chat-header,
  .message-list,
  .memo-panel {
    padding: 18px;
  }

  .assistant-intro {
    grid-template-columns: 1fr;
    justify-items: start;
    gap: 14px;
  }

  .assistant-portrait {
    width: 82px;
    height: 82px;
  }

  .assistant-avatar {
    width: 76px;
    height: 76px;
  }

  h1 {
    max-width: 100%;
    font-size: 26px;
  }

  .chat-form {
    grid-template-columns: 1fr;
  }

  .chat-form button {
    min-height: 46px;
  }

  .message-row {
    max-width: 100%;
  }

  .message-avatar {
    width: 34px;
    height: 34px;
  }
}
