:root {
  --head: #99ccff;
  --head-second: #bfbfdf;
  --accent: #007bd1;
  --link: #0000ff;
  --visited: #800080;
  --danger: #cc0000;
  --text: #000000;
  --muted: #555555;
  --paper: #ffffff;
  --rule: #d6e6f5;
  --code-bg: #f4f6f8;
  --font: "Hiragino Kaku Gothic ProN", "Hiragino Kaku Gothic Pro", "Meiryo", "Yu Gothic", "MS PGothic", Osaka, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 100%;
}

body {
  margin: 0;
  padding: 0 0 16px;
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  background-color: #ffffff;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 27px, #e8f1fb 27px, #e8f1fb 28px);
}

a {
  color: var(--link);
}

a:visited {
  color: var(--visited);
}

hr {
  border: 0;
  border-top: 2px groove #c8c8c8;
  margin: 8px 12px;
}

button,
select,
textarea {
  font-family: inherit;
  font-size: 100%;
}

.offscreen {
  position: fixed;
  left: -9999px;
  top: 0;
}

.masthead {
  text-align: center;
  padding: 10px 12px 2px;
}

.masthead h1,
.masthead h2 {
  margin: 0;
  padding: 0;
}

.toptitle {
  font-size: xx-large;
  font-weight: bold;
  line-height: 1.3;
}

.subtitle {
  font-size: small;
  font-weight: bold;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 12px;
  width: 95%;
  margin: 12px auto;
  height: calc(100dvh - 190px);
  min-height: 520px;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--paper);
  border: 1px solid var(--accent);
  border-radius: 10px;
  overflow: hidden;
}

.category {
  flex: none;
  padding: 6px 12px;
  background: var(--head);
  font-weight: bold;
}

.panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
}

.panel-foot {
  flex: none;
  border-top: 1px solid var(--rule);
  padding: 8px 10px;
}

.btn {
  display: inline-block;
  padding: 6px 14px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: #ffffff;
  color: var(--accent);
  cursor: pointer;
  line-height: 1.3;
}

.btn:hover:not(:disabled) {
  background: #e8f3ff;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  color: #ffffff;
}

.btn.primary:hover:not(:disabled) {
  background: #005f9f;
}

.btn.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.btn.primary.danger {
  background: var(--danger);
  color: #ffffff;
}

.btn.small {
  padding: 3px 10px;
  font-size: 85%;
}

.btn.block {
  display: block;
  width: 100%;
  text-align: center;
}

.conversation-list {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
}

.conv {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: 6px;
}

.conv:hover {
  background: #f0f7ff;
}

.conv.active {
  background: var(--head);
}

.conv-open {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}

.conv-title {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.conv-date {
  display: block;
  font-size: 75%;
  color: var(--muted);
}

.conv-action {
  flex: none;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  visibility: hidden;
}

.conv:hover .conv-action,
.conv:focus-within .conv-action,
.conv.active .conv-action {
  visibility: visible;
}

.conv-action:hover {
  background: #ffffff;
  color: var(--text);
}

.conv-empty {
  padding: 8px;
  color: var(--muted);
  font-size: 90%;
}

.fold summary {
  cursor: pointer;
  list-style: none;
}

.fold summary::-webkit-details-marker {
  display: none;
}

.readmore {
  color: var(--link);
  font-size: 90%;
}

.fold[open] .readmore {
  display: none;
}

.fold-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 8px;
}

.hint {
  margin: 0;
  font-size: 80%;
  color: var(--muted);
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

[hidden] {
  display: none !important;
}

.toggle {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: normal;
  font-size: 90%;
  cursor: pointer;
  user-select: none;
}

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

.model-label {
  flex: none;
  font-weight: normal;
  font-size: 90%;
}

.model-label select {
  max-width: 180px;
  padding: 2px 4px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: #ffffff;
}

#sidebar-toggle {
  display: none;
}

.warning {
  flex: none;
  margin: 0;
  padding: 6px 12px;
  background: #fff3cd;
  border-bottom: 1px solid #e6cf7a;
  font-size: 90%;
}

.messages {
  flex: 1;
  min-height: 0;
  padding: 14px 16px;
  overflow-y: auto;
}

.welcome {
  max-width: 640px;
  margin: 6vh auto 0;
  text-align: center;
}

.welcome h3 {
  margin: 0 0 6px;
  font-size: 140%;
}

.welcome p {
  margin: 0 0 14px;
  color: var(--muted);
}

.examples {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}

.example {
  padding: 8px 12px;
  border: 1px solid var(--head-second);
  border-radius: 8px;
  background: #f7f7fc;
  cursor: pointer;
  text-align: left;
}

.example:hover {
  background: var(--head-second);
}

.msg {
  max-width: 860px;
  margin: 0 auto 16px;
  border: 1px solid var(--head-second);
  border-radius: 10px;
  overflow: hidden;
  background: #ffffff;
}

.msg.user {
  border-color: var(--head);
}

.msg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 10px;
  background: var(--head-second);
  font-size: 85%;
  font-weight: bold;
}

.msg.user .msg-head {
  background: var(--head);
}

.role-tag {
  flex: 1;
}

.msg-actions {
  display: flex;
  gap: 6px;
}

.msg-actions .btn {
  padding: 1px 8px;
  font-weight: normal;
}

.msg-body {
  padding: 10px 14px;
  overflow-wrap: anywhere;
}

