/* Colour tokens for light and dark. Load before every page stylesheet. */
:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-logo: "Instrument Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --card: #FFFFFF;
  --ink: #16181D;
  --muted: #5B6170;
  --placeholder: #8A909C;
  --soft: #F3F4F1;
  --soft-hover: #E8E9E5;
  --line: #ECEDEA;
  --border: #D5D8DD;
  --border-soft: #E3E5E0;
  --green: #14A35E;
  --green-dark: #0E7A45;     /* accent text, links, icons */
  --green-tint: #E7F5EE;
  --accent: #0E7A45;         /* button fill */
  --accent-hover: #0B6639;
  --on-accent: #FFFFFF;
  --panel: #16181D;
  --panel-text: #FFFFFF;
  --panel-shape: #232730;
  --error: #C2361A;
  --danger: #B3301A;
  --danger-border: #F0C9BF;
  --danger-soft: #FDF1EE;
  --switch-off: #CDD1D6;
  --shadow: rgba(22, 24, 29, .12);
  --radius: 8px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0F1114;
  --surface: #171A1F;
  --card: #1E2228;
  --ink: #ECEEF0;
  --muted: #9AA1AD;
  --placeholder: #6E7581;
  --soft: #1C2026;
  --soft-hover: #252A31;
  --line: #23272E;
  --border: #353A44;
  --border-soft: #2C3139;
  --green: #2BC27A;
  --green-dark: #3DD68C;
  --green-tint: #123222;
  --accent: #2BC27A;
  --accent-hover: #36D488;
  --on-accent: #07140D;
  --panel: #1A1E24;
  --panel-text: #ECEEF0;
  --panel-shape: #252A32;
  --error: #FF7A5C;
  --danger: #FF7A5C;
  --danger-border: #5A2A22;
  --danger-soft: #2A1714;
  --switch-off: #3A3F48;
  --shadow: rgba(0, 0, 0, .4);
}

[hidden] { display: none !important; }

/* Logo number follows the text colour */
.mark text { fill: var(--ink); }

/* Dropdown chevrons (data URIs can't read variables) */
[data-theme="dark"] .select select,
[data-theme="dark"] .select-wrap select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23ECEEF0' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

