:root {
  color-scheme: light;
  --page: #e9e9e9;
  --panel: #f7f7f7;
  --panel-alt: #ededed;
  --ink: #111111;
  --muted: #626262;
  --line: #171717;
  --soft-line: #797979;
  --link: #001fa8;
  --online: #138923;
  --typing: #f0b400;
  --focus: #075dcc;
  --danger: #9b160d;
  --font-mono: "SFMono-Regular", "Cascadia Mono", "Roboto Mono",
    "Noto Sans Mono CJK JP", "BIZ UDGothic", "MS Gothic", Osaka-Mono, Menlo,
    Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 280px;
  min-height: 100%;
  background: var(--page);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  padding: clamp(10px, 2.1vw, 28px);
  color: var(--ink);
  background:
    linear-gradient(rgba(255, 255, 255, 0.36), rgba(255, 255, 255, 0.08)),
    repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.018) 0,
      rgba(0, 0, 0, 0.018) 1px,
      transparent 1px,
      transparent 4px
    ),
    var(--page);
  font-family: var(--font-mono);
  font-size: 16px;
  line-height: 1.45;
}

button,
input {
  font: inherit;
}

.chat-window {
  width: min(100%, 1280px);
  min-height: calc(100vh - clamp(20px, 4.2vw, 56px));
  min-height: calc(100dvh - clamp(20px, 4.2vw, 56px));
  margin: 0 auto;
  padding: 12px;
  border: 2px solid var(--line);
  background: rgba(247, 247, 247, 0.9);
  box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.08);
}

.title-bar {
  margin: -12px -12px 12px;
  padding: 4px 18px;
  border-bottom: 2px solid var(--line);
  background: linear-gradient(#f8f8f8, #e7e7e7);
}

.title-bar h1 {
  margin: 0;
  font-size: clamp(1.3rem, 2vw, 1.75rem);
  font-weight: 500;
  letter-spacing: 0.08em;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(280px, 1fr) auto auto;
  min-height: min(68vh, 680px);
}

.connection-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 5px 10px 9px;
  font-size: 1.02rem;
}

.connection-bar > span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.help-link {
  margin-left: auto;
  padding: 0;
  border: 0;
  color: var(--link);
  background: transparent;
  font: inherit;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}

.help-link:hover {
  text-decoration: underline;
}

.connection-light,
.typing-light {
  display: inline-block;
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-radius: 50%;
  background: var(--online);
  box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.14);
}

.chat-log {
  min-height: 280px;
  max-height: min(58vh, 590px);
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 2px solid var(--line);
  background: rgba(255, 255, 255, 0.44);
  scrollbar-color: #777 #ececec;
  scrollbar-width: thin;
}

.empty-log {
  display: grid;
  min-height: 100%;
  margin: 0;
  padding: 30px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.message {
  display: grid;
  grid-template-columns: 290px 126px minmax(0, 1fr) 82px;
  column-gap: 14px;
  align-items: start;
  padding: 7px 18px;
}

.message:first-child {
  padding-top: 14px;
}

.message:last-child {
  padding-bottom: 14px;
}

.message-meta {
  display: contents;
}

.message-time {
  grid-column: 1;
  grid-row: 1;
  color: var(--ink);
  white-space: nowrap;
}

.message-author {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  font-weight: 600;
}

.message-author::after {
  float: right;
  content: ":";
  color: var(--ink);
}

.message--user .message-author {
  color: var(--link);
}

.message-copy {
  grid-column: 3;
  grid-row: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-watermark {
  grid-column: 4;
  grid-row: 1;
  justify-self: end;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5rem;
  white-space: nowrap;
}

.message-badge {
  grid-column: 3 / 5;
  grid-row: 2;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.88rem;
}

.typing-status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  margin-top: -2px;
  padding: 5px 18px;
  border: 2px solid var(--line);
  border-top-style: dotted;
  background: var(--panel);
}

.typing-status[hidden] {
  display: none;
}

.typing-light {
  width: 16px;
  height: 16px;
  background: var(--typing);
  animation: typing-blink 620ms steps(1, end) infinite;
}

.typing-status time {
  white-space: nowrap;
}

.talk-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 14px;
  padding-top: 10px;
}

.talk-form input,
.talk-form button {
  min-height: 48px;
  border: 2px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: #fbfbfb;
}

.talk-form input {
  min-width: 0;
  padding: 8px 12px;
  box-shadow: inset 2px 2px 0 rgba(0, 0, 0, 0.08);
}

.talk-form input::placeholder {
  color: #666;
  opacity: 1;
}

.talk-form button {
  padding: 6px 18px;
  background: linear-gradient(#fafafa, #e3e3e3);
  box-shadow:
    inset 1px 1px 0 #fff,
    inset -2px -2px 0 #aaa;
  font-weight: 700;
  cursor: pointer;
}

.talk-form button:hover:not(:disabled) {
  background: linear-gradient(#fff, #ececec);
}

.talk-form button:active:not(:disabled) {
  box-shadow: inset 2px 2px 0 #aaa;
  transform: translate(1px, 1px);
}

.talk-form button:disabled,
.talk-form input:disabled {
  color: #777;
  cursor: wait;
}

.talk-form input:focus-visible,
.talk-form button:focus-visible,
.help-link:focus-visible,
.help-close:focus-visible,
.about-panel summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

.about-panel {
  margin-top: 12px;
  border: 2px solid var(--line);
  background: var(--panel);
}

.about-panel summary {
  padding: 5px 12px;
  border-bottom: 0;
  background: linear-gradient(#f6f6f6, #e4e4e4);
  cursor: pointer;
  font-size: 1rem;
  list-style-position: inside;
}

.about-panel[open] summary {
  border-bottom: 2px solid var(--line);
}

.about-copy {
  padding: 8px 14px 10px;
}

.about-copy p {
  margin: 0 0 4px;
}

.about-copy p:last-child {
  margin-bottom: 0;
}

.help-dialog {
  width: min(calc(100% - 32px), 640px);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: auto;
  border: 2px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 10px 10px 0 rgba(0, 0, 0, 0.24);
  font-family: var(--font-mono);
}

.help-dialog::backdrop {
  background: rgba(20, 20, 20, 0.46);
}

.help-window {
  min-width: 0;
}

.help-title-bar {
  padding: 6px 12px;
  border-bottom: 2px solid var(--line);
  color: #fff;
  background: linear-gradient(90deg, #073cb6, #002983);
}

.help-title-bar h2 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.help-content {
  padding: 18px;
}

.help-list {
  margin: 0;
  padding-left: 1.5rem;
}

.help-list li + li {
  margin-top: 6px;
}

.help-content h3 {
  margin: 20px 0 8px;
  padding-bottom: 3px;
  border-bottom: 1px dotted var(--soft-line);
  font-size: 1rem;
}

.help-definitions {
  margin: 0;
}

.help-definitions > div {
  display: grid;
  grid-template-columns: minmax(190px, auto) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  padding: 9px 0;
}

.help-definitions > div + div {
  border-top: 1px dotted var(--soft-line);
}

.help-definitions dt,
.help-definitions dd {
  margin: 0;
}

.help-watermark-sample,
.help-badge-sample {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--soft-line);
  background: #f9f9f9;
  font-size: 0.82rem;
  white-space: nowrap;
}

.help-privacy {
  margin: 16px 0 0;
  padding: 8px 10px;
  border: 1px solid var(--soft-line);
  background: var(--panel-alt);
  font-weight: 600;
}

.help-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

.help-close {
  min-width: 108px;
  min-height: 40px;
  padding: 5px 16px;
  border: 2px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: linear-gradient(#fafafa, #e3e3e3);
  box-shadow:
    inset 1px 1px 0 #fff,
    inset -2px -2px 0 #aaa;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.help-close:active {
  box-shadow: inset 2px 2px 0 #aaa;
  transform: translate(1px, 1px);
}

.notice {
  margin: 0;
  padding: 9px 18px;
  border-bottom: 1px dotted var(--soft-line);
  color: var(--danger);
}

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

@keyframes typing-blink {
  0%,
  49% {
    opacity: 1;
  }

  50%,
  100% {
    opacity: 0.28;
  }
}

@media (max-width: 760px) {
  body {
    padding: 8px;
    background: #f0f0f0;
    font-size: 15px;
  }

  .chat-window {
    min-height: calc(100dvh - 16px);
    padding: 8px;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .title-bar {
    margin: -8px -8px 12px;
    padding: 8px 14px;
    border: 0;
    color: #fff;
    background: linear-gradient(90deg, #073cb6, #002983);
  }

  .title-bar h1 {
    font-size: 1.28rem;
    font-weight: 600;
    letter-spacing: 0.14em;
  }

  .chat-panel {
    grid-template-rows: auto minmax(46vh, 1fr) auto auto;
    min-height: 0;
  }

  .connection-bar {
    padding: 1px 4px 7px;
    font-size: 0.77rem;
  }

  .connection-light {
    width: 11px;
    height: 11px;
  }

  .chat-log {
    min-height: 46vh;
    max-height: 58vh;
    border-width: 2px;
    background: rgba(255, 255, 255, 0.62);
  }

  .empty-log {
    padding: 20px 14px;
  }

  .message {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    row-gap: 8px;
    padding: 11px 12px 13px;
    border-bottom: 2px dashed var(--soft-line);
  }

  .message:first-child {
    padding-top: 11px;
  }

  .message:last-child {
    padding-bottom: 13px;
    border-bottom: 0;
  }

  .message-meta {
    display: flex;
    grid-column: 1;
    grid-row: 1;
    align-items: baseline;
    gap: 14px;
    min-width: 0;
  }

  .message-time,
  .message-author {
    display: inline;
    grid-column: auto;
  }

  .message-time .date-part {
    display: none;
  }

  .message-time::before {
    content: "[";
  }

  .message-time::after {
    content: "]";
  }

  .message-author::after {
    content: "";
  }

  .message-copy {
    grid-column: 1 / 3;
    grid-row: 2;
    padding-left: 18px;
    font-size: 1.02rem;
    line-height: 1.55;
  }

  .message-watermark {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
    padding: 0 5px;
    border: 1px solid var(--soft-line);
    color: var(--ink);
    font-size: 0.72rem;
    line-height: 1.45;
  }

  .message-badge {
    grid-column: 1 / 3;
    grid-row: 3;
    justify-self: start;
    margin: 0 0 0 18px;
    padding: 1px 6px;
    border: 1px solid var(--soft-line);
    color: var(--ink);
    font-size: 0.76rem;
  }

  .typing-status {
    min-height: 38px;
    margin-top: 10px;
    padding: 5px 10px;
    border-style: solid;
    color: var(--link);
  }

  .typing-light,
  .typing-status time {
    display: none;
  }

  .talk-form {
    grid-template-columns: minmax(0, 1fr) 84px;
    gap: 10px;
    padding-top: 10px;
  }

  .talk-form input,
  .talk-form button {
    min-height: 48px;
  }

  .talk-form input {
    padding-inline: 10px;
  }

  .talk-form button {
    padding-inline: 8px;
  }

  .about-panel {
    margin-top: 14px;
  }

  .about-panel summary {
    padding: 6px 8px;
    font-size: 0.9rem;
  }

  .about-copy {
    margin: 8px;
    padding: 8px 10px;
    border: 1px solid var(--soft-line);
    font-size: 0.9rem;
  }

  .about-copy p {
    margin-bottom: 12px;
  }

  .help-dialog {
    width: calc(100% - 16px);
    max-height: calc(100dvh - 16px);
    box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.24);
  }

  .help-content {
    padding: 14px;
    font-size: 0.9rem;
  }

  .help-definitions > div {
    display: block;
  }

  .help-definitions dd {
    margin-top: 6px;
  }

  .help-close {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .typing-light {
    animation: none;
  }
}
