:root {
  color-scheme: light;
  --bg: #f5f5f5;
  --ink: #1f2428;
  --muted: #66706f;
  --panel: #ffffff;
  --line: #d9ddd8;
  --sent: #050505;
  --received: #dedede;
  --accent: #050505;
  --accent-dark: #2a2a2a;
  --danger: #aa3f3f;
  font-family: "Cascadia Code", "Cascadia Mono", "Consolas", "SFMono-Regular", "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f5f5 0%, #eceff3 48%, #f8f0ed 100%);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: .02em;
  min-height: 42px;
  padding: 0 16px;
  text-transform: uppercase;
}

button:hover {
  background: var(--accent-dark);
}

button.secondary,
.message-actions button {
  background: transparent;
  color: var(--accent-dark);
  border: 1px solid var(--line);
}

button.danger-button {
  background: var(--danger);
}

button.danger-button:hover {
  background: #873131;
}

input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 12px;
  width: 100%;
}

textarea {
  line-height: 1.35;
  max-height: 140px;
  min-height: 44px;
  overflow-y: auto;
  resize: none;
}

.app-shell {
  width: min(1100px, calc(100vw - 28px));
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
}

.hidden {
  display: none !important;
}

.entry {
  width: 100%;
}

.brand {
  display: grid;
  gap: 10px;
  margin-bottom: 28px;
}

.brand-title {
  align-items: center;
  display: flex;
  gap: 16px;
  min-width: 0;
}

.mark {
  align-items: center;
  background: var(--ink);
  border-radius: 8px;
  color: white;
  display: grid;
  font-size: 28px;
  font-weight: 800;
  height: 64px;
  place-items: center;
  width: 64px;
}

h1,
h2,
p {
  margin: 0;
}

.brand h1 {
  font-size: clamp(34px, 8vw, 72px);
  line-height: .95;
}

.brand p,
.chat-header p,
label,
.meta {
  color: var(--muted);
}

.entry-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel {
  background: rgba(255, 255, 255, .84);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 20px;
}

.ttl-row {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 86px;
}

.chat {
  background: rgba(255, 255, 255, .72);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: min(840px, calc(100vh - 28px));
  height: min(840px, calc(100dvh - 28px));
  overflow: hidden;
  width: min(920px, 100%);
}

.chat-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 16px;
}

.chat-header h1 {
  font-size: 22px;
}

.share-box {
  display: flex;
  gap: 8px;
}

.messages {
  align-content: end;
  display: grid;
  gap: 10px;
  list-style: none;
  margin: 0;
  overflow-y: auto;
  padding: 18px;
}

.message {
  display: grid;
  gap: 6px;
  max-width: min(72%, 560px);
}

.message.mine {
  justify-self: end;
}

.bubble {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  padding: 10px 12px;
}

.mine .bubble {
  background: var(--sent);
  border-color: #050505;
  color: #ffffff;
}

.theirs .bubble {
  background: var(--received);
  color: var(--ink);
}

.sender-label {
  border: 1px solid #b8b8b8;
  border-radius: 999px;
  color: #4e5656;
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  line-height: 1;
  padding: 3px 7px;
  text-transform: uppercase;
}

.mine .sender-label {
  background: #050505;
  border-color: #050505;
  color: #ffffff;
  justify-self: end;
}

.theirs .sender-label {
  background: #f2f2f2;
  border-color: #b8b8b8;
  color: #4e5656;
  justify-self: start;
}

.deleted .bubble {
  background: transparent;
  border-color: transparent;
  color: #9a9f9f;
  font-size: 12px;
  font-style: italic;
  padding: 2px 0;
}

