/* ============================================
   汉语大师 PRO — Стили
   ============================================ */

:root {
  --bg: #fdfcf8;
  --bg2: #ffffff;
  --bg3: #f1f5f9;
  --a: #d32f2f;
  --a2: #f57c00;
  --a-hover: #b71c1c;
  --t: #1e293b;
  --d: #64748b;
  --ok: #059669;
  --ok-bg: #d1fae5;
  --err: #e11d48;
  --err-bg: #ffe4e6;
  --b: #e2e8f0;
  --glass: rgba(255, 255, 255, 0.85);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
}

body {
  background: var(--bg);
  color: var(--t);
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 10% 20%, rgba(211,47,47,0.03), transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(245,124,0,0.04), transparent 40%);
}

/* ============ HEADER ============ */
header {
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--b);
  background: var(--glass);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 20px;
  font-weight: 800;
  color: #0f172a;
}

.logo .zh {
  color: var(--a);
}

nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

nav button {
  background: transparent;
  border: none;
  color: var(--d);
  padding: 8px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

nav button:hover {
  color: var(--t);
  background: var(--bg3);
}

nav button.active {
  background: var(--a);
  color: #fff;
  box-shadow: 0 4px 12px rgba(211, 47, 47, 0.25);
}

/* ============ LAYOUT ============ */
main {
  max-width: 1700px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

.panel {
  display: none;
  animation: fadeIn 0.3s ease;
}

.panel.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-title {
  font-size: 28px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 20px;
}

.page-title.center {
  text-align: center;
}

/* ============ DASHBOARD STATS ============ */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat {
  background: var(--bg2);
  border: 1px solid var(--b);
  border-radius: 16px;
  padding: 20px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0,0,0,0.04);
}

.stat::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--a), var(--a2));
}

.stat-label {
  color: var(--d);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.stat-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--a);
}

.stat-value small {
  font-size: 16px;
  color: var(--d);
  font-weight: 500;
}

/* ============ ЗАГОЛОВОК + ВЫПАДАЮЩИЙ СПИСОК ============ */
.nav-header-row {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--b);
  padding-bottom: 16px;
  flex-wrap: wrap;
}

.nav-header-row h2 {
  font-size: 28px;
  font-weight: 800;
  color: #0f172a;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 20px;
}

