/* Тёмная тема, один акцент. Без внешних шрифтов — только системные. */
:root {
  --bg: #14161a;
  --panel: #1c1f26;
  --panel-2: #232732;
  --border: #2e3340;
  --text: #e7e9ee;
  --muted: #9aa2b1;
  --accent: #e6b450;
  --bad: #e06c6c;
  --ok: #d8a24a;
  --good: #5fbf8f;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

/* Сетке иероглифов нужно больше места, чем списку карточек. */
.app-wide { max-width: 960px; }

.hidden { display: none !important; }

h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.35rem; margin: 0; }

/* --- шапка списка --- */

.page-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  justify-content: space-between;
  margin: 8px 0 18px;
}

.user-box { display: flex; flex-direction: column; gap: 4px; }
.user-box label { font-size: 0.75rem; color: var(--muted); }

input, select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.95rem;
  font-family: inherit;
  min-width: 0;
}

input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.user-box input { width: 170px; }

/* --- вкладки --- */

.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.tab {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  min-height: 44px;
}

.tab:hover { color: var(--text); }

.tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* «Иероглифы» — отдельная страница, но выглядит как вкладка. */
a.tab { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

/* --- фильтры --- */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 14px;
}

.field { display: flex; flex-direction: column; gap: 4px; flex: 1 1 130px; }
.field span { font-size: 0.75rem; color: var(--muted); }
.field-wide { flex: 1 1 200px; }
.field select, .field input { width: 100%; }

.status { color: var(--muted); font-size: 0.85rem; margin: 0 0 10px; }

/* --- пагинация --- */

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 16px;
}

.pager .btn { flex: 0 0 auto; min-height: 44px; }

