:root {
  --bg0: #14201c;
  --bg1: #1a2a24;
  --ink: #e8f0ea;
  --muted: #8aa094;
  --line: rgba(232, 240, 234, 0.12);
  --accent: #6fbf9a;
  --mine: #2a4a3c;
  --theirs: #24302b;
  --danger: #d98b7a;
  --radius: 18px;
  --font: "IBM Plex Sans KR", system-ui, sans-serif;
  --display: "Syne", "IBM Plex Sans KR", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, #243a32 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #1e322c 0%, transparent 50%),
    var(--bg0);
  color: var(--ink);
  font-family: var(--font);
}

body {
  min-height: 100dvh;
}

.hidden {
  display: none !important;
}

#app {
  min-height: 100dvh;
}

.view {
  min-height: 100dvh;
}

.brand,
.brand-sm {
  font-family: var(--display);
  letter-spacing: -0.03em;
  margin: 0;
}

.brand {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--accent);
}

.brand-sm {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
}

.login-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2rem max(1.4rem, 4vw) 3rem;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  animation: rise 0.55s ease both;
  box-sizing: border-box;
}

.login-title {
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  margin: 1.4rem 0 0.4rem;
}

.login-sub {
  margin: 0 0 1.6rem;
  color: var(--muted);
  line-height: 1.5;
}

.login-form {
  display: grid;
  gap: 0.75rem;
}

.login-form input,
.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border-radius: 14px;
  padding: 0.95rem 1rem;
  font: inherit;
  outline: none;
}

.login-form input:focus,
.composer textarea:focus {
  border-color: rgba(111, 191, 154, 0.55);
}

.login-form button,
.composer button {
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #102018;
  font: inherit;
  font-weight: 600;
  padding: 0.95rem 1rem;
  cursor: pointer;
}

.error {
  margin-top: 0.9rem;
  color: var(--danger);
  font-size: 0.92rem;
}

#view-chat {
  display: grid;
  grid-template-rows: auto 1fr auto auto auto;
  height: 100dvh;
  width: 100%;
  max-width: none;
  margin: 0;
}

.chat-header {
  position: relative;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(20, 32, 28, 0.92);
  backdrop-filter: blur(10px);
}

.whoami {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.header-actions {
  display: flex;
  align-items: center;
  position: relative;
}

.menu-wrap {
  position: relative;
}

.menu-trigger {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.menu-trigger[aria-expanded="true"] {
  border-color: rgba(111, 191, 154, 0.45);
  background: rgba(111, 191, 154, 0.12);
}

.menu-dots,
.menu-dots::before,
.menu-dots::after {
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  position: relative;
}

.menu-dots::before,
.menu-dots::after {
  content: "";
  position: absolute;
  left: 0;
}

.menu-dots::before {
  top: -7px;
}

.menu-dots::after {
  top: 7px;
}

.chat-menu {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  width: min(240px, calc(100vw - 1.5rem));
  padding: 0.45rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #17241f;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  z-index: 50;
  display: grid;
  gap: 0.2rem;
  animation: pop 0.16s ease both;
}

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.55rem 0.65rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.menu-row select {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  font: inherit;
  font-size: 0.8rem;
  max-width: 7rem;
}

.menu-item {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  width: 100%;
  border-radius: 10px;
  padding: 0.7rem 0.75rem;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.menu-item:hover,
.menu-item:focus-visible {
  background: rgba(255, 255, 255, 0.06);
  outline: none;
}

.menu-item.danger {
  color: var(--danger);
}

.menu-item.is-on {
  color: var(--accent);
}

.account-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(8, 14, 12, 0.72);
}

.account-card {
  width: min(420px, 100%);
  background: #1a2a24;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.2rem;
  animation: pop 0.2s ease both;
}

.account-card h2 {
  margin: 0;
  font-size: 1.2rem;
}

.account-sub {
  margin: 0.4rem 0 1rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.account-form {
  display: grid;
  gap: 0.75rem;
}

.account-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.account-form input {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  font: inherit;
}

.account-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

.account-save {
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #102018;
  font: inherit;
  font-weight: 600;
  padding: 0.65rem 1rem;
  cursor: pointer;
}

.account-ok {
  margin: 0;
  color: var(--accent);
  font-size: 0.88rem;
}

.ghost {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.45rem 0.75rem;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}

.ghost.danger {
  color: var(--danger);
  border-color: rgba(217, 139, 122, 0.35);
}

.messages {
  position: relative;
  z-index: 1;
  overflow-y: auto;
  padding: 1rem 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.msg {
  max-width: min(88%, 560px);
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius);
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  animation: pop 0.22s ease both;
}

.msg.has-media {
  max-width: min(92%, 640px);
  white-space: normal;
}

.msg.mine {
  align-self: flex-end;
  background: var(--mine);
  border-bottom-right-radius: 6px;
}

.msg.theirs {
  align-self: flex-start;
  background: var(--theirs);
  border-bottom-left-radius: 6px;
}

.msg .meta {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 0.35rem;
}

.attach {
  margin-top: 0.2rem;
}

.attach img,
.attach video {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  border-radius: 12px;
  background: #0d1612;
}

.attach-image-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
  border-radius: 12px;
  overflow: hidden;
}

.attach video {
  object-fit: contain;
  background: #000;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.92);
  display: grid;
  grid-template-rows: auto 1fr;
}

.lightbox-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  padding: 0.7rem 0.8rem;
  background: rgba(0, 0, 0, 0.45);
}

.lightbox-btn {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-radius: 10px;
  padding: 0.45rem 0.75rem;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  min-width: 42px;
}

.lightbox-stage {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  touch-action: none;
}

.lightbox-stage img {
  max-width: min(96vw, 100%);
  max-height: calc(100dvh - 64px);
  object-fit: contain;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
  cursor: grab;
}

.lightbox-stage img:active {
  cursor: grabbing;
}

.file-card {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.2);
  color: inherit;
  text-decoration: none;
}

