/* Flokk — a small, warm app for a small group of friends.
 *
 * One stylesheet, no build step, CSS nesting. Every colour is a token defined
 * on :root and redefined for dark mode; nothing hardcodes a hex below the
 * token block.
 */

:root {
  --bg:            #f7f3ec;
  --surface:       #fffdfa;
  --surface-sunk:  #f0eae0;
  --line:          #e4dbcd;
  --ink:           #241f1a;
  --ink-soft:      #6b6158;
  --ink-faint:     #97897c;
  --accent:        #d2542b;
  --accent-ink:    #ffffff;
  --accent-soft:   #fbe9e1;
  --going:         #2f7d54;
  --maybe:         #b07d16;
  --declined:      #97897c;
  --danger:        #b3402a;

  --radius:    14px;
  --radius-sm: 9px;
  --radius-lg: 22px;
  --shadow:    0 1px 2px rgb(36 31 26 / 6%), 0 6px 18px rgb(36 31 26 / 6%);
  --shadow-sm: 0 1px 2px rgb(36 31 26 / 8%);

  --font: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
  --max:  760px;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #141210;
    --surface:       #1e1b18;
    --surface-sunk:  #262220;
    --line:          #332e29;
    --ink:           #f3ede4;
    --ink-soft:      #b1a698;
    --ink-faint:     #857a6d;
    --accent:        #f07a4d;
    --accent-ink:    #21120b;
    --accent-soft:   #3a241a;
    --going:         #6cc294;
    --maybe:         #dcac4b;
    --declined:      #857a6d;
    --danger:        #ef7b62;
    --shadow:        0 1px 2px rgb(0 0 0 / 40%), 0 6px 18px rgb(0 0 0 / 30%);
    --shadow-sm:     0 1px 2px rgb(0 0 0 / 45%);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 0.75em; }
p:last-child { margin-bottom: 0; }

/* --- Shell ------------------------------------------------------------- */

.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.top-bar__brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 1.1rem;
}
.top-bar__brand:hover { text-decoration: none; }

.brand-mark {
  width: 22px; height: 22px;
  border-radius: 7px;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #f2b544));
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--surface) 70%, transparent);
}

.top-bar__right { display: flex; align-items: center; gap: 10px; }

.main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 18px 16px 40px;
}

/* --- Flashes ----------------------------------------------------------- */

.flashes:empty { display: none; }
.flash {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 0.92rem;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.flash--alert { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); color: var(--danger); }

/* --- Buttons ----------------------------------------------------------- */

.btn, button, input[type="submit"] { font-family: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.94rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.12s ease, background 0.12s ease;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn:active { filter: brightness(0.95); }
.btn:disabled { opacity: 0.55; cursor: default; }

.btn--secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn--ghost { background: transparent; color: var(--ink-soft); border-color: transparent; }
.btn--ghost:hover { background: var(--surface-sunk); }
.btn--danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn--sm { padding: 5px 11px; font-size: 0.84rem; }
.btn--block { width: 100%; }

form.button_to { display: inline; }

/* --- Forms ------------------------------------------------------------- */

.field { margin-bottom: 14px; }
.field__label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 5px;
  letter-spacing: 0.01em;
}
.field__hint { font-size: 0.8rem; color: var(--ink-faint); margin-top: 5px; }

input[type="text"], input[type="email"], input[type="datetime-local"],
input[type="number"], textarea, select {
  width: 100%;
  padding: 10px 13px;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
textarea { resize: vertical; min-height: 80px; line-height: 1.45; }
input[type="file"] { font-size: 0.86rem; color: var(--ink-soft); }

.errors {
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.9rem;
}
.errors ul { margin: 0; padding-left: 18px; }

/* --- Cards & lists ------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.spacer { flex: 1; min-width: 0; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); font-size: 0.85rem; }
.tiny  { font-size: 0.78rem; }

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-soft);
}
.empty__title { font-weight: 600; color: var(--ink); margin-bottom: 4px; }
.empty__body { font-size: 0.92rem; }
.empty__action { margin-top: 16px; }

/* --- Avatars ------------------------------------------------------------ */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  object-fit: cover;
  flex: none;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: #fff;
  overflow: hidden;
}
.avatar--sm { width: 30px; height: 30px; font-size: 0.7rem; }
.avatar--md { width: 40px; height: 40px; font-size: 0.85rem; }
.avatar--lg { width: 64px; height: 64px; font-size: 1.25rem; }