.pager-info {
  flex: 1 1 auto;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Настройка повторения: фильтры идут колонкой, а не в одну строку. */
.controls-stack { flex-direction: column; align-items: stretch; }
.controls-stack .field { flex: 0 0 auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.panel-title { font-size: 1.05rem; margin: 0 0 10px; }
.panel .status { margin: 10px 0 0; }
.panel .field { margin-bottom: 10px; }

.hint { color: var(--muted); font-size: 0.82rem; margin: 12px 0 0; }

.error {
  background: #3a2326;
  border: 1px solid #6b3b40;
  color: #ffd9d9;
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 14px;
  font-size: 0.9rem;
}

/* --- кнопки --- */

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

.btn:hover:not(:disabled) { background: #2b3140; border-color: #3d4453; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-ghost { background: transparent; }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1408;
  font-weight: 600;
}

.btn-accent:hover:not(:disabled) { background: #f0c266; border-color: #f0c266; }

/* --- список карточек --- */

.card-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.card-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.card-item:hover { background: var(--panel-2); }
.card-item-title { font-size: 1.05rem; font-weight: 600; margin-bottom: 6px; }

.meta { display: flex; flex-wrap: wrap; gap: 6px; }

.badge {
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}

/* --- экран карточки --- */

.card-top { margin-bottom: 12px; }

.card-head {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.card-head h2 { margin-bottom: 8px; }

.preamble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  white-space: pre-wrap;
  font-size: 0.95rem;
}

.sections { display: flex; flex-direction: column; gap: 10px; }

/* --- спойлер --- */

.spoiler {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s ease;
}

.spoiler.open { border-color: #3d4453; }

.spoiler-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  text-align: left;
  padding: 14px;
  cursor: pointer;
  /* Крупная зона нажатия для пальца. */
  min-height: 52px;
}

.spoiler-head:hover { background: var(--panel-2); }

.spoiler-label { display: flex; align-items: center; gap: 8px; }
.spoiler-label::before {
  content: "▸";
  color: var(--accent);
  font-size: 0.9rem;
  transition: transform 0.15s ease;
}
.spoiler.open .spoiler-label::before { transform: rotate(90deg); }

.spoiler-hint { font-size: 0.72rem; font-weight: 400; color: var(--muted); white-space: nowrap; }

.spoiler-body {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.22s ease, opacity 0.22s ease;
}

.spoiler-content {
  padding: 0 14px 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-size: 0.98rem;
  line-height: 1.6;
}

.spoiler-content.cjk-large {
  font-family: "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", "Heiti SC", sans-serif;
  font-size: 2.1rem;
  line-height: 1.4;
  letter-spacing: 0.05em;
}

.spoiler-content.is-empty { color: var(--muted); font-style: italic; }

/* --- самооценка --- */

.rating {
  margin-top: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.rating-label { font-size: 0.85rem; color: var(--muted); margin-bottom: 10px; }

.rating-buttons { display: flex; gap: 10px; }

.rate {
  flex: 1 1 0;
  min-height: 56px;
  padding: 12px 8px;
  font-size: 0.95rem;
  border-radius: 12px;
}

.rate-bad { border-color: #5e3030; color: #ffb3b3; }
.rate-bad:hover:not(:disabled) { background: #35242a; }

.rate-ok { border-color: #5b4a28; color: #ffd79a; }
.rate-ok:hover:not(:disabled) { background: #332e22; }

.rate-good { border-color: #2c5142; color: #a9e6c9; }
.rate-good:hover:not(:disabled) { background: #22332c; }

.rating-info { margin: 12px 0 0; font-size: 0.85rem; color: var(--muted); transition: color 0.2s ease; }
.rating-info.flash { color: var(--accent); }

/* --- сессия повторения --- */

.session-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
}

.session-counter { font-size: 0.85rem; color: var(--muted); white-space: nowrap; }

.session-progress {
  flex: 1 1 120px;
  height: 6px;
  background: var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
}

.session-progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s ease;
}

.session-head .btn { padding: 6px 12px; font-size: 0.85rem; min-height: 0; }

/* «Новая карточка» в мете сессии. */
.badge.badge-new { color: #1a1408; background: var(--accent); border-color: var(--accent); }

/* --- навигация карточки --- */

.card-nav { display: flex; gap: 10px; margin-top: 18px; }
.card-nav .btn { flex: 1 1 0; min-height: 48px; }

/* --- подвал --- */

.foot { margin-top: 32px; text-align: center; font-size: 0.85rem; }
.foot a { color: var(--muted); text-decoration: none; border-bottom: 1px solid var(--border); }
.foot a:hover { color: var(--accent); border-color: var(--accent); }

/* --- сетка иероглифов --- */

.subtitle { color: var(--muted); font-size: 0.85rem; margin: 4px 0 0; }

.glyph-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 10px;
}

.glyph-tile {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-family: "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", "Heiti SC", sans-serif;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.glyph-tile:hover, .glyph-tile:focus-visible {
  background: var(--panel-2);
  border-color: var(--accent);
  color: var(--accent);
}

.glyph-tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.glyph-char { line-height: 1.1; text-align: center; word-break: break-all; }
.glyph-char.len-1 { font-size: 2.6rem; }
.glyph-char.len-2 { font-size: 1.8rem; }
.glyph-char.len-3 { font-size: 1.35rem; }
.glyph-char.len-many { font-size: 1rem; }

/* --- мобильные --- */

@media (max-width: 560px) {
  .app { padding: 12px 12px 32px; }
  h1 { font-size: 1.25rem; }
  h2 { font-size: 1.15rem; }
  .user-box, .user-box input { width: 100%; }
  .page-head { flex-direction: column; align-items: stretch; }
  .rating-buttons { flex-direction: column; }
  .rate { min-height: 60px; font-size: 1rem; }
  .spoiler-hint { display: none; } /* на узком экране подсказка не влезает */
  .spoiler-content.cjk-large { font-size: 1.8rem; }
  .tabs { gap: 0; }
  .tab { flex: 1 1 0; padding: 10px 6px; font-size: 0.9rem; }
  .session-head { padding: 10px; }
  .session-progress { flex: 1 1 100%; order: 3; }
  .glyph-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; }
  .glyph-char.len-1 { font-size: 2.1rem; }
  .glyph-char.len-2 { font-size: 1.5rem; }
  .glyph-char.len-3 { font-size: 1.1rem; }
  .glyph-char.len-many { font-size: 0.85rem; }
}

@media (max-width: 380px) {
  .app { padding: 10px 10px 28px; }
  .controls { padding: 10px; }
  .field { flex: 1 1 100%; }
  .card-item-title { font-size: 1rem; }
  .btn { padding: 9px 12px; font-size: 0.9rem; }
  .tab { padding: 9px 3px; font-size: 0.82rem; }
  .glyph-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 7px; }
}

/* --- серверный режим: шапка, вход, загрузка --- */

.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-badge-name {
  font-size: 0.95rem;
  color: var(--text);
  font-weight: 600;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-badge .btn { padding: 7px 12px; font-size: 0.85rem; }

.auth-panel { max-width: 460px; margin: 24px auto; }

.login-form { display: flex; flex-direction: column; gap: 10px; }
.login-form .field { margin-bottom: 0; }

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

textarea {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.5;
  resize: vertical;
  min-height: 64px;
  width: 100%;
  min-width: 0;
}

textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.panel-subtitle { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }

/* --- перенос локального прогресса --- */

.migration { border-color: #5b4a28; }
.migration .hint { margin: 0 0 4px; }

/* --- комментарии --- */

.comments {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.comment-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }

.comment {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.comment-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.comment-author { font-weight: 600; font-size: 0.92rem; color: var(--accent); }

.comment-date { font-size: 0.75rem; color: var(--muted); }

.comment-text {
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-size: 0.95rem;
  line-height: 1.55;
}

.comment-empty { color: var(--muted); font-size: 0.85rem; margin: 0 0 12px; }

.comment-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.comment-image-link { display: block; line-height: 0; }

.comment-image {
  width: 128px;
  height: 128px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
}

.comment-delete {
  margin-top: 10px;
  padding: 5px 10px;
  font-size: 0.78rem;
  color: var(--bad);
  border-color: #5e3030;
}

.comment-form { margin: 0; }
.comment-form .field { margin-bottom: 10px; }
.comment-form .btn { margin-top: 4px; }

.comment-preview { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 10px; }
.comment-preview:empty { display: none; }

.comment-preview-item { margin: 0; width: 96px; }
.comment-preview-image {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: block;
}
.comment-preview-name {
  font-size: 0.7rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- форма создания карточки --- */

.create-sections { display: flex; flex-direction: column; gap: 10px; }
.create-sections .field { margin-bottom: 0; }

/* --- статистика --- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.stat-value {
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.stat-label { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 140px;
  padding: 8px 2px 0;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.chart-bar {
  flex: 1 0 3px;
  min-width: 3px;
  max-width: 24px;
  background: linear-gradient(to top, var(--accent), #f0c266);
  border-radius: 2px 2px 0 0;
  min-height: 1px;
  opacity: 0.9;
}

.chart-bar.is-zero { background: var(--border); opacity: 0.5; }

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

.dist-row {
  display: grid;
  grid-template-columns: 110px 1fr 48px;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}

.dist-track { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.dist-fill { height: 100%; border-radius: 999px; }
.dist-fill.bad { background: var(--bad); }
.dist-fill.ok { background: var(--ok); }
.dist-fill.good { background: var(--good); }
.dist-count { text-align: right; color: var(--muted); }

.table-wrap { overflow-x: auto; }

.leaderboard {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.leaderboard th, .leaderboard td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.leaderboard th { color: var(--muted); font-weight: 500; font-size: 0.75rem; }
.leaderboard td.num, .leaderboard th.num { text-align: right; }
.leaderboard tr.is-me td { color: var(--accent); font-weight: 600; }
.leaderboard .rank { color: var(--muted); }

/* --- мобильные дополнения --- */

@media (max-width: 560px) {
  .user-badge { width: 100%; justify-content: space-between; }
  .user-badge-name { max-width: 60vw; }
  .comment-image { width: 96px; height: 96px; }
  .dist-row { grid-template-columns: 84px 1fr 40px; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); }
  .chart { height: 110px; }
  .row .btn { flex: 1 1 auto; }
}

@media (max-width: 380px) {
  .comment-image { width: 80px; height: 80px; }
  .stat-value { font-size: 1.4rem; }
}