.file-icon {
  flex-shrink: 0;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.35rem 0.4rem;
  border-radius: 8px;
  background: rgba(111, 191, 154, 0.2);
  color: var(--accent);
}

.file-meta {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
}

.file-meta strong {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta small {
  color: var(--muted);
  font-size: 0.75rem;
}

.attach-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 1rem 0;
  border-top: 1px solid var(--line);
  background: rgba(20, 32, 28, 0.92);
}

.attach-preview-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.attach-preview img,
.attach-preview video {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
  background: #0d1612;
}

.attach-file-info {
  color: var(--muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attach-clear {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  flex-shrink: 0;
}

.composer {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 0.55rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(20, 32, 28, 0.92);
  width: 100%;
  box-sizing: border-box;
}

.emoji-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  color: var(--accent);
  background: transparent;
  cursor: pointer;
  align-self: end;
  user-select: none;
}

.emoji-btn[aria-expanded="true"] {
  border-color: rgba(111, 191, 154, 0.55);
  background: rgba(111, 191, 154, 0.12);
}

.emoji-panel {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0.25rem;
  padding: 0.65rem 0.75rem;
  border-top: 1px solid var(--line);
  background: rgba(20, 32, 28, 0.96);
  max-height: 180px;
  overflow-y: auto;
  width: 100%;
  box-sizing: border-box;
}

.emoji-panel button {
  appearance: none;
  border: 0;
  background: transparent;
  border-radius: 10px;
  font-size: 1.45rem;
  line-height: 1.2;
  padding: 0.35rem 0;
  cursor: pointer;
}

.emoji-panel button:hover,
.emoji-panel button:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  outline: none;
}

@media (min-width: 720px) {
  .emoji-panel {
    grid-template-columns: repeat(12, minmax(0, 1fr));
  }

  .messages {
    padding-left: max(1rem, 4vw);
    padding-right: max(1rem, 4vw);
  }

  .chat-header,
  .composer,
  .attach-preview,
  .emoji-panel {
    padding-left: max(1rem, 4vw);
    padding-right: max(1rem, 4vw);
  }
}

.attach-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  color: var(--accent);
  cursor: pointer;
  align-self: end;
  user-select: none;
}

.composer textarea {
  resize: none;
  max-height: 120px;
  line-height: 1.4;
}

.composer button[type="submit"] {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  padding: 0;
  font-size: 1.2rem;
  align-self: end;
}

.empty {
  margin: auto;
  color: var(--muted);
  text-align: center;
  padding: 2rem 1rem;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