.macro-select {
  appearance: none;
  -webkit-appearance: none;
  padding: 8px 40px 8px 20px;
  border-radius: 12px;
  border: 2px solid var(--a);
  background: var(--bg2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23d32f2f' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") no-repeat right 12px center / 18px;
  color: var(--a);
  font-weight: 800;
  font-size: 18px;
  cursor: pointer;
  outline: none;
  box-shadow: 0 4px 10px rgba(211, 47, 47, 0.1);
  transition: all 0.2s;
}

.macro-select:hover {
  background-color: var(--a);
  color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

/* ============ ПОИСК ============ */
.search-wrap {
  flex: 1;
  min-width: 260px;
  max-width: 480px;
  display: flex;
  align-items: center;
}

.search-box {
  width: 100%;
  height: 48px;
  padding: 0 20px 0 44px;
  border-radius: 12px;
  border: 2px solid var(--a);
  background: var(--bg2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23d32f2f' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat left 14px center / 18px;
  color: var(--t);
  font-weight: 600;
  font-size: 15px;
  outline: none;
  transition: all 0.2s;
  box-shadow: 0 4px 10px rgba(211, 47, 47, 0.08);
}

.search-box::placeholder {
  color: var(--d);
  font-weight: 500;
  font-size: 14px;
}

.search-box:focus {
  border-color: var(--a-hover);
  box-shadow: 0 4px 14px rgba(211, 47, 47, 0.2);
  background-color: #fff;
}

.search-results {
  display: none;
  margin-bottom: 24px;
}

.search-results.active {
  display: block;
}

.search-results-header {
  font-size: 14px;
  color: var(--d);
  margin-bottom: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.search-results-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  max-height: 480px;
  overflow-y: auto;
  padding-right: 8px;
}

.search-result-item {
  padding: 14px 16px;
  background: var(--bg2);
  border: 1px solid var(--b);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.search-result-item:hover {
  background: var(--bg3);
  border-color: var(--a);
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0,0,0,0.06);
}

.search-result-hanzi {
  font-family: "Kaiti", serif;
  font-size: 1.4rem;
  color: var(--a);
  font-weight: bold;
  margin-bottom: 4px;
  letter-spacing: 1px;
}

.search-result-pinyin {
  font-size: 0.82rem;
  color: var(--d);
  font-style: italic;
  margin-bottom: 6px;
}

.search-result-trans {
  font-size: 0.85rem;
  color: var(--t);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.search-no-results {
  padding: 30px;
  text-align: center;
  color: var(--d);
  font-style: italic;
  font-size: 15px;
}

/* ============ ПАГИНАЦИЯ БЛОКОВ ============ */
.pagination-tier.blocks {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 12px;
  margin-bottom: 24px;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--a2) var(--b);
}

.pagination-tier.blocks::-webkit-scrollbar {
  height: 6px;
}

.pagination-tier.blocks::-webkit-scrollbar-thumb {
  background: var(--a2);
  border-radius: 10px;
}

.page-btn {
  flex: 0 0 auto;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--b);
  background: var(--bg2);
  color: var(--d);
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s;
  font-size: 14px;
}

.page-btn:hover {
  background: var(--bg3);
  color: var(--t);
  border-color: var(--d);
}

.page-btn.active {
  background: var(--a2);
  color: #fff;
  border-color: var(--a2);
  box-shadow: 0 4px 8px rgba(245, 124, 0, 0.2);
}

/* ============ 4-КОЛОНОЧНАЯ СТРУКТУРА ============ */
.cy-layout {
  display: grid;
  grid-template-columns: 150px 420px 1fr 1fr;
  gap: 24px;
  align-items: stretch;
}

/* 1. Вертикальное меню */
.sidebar-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-btn {
  font-family: "Kaiti", "KaiTi_GB2312", serif;
  font-size: 1.4rem;
  padding: 10px 12px;
  border-radius: 10px;
  text-align: center;
  background: var(--bg2);
  border: 1px solid var(--b);
  cursor: pointer;
  transition: 0.2s;
  color: var(--t);
  font-weight: bold;
  width: 100%;
  letter-spacing: 2px;
}

.item-btn:hover {
  background: var(--bg3);
  border-color: var(--a);
  color: var(--a);
  transform: translateX(3px);
}

.item-btn.active {
  background: linear-gradient(135deg, var(--a), var(--a-hover));
  color: #fff;
  border-color: var(--a);
  box-shadow: 0 4px 10px rgba(211, 47, 47, 0.25);
  transform: translateX(3px);
}

/* ============ КАРТОЧКА ============ */
.card-wrap {
  perspective: 1500px;
  width: 100%;
  cursor: pointer;
  height: 620px;
}

.card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.card.flip {
  transform: rotateY(180deg);
}

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 20px;
  background: var(--bg2);
  border: 1px solid var(--b);
  padding: 20px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 25px rgba(0,0,0,0.05);
}

.face-front {
  justify-content: center;
  align-items: center;
  text-align: center;
  background: linear-gradient(145deg, #fff, #f8fafc);
  overflow: hidden;
  z-index: 2;
}

.face-back {
  transform: rotateY(180deg);
  overflow-y: auto;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  padding: 16px;
  z-index: 1;
}

.card.flip .face-front {
  z-index: 1;
}

.card.flip .face-back {
  z-index: 2;
}

.face-back::-webkit-scrollbar {
  width: 4px;
}

.face-back::-webkit-scrollbar-thumb {
  background-color: var(--d);
  border-radius: 10px;
}

.watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: "Kaiti", "KaiTi", serif;
  font-size: 22rem;
  font-weight: 700;
  color: rgba(211, 47, 47, 0.05);
  pointer-events: none;
  user-select: none;
  z-index: 0;
  line-height: 1;
}

.face-front > *:not(.watermark):not(.df-badge) {
  position: relative;
}

/* ============ БЕЙДЖ DF ============ */
.df-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: #c0392b;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 5px;
  letter-spacing: 0.3px;
  display: none;
  box-shadow: 0 1px 4px rgba(192, 57, 43, 0.3);
  font-family: system-ui, -apple-system, sans-serif;
  line-height: 1.2;
  pointer-events: none;
}

/* ============ КАРТИНКА 240×240 ============ */
.card-image-wrap {
  width: 240px;
  height: 240px;
  margin: 0 auto 12px;
  border-radius: 12px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
  flex-shrink: 0;
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.3s;
  opacity: 0;
  position: relative;
  z-index: 1;
}

.card-image.loaded {
  opacity: 1;
}

.card-image-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Kaiti", serif;
  font-size: 5rem;
  color: rgba(211, 47, 47, 0.15);
  z-index: 0;
  background: linear-gradient(135deg, #fef2f2, #fef9f3);
}

