/* ==========================================================================
   Cubealg Tabler · 公式库（v2）
   设计取向：浅色、大留白、卡片化，让公式图本身成为视觉主体
   ========================================================================== */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --line: #e6e8ee;
  --line-strong: #d3d7e0;
  --ink: #14161c;
  --ink-2: #4b5261;
  --ink-3: #8b93a3;
  --accent: #2f6df6;
  --accent-soft: #eaf1ff;
  --red: #ee0000;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 22, 28, .04), 0 4px 14px rgba(20, 22, 28, .05);
  --shadow-hover: 0 2px 6px rgba(20, 22, 28, .07), 0 10px 28px rgba(20, 22, 28, .08);
  --mono: var(--font-mono);
}

* { box-sizing: border-box; }

/*
 * 必须显式声明：作者样式里的 .app{display:flex} / .boot{display:flex}
 * 与 UA 的 [hidden]{display:none} 特异度相同，但作者样式在后 ——
 * 不写这条的话 hidden 属性完全失效（实测加载层一直盖在页面上）。
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.6;
  /* Inter 的 cv05/ss03：单层 a、更清晰的 i，界面感更精致 */
  font-feature-settings: "cv05" 1, "ss03" 1;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font-family: inherit; color: inherit; }
button { font: inherit; }

/* ---------------------------------------------------------------- 布局 */

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 15.5px;
  letter-spacing: -.028em;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  width: 20px;
  height: 20px;
}

.brand-mark i {
  background: var(--c);
  border-radius: 3px;
}

/* 公式集切换 */
.sets {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.sets button {
  border: 0;
  background: none;
  padding: 6px 15px;
  border-radius: 7px;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink-2);
  cursor: pointer;
  transition: .14s;
}

.sets button:hover { color: var(--ink); }

.sets button[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
}

/* 分段控件 */
.seg {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.seg button {
  border: 0;
  background: none;
  padding: 5px 11px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-3);
  cursor: pointer;
  white-space: nowrap;
  transition: .14s;
}

.seg button:hover { color: var(--ink-2); }

.seg button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow);
}

.ctrl-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-right: 6px;
}

.ctrl {
  display: flex;
  align-items: center;
}

/* 色卡 */
.swatches { display: flex; gap: 4px; }

.rail-orient {
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.orient-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.orient-k {
  flex: 0 0 auto;
  width: 30px;
  font-size: 10.5px;
  font-weight: 800;
  color: var(--ink-3);
  font-family: var(--mono);
}

.swatch {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
  transition: .12s;
}

.swatch[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12), 0 0 0 2px var(--accent-soft);
}

.swatch[disabled] { opacity: .22; cursor: not-allowed; }

/* 主体 */
.body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

/* ---------------------------------------------------------------- 左栏 */

.rail {
  width: 232px;
  flex: 0 0 auto;
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.rail-search {
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.rail-search input {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--ink);
  outline: none;
  transition: .14s;
}

.rail-search input:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.rail-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px;
}

.rail-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  background: none;
  border-radius: 7px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  text-align: left;
  transition: .12s;
}

.rail-item:hover { background: var(--surface-2); color: var(--ink); }

.rail-item[aria-current="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.rail-item .cnt {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  font-weight: 500;
}

.rail-item[aria-current="true"] .cnt { color: var(--accent); }

.rail-foot {
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-3);
}

/* ---------------------------------------------------------------- 主区 */

.main {
  flex: 1 1 auto;
  overflow-y: auto;
  min-width: 0;
}

.main-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px 30px 80px;
}

.page-head {
  margin-bottom: 22px;
}

.page-title {
  margin: 0;
  font-family: var(--font-brand);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -.035em;
  line-height: 1.15;
}

.page-sub {
  margin: 5px 0 0;
  color: var(--ink-3);
  font-size: 13px;
}

/* 分组 */
.group {
  margin-bottom: 34px;
  scroll-margin-top: 16px;
}

.group-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 14px;
  padding-bottom: 9px;
  border-bottom: 2px solid var(--line);
}

.group-title {
  margin: 0;
  font-family: var(--font-brand);
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: -.025em;
}

.group-bracket {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-3);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
}

.group-cnt {
  margin-left: auto;
  font-size: 12px;
  color: var(--ink-3);
}

/* 卡片网格 */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 14px;
}

.card {
  display: flex;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px;
  transition: box-shadow .16s, border-color .16s, transform .16s;
}

.card:hover {
  box-shadow: var(--shadow-hover);
  border-color: var(--line-strong);
}

