/* Telegram passes its theme as --tg-theme-* variables; the fallbacks are for a plain browser,
   which is also where the sign-in pages open. */
:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1c1c1e);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --surface: var(--tg-theme-secondary-bg-color, #f0f2f5);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --danger: var(--tg-theme-destructive-text-color, #d14836);
  --line: color-mix(in srgb, var(--hint) 25%, transparent);
  /* Room for the iPhone's home indicator, from the browser or from Telegram. */
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --tabs-height: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #17212b);
    --text: var(--tg-theme-text-color, #f5f5f5);
    --link: var(--tg-theme-link-color, #6ab3f3);
    --surface: var(--tg-theme-secondary-bg-color, #232e3c);
  }
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabs-height) + var(--safe-bottom) + 24px);
}

h1 {
  font-size: 1.5rem;
  margin: 4px 0 16px;
}

h2 {
  font-size: 1.05rem;
  margin: 20px 0 8px;
}

a {
  color: var(--link);
}

.hint,
.notes {
  color: var(--hint);
  font-size: 0.9rem;
}

.notes {
  padding-inline-start: 20px;
}

.text {
  white-space: pre-line;
}

.empty {
  color: var(--hint);
  text-align: center;
  padding: 24px 0;
}

.notice,
#status:not(:empty) {
  white-space: pre-line;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.notice.error {
  color: var(--danger);
}

/* --- the tabs at the bottom --- */

.tabs {
  position: fixed;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-around;
  height: var(--tabs-height);
  padding-bottom: var(--safe-bottom);
  background: var(--section);
  border-top: 1px solid var(--line);
  z-index: 10;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--hint);
  text-decoration: none;
  font-size: 0.72rem;
}

.tab-icon {
  font-size: 1.3rem;
  line-height: 1;
  filter: grayscale(1);
  opacity: 0.7;
}

.tab.active {
  color: var(--button);
  font-weight: 600;
}

.tab.active .tab-icon {
  filter: none;
  opacity: 1;
}

/* --- cards (Home, Connections, Admin) --- */

.card {
  display: block;
  margin: 0 0 12px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.card h2 {
  margin: 0 0 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.card p {
  margin: 4px 0;
}

.card-link:active {
  opacity: 0.7;
}

.big {
  font-size: 1.25rem;
  font-weight: 600;
}

.chevron {
  color: var(--hint);
}

[dir="rtl"] .chevron {
  transform: scaleX(-1);
}

.bar {
  height: 6px;
  margin: 8px 0 2px;
  border-radius: 3px;
  background: var(--bg);
  overflow: hidden;
}

.bar .fill {
  height: 100%;
  background: var(--button);
}

.bar .fill.full {
  background: var(--danger);
}

.status-line {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--hint);
}

.dot.ok {
  background: #2ea043;
}

.dot.bad {
  background: var(--danger);
}

/* --- the Settings list --- */

.menu {
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
}

.menu-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}

.menu-row:last-child {
  border-bottom: 0;
}

.menu-row:active {
  background: var(--line);
}

.menu-icon {
  font-size: 1.2rem;
}

.menu-label {
  flex: 1;
}

.menu-value {
  color: var(--hint);
  font-size: 0.9rem;
  max-width: 45%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- lists of things --- */

.list,
.plain {
  list-style: none;
  padding: 0;
  margin: 0 0 8px;
}

.item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}

.card .item:last-child {
  border-bottom: 0;
}

.item-main {
  flex: 1;
  min-width: 0;
}

.item-meta {
  color: var(--hint);
  font-size: 0.85rem;
}

.group {
  color: var(--hint);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.grow {
  flex: 1;
  margin: 0;
}

/* --- forms and buttons --- */

label {
  display: block;
  margin: 12px 0 4px;
  font-weight: 600;
}

input,
select {
  box-sizing: border-box;
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}

/* Searching looks unlike the fields you type something new into: filled, with a magnifier. */
.search {
  margin: 12px 0 4px;
  border-color: transparent;
  background: var(--surface) no-repeat 12px center / 16px
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.5'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-4-4'/%3E%3C/svg%3E");
  padding-inline-start: 36px;
}

[dir="rtl"] .search {
  background-position: right 12px center;
}

.row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.row input {
  flex: 1;
  min-width: 0;
}

button,
.button-link {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border: 0;
  border-radius: 10px;
  background: var(--button);
  color: var(--button-text);
  text-decoration: none;
  cursor: pointer;
}

.button-link {
  margin-top: 12px;
}

button.wide {
  display: block;
  width: 100%;
  margin-top: 14px;
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

button.small {
  padding: 4px 10px;
  font-size: 0.85rem;
  flex-shrink: 0;
}

button.secondary {
  background: var(--surface);
  color: var(--text);
}

.card button.secondary,
.card .chip:not(.on),
.card input {
  background: var(--bg);
}

button.danger {
  background: var(--danger);
  color: #ffffff;
}

.hint-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.9rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  padding: 6px 12px;
  border-radius: 16px;
  font-weight: 400;
  background: var(--surface);
  color: var(--text);
}

.chip.on {
  background: var(--button);
  color: var(--button-text);
}

.choices {
  list-style: none;
  padding: 0;
  margin: 8px 0;
}

.choice {
  width: 100%;
  margin: 4px 0;
  text-align: start;
  overflow-wrap: anywhere;
  background: var(--surface);
  color: var(--text);
  font-weight: 400;
}

.choice.on {
  outline: 2px solid var(--button);
}

/* --- Admin --- */

.person-title {
  margin-bottom: 2px;
}

.tag {
  margin-inline-start: 8px;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 0.8rem;
  background: var(--bg);
  color: var(--hint);
}

/* --- the notice that a change was saved, above the tabs --- */

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--tabs-height) + var(--safe-bottom) + 12px);
  margin: 0 auto;
  max-width: 600px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  white-space: pre-line;
  z-index: 20;
}

