:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b7280;
  --accent: #0f7b3a;
  --card-bg: #f5f6f8;
  --border: #e5e7eb;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --gutter: 16px;
  /* Telegram theme params (app.js overrides these on boot when opened in-app). */
  --tg-theme-bg-color: var(--bg);
  --tg-theme-text-color: var(--fg);
  --tg-theme-hint-color: var(--muted);
  --tg-theme-button-color: var(--accent);
  --tg-theme-button-text-color: #ffffff;
  font-family: "DM Sans", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --fg: #f3f4f6;
    --muted: #9ca3af;
    --card-bg: #1a1d23;
    --border: #2a2e37;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --fg: #f3f4f6;
  --muted: #9ca3af;
  --card-bg: #1a1d23;
  --border: #2a2e37;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--tg-theme-bg-color, var(--bg));
  color: var(--tg-theme-text-color, var(--fg));
  overflow-x: hidden;
}

[x-cloak] { display: none !important; }

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 12px) var(--gutter) 12px;
  background: var(--tg-theme-bg-color, var(--bg));
  border-bottom: 1px solid var(--border);
}
.appbar-back {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--tg-theme-text-color, var(--fg));
  cursor: pointer;
  padding: 0 4px;
}
.appbar-title { font-size: 17px; font-weight: 600; margin: 0; text-transform: capitalize; }

.content {
  flex: 1 1 auto;
  padding: 16px var(--gutter) calc(88px + var(--safe-bottom));
  overflow-y: auto;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}
.card h3 { margin: 0 0 4px; }
.badge {
  display: inline-block;
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  margin-top: 6px;
}

.empty-state { text-align: center; padding: 48px 16px; color: var(--muted); }

.bottomnav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  padding: 6px var(--gutter) calc(6px + var(--safe-bottom));
  background: var(--tg-theme-bg-color, var(--bg));
  border-top: 1px solid var(--border);
}
.bottomnav button {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
  padding: 4px 8px;
  cursor: pointer;
}
.bottomnav button.active { color: var(--accent); }
.bottomnav svg { width: 22px; height: 22px; }

.guest-panel { padding: 64px var(--gutter); text-align: center; }

.btn {
  display: inline-block;
  background: var(--tg-theme-button-color, var(--accent));
  color: var(--tg-theme-button-text-color, #ffffff);
  border: none;
  border-radius: 10px;
  padding: 10px 20px;
  text-decoration: none;
  font-weight: 600;
  margin-top: 12px;
  cursor: pointer;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + var(--safe-bottom));
  transform: translateX(-50%);
  background: #1a1a1a;
  color: #ffffff;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  max-width: calc(100% - 32px);
  z-index: 20;
}

.locale-toggle { display: flex; gap: 8px; margin-top: 8px; }
.locale-toggle button {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--fg);
  cursor: pointer;
}
.locale-toggle button.active { border-color: var(--accent); color: var(--accent); }

.muted { color: var(--muted); }

.join-placeholder { text-align: center; padding-top: 64px; }

@media (min-width: 431px) {
  #app { max-width: 430px; margin: 0 auto; box-shadow: 0 0 0 1px var(--border); }
}

