:root {
  --navy: #182848;
  --navy-2: #24375E;
  --navy-line: #3A4E78;
  --brass: #C9A227;
  --brass-dark: #8A6A12;
  --brass-text: #5A4306;
  --brass-soft: #FDF3D0;
  --cream: #E8D9A0;
  --ink: #1A2233;
  --muted: #5A6475;
  --on-navy-muted: #C8D2E6;
  --card: #FFFFFF;
  --line: #DCE2EA;
  --chip: #F4F6F8;
  --tile: #E9EEF0;
  --tile-line: #D5DDE1;
  --poo: #6B4226;
  --danger: #9A3412;
  --ok: #4ADE80;
  --radius: 16px;
  font-family: Nunito, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background-color: var(--tile);
  background-image: linear-gradient(var(--tile-line) 1px, transparent 1px), linear-gradient(90deg, var(--tile-line) 1px, transparent 1px);
  background-size: 32px 32px;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brass-text); }
h1, h2, h3, .display { font-family: Fredoka, Nunito, sans-serif; margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#app { max-width: 480px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }

/* Header */
.top {
  background: var(--navy); color: #fff; border-bottom: 4px solid var(--brass);
  padding: calc(env(safe-area-inset-top) + 16px) 16px 16px;
  display: flex; align-items: center; gap: 12px;
  position: sticky; top: 0; z-index: 5;
}
.top .titles { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.top h1 { font-size: 22px; }
.top .sub { font-size: 13px; color: var(--on-navy-muted); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--navy-line);
  background: var(--navy-2); color: #fff; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  text-decoration: none;
}

main { flex: 1; padding: 14px 16px 110px; display: flex; flex-direction: column; gap: 12px; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card.navy { background: var(--navy); color: #fff; border: 2px solid var(--brass); }
.card.brass { background: var(--brass-soft); border: 2px solid var(--brass); }
.card h2 { font-size: 17px; }
.label { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.navy .label { color: var(--cream); }
.muted { color: var(--muted); font-size: 13px; }
.navy .muted { color: var(--on-navy-muted); }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }

/* Dual flush */
.flush { display: grid; grid-template-columns: 1fr 1fr; border-radius: 22px; overflow: hidden; border: 3px solid var(--brass); box-shadow: 0 6px 0 var(--brass-dark); }
.flush button {
  min-height: 72px; border: 0; color: var(--navy); display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(#F3DE8A, var(--brass));
}
.flush button + button { border-left: 2px solid var(--brass-dark); background: linear-gradient(#E9CF6B, #B38D1A); }
.flush .big { font-family: Fredoka, sans-serif; font-weight: 700; font-size: 19px; }
.flush .small { font-size: 12px; font-weight: 700; }
.flush button:active { filter: brightness(.92); }

.btn {
  min-height: 48px; border-radius: 14px; border: 0; padding: 0 18px; font-weight: 800; font-size: 15px;
  background: var(--navy); color: var(--brass); display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
.btn.ghost { background: var(--chip); color: var(--ink); border: 1px solid var(--line); }
.btn.gold {
  background: linear-gradient(#F3DE8A, var(--brass)); color: var(--navy); border: 3px solid var(--brass-dark);
  box-shadow: 0 5px 0 var(--brass-dark); font-family: Fredoka, sans-serif; font-size: 19px; min-height: 58px; border-radius: 18px;
}
.btn.danger { background: #FDECE7; color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }

.input {
  min-height: 46px; border-radius: 14px; border: 1px solid #C8D0D8; background: #fff; padding: 0 14px; font-size: 16px; width: 100%; min-width: 0;
  color: var(--ink); /* never inherit white text from dark cards */
}
.input::placeholder { color: #6B7485; }
textarea.input { padding: 10px 14px; min-height: 70px; resize: vertical; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 36px; padding: 0 12px; border-radius: 18px; border: 1px solid transparent; background: var(--chip);
  font-size: 13px; font-weight: 700; display: inline-flex; align-items: center;
}
.chip[aria-pressed="true"] { background: var(--navy); color: #fff; font-weight: 800; }
.chip.tag[aria-pressed="true"] { background: var(--brass-soft); color: var(--brass-text); border-color: var(--brass); }

/* Segmented */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--navy-2); border-radius: 14px; padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--on-navy-muted); border-radius: 11px; min-height: 36px; font-weight: 700; font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--brass); color: var(--navy); font-weight: 800; }

/* Timer */
.timer { font-family: Fredoka, sans-serif; font-weight: 700; font-size: 60px; line-height: 1; color: var(--brass); font-variant-numeric: tabular-nums; }
.switch { width: 52px; height: 30px; border-radius: 15px; border: 0; background: var(--navy-line); padding: 3px; display: flex; justify-content: flex-start; }
.switch::after { content: ""; width: 24px; height: 24px; border-radius: 12px; background: #fff; }
.switch[aria-pressed="true"] { background: var(--ok); justify-content: flex-end; }

.stepper { display: flex; align-items: center; justify-content: space-between; }
.stepper button { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--chip); font-size: 22px; font-weight: 800; color: var(--navy); }
.stepper button.plus { background: var(--navy); color: var(--brass); border: 0; }
.stepper .val { font-family: Fredoka, sans-serif; font-weight: 700; font-size: 30px; }

.bristol { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.bristol button { height: 40px; border-radius: 8px; border: 0; background: var(--chip); font-weight: 800; }
.bristol button[aria-pressed="true"] { background: var(--poo); color: #fff; }

/* Stats */
.best { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; }
.best.hero { background: var(--navy); color: #fff; border: 2px solid var(--brass); }
.best .k { font-size: 11px; font-weight: 800; color: var(--muted); }
.best.hero .k { color: var(--cream); }
.best .v { font-family: Fredoka, sans-serif; font-weight: 700; font-size: 22px; font-variant-numeric: tabular-nums; }
.best.hero .v { color: var(--brass); }
.total { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px 4px; text-align: center; }
.total .v { font-family: Fredoka, sans-serif; font-weight: 700; font-size: 20px; display: block; }
.total .k { font-size: 11px; font-weight: 700; color: var(--muted); }

.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .wd { text-align: center; font-size: 10px; font-weight: 800; color: var(--muted); }
.cal .d { height: 34px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; background: #EEF1F4; color: var(--muted); }
.cal .d.l1 { background: #C8D2E6; color: var(--navy); }
.cal .d.l2 { background: #6B82AE; color: #fff; }
.cal .d.l3 { background: var(--navy); color: var(--brass); }
.cal .d.future { background: transparent; border: 1px dashed #C8D0D8; }
.cal .d.today { outline: 3px solid var(--brass); outline-offset: -1px; }
.cal .d.blank { background: transparent; }

/* Reactions */
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.react {
  min-height: 32px; min-width: 40px; padding: 0 8px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--chip); font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 3px; color: var(--ink);
}
.react b { font-size: 12px; }
.react[aria-pressed="true"] { background: var(--brass-soft); border-color: var(--brass); }
.react.add { color: var(--muted); }
.reacts.dark .react { background: var(--navy-2); border-color: var(--navy-line); color: #fff; }
.reacts.dark .react[aria-pressed="true"] { background: var(--brass); color: var(--navy); border-color: var(--brass); }
.reacts.dark .react.add { color: var(--on-navy-muted); }
img.avatar { display: inline-block; object-fit: cover; background: var(--chip); }

/* Any-emoji picker */
.emoji-more {
  flex-basis: 100%; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 2px;
  max-height: 180px; overflow-y: auto; padding: 6px; border-radius: 12px; background: #fff; border: 1px solid var(--line);
}
.emoji-more > button { border: 0; background: transparent; font-size: 22px; min-height: 40px; border-radius: 8px; }
.emoji-more > button:active { background: var(--chip); }
.reacts.dark .emoji-more { background: var(--navy-2); border-color: var(--navy-line); }

/* Cheers to whoever's on the throne */
.cheer { font-size: 14px; padding: 6px 10px; border-radius: 10px; background: #fff; border: 1px solid #EBD9A0; overflow-wrap: anywhere; }
.cheer.dark { background: var(--navy-2); border-color: var(--navy-line); color: #fff; }

/* Streak restore */
.restore { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; background: #FFF4E5; border: 1px solid #F5C08A; font-size: 14px; }

/* Tab badge */
.tab-badge {
  position: absolute; top: -2px; right: calc(50% - 22px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center;
}

/* Profiles */
.avatar-link { display: inline-flex; border-radius: 50%; flex-shrink: 0; }
.banner-preview { height: 72px; border-radius: 12px; border: 1px solid var(--line); }
.swatch { width: 44px; height: 32px; border-radius: 8px; border: 1px solid var(--line); }
.swatch[aria-pressed="true"] { outline: 3px solid var(--navy); outline-offset: 1px; }
.profile-banner { height: calc(env(safe-area-inset-top) + 150px); position: relative; border-bottom: 4px solid var(--brass); }
.profile-head { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: -52px; }
.profile-avatar { border-radius: 50%; border: 4px solid var(--brass); background: #fff; display: inline-flex; }
.tag-x { border: 0; background: transparent; margin-left: 4px; padding: 0 2px; font-size: 16px; font-weight: 900; color: var(--brass-text); min-width: 24px; min-height: 24px; }

/* Chat */
.chat-main { padding-bottom: 230px; gap: 10px; }
.chat-day { align-self: center; font-size: 11px; font-weight: 800; color: #3A4456; background: #fff; padding: 3px 10px; border-radius: 10px; }
.chat-row { display: flex; gap: 8px; align-items: flex-start; }
.chat-row.mine { justify-content: flex-end; }
.bubble { background: #fff; border-radius: 16px 16px 16px 4px; padding: 8px 12px; font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.mine { background: var(--navy); color: #fff; border-radius: 16px 16px 4px 16px; }
.bubble.ai { background: var(--brass-soft); border: 1px solid var(--brass); max-width: 78%; }
.bubble .who { display: block; font-size: 11px; font-weight: 800; color: var(--brass-text); }
.chat-visit { background: var(--navy); color: #fff; border: 2px solid var(--brass); border-radius: 16px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.chat-visit .muted { color: var(--on-navy-muted); }
.link-btn { border: 0; background: none; padding: 0 4px; min-height: 24px; font-size: 11px; font-weight: 800; color: var(--muted); }
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 66px); z-index: 6;
  background: #fff; border-top: 1px solid var(--line); padding: 6px 10px 8px; display: flex; flex-direction: column; gap: 6px;
  max-width: 480px; margin: 0 auto; overflow: hidden;
}
.emoji-row { display: flex; gap: 2px; overflow-x: auto; }
.emoji-row button { border: 0; background: transparent; font-size: 22px; min-width: 40px; min-height: 36px; border-radius: 10px; }
.emoji-row button:active { background: var(--chip); }

/* GIFs */
.gif-msg { position: relative; border-radius: 14px; overflow: hidden; max-width: 240px; background: var(--chip); }
.gif-msg img { display: block; width: 100%; height: auto; }
.gif-star {
  position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 16px; border: 0;
  background: rgba(24, 40, 72, .7); color: #fff; font-size: 17px; line-height: 1;
}
.gif-star[aria-pressed="true"] { background: var(--brass); color: var(--navy); }
.gif-panel { display: flex; flex-direction: column; gap: 8px; }
/* Two Discord-style columns; each GIF keeps its shape; the list scrolls inside a fixed-height box. */
.gif-scroll { height: 42vh; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.gif-grid { column-count: 2; column-gap: 6px; }
.gif-cell {
  position: relative; display: block; break-inside: avoid; -webkit-column-break-inside: avoid;
  margin: 0 0 6px; border-radius: 10px; overflow: hidden; background: var(--chip); min-height: 60px;
}
.gif-pick { border: 0; padding: 0; width: 100%; display: block; background: none; }
.gif-pick img { width: 100%; height: auto; display: block; }
.gif-cell .gif-star { top: 4px; right: 4px; width: 28px; height: 28px; font-size: 15px; }
.gif-empty { margin: 8px 0; text-align: center; }

/* Achievements */
.ach { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; background: var(--brass-soft); border: 1px solid var(--brass); }
.ach .ach-emoji { font-size: 26px; line-height: 1; flex-shrink: 0; }
.ach.locked { background: var(--chip); border-color: var(--line); }
.ach.locked .ach-emoji { filter: grayscale(1); opacity: .45; }
.ach.locked b { color: var(--muted); }

/* Lists */
.list { display: flex; flex-direction: column; }
.list .item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid #EEF1F4; }
.list .item:first-child { border-top: 0; }
.badge { padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 800; background: #FFF4E5; color: var(--danger); }
.avatar { width: 34px; height: 34px; border-radius: 17px; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; color: var(--navy); flex-shrink: 0; }
.kind-dot { width: 34px; height: 34px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 13px; flex-shrink: 0; }
.kind-dot.pee { background: #FDF3D0; color: var(--brass-text); }
.kind-dot.poo { background: #F1E7DF; color: #4A2D18; }

/* Bottom nav */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  background: #fff; border-top: 1px solid var(--line);
  padding: 8px 4px calc(env(safe-area-inset-bottom) + 10px);
}
.tabs .inner { max-width: 480px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 44px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 700; }
.tabs a[aria-current="page"] { color: var(--navy); font-weight: 800; }

/* Toast + banners */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 20;
  background: var(--navy); color: #fff; border: 2px solid var(--brass); border-radius: 14px;
  padding: 12px 16px; font-weight: 700; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(24, 40, 72, .3);
}
.banner { background: var(--brass-soft); border: 1px solid var(--brass); border-radius: 14px; padding: 10px 12px; font-size: 13px; color: var(--brass-text); font-weight: 700; }
.err { color: var(--danger); font-weight: 700; font-size: 13px; }

@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .35 } }
.pulse { width: 10px; height: 10px; border-radius: 5px; background: var(--ok); animation: pulse 1.4s ease-in-out infinite; }

@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }
