:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #0f0f10);
  --text: var(--tg-theme-text-color, #f5f5f7);
  --hint: var(--tg-theme-hint-color, #98989d);
  --accent: var(--tg-theme-button-color, #0a84ff);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --secondary: var(--tg-theme-secondary-bg-color, #1c1c1e);
  --border: rgba(127, 127, 127, 0.22);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  --radius: 14px;
  --nav-h: 62px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.boot {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.boot-error {
  font-size: 15px;
  letter-spacing: normal;
  text-transform: none;
  padding: 24px;
  text-align: center;
  color: var(--text);
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
}

.hidden { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 12px 0;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

h1, h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#app-title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #fff));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

#page-subtitle {
  margin: 0;
  font-size: 13px;
  color: var(--hint);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--secondary);
  color: var(--text);
  font-size: 18px;
}

.board-tabs-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 10px;
}

.board-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
}

.board-tabs::-webkit-scrollbar { display: none; }

.board-tab {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  background: var(--secondary);
  color: var(--text);
  white-space: nowrap;
  font-size: 14px;
}

.board-tab.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.board-tab.custom .tab-delete {
  margin-left: 6px;
  opacity: 0.7;
}

.tab-add {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--accent);
  font-size: 22px;
  line-height: 1;
}

.content {
  flex: 1;
  min-height: 0;
}

.board-meta {
  padding: 10px 14px 0;
  color: var(--hint);
  font-size: 13px;
}

.board {
  display: flex;
  gap: 12px;
  padding: 12px;
  overflow-x: auto;
  min-height: calc(100vh - 190px);
  align-items: flex-start;
}

.column {
  flex: 0 0 280px;
  background: var(--secondary);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}

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

.column-head h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.column-count {
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

.card {
  background: var(--bg);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease;
}

.card[draggable="true"] { cursor: grab; }
.card[draggable="true"]:active { cursor: grabbing; transform: scale(.98); }

.card-id {
  font-weight: 700;
  font-size: 13px;
  color: var(--accent);
}

.card-summary {
  margin-top: 6px;
  font-size: 14px;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.column.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

.empty-board {
  padding: 40px 20px;
  text-align: center;
  color: var(--hint);
}

.task-search {
  display: flex;
  gap: 8px;
  padding: 14px;
}

.task-search input {
  flex: 1;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--secondary);
  color: var(--text);
  padding: 12px 14px;
  font-size: 16px;
}

.task-search button,
.btn-primary,
.btn-secondary {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
}

.task-search button,
.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn-secondary {
  background: var(--secondary);
  color: var(--text);
  border: 1px solid var(--border);
}

.task-result {
  padding: 0 14px 14px;
}

.task-card {
  background: var(--secondary);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.task-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.task-card-head h2 {
  font-size: 18px;
  color: var(--accent);
}

.stage-badge {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  white-space: nowrap;
}

.task-summary {
  margin: 12px 0;
  font-size: 17px;
  font-weight: 600;
}

.task-description {
  white-space: pre-wrap;
  color: var(--hint);
  font-size: 14px;
  margin-bottom: 14px;
}

.stage-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.stage-chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

.stage-chip.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.comments-block {
  margin-top: 16px;
}

.comments-block h3,
.section-title {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.comment {
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
}

.comment-author {
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 4px;
}

.comment-text {
  white-space: pre-wrap;
  font-size: 14px;
}

.task-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.task-actions textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 10px 12px;
}

.questions { padding: 14px; }

.q-item {
  background: var(--secondary);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.q-item textarea {
  width: 100%;
  margin-top: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 10px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}

.nav-btn {
  position: relative;
  border: 0;
  background: transparent;
  color: var(--hint);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
}

.nav-btn.active { color: var(--accent); }
.nav-icon { font-size: 18px; line-height: 1; }

.badge {
  position: absolute;
  top: 8px;
  right: calc(50% - 24px);
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #ff453a;
  color: #fff;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 16px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.88);
  color: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
  z-index: 20;
}

#toast.show { opacity: 1; }

dialog {
  border: 0;
  border-radius: 18px;
  padding: 18px;
  width: min(440px, calc(100vw - 24px));
  background: var(--secondary);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

dialog label {
  display: block;
  margin-top: 12px;
}

dialog label span {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--hint);
}

dialog input,
dialog textarea,
#dialog-comment {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 10px 12px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.dialog-head a {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
}

.dialog-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

#view-task.hidden,
#view-boards.hidden,
#view-questions.hidden,
#board-tabs-wrap.hidden {
  display: none;
}
