/* ============================================================
   The Matrix — our Township co-op. Sunny farm/town theme.
   Bright skies, cream wooden cards, warm rounded type.
   ============================================================ */
:root {
  /* softened sky — gentler on the eyes than full-saturation blue */
  --sky-top: #aed6ea;
  --sky-bot: #e3eef0;
  --sky-horizon: #e9f3da;
  --grass: #6cc24a;
  --grass-d: #4ea73b;

  /* warm creams instead of stark white, so reading/typing isn't blinding */
  --card: #fdf7ec;
  --panel: #fbf2e0;
  --panel-2: #f7ecd6;
  --tan: #e7d4b4;
  --tan-d: #d4b88e;
  --surface-read: #fbf4e6;   /* the big message panel */
  --surface-input: #fffdf6;  /* text fields */
  --card-hi: #ffffff;        /* top highlight on cards */
  --cloud-opacity: 0.8;

  --ink: #4a3526;
  --ink-soft: #8a7864;
  --ink-faint: #b6a690;

  --barn: #e0563f;
  --barn-d: #c33f2c;
  --leaf: #4ea73b;
  --leaf-d: #3f8f2e;
  --gold: #f5a623;
  --gold-d: #e08e12;
  --sun: #ffd23f;
  --sky-blue: #3fa9f5;
  --brown: #b07a4f;

  --radius: 20px;
  --radius-sm: 13px;
  --shadow: 0 12px 26px -12px rgba(120, 86, 50, 0.4);
  --shadow-lg: 0 22px 50px -18px rgba(90, 64, 36, 0.5);
  --ring: 0 0 0 4px rgba(78, 167, 59, 0.18);

  --ui: "Fredoka", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Fredoka", var(--ui);

  --t-fast: 140ms cubic-bezier(0.34, 1.56, 0.64, 1);
  --t: 260ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* [hidden] must beat class-level display so screens/modals hide correctly. */
[hidden] { display: none !important; }
html, body { height: 100%; width: 100%; overflow-x: hidden; }
/* dynamic viewport height handles the mobile address bar growing/shrinking */
@supports (height: 100dvh) { html, body { height: 100dvh; } }
body {
  font-family: var(--ui);
  font-weight: 400;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bot) 62%, var(--sky-horizon) 100%);
  background-attachment: fixed;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}