.bubble p {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.bubble img,
.bubble video {
  border-radius: 6px;
  display: block;
  max-height: 360px;
  max-width: 100%;
}

.file-name {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.mine .file-name {
  color: #d6d6d6;
}

.meta {
  align-items: center;
  display: flex;
  font-size: 12px;
  gap: 8px;
}

.message-footer {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mine .message-footer {
  justify-content: flex-end;
}

.theirs .message-footer {
  justify-content: flex-start;
}

.message-actions {
  align-items: center;
  display: flex;
  gap: 4px;
}

.message-actions button {
  border-radius: 6px;
  font-size: 11px;
  min-height: 22px;
  padding: 0 6px;
}

.message-actions .danger {
  color: var(--danger);
}

.composer {
  align-items: end;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: 42px 58px 42px 1fr auto;
  padding: 12px;
  position: relative;
}

#attachButton {
  font-size: 24px;
  padding: 0;
}

#cameraButton {
  align-items: center;
  display: grid;
  justify-items: center;
  padding: 0;
}

#emojiButton {
  font-size: 13px;
  padding: 0;
}

.emoji-panel {
  background: #111111;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  bottom: calc(100% + 8px);
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(6, 34px);
  left: 112px;
  padding: 8px;
  position: absolute;
  z-index: 12;
}

.emoji-panel button {
  align-items: center;
  background: #050505;
  border: 1px solid #333333;
  border-radius: 6px;
  display: grid;
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  font-size: 18px;
  justify-items: center;
  min-height: 34px;
  padding: 0;
  text-transform: none;
}

.emoji-panel button:hover {
  background: #2a2a2a;
}

.camera-icon {
  border: 2px solid #ffffff;
  border-radius: 3px;
  display: block;
  height: 15px;
  position: relative;
  width: 22px;
}

.camera-icon::before {
  border: 2px solid #ffffff;
  border-radius: 50%;
  content: "";
  height: 6px;
  left: 50%;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 6px;
}

.camera-icon::after {
  background: #ffffff;
  border-radius: 50%;
  content: "";
  height: 3px;
  right: 3px;
  position: absolute;
  top: 3px;
  width: 3px;
}

.camera-panel {
  align-items: center;
  background: rgba(5, 5, 5, .72);
  display: grid;
  inset: 0;
  justify-items: center;
  padding: 18px;
  position: fixed;
  z-index: 20;
}

.camera-dialog {
  background: #111111;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 12px;
  width: min(720px, 100%);
}

.camera-dialog video {
  aspect-ratio: 4 / 3;
  background: #000000;
  border-radius: 6px;
  display: block;
  object-fit: cover;
  width: 100%;
}

.camera-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.app-footer {
  bottom: 8px;
  color: #8a9090;
  display: flex;
  font-size: 11px;
  gap: 10px;
  left: 50%;
  letter-spacing: .04em;
  pointer-events: none;
  position: fixed;
  transform: translateX(-50%);
  white-space: nowrap;
  z-index: 5;
}

.toast {
  background: var(--ink);
  border-radius: 8px;
  bottom: 20px;
  color: white;
  left: 50%;
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 20px);
  transition: opacity .2s ease, transform .2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 720px) {
  .app-shell {
    min-height: 100dvh;
    place-items: stretch;
    width: 100vw;
  }

  .chat {
    border-left: 0;
    border-radius: 0;
    border-right: 0;
    height: 100dvh;
    position: relative;
    z-index: 6;
  }

  .brand {
    gap: 8px;
  }

  .brand-title {
    gap: 12px;
  }

  .brand h1 {
    font-size: clamp(32px, 10vw, 42px);
  }

  .entry-grid,
  .chat-header {
    grid-template-columns: 1fr;
  }

  .entry-grid {
    display: grid;
  }

  .chat-header {
    align-items: stretch;
    display: grid;
  }

  .share-box {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .composer {
    align-items: stretch;
    grid-template-areas:
      "message message message message message"
      "attach camera emoji spacer send";
    grid-template-columns: 42px 54px 42px 1fr 76px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  #attachButton {
    grid-area: attach;
  }

  #cameraButton {
    grid-area: camera;
  }

  #emojiButton {
    grid-area: emoji;
  }

  #messageInput {
    font-size: 16px;
    grid-area: message;
    min-height: 56px;
  }

  .composer button[type="submit"] {
    grid-area: send;
  }

  .emoji-panel {
    grid-template-columns: repeat(3, 34px);
    left: 104px;
  }

  .message {
    max-width: 88%;
  }
}