/* ============ ИЕРОГЛИФЫ ============ */
.hanzi-lg {
  font-family: "Kaiti", serif;
  font-size: 3.8rem;
  font-weight: 700;
  line-height: 1.2;
  background: linear-gradient(135deg, var(--a), var(--a2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 10px;
  text-shadow: 2px 2px 4px rgba(211, 47, 47, 0.1);
  letter-spacing: 4px;
}

.pinyin {
  color: var(--d);
  font-size: 1.2rem;
  text-align: center;
  font-weight: 500;
  font-style: italic;
  width: 100%;
  margin: 0;
}

.trans {
  text-align: center;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--a);
  width: 100%;
  margin: 0;
  line-height: 1.4;
}

/* ============ РАЗБОР ПО ИЕРОГЛИФАМ ============ */
.breakdown {
  background: transparent;
  border: none;
  border-radius: 12px;
  padding: 0;
  width: 100%;
  margin-top: 6px;
}

.breakdown-item {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
  background: var(--bg3);
  padding: 6px 10px;
  border-radius: 8px;
  border-left: 4px solid var(--a2);
}

.breakdown-item:last-child {
  margin-bottom: 0;
}

.breakdown-char {
  font-family: "Kaiti", serif;
  font-size: 1.6rem;
  color: var(--a);
  font-weight: bold;
  margin-right: 10px;
  line-height: 1;
  min-width: 32px;
}

.breakdown-py {
  font-size: 0.95rem;
  color: var(--d);
  margin-right: 10px;
  font-style: italic;
  font-weight: 600;
  min-width: 55px;
}

.breakdown-mean {
  font-size: 0.95rem;
  color: #1e293b;
  font-weight: 500;
}

.hint-bottom {
  color: var(--d);
  font-size: 14px;
  position: absolute;
  bottom: 16px;
}

/* ============ ИНФО-ПАНЕЛИ ============ */
.info-panel {
  background: var(--bg2);
  border: 1px solid var(--b);
  border-radius: 20px;
  padding: 20px 26px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 620px;
}

.info-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--a);
  margin-bottom: 16px;
  border-bottom: 2px dashed var(--b);
  padding-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ============ ТЕКСТ ИСТОРИИ ============ */
.info-text {
  font-size: 0.95rem;
  line-height: 1.7;
  color: #334155;
  overflow-y: auto;
  padding-right: 12px;
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
  word-break: break-word;
}

.info-text p {
  text-indent: 2rem;
  margin-bottom: 12px;
}

.info-text p:first-child,
.info-text p.no-indent,
.info-text p:has(> b:first-child),
.info-text .source-line,
.info-text .source-line *,
.info-text .quote,
.info-text .quote * {
  text-indent: 0 !important;
}

.info-text p:last-child {
  margin-bottom: 0;
}

.info-text::-webkit-scrollbar {
  width: 4px;
}

.info-text::-webkit-scrollbar-thumb {
  background-color: var(--d);
  border-radius: 10px;
}

/* ============ ИСТОЧНИК И ЦИТАТА ============ */
.source-line {
  background: #fff8e6;
  border-left: 3px solid #f0b429;
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 13.5px;
  color: #8a6d1f;
  border-radius: 4px;
  font-family: 'Microsoft YaHei', 'PingFang SC', 'SimHei', sans-serif;
  line-height: 1.5;
  text-align: left;
}

.source-line.source-none {
  background: #f0f0f0;
  border-left-color: #b0b0b0;
  color: #666;
  font-family: inherit;
}

.quote {
  background: #f8f6f1;
  padding: 10px 14px;
  margin-bottom: 14px;
  border-radius: 6px;
  text-align: left;
}

.quote .q-zh {
  font-size: 15px;
  margin-bottom: 6px;
  color: #2c3e50;
  font-family: 'Microsoft YaHei', 'PingFang SC', 'SimHei', 'Kaiti', serif;
  line-height: 1.5;
}

.quote .q-ru {
  font-size: 13px;
  color: #7f8c8d;
  font-style: italic;
  line-height: 1.4;
}

/* ============ ПРИМЕРЫ ============ */
.examples-container {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  flex: 1;
  height: 100%;
  gap: 10px;
  overflow-y: auto;
  padding-right: 8px;
}

.examples-container::-webkit-scrollbar {
  width: 4px;
}

.examples-container::-webkit-scrollbar-thumb {
  background-color: var(--d);
  border-radius: 10px;
}

