/* ---------- colour themes: every colour in the interface comes from these ---------- */
:root {
  --surface: #fff;       --surface-2: #f6eafb;   --tint: #fff6fb;
  --panel: rgba(255, 255, 255, 0.86);  --glass: rgba(255, 255, 255, 0.55);
  --glass-2: rgba(255, 255, 255, 0.75); --glass-strong: rgba(255, 255, 255, 0.92);
  --ink: #7a5a8c;  --ink-body: #6a4a7c;  --ink-strong: #5a3f6c;  --ink-2: #8a6aa0;  --ink-3: #a98bc0;
  --line: #ecd9f5;
  --a1: #ffd1e6;  --a2: #ffb3d4;  --a3: #f08fbb;  --a4: #ff9cc6;
  --a-soft: #ffe3f0;  --a-line: #ffd0e4;  --a-text: #c4608f;  --a-border: #f6c8e0;
  --on: #5fd6a0;  --off: #c9bfd6;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: linear-gradient(180deg, #d9ecff 0%, #f3e5ff 100%);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Quicksand", system-ui, sans-serif;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.title {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 18px);
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
}

.title h1 {
  font-size: clamp(1.4rem, 4.5vw, 2.2rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff;
  text-shadow: 0 2px 0 #c9a6e8, 0 4px 14px rgba(150, 100, 200, 0.35);
}

.title p {
  margin-top: 4px;
  font-size: clamp(0.9rem, 2.6vw, 1.1rem);
  font-weight: 700;
  opacity: 0.85;
  transition: opacity 0.8s ease;
}

.title p.gone { opacity: 0; }

.dock {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 6px 22px rgba(150, 100, 200, 0.2), inset 0 0 0 2px rgba(255, 255, 255, 0.7);
}

.dock button {
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--a1), var(--a2));
  box-shadow: 0 4px 0 var(--a3), 0 8px 14px rgba(240, 143, 187, 0.35);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.dock button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--a3), 0 3px 8px rgba(240, 143, 187, 0.35);
}

.dock svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: #fff;
  stroke-width: 3.2;
  stroke-linecap: round;
}

@media (min-width: 700px) {
  .dock button { width: 68px; height: 68px; }
  .dock svg { width: 32px; height: 32px; }
}

/* ---------- builder ---------- */

.dock { transition: transform 0.35s cubic-bezier(.2, .9, .3, 1), opacity 0.25s ease; }
body.editing .dock, body.scening .dock { transform: translate(-50%, 160%); opacity: 0; pointer-events: none; }
body.editing .title p { opacity: 0; }

.builder {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  width: min(100%, 560px);
  padding: 8px 18px calc(env(safe-area-inset-bottom) + 14px);
  border-radius: 30px 30px 0 0;
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 -8px 30px rgba(150, 100, 200, 0.22), inset 0 0 0 2px rgba(255, 255, 255, 0.8);
  transform: translateY(110%);
  visibility: hidden;
  transition: transform 0.4s cubic-bezier(.2, .9, .3, 1.15), visibility 0s linear 0.4s;
}

body .builder.open {
  transform: none;
  visibility: visible;
  transition: transform 0.4s cubic-bezier(.2, .9, .3, 1.15), visibility 0s;
}

.grip {
  width: 44px;
  height: 5px;
  margin: 0 auto 10px;
  border-radius: 99px;
  background: var(--line);
}

.builder .head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.builder h2 {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--ink);
}

.done {
  border: 0;
  padding: 9px 20px;
  border-radius: 99px;
  font: inherit;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, var(--a1), var(--a2));
  box-shadow: 0 3px 0 var(--a3);
  cursor: pointer;
}

.done:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--a3); }

.field { display: block; margin-top: 8px; }

.field > span {
  display: block;
  margin: 0 0 6px 4px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

#name {
  width: 100%;
  padding: 9px 16px;
  border: 2px solid var(--a-border);
  border-radius: 18px;
  font: inherit;
  font-size: 16px;            /* 16px stops iOS zooming into the field */
  font-weight: 700;
  color: var(--ink-body);
  background: var(--surface);
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}

#name:focus { border-color: var(--a4); box-shadow: 0 0 0 4px rgba(255, 156, 198, 0.25); }

.faces {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.faces button {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 5px 2px 4px;
  border: 2px solid transparent;
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink-strong);
  font: inherit;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--line);
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.faces button[aria-pressed="true"] {
  background: var(--a-soft);
  border-color: var(--a4);
  transform: translateY(-2px);
}

.faces svg { width: 100%; max-width: 46px; height: auto; fill: currentColor; }
.faces svg .ln { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.faces svg .ln.w { fill: #fff; }
.faces svg .tear { fill: #7cc4ff; }

.faces em {
  font-style: normal;
  font-size: 0.66rem;
  font-weight: 800;
  color: var(--ink-2);
}

.swatches {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.swatch {
  flex: 1;
  max-width: 44px;
  aspect-ratio: 1;
  border: 3px solid var(--surface);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--line), 0 4px 10px rgba(150, 100, 200, 0.2);
  transition: transform 0.12s ease;
}

.swatch[aria-pressed="true"] {
  transform: scale(1.12);
  box-shadow: 0 0 0 3px var(--a4), 0 4px 10px rgba(150, 100, 200, 0.25);
}

/* landscape phones & tablets: a side panel instead of a bottom sheet */
body.side .builder {
  left: auto;
  right: 12px;
  top: 12px;
  bottom: 12px;
  margin: 0;
  width: min(340px, 42vw);
  overflow-y: auto;
  padding-bottom: 18px;
  border-radius: 28px;
  transform: translateX(120%);
}

body.side .builder.open { transform: none; }
body.side .grip { display: none; }
body.side .title { right: 0; }

body.side.editing .title { opacity: 0; transition: opacity 0.3s ease; }

/* ---------- account ---------- */

.account {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 14px);
  right: 14px;
  min-width: 44px;
  height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 99px;
  font: inherit;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--glass-2);
  box-shadow: 0 3px 12px rgba(150, 100, 200, 0.2), inset 0 0 0 2px rgba(255, 255, 255, 0.8);
  cursor: pointer;
  transition: opacity 0.25s ease, transform 0.12s ease;
}

.account:active { transform: scale(0.95); }
.account.in { width: 44px; padding: 0; color: #fff; background: linear-gradient(180deg, var(--a2), var(--a3)); }
body.editing .account, body.scening .account { opacity: 0; pointer-events: none; }

.toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 70px);
  transform: translate(-50%, -12px);
  max-width: min(92vw, 420px);
  padding: 10px 18px;
  border-radius: 99px;
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--glass-strong);
  box-shadow: 0 4px 16px rgba(150, 100, 200, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(122, 90, 140, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal[hidden] { display: none; }

.card {
  width: min(100%, 380px);
  padding: 26px 22px 18px;
  border-radius: 30px;
  text-align: center;
  background: var(--surface);
  box-shadow: 0 16px 50px rgba(122, 90, 140, 0.35);
}

.card h2 { font-size: 1.35rem; font-weight: 800; color: var(--ink); }
.card p { margin: 8px 0 18px; font-weight: 700; font-size: 0.95rem; line-height: 1.4; color: var(--ink-3); }

.oauth {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  margin-bottom: 10px;
  border: 2px solid var(--line);
  border-radius: 18px;
  font: inherit;
  font-weight: 800;
  color: var(--ink-strong);
  background: var(--surface);
  box-shadow: 0 3px 0 var(--line);
  cursor: pointer;
}

.oauth svg { width: 24px; height: 24px; }
.oauth.x { color: #fff; background: #111; border-color: #111; box-shadow: 0 3px 0 #444; }
.oauth.out { color: #fff; background: linear-gradient(180deg, var(--a1), var(--a2)); border-color: transparent; box-shadow: 0 3px 0 var(--a3); }
.oauth:active { transform: translateY(2px); box-shadow: none; }
.oauth:disabled { opacity: 0.6; }

.card .link {
  margin-top: 4px;
  padding: 10px 16px;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 800;
  color: var(--ink-3);
  cursor: pointer;
}

.card .fine { margin: 10px 0 0; font-size: 0.75rem; font-weight: 700; color: var(--ink-3); }
.card .fine a { color: var(--ink-3); }

.oauth[hidden] { display: none; }

.oauth.soft { color: var(--a-text); background: var(--tint); border-color: var(--a-line); box-shadow: 0 3px 0 var(--a-line); }
.install { margin-top: 6px; padding-top: 12px; border-top: 2px dashed var(--line); }
.install[hidden], .steps[hidden] { display: none; }

.steps {
  margin: 4px 0 8px;
  padding: 12px 14px 12px 34px;
  border-radius: 16px;
  text-align: left;
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--ink-2);
  background: var(--surface-2);
}

.steps li { margin: 4px 0; }

/* ---------- scene sheet & night mode ---------- */

.faces.cols4 { grid-template-columns: repeat(4, 1fr); }
.faces.cols6 { grid-template-columns: repeat(6, 1fr); }
.faces.cols6 em { font-size: 0.6rem; }

body.night .title p { color: #ddd0f7; }
body.night .account:not(.in) { color: #f1e8ff; background: rgba(70, 60, 125, 0.65); box-shadow: 0 3px 12px rgba(10, 5, 40, 0.4), inset 0 0 0 2px rgba(255, 255, 255, 0.18); }
body.night .title h1 { text-shadow: 0 2px 0 #7c63b8, 0 4px 14px rgba(10, 5, 40, 0.5); }

/* ---------- games ---------- */

.remove {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 9px;
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--a-text);
  background: var(--tint);
  cursor: pointer;
}

.game-list { display: grid; gap: 10px; margin-top: 6px; }

.game-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 10px 14px;
  border: 2px solid transparent;
  border-radius: 20px;
  text-align: left;
  font: inherit;
  color: var(--ink-strong);
  background: var(--surface);
  box-shadow: 0 3px 0 var(--line);
  cursor: pointer;
}

.game-card:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.game-card svg { flex: none; width: 48px; height: 48px; }
.game-card strong { display: block; font-size: 1.05rem; font-weight: 800; color: var(--ink); }
.game-card small { display: block; font-size: 0.78rem; font-weight: 700; color: var(--ink-3); line-height: 1.3; }
.game-card em { display: block; margin-top: 2px; font-style: normal; font-size: 0.72rem; font-weight: 800; color: var(--a3); }

.game-overlay { position: fixed; inset: 0; z-index: 40; }
.game-overlay[hidden] { display: none; }
.game-overlay canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

.game-close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 12px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--glass-strong);
  box-shadow: 0 3px 12px rgba(150, 100, 200, 0.25);
  cursor: pointer;
}

.game-close svg { width: 22px; height: 22px; fill: none; stroke: var(--ink-3); stroke-width: 3; stroke-linecap: round; }
.card .best { margin: -8px 0 16px; font-weight: 800; color: var(--a3); }

@media (max-width: 420px) {
  .dock { gap: 9px; padding: 9px 12px; }
  .dock button { width: 50px; height: 50px; }
  .dock svg { width: 24px; height: 24px; }
}

/* ---------- mailbox & friends ---------- */

.dock button { position: relative; }

.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 22px;
  color: #fff;
  background: #ff4f86;
  box-shadow: 0 0 0 3px var(--surface);
}

.badge[hidden] { display: none; }

.builder.mail { max-height: min(78vh, 640px); overflow-y: auto; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 4px 0 10px; padding: 4px; border-radius: 99px; background: var(--surface-2); }
.tabs[hidden] { display: none; }
.tabs button { padding: 9px; border: 0; border-radius: 99px; font: inherit; font-weight: 800; color: var(--ink-3); background: none; cursor: pointer; }
.tabs button[aria-pressed="true"] { color: #fff; background: linear-gradient(180deg, var(--a1), var(--a2)); box-shadow: 0 2px 0 var(--a3); }

.mail-hint { margin: 10px 4px; font-weight: 700; font-size: 0.9rem; text-align: center; color: var(--ink-3); }
.mail-hint.strong { font-size: 1rem; color: var(--ink); }
.mail-empty { padding: 18px 8px; text-align: center; font-weight: 700; color: var(--ink-3); }
.mail-empty .oauth { margin-top: 12px; }

.mail-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 8px;
  padding: 10px 12px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 2px 0 var(--line);
}

.mail-item.new { background: var(--tint); box-shadow: 0 2px 0 var(--a-line), inset 0 0 0 2px var(--a-line); }
.mail-item.friend { align-items: center; justify-content: space-between; }
.mail-gift { flex: none; width: 46px; height: 46px; }
.mail-gift svg { width: 100%; height: 100%; }
.mail-text { min-width: 0; flex: 1; font-weight: 700; color: var(--ink-body); }
.mail-text strong { font-weight: 800; color: var(--ink); }
.mail-text small { font-weight: 700; color: var(--ink-3); }
.mail-sub { font-size: 0.85rem; color: var(--ink-3); }
.mail-text p { margin: 4px 0 0; word-break: break-word; line-height: 1.35; }

.mail-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.mail-actions.center { justify-content: center; }
.mail-item.friend .mail-actions { margin-top: 0; justify-content: flex-end; }

.mail-actions button, .visit-bar .done {
  padding: 7px 13px;
  border: 0;
  border-radius: 99px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--a-text);
  background: var(--a-soft);
  cursor: pointer;
}

.mail-actions button.quiet, .visit-bar .done.quiet { color: var(--ink-3); background: var(--surface-2); }

.code-card { margin: 4px 0 10px; padding: 12px; border-radius: 20px; text-align: center; background: linear-gradient(180deg, var(--tint), var(--surface-2)); }
.code-card small { font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); font-size: 0.72rem; }
.code { margin-top: 2px; font-size: 1.9rem; font-weight: 800; letter-spacing: 0.14em; color: var(--ink); -webkit-user-select: text; user-select: text; }

.add-row { display: flex; gap: 8px; margin-bottom: 12px; }
.add-row input, .builder.mail textarea {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 2px solid var(--a-border);
  border-radius: 16px;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-body);
  background: var(--surface);
  outline: none;
  text-transform: uppercase;
  -webkit-user-select: text;
  user-select: text;
}

.builder.mail textarea { width: 100%; resize: none; text-transform: none; }
.add-row input:focus, .builder.mail textarea:focus { border-color: var(--a4); }
.count { display: block; margin: 4px 6px 10px; text-align: right; font-weight: 700; color: var(--ink-3); }

.gift-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.gift-picker button { padding: 6px; border: 2px solid transparent; border-radius: 16px; background: var(--surface); box-shadow: 0 2px 0 var(--line); cursor: pointer; }
.gift-picker button[aria-pressed="true"] { background: var(--a-soft); border-color: var(--a4); transform: translateY(-2px); }
.gift-picker svg { display: block; width: 100%; max-width: 44px; margin: 0 auto; }