/* ---- CSP-10b/11b screens: forms, lists, avatars, team page ---- */
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.input {
  width: 100%;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  color: var(--fg);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
textarea.input { resize: vertical; }

.btn:disabled { opacity: 0.5; cursor: default; }
.btn-small { padding: 6px 12px; font-size: 13px; margin-top: 0; }
.btn-secondary { background: var(--card-bg); color: var(--fg); border: 1px solid var(--border); }
.btn-danger { background: #b91c1c; color: #fff; }
.btn-icon { background: none; border: none; font-size: 18px; color: var(--muted); padding: 4px 8px; cursor: pointer; }
.link-like { color: var(--accent); cursor: pointer; font-size: 13px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row-gap { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.center { text-align: center; }
.small { font-size: 12px; }

.list { list-style: none; margin: 8px 0 16px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; cursor: pointer;
}
.list-item-static { cursor: default; }
.list-main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
.list-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.crest, .avatar { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; flex: 0 0 auto; }
.avatar { border-radius: 50%; }
.crest-lg, .avatar-lg { width: 72px; height: 72px; }
.crest-placeholder {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 14px;
}
.avatar-pick { display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; }

.team-header { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.team-header h2 { margin: 0 0 2px; }

.pill { font-size: 11px; border-radius: 999px; padding: 2px 8px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.invite-link { display: block; font-size: 12px; word-break: break-all; background: var(--bg); border: 1px dashed var(--border); border-radius: 8px; padding: 8px; margin: 8px 0; }
.qr { display: block; width: 160px; height: 160px; margin: 12px auto 0; border-radius: 8px; background: #fff; }

.menu { position: relative; }
.menu-items {
  position: absolute; right: 0; top: 28px; z-index: 5; min-width: 180px;
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 4px;
  display: flex; flex-direction: column;
}
.menu-items button { text-align: left; background: none; border: none; color: var(--fg); padding: 8px 10px; font: inherit; cursor: pointer; border-radius: 6px; }
.menu-items button:hover { background: var(--bg); }
.menu-items button.danger { color: #b91c1c; }

.steps { display: flex; gap: 8px; margin: 4px 0 12px; }
.steps span {
  width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; border: 1px solid var(--border); color: var(--muted);
}
.steps span.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.join-page { max-width: 430px; margin: 0 auto; padding: 48px var(--gutter); text-align: center; }
.join-page .crest-lg { margin: 0 auto 12px; display: flex; }

/* ---- CSP-14: passport + matches ---- */
.passport-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.tier-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-weight: 600; font-size: 13px; }
.tier-kyu { background: color-mix(in srgb, #2e7d32 18%, transparent); color: #2e7d32; }
.tier-dan { background: color-mix(in srgb, #b8860b 22%, transparent); color: #b8860b; }
:root[data-theme="dark"] .tier-kyu, :root:not([data-theme="light"]) .tier-kyu { color: #7ed491; }
:root[data-theme="dark"] .tier-dan, :root:not([data-theme="light"]) .tier-dan { color: #f2c94c; }
.rating-big { font-size: 44px; font-weight: 700; line-height: 1; letter-spacing: -1px; }
.rating-band { font-size: 16px; opacity: .7; margin-left: 6px; font-weight: 500; }
.progress { height: 8px; border-radius: 999px; background: color-mix(in srgb, currentColor 12%, transparent); overflow: hidden; margin: 8px 0 4px; }
.progress > span { display: block; height: 100%; border-radius: 999px; background: var(--tg-theme-button-color, #2e7d32); }
.spark { width: 100%; height: 56px; display: block; }
.spark polyline { fill: none; stroke: var(--tg-theme-button-color, #2e7d32); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark circle { fill: var(--tg-theme-button-color, #2e7d32); }
.form-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.form-pill { width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #fff; }
.form-W { background: #2e7d32; } .form-D { background: #8d8d8d; } .form-L { background: #c62828; }
.match-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.match-score { font-weight: 700; font-variant-numeric: tabular-nums; }
.status-pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: color-mix(in srgb, currentColor 10%, transparent); }
.section-title { margin: 18px 0 8px; font-size: 15px; opacity: .8; text-transform: uppercase; letter-spacing: .04em; }
.lineup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin: 8px 0; }
.lineup-grid label { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 6px 0; border-bottom: 1px solid color-mix(in srgb, currentColor 10%, transparent); font-size: 14px; }
.delta-pos { color: #2e7d32; } .delta-neg { color: #c62828; }

/* CSP-15 reflections */
.goal-card { border-left: 4px solid var(--accent, #0f7b3a); }
.goal-text { font-size: 1.05rem; margin: 4px 0; }
.mood-row { display: flex; gap: 8px; margin-top: 6px; }
.mood { font-size: 1.6rem; background: transparent; border: 2px solid transparent; border-radius: 12px; padding: 4px 8px; }
.mood.active { border-color: var(--accent, #0f7b3a); background: var(--card-2, rgba(15,123,58,0.08)); }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