.fig {
  flex: 0 0 auto;
  width: 92px;
  height: 92px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.fig svg { display: block; max-width: 100%; max-height: 100%; }

.fig-wide { width: 108px; height: 108px; }

.meta { flex: 1 1 auto; min-width: 0; }

.case-name {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 6px;
}

.case-id {
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 14.5px;
  letter-spacing: -.02em;
}

.case-num {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 5px;
}

.tags { display: flex; flex-wrap: wrap; gap: 4px; }

.tag {
  font-size: 10.5px;
  font-weight: 600;
  color: #a1601a;
  background: #fff4e2;
  border: 1px solid #ffe0b5;
  border-radius: 5px;
  padding: 1px 5px;
  white-space: nowrap;
}

/*
 * 公式列表限高：PLL A+ 有 12 条解法，不限高会把卡片撑到 500px，
 * 同一行的卡片按最高的对齐，网格里就会出现大片空白。
 */
.algs {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 186px;
  overflow-y: auto;
  scrollbar-width: thin;
  padding-right: 4px;
}

.algs::-webkit-scrollbar { width: 5px; }
.algs::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }

.algs li {
  display: flex;
  gap: 7px;
  align-items: baseline;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--ink);
  line-height: 1.5;
}

.algs li .idx {
  flex: 0 0 auto;
  min-width: 15px;
  font-size: 10px;
  color: var(--ink-3);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.algs li .alg { word-break: break-word; }

.algs li.primary .alg { font-weight: 600; }

.scramble {
  margin-top: 7px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
}

.scramble b { color: var(--ink-2); font-weight: 600; }

.pre {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-3);
  border: 1px dashed var(--line-strong);
  border-radius: 4px;
  padding: 0 4px;
  margin-left: 5px;
}

/* ---------------------------------------------------------------- Cross 文档流 */

.doc { max-width: 880px; }

.doc h2 {
  font-size: 19px;
  margin: 34px 0 12px;
  letter-spacing: -.02em;
  padding-bottom: 7px;
  border-bottom: 2px solid var(--line);
}

.doc h2:first-child { margin-top: 0; }

.doc h3 {
  font-size: 14.5px;
  margin: 22px 0 10px;
  color: var(--ink-2);
}

.doc-group {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 16px 12px;
  margin-bottom: 14px;
}

.doc-alg {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px dashed var(--line);
}

.fig-sm {
  width: 74px;
  height: 74px;
  border-radius: 8px;
}

.doc-alg-body { flex: 1 1 auto; min-width: 0; }

.doc-alg-line { display: flex; gap: 10px; align-items: baseline; }

.doc-alg-scr {
  margin-top: 2px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-3);
}

.doc-alg:last-child { border-bottom: 0; }

.doc-alg .no {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}

.doc-alg .alg-list {
  font-family: var(--mono);
  font-size: 13.5px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 4px;
  align-items: baseline;
}

.doc-alg .alt {
  color: var(--ink);
}

.doc-alg .alt + .alt::before {
  content: "/";
  color: var(--ink-3);
  margin-right: 7px;
}

.doc-alg .flag {
  font-size: 10.5px;
  color: var(--ink-3);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 0 5px;
}

.doc-text {
  color: var(--ink-2);
  font-size: 13.5px;
  padding: 5px 0;
}

.doc-item {
  color: var(--ink-2);
  font-size: 13.5px;
  padding: 4px 0 4px 18px;
  position: relative;
}

.doc-item::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 13px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--line-strong);
}

.doc-sub {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-3);
  text-transform: none;
  margin: 12px 0 2px;
  letter-spacing: .01em;
}

/* ---------------------------------------------------------------- 加载/空态 */

.placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--line-strong);
  font-size: 11px;
}

.empty {
  padding: 70px 20px;
  text-align: center;
  color: var(--ink-3);
}

.boot {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 50;
}

.boot-inner { text-align: center; color: var(--ink-3); font-size: 13px; }

.boot-dots { display: flex; gap: 5px; justify-content: center; margin-bottom: 12px; }

.boot-dots i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--line-strong);
  animation: bob 1s infinite ease-in-out;
}

.boot-dots i:nth-child(2) { animation-delay: .12s; }
.boot-dots i:nth-child(3) { animation-delay: .24s; }

@keyframes bob {
  0%, 80%, 100% { transform: translateY(0); opacity: .5; }
  40% { transform: translateY(-5px); opacity: 1; }
}

.fatal {
  padding: 40px;
  font-family: var(--mono);
  color: #b91c1c;
  white-space: pre-wrap;
}


/* 顶部导航链接（公式库 <-> 版式设计） */
.tab-link {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  text-decoration: none;
  white-space: nowrap;
  transition: .14s;
}

.tab-link:hover { color: var(--accent); background: var(--accent-soft); }
