:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f7f7f2;
  --panel: #ffffff;
  --panel-2: #eeefe8;
  --line: #d8d9d0;
  --muted: #6d7066;
  --text: #20221d;
  --accent: #84b82f;
  --accent-dark: #52781b;
  --danger: #b4233c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 0%, rgb(163 230 53 / 24%), transparent 32rem),
    var(--bg);
  color: var(--text);
}

button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }

button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .65rem .9rem;
  background: var(--panel-2);
  color: var(--text);
}

button:hover:not(:disabled) { border-color: #a5a79d; transform: translateY(-1px); }
button:disabled { cursor: not-allowed; opacity: .45; }
.primary { background: var(--accent); color: #182109; border-color: var(--accent); font-weight: 750; }
.danger { color: var(--danger); }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
  padding: .7rem .8rem;
  outline: none;
}

input:focus, select:focus, textarea:focus { border-color: var(--accent-dark); box-shadow: 0 0 0 3px rgb(82 120 27 / 12%); }
a { color: var(--accent-dark); }

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 2rem;
}

.login-card {
  width: min(520px, 100%);
  padding: clamp(2rem, 7vw, 4.5rem);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgb(255 255 255 / 92%);
  box-shadow: 0 28px 90px rgb(47 52 38 / 14%);
}

.eyebrow { color: var(--accent-dark); font-size: .76rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
.login-card h1 { font-size: clamp(2.6rem, 10vw, 5rem); line-height: .9; letter-spacing: -.07em; margin: 1rem 0; }
.login-card p { color: var(--muted); line-height: 1.6; }
.github-login { display: inline-flex; margin-top: 1rem; text-decoration: none; background: var(--text); color: #fff; padding: .85rem 1.1rem; border-radius: 12px; font-weight: 750; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 330px 1fr; }
.shell.anonymous { grid-template-columns: 1fr; }
.sidebar { border-right: 1px solid var(--line); padding: 1.2rem; background: rgb(255 255 255 / 82%); display: flex; flex-direction: column; gap: 1rem; }
.brand-row, .profile, .section-title, .room-header, .message-meta, .permission-row { display: flex; align-items: center; }
.brand-row, .section-title, .room-header { justify-content: space-between; gap: 1rem; }
.brand { font-size: 1.25rem; font-weight: 850; letter-spacing: -.04em; }
.profile { gap: .7rem; border: 1px solid var(--line); border-radius: 14px; padding: .7rem; }
.profile img, .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--panel-2); }
.profile-copy { min-width: 0; flex: 1; }
.profile-copy strong, .profile-copy small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-copy small { color: var(--muted); }
.icon-button { padding: .45rem .6rem; }
.room-list { display: flex; flex-direction: column; gap: .6rem; overflow-y: auto; }
.room-card { text-align: left; padding: .9rem; background: transparent; }
.room-card.active { border-color: var(--accent-dark); background: rgb(132 184 47 / 13%); }
.room-card strong { display: block; margin-bottom: .5rem; }
.badges { display: flex; flex-wrap: wrap; gap: .3rem; }
.badge { display: inline-flex; align-items: center; padding: .18rem .45rem; border-radius: 999px; background: var(--panel-2); color: var(--muted); font-size: .68rem; }
.badge.public { color: var(--accent-dark); }