/* One stable colour per person, picked from their id. */
.avatar--initials[data-hue="0"]  { background: #c4562f; }
.avatar--initials[data-hue="1"]  { background: #2f7d54; }
.avatar--initials[data-hue="2"]  { background: #3a6ea5; }
.avatar--initials[data-hue="3"]  { background: #8a4f9e; }
.avatar--initials[data-hue="4"]  { background: #b07d16; }
.avatar--initials[data-hue="5"]  { background: #2f7d7d; }
.avatar--initials[data-hue="6"]  { background: #a34464; }
.avatar--initials[data-hue="7"]  { background: #57692f; }
.avatar--initials[data-hue="8"]  { background: #6a5acd; }
.avatar--initials[data-hue="9"]  { background: #b3602a; }
.avatar--initials[data-hue="10"] { background: #38796b; }
.avatar--initials[data-hue="11"] { background: #8c5a3c; }

.avatar-stack { display: flex; }
.avatar-stack .avatar { margin-left: -8px; box-shadow: 0 0 0 2px var(--surface); }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* --- Sign in ------------------------------------------------------------ */

.gate {
  max-width: 400px;
  margin: 8vh auto 0;
  padding: 0 16px;
  text-align: center;
}
.gate__mark {
  width: 56px; height: 56px;
  border-radius: 18px;
  margin: 0 auto 18px;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 50%, #f2b544));
  box-shadow: var(--shadow);
}
.gate__title { font-size: 1.9rem; margin-bottom: 6px; }
.gate__lede { color: var(--ink-soft); margin-bottom: 26px; }
.gate form { text-align: left; }
.gate .card { text-align: left; }

/* --- Group list --------------------------------------------------------- */

.group-list { display: grid; gap: 10px; }

.group-card {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.group-card:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow); }
/* These are spans inside an <a>, so they need to be told to stack — and to
   be allowed to shrink, or a long description pushes the card wider than the
   screen. */
.group-card__body { display: block; min-width: 0; flex: 1; }
.group-card__name { display: block; font-weight: 650; }
.group-card__meta {
  display: block;
  font-size: 0.84rem;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.75rem;
  font-weight: 700;
}

/* --- Group header & tabs ------------------------------------------------ */

.group-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.group-head__name { font-size: 1.3rem; }
.group-head__meta { font-size: 0.84rem; color: var(--ink-faint); }

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-sunk);
  border-radius: 999px;
  margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1;
  text-align: center;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
}
.tab:hover { text-decoration: none; color: var(--ink); }
.tab[aria-current="page"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* --- Chat --------------------------------------------------------------- */

.chat { display: flex; flex-direction: column; gap: 2px; }

.chat__scroll {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 40vh;
  padding-bottom: 8px;
}

.msg {
  display: flex;
  gap: 10px;
  padding: 3px 0;
  align-items: flex-start;
}
.msg__avatar { padding-top: 2px; }
.msg__body { min-width: 0; flex: 1; }
.msg__head { display: flex; align-items: baseline; gap: 7px; }
.msg__author { font-weight: 650; font-size: 0.9rem; }
.msg__time { font-size: 0.74rem; color: var(--ink-faint); }
.msg__text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg__images { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.msg__images img { border-radius: var(--radius-sm); max-height: 240px; width: auto; }
.msg__tools { display: flex; align-items: flex-start; gap: 2px; }

/* Hidden until hovered on a mouse, but always there on a touch screen —
   there is nothing to hover with on a phone. */
@media (hover: hover) and (pointer: fine) {
  .msg__tools { opacity: 0; transition: opacity 0.1s ease; }
  .msg:hover .msg__tools,
  .msg:focus-within .msg__tools { opacity: 1; }
}
@media (hover: none) {
  .msg__tools { opacity: 0.5; }
}

/* Consecutive messages from the same person lose the avatar and the name —
   it reads as one person talking rather than a stack of business cards. */
.msg--continued .msg__avatar { visibility: hidden; height: 0; }
.msg--continued .msg__head { display: none; }

.composer {
  position: sticky;
  bottom: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0px));
  margin-top: 8px;
  border-top: 1px solid var(--line);
}
.composer form { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 160px; min-width: 0; }

/* --- Reactions ---------------------------------------------------------- */

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
/* A message nobody has reacted to must not reserve a line for the row that
   would have held them. */
.reactions:empty { display: none; }
.reaction {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 0.8rem;
  color: var(--ink-soft);
  cursor: pointer;
  line-height: 1.6;
}
.reaction:hover { background: var(--surface-sunk); }
.reaction--mine { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }

/* The picker sits in the message's tool strip. Closed it is one small glyph;
   open it drops a row of emoji below itself. */
.picker { position: relative; }
.picker__toggle {
  list-style: none;
  cursor: pointer;
  padding: 3px 7px;
  border-radius: 999px;
  color: var(--ink-faint);
  font-size: 0.9rem;
  line-height: 1.2;
}
.picker__toggle::-webkit-details-marker { display: none; }
.picker__toggle:hover { background: var(--surface-sunk); color: var(--ink); }
.picker__menu {
  position: absolute;
  right: 0;
  z-index: 5;
  display: flex;
  gap: 2px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.picker__option {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 4px 5px;
  border-radius: 999px;
}
.picker__option:hover { background: var(--surface-sunk); }

/* --- Events ------------------------------------------------------------- */

.event-card {
  display: flex;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.event-card:hover { text-decoration: none; box-shadow: var(--shadow); }
.event-card--cancelled .event-card__title { text-decoration: line-through; color: var(--ink-faint); }

.datechip {
  flex: none;
  width: 52px;
  text-align: center;
  padding: 7px 0;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
}
.datechip__month { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.datechip__day { font-size: 1.35rem; font-weight: 700; line-height: 1.05; }

/* Same story as the group card: spans inside a link. */
.event-card > .spacer { display: block; min-width: 0; }
.event-card__title { display: block; font-weight: 650; }
.event-card__meta { display: block; font-size: 0.84rem; color: var(--ink-faint); }

.rsvp { display: flex; gap: 6px; flex-wrap: wrap; }
.rsvp .btn { flex: 1; min-width: 92px; }
.rsvp__current { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.tally { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.86rem; }
.tally__going    { color: var(--going); font-weight: 650; }
.tally__maybe    { color: var(--maybe); font-weight: 650; }
.tally__declined { color: var(--declined); font-weight: 650; }

.responder-group { margin-bottom: 14px; }
.responder-group__label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  margin-bottom: 6px;
}
.responder { display: flex; align-items: center; gap: 8px; padding: 4px 0; }

/* --- Wall --------------------------------------------------------------- */

.post {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow-sm);
}
.post__head { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.post__author { font-weight: 650; font-size: 0.92rem; }
.post__time { font-size: 0.76rem; color: var(--ink-faint); }
.post__body { white-space: pre-wrap; overflow-wrap: anywhere; }
.post__images { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 6px; margin-top: 10px; }
.post__images img { border-radius: var(--radius-sm); width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.post__foot { display: flex; align-items: center; gap: 12px; margin-top: 10px; }

.comment { display: flex; gap: 9px; padding: 8px 0; border-top: 1px solid var(--line); }
.comment__body { min-width: 0; flex: 1; }
.comment__text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.94rem; }

/* --- Members ------------------------------------------------------------ */

.member-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.member-row:last-child { border-bottom: none; }
.member-row__name { font-weight: 600; }
.pill {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-sunk);
  color: var(--ink-soft);
}

.invite-code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  word-break: break-all;
  padding: 9px 12px;
  background: var(--surface-sunk);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

.capacity {
  height: 5px;
  border-radius: 999px;
  background: var(--surface-sunk);
  overflow: hidden;
}
.capacity__fill { height: 100%; background: var(--accent); border-radius: 999px; }

@media (max-width: 480px) {
  .page-head { flex-direction: column; align-items: stretch; }
  .main { padding: 14px 14px 32px; }
}