.toast.error {
  background: var(--danger);
  color: #ffffff;
}

/* --- Tasks: rows that open, and the form --- */

.item-link {
  color: inherit;
  text-decoration: none;
}

.item-link:active {
  opacity: 0.6;
}

a.button-link.wide-link {
  display: block;
  margin: 0 0 8px;
  text-align: center;
}

textarea {
  box-sizing: border-box;
  width: 100%;
  min-height: 84px;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}

/* A choice of a few, side by side: the selected one filled. */
.segments {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface);
}

.segment {
  flex: 1;
  padding: 8px 6px;
  font-weight: 500;
  background: transparent;
  color: var(--text);
}

.segment.on {
  background: var(--bg);
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 1px 3px color-mix(in srgb, var(--text) 18%, transparent);
}

.task-form .row input {
  flex: 1;
}

.task-form > .hint {
  margin: 6px 0 12px;
}

button.danger.wide {
  margin-top: 10px;
}

/* --- Explore: rows of cards to swipe through --- */

.shelf {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: 16px; /* cards snap in line with the page, not against the screen's edge */
  margin: 0 -16px 8px;
  padding: 2px 16px 10px;
  scrollbar-width: none;
}

.shelf::-webkit-scrollbar {
  display: none;
}

.activity {
  flex: 0 0 62%;
  max-width: 230px;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

.activity:active {
  opacity: 0.7;
}

.activity.locked {
  opacity: 0.65;
}

.activity-icon {
  font-size: 1.7rem;
  line-height: 1.2;
}

.activity-title {
  font-size: 1rem;
}

.activity-about {
  flex: 1;
  color: var(--hint);
  font-size: 0.85rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.badge {
  align-self: flex-start;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  background: var(--bg);
  color: var(--hint);
}

.activity-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.activity-head h1 {
  margin: 0;
}

.big-icon {
  font-size: 2.6rem;
}

/* --- Admin: usage --- */

h3 {
  font-size: 0.95rem;
  margin: 18px 0 6px;
}

.section-break {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.filters .segments {
  flex: 1;
  min-width: 140px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface);
}

.stat-label {
  color: var(--hint);
  font-size: 0.8rem;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 600;
}

/* A column chart: an axis, a plot with hairline gridlines, then the day labels under the plot. */
.chart {
  display: grid;
  grid-template-columns: 34px 1fr;
  grid-template-rows: 150px auto;
  column-gap: 6px;
}

.chart-axis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-end;
  color: var(--hint);
  font-size: 0.7rem;
  line-height: 1;
}

.chart-plot {
  position: relative;
}

.chart-grid {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--line);
}

.chart-columns {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  gap: 2px;
}

.chart-col {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  border-radius: 0;
  background: transparent;
}

.chart-bar {
  position: relative;
  width: 100%;
  max-width: 24px;
  min-height: 0;
  border-radius: 4px 4px 0 0;
  background: var(--button);
}

.chart-col.lifted .chart-bar,
.chart-col:focus-visible .chart-bar {
  filter: brightness(1.15);
  outline: 2px solid var(--text);
  outline-offset: 1px;
}

.chart-value {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding-bottom: 2px;
  color: var(--text);
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

.chart-tip {
  position: absolute;
  top: -6px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.8rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 2;
}

.chart-labels {
  display: flex;
  gap: 2px;
  margin-top: 4px;
  color: var(--hint);
  font-size: 0.7rem;
}

.chart-labels span {
  flex: 1;
  text-align: center;
  white-space: nowrap;
}

.table-view {
  margin-top: 8px;
  font-size: 0.85rem;
}

.table-view summary {
  color: var(--link);
  cursor: pointer;
}

.table-view table {
  width: 100%;
  margin-top: 6px;
  border-collapse: collapse;
}

.table-view th,
.table-view td {
  padding: 4px 6px;
  text-align: end;
  border-bottom: 1px solid var(--line);
}

.table-view th:first-child,
.table-view td:first-child {
  text-align: start;
}

.ranking {
  list-style: none;
  padding: 0;
  margin: 0;
}

.ranking li {
  display: grid;
  grid-template-columns: minmax(0, 38%) 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
}

.rank-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-track {
  height: 10px;
  border-radius: 0 4px 4px 0;
  background: var(--surface);
}

.rank-fill {
  height: 100%;
  border-radius: 0 4px 4px 0;
  background: var(--button);
}

.rank-value {
  color: var(--hint);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

/* --- the Danger zone --- */

.danger-title {
  margin-top: 28px;
  color: var(--danger);
}

.danger-row {
  color: var(--danger);
  font-weight: 600;
}

.erase-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.erase-choice {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
}

.erase-choice.on {
  outline: 2px solid var(--danger);
}

/* --- the welcome --- */

.progress {
  display: flex;
  gap: 6px;
  margin: 4px 0 2px;
}

.dot-step {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--surface);
}

.dot-step.done {
  background: var(--button);
}

.step-count {
  margin: 0 0 10px;
  font-size: 0.8rem;
}

.tour-card {
  margin: 12px 0 16px;
  padding: 28px 20px;
  border-radius: 18px;
  background: var(--surface);
  text-align: center;
}

.tour-card h2 {
  margin: 8px 0;
  font-size: 1.3rem;
}

.tour-icon {
  font-size: 3rem;
  line-height: 1.2;
}

.tour-dots {
  justify-content: center;
  margin-bottom: 4px;
}

.tour-dots .dot-step {
  flex: 0 0 22px;
}

.skip-link {
  display: block;
  margin-top: 14px;
  text-align: center;
  color: var(--hint);
}