button, input { font-family: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
::selection { background: rgba(245, 166, 35, 0.3); }

/* rolling green field along the bottom of the whole page */
body::after {
  content: ""; position: fixed; left: 0; right: 0; bottom: 0; height: 26vh;
  z-index: 0; pointer-events: none;
  background:
    radial-gradient(120% 80% at 20% 100%, var(--grass-d) 0 40%, transparent 41%),
    radial-gradient(120% 70% at 80% 100%, var(--grass-d) 0 40%, transparent 41%),
    linear-gradient(180deg, transparent 0, var(--grass) 55%);
  -webkit-mask: linear-gradient(180deg, transparent 0, #000 45%);
  mask: linear-gradient(180deg, transparent 0, #000 45%);
  opacity: 0.9;
}

#rain { position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: var(--cloud-opacity); transition: opacity var(--t); }
#scanlines { display: none; }

/* cream wooden card */
.glass {
  background: var(--card);
  border: 2px solid var(--tan);
  box-shadow: var(--shadow), inset 0 2px 0 var(--card-hi);
}

/* ============================================================
   AUTH
   ============================================================ */
.auth { position: relative; z-index: 2; min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(400px, 100%); border-radius: var(--radius); padding: 36px 30px 26px; animation: pop-in var(--t) both; }
.auth-brand { text-align: center; margin-bottom: 24px; }
.logo-glyph { display: inline-block; font-size: 52px; line-height: 1; animation: bob 3s ease-in-out infinite; }
.logo-glyph.small { font-size: 30px; }
.auth-brand h1 {
  font-family: var(--display); font-weight: 700; letter-spacing: 1px;
  font-size: 34px; margin-top: 8px; color: var(--leaf-d);
  text-shadow: 0 2px 0 #fff, 0 3px 0 rgba(120, 86, 50, 0.15);
}
.tagline { color: var(--gold-d); font-size: 13px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; margin-top: 4px; }

.seg {
  display: flex; gap: 5px; padding: 5px; background: var(--panel-2);
  border: 2px solid var(--tan); border-radius: 14px; margin-bottom: 22px;
}
.seg-btn {
  flex: 1; padding: 10px 12px; border-radius: 10px; color: var(--ink-soft);
  font-weight: 600; font-size: 15px; transition: var(--t-fast);
}
.seg-btn.active { background: linear-gradient(180deg, #6fd04f, var(--leaf)); color: #fff; box-shadow: 0 3px 0 var(--leaf-d); }
.seg-btn:not(.active):hover { color: var(--ink); background: #fff; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.field input[type="text"], .field input[type="password"] {
  width: 100%; padding: 13px 15px; font-size: 16px; font-weight: 500;
  background: var(--surface-input); color: var(--ink); border: 2px solid var(--tan);
  border-radius: var(--radius-sm); transition: var(--t-fast);
}
.field input::placeholder { color: var(--ink-faint); font-weight: 400; }
.field input:focus { outline: none; border-color: var(--leaf); box-shadow: var(--ring); }

.btn-primary {
  width: 100%; padding: 15px; margin-top: 6px; font-family: var(--display);
  font-weight: 600; font-size: 17px; color: #fff;
  background: linear-gradient(180deg, #ffc24d, var(--gold));
  border-radius: var(--radius-sm); box-shadow: 0 5px 0 var(--gold-d); transition: var(--t-fast);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 7px 0 var(--gold-d); }
.btn-primary:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--gold-d); }
.btn-primary:disabled { opacity: 0.65; cursor: wait; }

.auth-error { color: var(--barn-d); font-weight: 600; font-size: 13.5px; min-height: 18px; margin: 4px 0 6px; }
.auth-hint { text-align: center; color: var(--ink-faint); font-size: 13px; margin-top: 14px; }

/* ============================================================
   APP SHELL
   ============================================================ */
.app { position: relative; z-index: 2; height: 100%; display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 14px; padding: 14px; }

.sidebar {
  display: flex; flex-direction: column; gap: 12px; min-height: 0;
  background: var(--card); border: 2px solid var(--tan);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow), inset 0 2px 0 var(--card-hi);
}
.side-head { display: flex; align-items: center; gap: 12px; padding: 4px 6px 10px; border-bottom: 2px dashed var(--tan); }
.side-head strong { font-family: var(--display); font-weight: 700; letter-spacing: 0.5px; font-size: 17px; color: var(--leaf-d); display: block; }
.side-head small { color: var(--gold-d); font-size: 12px; font-weight: 600; }

.roster { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding-right: 4px; }
.roster-group-label { font-size: 11px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase; margin: 2px 4px 6px; }
.roster-item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 12px; transition: var(--t-fast); }
.roster-item:hover { background: var(--panel); }
.roster-item .avatar { width: 36px; height: 36px; }
.roster-name { font-weight: 600; font-size: 14.5px; line-height: 1.1; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--leaf); box-shadow: 0 0 0 3px rgba(78,167,59,0.2); flex-shrink: 0; }

.avatar {
  width: 42px; height: 42px; border-radius: 50%; object-fit: cover;
  background: linear-gradient(180deg, #bfe8ff, #eaf8ff);
  border: 2px solid #fff; box-shadow: 0 2px 6px -2px rgba(120,86,50,0.4); flex-shrink: 0;
}
.avatar.xl { width: 88px; height: 88px; border-width: 3px; }

.me-card { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: var(--radius-sm); background: var(--panel); border: 2px solid var(--tan); }
.me-meta { flex: 1; min-width: 0; }
.me-meta strong { display: block; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-meta small { color: var(--ink-soft); font-size: 12px; font-weight: 500; }

.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; color: var(--ink-soft); font-size: 18px; background: #fff; border: 2px solid var(--tan); transition: var(--t-fast); flex-shrink: 0; }
.icon-btn:hover { background: var(--panel-2); color: var(--ink); transform: translateY(-1px); }

/* ---- chat ---- */
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; gap: 12px; }
.chat-head {
  display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-radius: var(--radius);
  background: linear-gradient(180deg, #6fd04f, var(--leaf)); border: 2px solid var(--leaf-d);
  box-shadow: var(--shadow), inset 0 2px 0 rgba(255,255,255,0.35); color: #fff;
}
.chat-title { font-family: var(--display); font-weight: 700; font-size: 19px; display: flex; align-items: baseline; gap: 8px; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-shadow: 0 1px 0 rgba(0,0,0,0.12); }
.chat-actions { flex-shrink: 0; }
.chat-title .hash { opacity: 0.85; }
.chat-title em { font-style: normal; color: rgba(255,255,255,0.85); font-size: 13px; font-weight: 500; }
.chat-actions { display: flex; gap: 8px; align-items: center; }
.ghost-btn { padding: 9px 15px; border-radius: 11px; font-weight: 600; font-size: 14px; color: var(--gold-d); border: 2px solid #fff; background: #fff; box-shadow: 0 3px 0 rgba(120,86,50,0.18); transition: var(--t-fast); }
.ghost-btn:hover { transform: translateY(-1px); background: #fffdf6; }
.chat-actions .icon-btn { background: rgba(255,255,255,0.9); border-color: rgba(255,255,255,0.6); }
.menu-btn { display: none; }   /* hamburger — mobile only */
.side-scrim { display: none; } /* dim backdrop behind the mobile members panel */

.messages {
  flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; padding: 14px;
  background: var(--surface-read); border: 2px solid var(--tan); border-radius: var(--radius); box-shadow: var(--shadow), inset 0 2px 0 var(--card-hi);
  -webkit-overflow-scrolling: touch;
}

.msg { display: flex; gap: 12px; padding: 8px 10px; border-radius: 14px; transition: background var(--t-fast); }
.msg:hover { background: var(--panel); }
.msg.grouped { padding-top: 1px; padding-bottom: 1px; }
.msg.grouped .msg-avatar { visibility: hidden; height: 0; }
.msg.grouped .msg-head { display: none; }
.msg-avatar { width: 42px; }
.msg-body { flex: 1; min-width: 0; }
.msg-head { display: flex; align-items: baseline; gap: 9px; margin-bottom: 2px; flex-wrap: wrap; }
.msg-name { font-weight: 700; font-size: 15px; }
.msg-time { font-size: 11.5px; color: var(--ink-faint); font-weight: 500; }
.msg-text { font-size: 15px; font-weight: 450; line-height: 1.5; color: var(--ink); word-wrap: break-word; overflow-wrap: anywhere; }
.msg-text.emoji-only { font-size: 42px; line-height: 1.2; }

.badge {
  display: inline-flex; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.2px;
  padding: 2px 9px; border-radius: 999px; text-transform: uppercase; color: #fff; line-height: 1.5;
  background: var(--badge-c, var(--leaf)); box-shadow: 0 2px 0 rgba(0,0,0,0.12);
}
.badge .b-ic { font-size: 11px; }

.msg-sticker { font-size: 78px; line-height: 1; padding: 4px 0; animation: pop-in var(--t) both; }
.msg-gif img { max-width: 280px; max-height: 220px; border-radius: 14px; border: 3px solid #fff; box-shadow: var(--shadow); display: block; }

.msg-gift { display: inline-flex; align-items: center; gap: 12px; padding: 12px 18px; border-radius: 16px; margin-top: 3px; background: var(--panel-2); border: 2px solid var(--gold); }
.msg-gift .g-ic { font-size: 36px; animation: bob 2s ease-in-out infinite; }
.msg-gift .g-txt { font-size: 14px; font-weight: 500; }
.msg-gift .g-txt b { font-weight: 700; }

.sys-line { text-align: center; font-size: 12.5px; color: var(--ink-faint); font-weight: 600; padding: 8px; }

.typing-line { height: 16px; padding: 0 18px; font-size: 12.5px; color: var(--leaf-d); font-weight: 600; }
.typing-line .dots span { animation: blink 1.2s infinite; }
.typing-line .dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-line .dots span:nth-child(3) { animation-delay: 0.4s; }

.composer { position: relative; display: flex; align-items: center; gap: 8px; padding: 11px 12px; border-radius: var(--radius); background: var(--card); border: 2px solid var(--tan); box-shadow: var(--shadow), inset 0 2px 0 var(--card-hi); }
.tray-anchor { display: flex; gap: 3px; }
.tray-btn { width: 40px; height: 40px; border-radius: 12px; font-size: 19px; display: grid; place-items: center; color: var(--ink-soft); background: var(--panel); border: 2px solid var(--tan); transition: var(--t-fast); font-weight: 700; }
.tray-btn[data-tray="gif"] { font-size: 12px; letter-spacing: 0.3px; color: var(--barn); }
.tray-btn:hover { background: var(--panel-2); transform: translateY(-2px); }
.tray-btn.gift:hover { border-color: var(--gold); }
#composer-input { flex: 1; min-width: 0; padding: 13px 15px; font-size: 16px; font-weight: 500; background: var(--surface-input); border: 2px solid var(--tan); border-radius: 13px; transition: var(--t-fast); }
#composer-input:focus { outline: none; border-color: var(--leaf); box-shadow: var(--ring); }
.send-btn { width: 46px; height: 46px; border-radius: 13px; font-size: 19px; color: #fff; background: linear-gradient(180deg, #ffc24d, var(--gold)); box-shadow: 0 4px 0 var(--gold-d); display: grid; place-items: center; transition: var(--t-fast); }
.send-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--gold-d); }
.send-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--gold-d); }

/* ---- tray popover ---- */
.tray-pop {
  position: absolute; bottom: calc(100% + 12px); left: 12px; width: min(380px, calc(100vw - 40px)); max-height: 340px;
  border-radius: var(--radius); overflow: hidden; background: var(--card); border: 2px solid var(--tan-d);
  box-shadow: var(--shadow-lg); animation: pop-in var(--t-fast) both; display: flex; flex-direction: column; z-index: 30;
}
.tray-pop .pop-head { padding: 11px 15px; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); letter-spacing: 0.5px; text-transform: uppercase; border-bottom: 2px dashed var(--tan); }
.tray-grid { padding: 10px; overflow-y: auto; display: grid; gap: 4px; }
.tray-grid.emoji { grid-template-columns: repeat(8, 1fr); }
.tray-grid.sticker { grid-template-columns: repeat(5, 1fr); }
.tray-grid.gift { grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 12px; }
.tray-cell { aspect-ratio: 1; display: grid; place-items: center; font-size: 23px; border-radius: 11px; transition: var(--t-fast); }
.tray-cell:hover { background: var(--panel-2); transform: scale(1.15); }
.tray-grid.sticker .tray-cell { font-size: 35px; }
.gift-cell { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 13px; border: 2px solid var(--tan); background: var(--panel); transition: var(--t-fast); text-align: left; }
.gift-cell:hover { border-color: var(--gold); transform: translateY(-2px); box-shadow: var(--shadow); }
.gift-cell .gc-ic { font-size: 30px; }
.gift-cell .gc-name { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.gif-pane { padding: 12px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.gif-pane input { width: 100%; padding: 11px 13px; background: var(--surface-input); color: var(--ink); border: 2px solid var(--tan); border-radius: 11px; font-size: 16px; }
.gif-pane input:focus { outline: none; border-color: var(--leaf); }
.gif-preview { display: grid; place-items: center; min-height: 60px; }
.gif-preview img { max-width: 100%; max-height: 160px; border-radius: 11px; }
.gif-note { font-size: 12px; color: var(--ink-faint); line-height: 1.5; }

/* ============================================================
   CHAT POWER FEATURES — reactions, replies, edit/delete, mentions
   ============================================================ */
.chat { position: relative; }
.msg { position: relative; }
.msg-actions {
  position: absolute; top: -12px; right: 10px; display: flex; gap: 2px;
  background: var(--card); border: 2px solid var(--tan); border-radius: 12px; padding: 2px;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(4px);
  transition: var(--t-fast); z-index: 6;
}
.msg:hover .msg-actions, .msg.show-actions .msg-actions { opacity: 1; pointer-events: auto; transform: none; }
.msg-action { width: 32px; height: 32px; border-radius: 8px; font-size: 15px; display: grid; place-items: center; transition: var(--t-fast); }
.msg-action:hover { background: var(--panel-2); transform: scale(1.1); }

.reactions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.reactions:empty { display: none; }
.reaction-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; padding: 2px 9px; border-radius: 999px; border: 2px solid var(--tan); background: var(--panel); transition: var(--t-fast); line-height: 1.6; }
.reaction-chip b { font-weight: 700; font-size: 12px; color: var(--ink-soft); }
.reaction-chip:hover { transform: translateY(-1px); }
.reaction-chip.mine { background: rgba(78, 167, 59, 0.16); border-color: var(--leaf); }
.reaction-chip.mine b { color: var(--leaf-d); }

.react-pop { position: fixed; z-index: 95; display: flex; gap: 2px; padding: 6px; background: var(--card); border: 2px solid var(--tan-d); border-radius: 14px; box-shadow: var(--shadow-lg); animation: pop-in var(--t-fast) both; }
.rp-emoji { width: 34px; height: 34px; border-radius: 9px; font-size: 19px; display: grid; place-items: center; transition: var(--t-fast); }
.rp-emoji:hover { background: var(--panel-2); transform: scale(1.25); }

.reply-quote { display: flex; gap: 8px; align-items: baseline; margin-bottom: 4px; padding: 3px 10px; border-left: 3px solid var(--leaf); background: var(--panel); border-radius: 0 8px 8px 0; font-size: 12.5px; cursor: pointer; max-width: 100%; overflow: hidden; }
.reply-quote:hover { background: var(--panel-2); }
.rq-name { font-weight: 700; color: var(--leaf-d); flex-shrink: 0; }
.rq-snip { color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.msg-edited { font-size: 11px; color: var(--ink-faint); font-weight: 500; }
.msg-text a { color: var(--sky-blue); text-decoration: underline; word-break: break-all; }
.mention { color: var(--leaf-d); font-weight: 700; background: rgba(78, 167, 59, 0.12); padding: 0 3px; border-radius: 5px; }
.mention.me { color: var(--gold-d); background: rgba(245, 166, 35, 0.2); }
.msg.mentions-me { background: rgba(245, 166, 35, 0.08); box-shadow: inset 3px 0 0 var(--gold); }
.msg.flash { animation: flashRow 1.2s ease; }

.composer-ctx { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 14px; border-radius: 13px 13px 0 0; margin-bottom: -4px; background: var(--panel-2); border: 2px solid var(--tan); border-bottom: none; font-size: 13px; color: var(--ink-soft); }
.composer-ctx .ctx-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-ctx .ctx-label b { color: var(--leaf-d); }
.composer-ctx .ctx-label em { font-style: italic; }
.ctx-x { width: 26px; height: 26px; border-radius: 8px; flex-shrink: 0; color: var(--ink-soft); font-size: 14px; }
.ctx-x:hover { background: var(--card); color: var(--barn-d); }

.scroll-bottom { position: absolute; right: 18px; bottom: 92px; z-index: 20; width: 44px; height: 44px; border-radius: 50%; font-size: 20px; color: #fff; background: linear-gradient(180deg, #ffc24d, var(--gold)); box-shadow: 0 5px 0 var(--gold-d), var(--shadow); display: grid; place-items: center; transition: var(--t-fast); }
.scroll-bottom:hover { transform: translateY(-2px); }
.sb-count { position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; background: var(--barn); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--card); }

@keyframes flashRow { 0%, 100% { background: transparent; } 30% { background: rgba(245, 166, 35, 0.22); } }

/* ============================================================
   MODALS
   ============================================================ */
.modal-back { position: fixed; inset: 0; z-index: 60; background: rgba(74, 53, 38, 0.4); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 20px; animation: fade var(--t-fast) both; }
.modal { width: min(440px, 100%); max-height: 86vh; border-radius: var(--radius); display: flex; flex-direction: column; animation: pop-in var(--t) both; background: var(--card); border: 2px solid var(--tan-d); box-shadow: var(--shadow-lg); }
.modal.wide { width: min(720px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 2px dashed var(--tan); }
.modal-head h2 { font-family: var(--display); font-size: 19px; font-weight: 700; color: var(--leaf-d); }
.modal-body { padding: 22px; overflow-y: auto; }

.perk-avatar { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.perk-avatar-side { display: flex; flex-direction: column; gap: 6px; }
.perk-hint { font-size: 12px; color: var(--ink-faint); }
.avatar-presets { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 8px; }
.avatar-presets .preset { aspect-ratio: 1; border-radius: 14px; overflow: hidden; cursor: pointer; border: 3px solid transparent; transition: var(--t-fast); padding: 0; line-height: 0; }
.avatar-presets .preset img { width: 100%; height: 100%; display: block; }
.avatar-presets .preset:hover { transform: translateY(-3px) scale(1.04); }
.avatar-presets .preset.sel { border-color: var(--leaf); box-shadow: 0 4px 0 var(--leaf-d); }
@media (max-width: 520px) { .avatar-presets { grid-template-columns: repeat(4, 1fr); } }

.btn-mini { display: inline-block; padding: 9px 15px; font-size: 13.5px; font-weight: 600; border-radius: 11px; color: #fff; cursor: pointer; background: linear-gradient(180deg, #6fd04f, var(--leaf)); box-shadow: 0 3px 0 var(--leaf-d); transition: var(--t-fast); }
.btn-mini:hover { transform: translateY(-1px); }
.btn-mini.ghost { color: var(--ink-soft); background: #fff; border: 2px solid var(--tan); box-shadow: none; margin-top: 8px; }
.color-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.swatch { width: 28px; height: 28px; border-radius: 9px; cursor: pointer; border: 3px solid #fff; box-shadow: 0 2px 5px -1px rgba(120,86,50,0.4); transition: var(--t-fast); }
.swatch:hover, .swatch.sel { transform: scale(1.15); box-shadow: 0 0 0 2px var(--leaf); }
#set-color { width: 100%; height: 40px; background: #fff; border: 2px solid var(--tan); border-radius: 11px; cursor: pointer; }

.admin-tabs { margin: 16px 22px 0; }
.admin-pane { display: flex; flex-direction: column; gap: 8px; }
.admin-row { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 14px; border: 2px solid var(--tan); background: var(--panel); }
.admin-row .avatar { width: 38px; height: 38px; }
.admin-row .ar-meta { flex: 1; min-width: 0; }
.admin-row .ar-meta strong { font-size: 14.5px; font-weight: 600; }
.admin-row .ar-meta small { display: block; color: var(--ink-faint); font-size: 11.5px; }
.role-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.role-chip { font-size: 10.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; border: 2px solid currentColor; cursor: pointer; opacity: 0.45; transition: var(--t-fast); display: inline-flex; gap: 3px; align-items: center; }
.role-chip.on { opacity: 1; color: #fff !important; }
.role-chip:hover { opacity: 0.8; }
.ar-actions { display: flex; gap: 6px; }
.mini-act { padding: 7px 11px; font-size: 12.5px; font-weight: 600; border-radius: 10px; border: 2px solid var(--tan); background: #fff; color: var(--ink-soft); transition: var(--t-fast); }
.mini-act:hover { color: var(--ink); border-color: var(--tan-d); }
.mini-act.danger:hover { color: var(--barn-d); border-color: var(--barn); }

.role-editor { display: grid; grid-template-columns: 1fr 90px 70px 64px auto; gap: 8px; align-items: center; padding: 10px; border: 2px solid var(--tan); border-radius: 14px; margin-bottom: 8px; background: var(--panel); }
.role-editor input[type="text"] { padding: 9px 11px; background: #fff; border: 2px solid var(--tan); border-radius: 9px; font-size: 13px; }
.role-editor input[type="color"] { width: 100%; height: 36px; border: 2px solid var(--tan); background: #fff; border-radius: 9px; }
.role-editor input[type="number"] { padding: 9px; background: #fff; border: 2px solid var(--tan); border-radius: 9px; font-size: 13px; width: 100%; }
.add-role-btn { width: 100%; padding: 12px; margin-top: 6px; border-radius: 12px; border: 2px dashed var(--leaf); color: var(--leaf-d); font-weight: 700; background: var(--panel); transition: var(--t-fast); }
.add-role-btn:hover { background: var(--panel-2); }

/* ============================================================
   OVERLAYS: gifts + toast
   ============================================================ */
#gift-layer { position: fixed; inset: 0; z-index: 80; pointer-events: none; overflow: hidden; }
.gift-fly { position: absolute; bottom: -120px; font-size: 90px; filter: drop-shadow(0 6px 10px rgba(120,86,50,0.4)); animation: giftFloat 4.2s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.gift-banner { position: fixed; top: 22%; left: 50%; transform: translateX(-50%); z-index: 81; pointer-events: none; display: flex; align-items: center; gap: 14px; padding: 16px 26px; border-radius: 20px; background: var(--card); border: 3px solid var(--gold); box-shadow: var(--shadow-lg); animation: bannerPop 3s ease forwards; }
.gift-banner .gb-ic { font-size: 52px; }
.gift-banner .gb-txt { font-size: 15px; font-weight: 500; color: var(--ink); }
.gift-banner .gb-txt b { font-family: var(--display); font-weight: 700; color: var(--leaf-d); }

#toast-wrap { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { padding: 12px 20px; border-radius: 14px; font-size: 14px; font-weight: 600; background: var(--card); border: 2px solid var(--tan-d); box-shadow: var(--shadow-lg); animation: pop-in var(--t-fast) both; color: var(--ink); }
.toast.err { border-color: var(--barn); color: var(--barn-d); }
.toast.ok { border-color: var(--leaf); color: var(--leaf-d); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--tan-d); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--brown); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes blink { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
@keyframes giftFloat {
  0% { transform: translateY(0) scale(0.4) rotate(-8deg); opacity: 0; }
  15% { opacity: 1; transform: translateY(-30vh) scale(1.2) rotate(4deg); }
  70% { opacity: 1; }
  100% { transform: translateY(-115vh) scale(0.9) rotate(-6deg); opacity: 0; }
}
@keyframes bannerPop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.8); }
  12%, 80% { opacity: 1; transform: translateX(-50%) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) scale(0.96); }
}

/* ============================================================
   NIGHT THEME — easy on the eyes for late reading + texting
   ============================================================ */
[data-theme="night"] {
  --sky-top: #15233c;
  --sky-bot: #1d2f47;
  --sky-horizon: #1b3326;
  --grass: #2f5a34;
  --grass-d: #244829;
  --card: #243349;
  --panel: #2a3a52;
  --panel-2: #32435e;
  --tan: #3a4d6a;
  --tan-d: #4b5f80;
  --surface-read: #1f2c41;
  --surface-input: #2b3b54;
  --card-hi: rgba(255, 255, 255, 0.05);
  --cloud-opacity: 0.06;
  --ink: #eae0cd;
  --ink-soft: #aab4c6;
  --ink-faint: #7d8799;
  --gold-d: #d99e36;
  --leaf-d: #61bd4a;
  --shadow: 0 12px 26px -12px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 22px 50px -18px rgba(0, 0, 0, 0.72);
  --ring: 0 0 0 4px rgba(97, 189, 74, 0.28);
}
[data-theme="night"] body { background-blend-mode: normal; }
[data-theme="night"] .avatar { border-color: rgba(255, 255, 255, 0.18); }
[data-theme="night"] .chat-head { border-color: var(--leaf-d); }

/* ============================================================
   RESPONSIVE  (Android / iOS)
   ============================================================ */
@media (max-width: 820px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    max-width: 100vw;
    overflow: hidden;
    padding: calc(8px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right))
             calc(8px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
  }
  .menu-btn { display: grid; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(84vw, 300px); z-index: 60;
    transform: translateX(-105%); transition: transform var(--t); border-radius: 0 var(--radius) var(--radius) 0;
    padding-top: calc(14px + env(safe-area-inset-top));
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  .sidebar.open { transform: none; }
  .side-scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(35, 24, 12, 0.45); backdrop-filter: blur(2px); }
  .chat-head { padding: 12px 14px; }
  .chat-title { font-size: 17px; }
  .chat-title em { display: none; }
  .composer { padding: 11px 10px calc(11px + env(safe-area-inset-bottom)); }
  /* finger-friendly hit targets */
  .tray-btn, .icon-btn, .send-btn { min-width: 44px; min-height: 44px; }
  .tray-cell { min-height: 40px; }
  .msg-gif img { max-width: 220px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
  #rain { display: none; }
}