.visit-bar {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 20px);
  padding: 10px 12px;
  border-radius: 28px;
  font-weight: 800;
  color: var(--ink);
  background: var(--panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 6px 22px rgba(150, 100, 200, 0.25), inset 0 0 0 2px rgba(255, 255, 255, 0.7);
}

.visit-bar[hidden] { display: none; }
.visit-bar span { padding: 0 6px; font-size: 0.9rem; }
.visit-bar .done { color: #fff; background: linear-gradient(180deg, var(--a1), var(--a2)); box-shadow: 0 2px 0 var(--a3); }
.visit-bar .done.quiet { color: var(--ink-3); background: var(--surface-2); box-shadow: none; }
body.visiting .dock { transform: translate(-50%, 160%); opacity: 0; pointer-events: none; }
body.visiting .account { opacity: 0; pointer-events: none; }

.builder .link { display: block; margin: 6px auto 0; padding: 10px 16px; border: 0; background: none; font: inherit; font-weight: 800; color: var(--ink-3); cursor: pointer; }
.visit-bar { flex-wrap: wrap; justify-content: center; row-gap: 8px; width: min(340px, calc(100vw - 20px)); }
.visit-bar span { flex-basis: 100%; text-align: center; padding: 0; }

/* ---------- colour schemes (Settings -> Color theme) ---------- */
html[data-ui="lavender"] {
  --surface-2: #efe6ff; --tint: #f7f2ff; --line: #e1d5fa;
  --a1: #e2d4ff; --a2: #c9b4f6; --a3: #9d83e0; --a4: #b79cf2; --a-soft: #efe6ff; --a-line: #d8c8fa; --a-text: #6f4fc0; --a-border: #d2c1f5;
}
html[data-ui="mint"] {
  --surface-2: #e2faf1; --tint: #f1fcf7; --line: #cdeedd; --ink: #3f7a6c; --ink-body: #3b6a5f; --ink-strong: #2f574d; --ink-2: #5a9686; --ink-3: #7fb5a5;
  --a1: #c8f5e6; --a2: #9be8cf; --a3: #4fc4a0; --a4: #7fd9b8; --a-soft: #e2faf1; --a-line: #bdeedb; --a-text: #278a6c; --a-border: #b5ead6;
}
html[data-ui="sky"] {
  --surface-2: #e3f1ff; --tint: #f1f8ff; --line: #d0e4f7; --ink: #4a6a94; --ink-body: #435e84; --ink-strong: #374f72; --ink-2: #6485ae; --ink-3: #86a4c8;
  --a1: #cfe9ff; --a2: #a6d4ff; --a3: #5fa8ec; --a4: #86c0f7; --a-soft: #e3f1ff; --a-line: #c4def6; --a-text: #2f72bc; --a-border: #bddaf5;
}
html[data-ui="peach"] {
  --surface-2: #fff0e6; --tint: #fff7f1; --line: #f6dccb; --ink: #96624a; --ink-body: #85543e; --ink-strong: #6f4430; --ink-2: #b27a60; --ink-3: #c79a84;
  --a1: #ffe0cc; --a2: #ffc4a3; --a3: #ee8a58; --a4: #ffab80; --a-soft: #fff0e6; --a-line: #fdd5bd; --a-text: #bf5c2d; --a-border: #fbd0b5;
}
html[data-ui="midnight"] {
  --surface: #2e2a5a; --surface-2: #3a3570; --tint: #3a3472;
  --panel: rgba(36, 32, 80, 0.93); --glass: rgba(52, 46, 104, 0.62); --glass-2: rgba(52, 46, 104, 0.78); --glass-strong: rgba(46, 42, 92, 0.96);
  --ink: #e4d9ff; --ink-body: #d6c9f5; --ink-strong: #f2eaff; --ink-2: #bfb0e8; --ink-3: #a193d6;
  --line: #4a4388;
  --a1: #9b86f0; --a2: #8570e6; --a3: #5b47c4; --a4: #a493f5; --a-soft: #443d8a; --a-line: #5a50a8; --a-text: #d4c8ff; --a-border: #5b53a0;
  --off: #6f66a8;
}
html[data-ui="midnight"] .field > span, html[data-ui="midnight"] .faces em { color: var(--ink-3); }
html[data-ui="midnight"] .game-card, html[data-ui="midnight"] .mail-item { box-shadow: 0 2px 0 var(--line); }

/* ---------- swipe-to-close sheets ---------- */

.builder .grip { height: 6px; margin: 4px auto 12px; cursor: pointer; position: relative; }
.builder .grip::after { content: ""; position: absolute; inset: -14px -30px; }   /* a bigger target to grab */
.builder .grip, .builder .head { touch-action: none; }
.builder .head { min-height: 34px; }
.builder.settings, .builder.mail { max-height: min(84vh, 700px); overflow-y: auto; overscroll-behavior: contain; }

/* ---------- settings ---------- */

.set-block { margin: 2px 0 6px; padding: 12px; border-radius: 20px; background: var(--surface); box-shadow: 0 2px 0 var(--line); }
.set-row { display: flex; align-items: center; gap: 12px; }
.avatar { flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 1.2rem; color: #fff; background: linear-gradient(180deg, var(--a2), var(--a3)); }
.set-who { min-width: 0; flex: 1; }
.set-who strong { display: block; font-weight: 800; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-who small { display: block; font-weight: 700; font-size: 0.75rem; line-height: 1.3; color: var(--ink-3); }
.pill { flex: none; padding: 9px 16px; border: 0; border-radius: 99px; font: inherit; font-weight: 800; font-size: 0.85rem; color: #fff; background: linear-gradient(180deg, var(--a1), var(--a2)); box-shadow: 0 3px 0 var(--a3); cursor: pointer; }
.pill:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--a3); }

.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.themes button { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 2px solid transparent; border-radius: 16px; font: inherit; color: var(--ink-body); background: var(--surface); box-shadow: 0 2px 0 var(--line); cursor: pointer; }
.themes button[aria-pressed="true"] { border-color: var(--a4); background: var(--a-soft); transform: translateY(-2px); }
.themes em { font-style: normal; font-size: 0.78rem; font-weight: 800; }
.theme-dot { flex: none; width: 26px; height: 26px; border-radius: 50%; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.08); }

.switch-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 18px; background: var(--surface); box-shadow: 0 2px 0 var(--line); cursor: pointer; }
.switch-text { flex: 1; min-width: 0; }
.switch-text strong { display: block; font-weight: 800; color: var(--ink-body); }
.switch-text small { display: block; font-size: 0.75rem; font-weight: 700; line-height: 1.3; color: var(--ink-3); }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch { flex: none; position: relative; width: 50px; height: 30px; border-radius: 99px; background: var(--line); transition: background 0.2s ease; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25); transition: transform 0.2s ease; }
.switch-row input:checked + .switch { background: var(--on); }
.switch-row input:checked + .switch::after { transform: translateX(20px); }
.switch-row input:disabled + .switch { opacity: 0.5; }
.switch-row input:focus-visible + .switch { outline: 3px solid var(--a4); outline-offset: 2px; }