/* Theme toggle */
.theme-toggle {
  flex: none;
  width: 46px; height: 46px; border-radius: 8px; border: 0;
  background: var(--soft); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .15s;
}
.theme-toggle:hover { background: var(--soft-hover); }
.theme-toggle:focus-visible { outline: 2px solid var(--green-dark); outline-offset: 2px; }
.theme-toggle svg {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* Circular reveal: the new theme grows out of the toggle */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
::view-transition-old(root) { z-index: 1; }
::view-transition-new(root) { z-index: 2; }

/* Logo keeps its own typeface; everything else uses the system font */
.wordmark { font-family: var(--font-logo); }

/* Maps: show the tile style that matches the theme (no filters = no colour flash) */
.tiles-dark { visibility: hidden; }
[data-theme="dark"] .tiles-dark { visibility: visible; }
[data-theme="dark"] .tiles-light { visibility: hidden; }

/* Growing pandan (sprout.js) */
.sprout { overflow: visible; }
.sprout .sa-circle { transform-origin: 50px 50px; animation: saPop .7s cubic-bezier(.2, 1.3, .4, 1) both; }
.sprout .sa-leaf { transform-box: fill-box; transform-origin: 50% 100%; animation: saGrow .9s cubic-bezier(.2, 1.2, .4, 1) both; }
.sprout .sa-l0 { animation-delay: .3s; }
.sprout .sa-l1 { animation-delay: .4s; }
.sprout .sa-l2 { animation-delay: .6s; }
.sprout .sa-l3 { animation-delay: .8s; }
.sprout.loop .sa-circle { animation: none; }
.sprout.loop .sa-leaf { animation: saLoop 1.6s ease-in-out infinite; }
.sprout.loop .sa-l0 { animation-delay: -.15s; }
.sprout.loop .sa-l1 { animation-delay: 0s; }
.sprout.loop .sa-l2 { animation-delay: .15s; }
.sprout.loop .sa-l3 { animation-delay: .3s; }
@keyframes saPop { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes saGrow { from { transform: scaleY(0); opacity: 0; } 60% { opacity: 1; } to { transform: scaleY(1); opacity: 1; } }
@keyframes saLoop { 0%, 100% { transform: scaleY(.15); opacity: .4; } 45%, 60% { transform: scaleY(1); opacity: 1; } }
@keyframes saOut { to { transform: scale(.92); opacity: 0; } }
.sprout-overlay {
  position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: var(--bg); animation: saFade .2s ease both;
}
.sprout-overlay .sprout { width: 112px; height: 112px; }
.sprout-overlay p { margin: 0; font-size: 16px; font-weight: 600; color: var(--ink); animation: saFade .4s .8s ease both; }
.sprout-overlay.leaving > * { animation: saOut .45s ease-in forwards; }
@keyframes saFade { from { opacity: 0; } to { opacity: 1; } }
.sprout-loader { display: flex; justify-content: center; padding: 48px 0; }
.sprout-loader .sprout { width: 56px; height: 56px; }
@media (prefers-reduced-motion: reduce) { .sprout *, .sprout-overlay, .sprout-overlay * { animation: none !important; } }
.sprout, .sprout * { stroke: none !important; }
/* Opening splash (splash.js) */
.sprout-overlay.splash { z-index: 1000; animation: none; transition: opacity .4s ease; }
.sprout-overlay.splash.gone { opacity: 0; pointer-events: none; }
.splash-word { font-size: 20px; font-weight: 700; letter-spacing: 1.5px; color: var(--ink); animation: saFade .5s 1s ease both; }
/* Save / connection problems (data.js) */
.net-toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 900; max-width: min(92vw, 420px); padding: 12px 16px; border-radius: 8px; background: #B42318; color: #fff; font-size: 14px; font-weight: 500; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.net-toast[hidden] { display: none; }

/* Unread chats */
.topbar a[href="chats.html"], .bottom-nav a[href="chats.html"] { position: relative; }
.unread-badge {
  position: absolute; top: 4px; right: 4px; min-width: 18px; height: 18px; padding: 0 5px; box-sizing: border-box;
  border-radius: 9px; background: #E5383B; color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
  pointer-events: none;
}
.bottom-nav .unread-badge { top: 4px; right: calc(50% - 22px); }

/* Notifications bell */
.bell { position: relative; display: inline-flex; }
.bell-btn { position: relative; border: 0; cursor: pointer; }
.bell-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bell-btn[aria-expanded="true"] { background: var(--soft-hover); }
.bell-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 60; width: 340px; max-width: calc(100vw - 24px);
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: 10px; box-shadow: 0 12px 32px var(--shadow);
  overflow: hidden;
}
.bell-menu[hidden] { display: none; }
.bell-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); font-size: 15px; }
.bell-head a { font-size: 13px; font-weight: 600; color: var(--green-dark); text-decoration: none; }
.bell-list { list-style: none; margin: 0; padding: 6px; max-height: min(420px, 65vh); overflow-y: auto; }
.bell-list a { display: flex; align-items: flex-start; gap: 12px; padding: 10px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.bell-list a:hover { background: var(--soft); }
.bell-list a.fresh { background: var(--green-tint); }
.bell-ic { width: 34px; height: 34px; flex: none; border-radius: 50%; background: var(--soft); display: flex; align-items: center; justify-content: center; color: var(--ink); }
.bell-ic svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bell-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.bell-txt span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bell-list time { font-size: 12px; color: var(--muted); flex: none; padding-top: 2px; }
.bell-empty { padding: 28px 12px; text-align: center; color: var(--muted); font-size: 14px; }
@media (max-width: 760px) {
  .topbar .icon-btn.bell-btn { display: inline-flex; width: 44px; height: 44px; }
  .bell-menu { position: fixed; top: 64px; right: 12px; left: 12px; width: auto; max-width: none; }
}