.msg.user .msg-body {
  white-space: pre-wrap;
}

.msg.streaming .msg-body:empty::after {
  content: "考え中…";
  color: var(--muted);
  animation: blink 1.2s ease-in-out infinite;
}

.msg.streaming .msg-body > :last-child::after {
  content: "▍";
  margin-left: 1px;
  color: var(--accent);
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  50% {
    opacity: 0.2;
  }
}

.error-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 860px;
  margin: 0 auto 16px;
  padding: 8px 12px;
  border: 1px solid var(--danger);
  border-radius: 10px;
  background: #fff0f0;
  color: var(--danger);
}

.error-banner span {
  flex: 1;
}

.md > :first-child {
  margin-top: 0;
}

.md > :last-child {
  margin-bottom: 0;
}

.md p {
  margin: 0 0 0.8em;
  white-space: pre-wrap;
}

.md h1,
.md h2,
.md h3,
.md h4,
.md h5,
.md h6 {
  margin: 1.1em 0 0.5em;
  line-height: 1.35;
}

.md h1 {
  font-size: 150%;
}

.md h2 {
  font-size: 130%;
  border-bottom: 1px solid var(--rule);
}

.md h3 {
  font-size: 115%;
}

.md h4,
.md h5,
.md h6 {
  font-size: 100%;
}

.md ul,
.md ol {
  margin: 0 0 0.8em;
  padding-left: 1.6em;
}

.md li {
  margin: 0.2em 0;
}

.md li > ul,
.md li > ol {
  margin: 0.2em 0;
}

.md li > p {
  margin: 0 0 0.4em;
}

.md blockquote {
  margin: 0 0 0.8em;
  padding: 2px 12px;
  border-left: 4px solid var(--head);
  color: var(--muted);
}

.md hr {
  margin: 1em 0;
}

.md code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: 90%;
}

.codeblock {
  margin: 0 0 0.9em;
  border: 1px solid var(--rule);
  border-radius: 8px;
  overflow: hidden;
  background: var(--code-bg);
}

.codeblock-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 10px;
  background: var(--rule);
  font-size: 80%;
  font-family: var(--mono);
}

.codeblock pre {
  margin: 0;
  padding: 10px 12px;
  overflow-x: auto;
}

.codeblock pre code {
  padding: 0;
  background: transparent;
  font-size: 88%;
  line-height: 1.5;
}

.table-wrap {
  margin: 0 0 0.9em;
  overflow-x: auto;
}

.md table {
  border-collapse: collapse;
  min-width: 50%;
}

.md th,
.md td {
  padding: 4px 10px;
  border: 1px solid var(--head-second);
  text-align: left;
}

.md th {
  background: #eef5ff;
}

.md .align-center {
  text-align: center;
}

.md .align-right {
  text-align: right;
}

.composer {
  flex: none;
  padding: 10px 12px;
  border-top: 1px solid var(--rule);
  background: #fafcff;
}

.composer .fold {
  margin-bottom: 8px;
  font-size: 90%;
}

.composer-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.composer textarea,
.fold-body textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: #ffffff;
  line-height: 1.5;
  resize: none;
}

#prompt {
  flex: 1;
  max-height: 200px;
}

#send-btn {
  flex: none;
  min-width: 72px;
  padding: 9px 16px;
}

.composer-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-height: 1.3em;
  font-size: 80%;
  color: var(--muted);
}

.composer-meta .over {
  color: var(--danger);
  font-weight: bold;
}

.footer {
  width: 95%;
  margin: 0 auto;
  font-size: 85%;
}

.footer p {
  margin: 4px 0;
}

.privacy {
  padding: 8px 12px;
  background: var(--head-second);
  border-radius: 8px;
}

.copyright {
  color: var(--muted);
  text-align: center;
}

.legal-links {
  text-align: center;
}

.doc {
  width: 95%;
  max-width: 860px;
  margin: 12px auto;
  background: var(--paper);
  border: 1px solid var(--accent);
  border-radius: 10px;
  overflow: hidden;
}

.doc-body {
  padding: 8px 20px 20px;
}

.doc h2 {
  margin: 1.6em 0 0.4em;
  padding: 3px 10px;
  background: var(--head);
  font-size: 105%;
  border-radius: 4px;
}

.doc p,
.doc li {
  margin: 0.4em 0;
}

.doc ol,
.doc ul {
  margin: 0.4em 0;
  padding-left: 1.6em;
}

.doc-meta {
  color: var(--muted);
  font-size: 90%;
}

.doc-nav {
  width: 95%;
  max-width: 860px;
  margin: 0 auto 16px;
  text-align: center;
  font-size: 90%;
}

.masthead a {
  color: inherit;
  text-decoration: none;
}

.todo {
  color: var(--danger);
  font-weight: bold;
}

@media (max-width: 800px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    height: calc(100dvh - 150px);
    min-height: 460px;
    gap: 8px;
  }

  .sidebar {
    display: none;
    max-height: 42dvh;
  }

  .sidebar.open {
    display: flex;
  }

  #sidebar-toggle {
    display: inline-block;
  }

  .toptitle {
    font-size: large;
    overflow-wrap: anywhere;
  }

  .model-label {
    font-size: 80%;
  }

  .model-label select {
    max-width: 110px;
  }

  .conv-action {
    visibility: visible;
  }
}