.builder.settings .install { margin-top: 14px; padding-top: 0; border-top: 0; }
.set-links { margin: 14px 0 4px; text-align: center; font-weight: 700; font-size: 0.85rem; color: var(--ink-3); }
.set-links a { color: var(--ink-2); }
.set-links small { font-size: 0.72rem; }

/* ---------- mailbox 2.0 ---------- */

.tabs { grid-template-columns: repeat(3, 1fr); }
.tabs button { font-size: 0.88rem; padding: 9px 4px; }

.mail-h { margin: 12px 4px 6px; font-size: 0.78rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.online-count { color: #34b27b; text-transform: none; letter-spacing: 0; }

.new-mail { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; margin: 2px 0 4px; padding: 12px; border: 0; border-radius: 18px; font: inherit; font-weight: 800; color: #fff; background: linear-gradient(180deg, var(--a1), var(--a2)); box-shadow: 0 3px 0 var(--a3); cursor: pointer; }
.new-mail:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--a3); }
.new-mail svg { width: 20px; height: 20px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; display: block; }

.new-tag { margin-left: 6px; padding: 2px 7px; border-radius: 99px; font-size: 0.62rem; font-weight: 800; letter-spacing: 0.06em; color: #fff; background: #ff4f86; vertical-align: 2px; }
.tag { padding: 7px 4px; font-size: 0.8rem; font-weight: 800; color: #34b27b; }

.f-head { display: flex; align-items: center; justify-content: space-between; }
.f-head .mail-h { margin-top: 4px; }
.plus { flex: none; width: 38px; height: 38px; border: 0; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(180deg, var(--a1), var(--a2)); box-shadow: 0 3px 0 var(--a3); cursor: pointer; transition: transform 0.15s ease; }
.plus svg { width: 20px; height: 20px; fill: none; stroke: #fff; stroke-width: 3.2; stroke-linecap: round; }
.plus.on { transform: rotate(45deg); }

.add-panel { margin-bottom: 10px; padding: 8px; border-radius: 22px; background: var(--surface-2); }
.add-panel .code-card { margin: 0 0 8px; }
.add-panel .add-row { margin-bottom: 0; }

.f-avatar { position: relative; flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 1.15rem; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--off); }
.dot.on { background: var(--on); }
.f-avatar .dot { position: absolute; right: -1px; bottom: -1px; width: 15px; height: 15px; box-shadow: 0 0 0 3px var(--surface); }
.status { font-size: 0.78rem; font-weight: 700; color: var(--ink-3); }
.status.on { color: #34b27b; }

.inv-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.inv-tile { display: grid; justify-items: center; gap: 2px; padding: 10px 6px; border-radius: 18px; text-align: center; background: var(--surface); box-shadow: 0 2px 0 var(--line); }
.inv-tile.placed { background: var(--a-soft); box-shadow: 0 2px 0 var(--a-line); }
.inv-tile strong { color: var(--ink); font-weight: 800; }
.inv-tile small { color: var(--ink-3); font-weight: 700; font-size: 0.75rem; }

.who-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.who-picker button { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border: 2px solid transparent; border-radius: 99px; font: inherit; font-weight: 800; color: var(--ink-body); background: var(--surface); box-shadow: 0 2px 0 var(--line); cursor: pointer; }
.who-picker button[aria-pressed="true"] { border-color: var(--a4); background: var(--a-soft); }
.mail-item.friend { gap: 12px; }
.mail-item.friend .mail-actions { flex-wrap: nowrap; }
@media (max-width: 380px) { .mail-item.friend { flex-wrap: wrap; } .mail-item.friend .mail-actions { width: 100%; justify-content: flex-start; } }

/* the title sits on the sky, so it must not follow the panel theme */
.title p { color: #7a5a8c; }
body.night .title p { color: #ddd0f7; }

.themes { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.themes button { min-width: 0; padding: 7px 8px; gap: 6px; }
.themes em { overflow: hidden; text-overflow: ellipsis; font-size: 0.74rem; }
.theme-dot { width: 22px; height: 22px; }

.add-row input::placeholder, .builder.mail textarea::placeholder { text-transform: none; font-weight: 700; color: var(--ink-3); }
.inv-tile.placed .mail-actions button { background: var(--surface); }

/* white text on pastel buttons: a touch of shadow keeps it readable */
.pill, .new-mail, .done, .oauth.out, .tabs button[aria-pressed="true"], .plus, .visit-bar .done:not(.quiet) { text-shadow: 0 1px 2px rgba(120, 60, 100, 0.28); }

.themes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 520px) { .themes { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