.example-box {
  background: var(--bg3);
  border-left: 4px solid var(--ok);
  padding: 10px 14px;
  border-radius: 10px;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.example-box:hover {
  transform: translateX(4px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.03);
}

.ex-zh {
  font-size: 1.05rem;
  color: var(--t);
  margin-bottom: 5px;
  line-height: 1.5;
}

.ex-zh b {
  color: var(--a);
  font-size: 1.2rem;
  font-family: "Kaiti", serif;
  padding: 0 3px;
  font-weight: 700;
}

.ex-ru {
  font-size: 0.9rem;
  color: var(--d);
  line-height: 1.4;
}

.ex-ru b {
  color: var(--a);
  font-weight: 700;
}

/* ============ КНОПКИ ============ */
.controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 20px;
}

.btn {
  padding: 12px 24px;
  border-radius: 14px;
  border: 1px solid var(--b);
  background: var(--bg2);
  color: var(--t);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:hover:not(:disabled) {
  background: var(--bg3);
  transform: translateY(-1px);
}

.btn-p {
  background: var(--a);
  border-color: var(--a);
  color: #fff;
}

.btn-p:hover:not(:disabled) {
  background: var(--a-hover);
  border-color: var(--a-hover);
}

.btn-ok {
  background: var(--ok-bg);
  border-color: var(--ok);
  color: var(--ok);
}

.btn-err {
  background: var(--err-bg);
  border-color: var(--err);
  color: var(--err);
}

.btn-icon {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  background: var(--bg3);
}

/* ============ ВИКТОРИНА ============ */
.quiz-box {
  max-width: 600px;
  margin: 0 auto;
  background: var(--bg2);
  border: 1px solid var(--b);
  border-radius: 24px;
  padding: 28px;
}

.quiz-hanzi {
  margin-bottom: 0;
  text-align: center;
}

#qP {
  text-align: center;
}

.quiz-opts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 24px;
}

.quiz-opt {
  padding: 14px;
  background: var(--bg3);
  border: 2px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
  text-align: center;
  line-height: 1.4;
  font-size: 0.95rem;
}

.quiz-opt:hover:not(:disabled) {
  border-color: var(--a);
  background: var(--bg2);
}

.quiz-opt.ok {
  background: var(--ok-bg);
  border-color: var(--ok);
  color: var(--ok);
}

.quiz-opt.err {
  background: var(--err-bg);
  border-color: var(--err);
  color: var(--err);
}

.quiz-feedback {
  text-align: center;
  margin-top: 20px;
  font-weight: 600;
  min-height: 24px;
}

.quiz-controls {
  margin-top: 20px;
}

#qN {
  width: 100%;
}

/* ============ ПРОПИСИ ============ */
.writer-wrap {
  max-width: 500px;
  margin: 0 auto;
  text-align: center;
}

.writer-hanzi {
  font-size: 3rem;
  margin-bottom: 8px;
  color: var(--a2);
  text-shadow: none;
}

#wrT {
  font-size: 1.2rem;
  margin-bottom: 24px;
}

#character-target-div {
  width: 300px;
  height: 300px;
  margin: 0 auto 24px;
  background: #fff;
  border-radius: 24px;
  border: 4px solid var(--bg3);
  position: relative;
}

.writer-msg {
  margin-top: 16px;
  font-weight: 600;
  color: var(--a2);
}

/* ============ АДАПТИВ ============ */
@media (max-width: 1450px) {
  .cy-layout {
    grid-template-columns: 130px 350px 1fr;
  }
  .info-panel.examples {
    grid-column: 2 / -1;
    height: auto;
    min-height: 400px;
  }
}

@media (max-width: 950px) {
  .cy-layout {
    grid-template-columns: 1fr;
  }
  .sidebar-menu {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
  }
  .item-btn {
    width: calc(20% - 8px);
    text-align: center;
  }
  .card-wrap {
    max-width: 500px;
    margin: 0 auto;
    height: 600px;
  }
  .info-panel {
    height: auto;
    min-height: 300px;
  }
  .info-panel.examples {
    grid-column: 1 / -1;
  }
  .nav-header-row h2 {
    flex-direction: column;
    align-items: flex-start;
    gap: 15px;
  }
}

@media (max-width: 640px) {
  header {
    padding: 12px;
  }
  nav button {
    padding: 8px 12px;
    font-size: 13px;
  }
  .item-btn {
    width: calc(50% - 8px);
  }
  .macro-select {
    width: 100%;
  }
  .quiz-opts {
    grid-template-columns: 1fr;
  }
  .search-wrap {
    width: 100%;
    max-width: none;
  }
  .hanzi-lg {
    font-size: 3rem;
  }
  .card-image-wrap {
    width: 200px;
    height: 200px;
  }
}