.empty, .loading { color: var(--muted); padding: 2rem; text-align: center; }
.workspace { min-width: 0; display: flex; flex-direction: column; height: 100vh; }
.welcome { margin: auto; text-align: center; color: var(--muted); max-width: 32rem; padding: 2rem; }
.room-header { padding: 1rem 1.4rem; border-bottom: 1px solid var(--line); }
.room-header h2 { margin: 0; letter-spacing: -.035em; }
.room-header p { margin: .15rem 0 0; color: var(--muted); font-size: .85rem; }
.room-actions { display: flex; align-items: center; gap: .75rem; }
.connection { font-size: .75rem; color: var(--muted); }
.connection.live { color: var(--accent-dark); }
.chat-grid { min-height: 0; flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 310px; }
.chat-main { min-height: 0; display: flex; flex-direction: column; }
.messages { min-height: 0; flex: 1; overflow-y: auto; padding: 1.2rem max(1.2rem, calc((100% - 760px) / 2)); }
.message { display: grid; grid-template-columns: 36px 1fr; gap: .7rem; margin: 1rem 0; }
.message-body { min-width: 0; }
.message-meta { gap: .5rem; margin-bottom: .25rem; }
.message-meta time { color: var(--muted); font-size: .72rem; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.attachment { display: inline-flex; flex-direction: column; margin-top: .55rem; padding: .65rem .8rem; border: 1px solid var(--line); border-radius: 10px; text-decoration: none; max-width: 100%; }
.attachment span { color: var(--muted); font-size: .72rem; margin-top: .2rem; }
.composer { border-top: 1px solid var(--line); padding: 1rem max(1rem, calc((100% - 760px) / 2)); }
.composer textarea { resize: vertical; min-height: 46px; max-height: 180px; }
.composer-actions { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin-top: .65rem; }
.file-picker { min-width: 0; color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-picker input { display: none; }
.anonymous-cta { border-top: 1px solid var(--line); padding: 1rem max(1rem, calc((100% - 760px) / 2)); display: flex; align-items: center; justify-content: space-between; gap: 1rem; color: var(--muted); }
.primary-link, .header-login { display: inline-flex; align-items: center; border-radius: 9px; padding: .5rem .72rem; text-decoration: none; font-weight: 750; white-space: nowrap; }
.primary-link { background: var(--accent); color: #182109; }
.header-login { border: 1px solid var(--line); background: var(--panel); color: var(--text); }

.access-panel { border-left: 1px solid var(--line); padding: 1rem; overflow-y: auto; background: rgb(255 255 255 / 58%); }
.access-panel h3 { margin-bottom: .3rem; }
.access-panel > p { color: var(--muted); font-size: .82rem; line-height: 1.45; }
.public-toggle { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .8rem 0; border-block: 1px solid var(--line); }
.public-toggle input { width: auto; }
.public-toggle strong, .public-toggle small { display: block; }
.public-toggle small { color: var(--muted); margin-top: .15rem; }
.invite { display: grid; gap: .5rem; padding: 1rem 0; }
.invite-controls { display: grid; grid-template-columns: 1fr 94px; gap: .5rem; }
.permission-list { display: grid; gap: .55rem; }
.permission-row { gap: .55rem; }
.permission-row img { width: 28px; height: 28px; border-radius: 50%; }
.permission-user { min-width: 0; flex: 1; }
.permission-user strong, .permission-user small { display: block; overflow: hidden; text-overflow: ellipsis; }
.permission-user small { color: var(--muted); }
.permission-row select { width: 92px; padding: .45rem; font-size: .78rem; }
.viewer-note { margin-top: 1rem; padding: .8rem; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); font-size: .82rem; }

.modal-backdrop { position: fixed; inset: 0; display: grid; place-items: center; background: rgb(31 35 25 / 42%); padding: 1rem; z-index: 10; }
.modal { width: min(430px, 100%); border: 1px solid var(--line); border-radius: 18px; background: var(--panel); padding: 1.2rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }
#toast { position: fixed; right: 1rem; bottom: 1rem; max-width: min(420px, calc(100vw - 2rem)); padding: .8rem 1rem; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s; z-index: 20; }
#toast.show { opacity: 1; transform: translateY(0); }
#toast.error { border-color: #e0a0aa; background: #fff1f3; color: #8f1730; }

@media (max-width: 850px) {
  .shell { grid-template-columns: 250px 1fr; }
  .chat-grid { grid-template-columns: 1fr; }
  .access-panel { display: none; }
}

@media (max-width: 620px) {
  .shell { display: block; }
  .sidebar { min-height: 100vh; border-right: 0; }
  .shell.room-open .sidebar { display: none; }
  .workspace { display: none; }
  .shell.room-open .workspace { display: flex; }
  .mobile-back { display: inline-flex !important; }
}

.mobile-back { display: none; }
