/*! 计算题生成器：应用自身布局（来自原版 taez/tools/tksc），整体放在 metro.css 之后生效 */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f2f3f5; color: #222; overflow: hidden;
}
.app { display: flex; flex-direction: column; height: 100vh; }

/* ============ 顶部栏 ============ */
.topbar {
  background: #fff; border-bottom: 1px solid #ddd;
  padding: 10px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.topbar h1 { font-size: 16px; font-weight: 700; margin: 0 12px 0 0; color: #2c5fa8; }
.topbar label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: #555;
}
.topbar input[type="text"], .topbar input[type="number"] {
  padding: 6px 10px; border: 1px solid #ccc; border-radius: 3px;
  font-size: 13px; font-family: inherit;
}
.topbar input[type="number"] { width: 64px; }
.topbar input[type="text"] { width: 160px; }
.topbar select {
  padding: 6px 10px; border: 1px solid #ccc; border-radius: 3px;
  font-size: 13px; font-family: inherit; background: #fff;
}
.topbar .spacer { flex: 1; }

.btn {
  padding: 7px 16px; border: 1px solid #bbb; border-radius: 3px;
  background: #fff; color: #222; font-size: 13px; cursor: pointer;
  font-family: inherit; text-decoration: none; display: inline-block;
  transition: all .1s;
}
.btn:hover { background: #f5f5f5; }
.btn.primary { background: #2c5fa8; border-color: #2c5fa8; color: #fff; font-weight: 500; }
.btn.primary:hover { background: #244d8a; border-color: #244d8a; }
.btn.big { padding: 9px 22px; font-size: 14px; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ============ 主区 ============ */
.main { display: flex; flex: 1; min-height: 0; }

/* ============ 左侧：题型选择 ============ */
.types {
  width: 340px; flex-shrink: 0;
  background: #fff; border-right: 1px solid #ddd;
  display: flex; flex-direction: column;
}
.types-head {
  padding: 12px 14px;
  background: #fafbfc;
  border-bottom: 1px solid #eee;
  display: flex; align-items: center; gap: 8px;
}
.types-head .title {
  flex: 1;
  font-size: 13px; font-weight: 600; color: #333;
}
.types-head .title .badge {
  display: inline-block; padding: 1px 6px; margin-left: 6px;
  background: #2c5fa8; color: #fff; border-radius: 10px;
  font-size: 11px; font-weight: 500; min-width: 20px; text-align: center;
}
.types-head .btn { padding: 4px 10px; font-size: 12px; }
.types-body {
  flex: 1; overflow-y: auto; padding: 4px 0;
}

.cat-group { margin-bottom: 2px; }
.cat-title {
  font-size: 11px; font-weight: 700; color: #999;
  padding: 10px 14px 4px; letter-spacing: 1px;
  text-transform: uppercase;
  background: #fafbfc;
  border-top: 1px solid #f0f0f0;
}
.cat-group:first-child .cat-title { border-top: none; }

.type-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px 8px 14px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  transition: background .1s;
  border-left: 3px solid transparent;
}
.type-row:hover { background: #f0f5fb; }
.type-row.checked {
  background: #eef3fb;
  border-left-color: #2c5fa8;
}
.type-row.checked .type-name { color: #2c5fa8; font-weight: 600; }
.type-row.viewing { background: #e2edfa; }

.type-row input[type="checkbox"] {
  width: 22px; height: 22px;
  margin: 0; flex-shrink: 0;
  cursor: pointer;
  accent-color: #2c5fa8;
}
.type-row .type-name {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: #333;
}
.type-row .type-params {
  flex-shrink: 0;
  width: 26px; height: 26px; padding: 0;
  border: 1px solid #ccc; border-radius: 3px;
  background: #fff; cursor: pointer;
  font-size: 14px; color: #666;
  line-height: 1;
  display: none;
}
.type-row.checked .type-params { display: block; }
.type-row .type-params:hover {
  background: #2c5fa8; border-color: #2c5fa8; color: #fff;
}
.type-row .type-params.active {
  background: #2c5fa8; border-color: #2c5fa8; color: #fff;
}

.type-row .type-count {
  width: 52px; padding: 4px 6px;
  border: 1px solid #ccc; border-radius: 3px;
  font-size: 13px; font-family: inherit;
  text-align: center;
  flex-shrink: 0;
  cursor: text;
}
.type-row .type-count:disabled {
  opacity: .3; background: #f5f5f5; cursor: default;
}

/* ============ 右侧 ============ */
.work {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
}
.params {
  background: #fff; border-bottom: 1px solid #ddd;
  padding: 12px 16px; flex-shrink: 0;
  max-height: 42vh; overflow-y: auto;
}
.params-empty {
  color: #aaa; font-size: 13px; padding: 8px 0;
}
.params h2 {
  font-size: 14px; font-weight: 600; margin: 0 0 10px; color: #333;
  display: flex; align-items: center; gap: 8px;
}
.params h2 .cat-badge {
  font-size: 10px; padding: 1px 6px; background: #eef3fb;
  color: #2c5fa8; border-radius: 2px; font-weight: 500;
}
.param-grid {
  display: flex; flex-wrap: wrap; gap: 12px 22px;
  align-items: flex-end;
}
.param-item { display: flex; flex-direction: column; gap: 4px; }
.param-item label { font-size: 12px; color: #666; }
.param-item input[type="number"] {
  width: 100px; padding: 5px 8px; border: 1px solid #ccc;
  border-radius: 3px; font-size: 13px; font-family: inherit;
}
.param-item input[type="text"] {
  width: 150px; padding: 5px 8px; border: 1px solid #ccc;
  border-radius: 3px; font-size: 13px; font-family: inherit;
}
.param-item select {
  padding: 5px 10px; border: 1px solid #ccc;
  border-radius: 3px; font-size: 13px; font-family: inherit;
  background: #fff; min-width: 110px;
}
.param-item.param-check {
  flex-direction: row; align-items: center; gap: 8px;
  padding: 6px 0;
}
.param-item.param-check input[type="checkbox"] {
  width: 18px; height: 18px; margin: 0; cursor: pointer;
  accent-color: #2c5fa8;
}
.param-item.param-check label { font-size: 13px; color: #333; cursor: pointer; }

/* 无解参数块 */
.nosol-block {
  margin-top: 12px; padding: 10px 14px;
  background: #fef8e7; border: 1px solid #f0d8a0;
  border-radius: 4px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.nosol-block .title {
  font-size: 12px; font-weight: 600; color: #8a5000;
  flex-shrink: 0;
}
.nosol-block label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: #333; cursor: pointer;
}
.nosol-block input[type="checkbox"] {
  width: 18px; height: 18px; margin: 0; cursor: pointer;
  accent-color: #d18f00;
}
.nosol-block input[type="number"] {
  width: 70px; padding: 4px 8px; border: 1px solid #ccc;
  border-radius: 3px; font-size: 13px; font-family: inherit;
}
.nosol-block .ratio-label { display: flex; align-items: center; gap: 6px; }
.nosol-block.off .ratio-label { opacity: .35; pointer-events: none; }

/* ============ 预览区 ============ */
.preview-wrap {
  flex: 1; overflow-y: auto; padding: 20px;
  background: #e8e9eb;
}
.paper {
  background: #fff; max-width: 800px; margin: 0 auto;
  padding: 40px 48px; box-shadow: 0 2px 12px rgba(0,0,0,.08);
  font-family: "Times New Roman", "SimSun", "宋体", serif;
  line-height: 1.8; color: #000;
}
.paper-title {
  text-align: center; font-size: 22px; font-weight: 700;
  margin-bottom: 6px;
}
.paper-sub {
  text-align: center; font-size: 13px; color: #555;
  margin-bottom: 4px;
}
.paper-meta {
  display: flex; justify-content: space-between;
  font-size: 13px; color: #555;
  padding: 8px 0 14px;
  border-bottom: 1px solid #ccc;
  margin-bottom: 18px;
}
.paper-meta .fill-line {
  flex: 1; border-bottom: 1px solid #999;
  margin: 0 6px; min-width: 80px;
  display: inline-block;
}
.q-list { margin: 0; padding: 0; }

.gen-warn {
  background: #fef3e0;
  border: 1px solid #f0d0a0;
  color: #8a5000;
  padding: 8px 12px;
  border-radius: 3px;
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 16px;
  white-space: pre-wrap;
}

.section-title {
  font-size: 15px; font-weight: 700;
  margin: 24px 0 10px;
  padding-bottom: 4px;
  border-bottom: 1px dashed #ccc;
}
.section-title:first-child { margin-top: 0; }

.q-item {
  position: relative;
  margin-bottom: 12px;
  display: flex; gap: 6px;
  align-items: flex-start;
  padding: 4px 6px 4px 18px;
  border-radius: 3px;
  transition: background .1s;
}
.q-item:hover { background: #f5f8fd; }
.q-item.dragging { opacity: .4; }
.q-item.drag-over { border-top: 2px solid #2c5fa8; }
.q-item .q-num {
  flex-shrink: 0; font-weight: 600;
  min-width: 30px;
}
.q-item .q-body { flex: 1; min-width: 0; }
.q-item .q-body pre {
  margin: 0; font-family: "Consolas", "Courier New", monospace;
  font-size: 14px; line-height: 1.4; white-space: pre;
}
.q-item .q-ans {
  color: #c62828; font-size: 13px;
  margin-left: 30px; margin-top: 2px;
}
.q-item .q-ans::before { content: "【答案】"; color: #888; margin-right: 4px; }

.q-item .drag-handle {
  position: absolute;
  left: 2px; top: 4px;
  width: 14px; height: 20px;
  cursor: grab;
  opacity: 0;
  color: #aaa;
  font-size: 14px;
  line-height: 18px;
  text-align: center;
  user-select: none;
}
.q-item:hover .drag-handle { opacity: 1; }
.q-item .drag-handle:active { cursor: grabbing; }

.q-item .q-actions {
  position: absolute;
  right: 4px; top: 4px;
  display: none;
  gap: 4px;
}
.q-item:hover .q-actions { display: flex; }
.q-item .q-actions button {
  width: 24px; height: 24px; padding: 0;
  border: 1px solid #bbb; border-radius: 3px;
  background: #fff; cursor: pointer;
  font-size: 13px; color: #666;
  line-height: 1;
}
.q-item .q-actions button:hover {
  background: #eef3fb; border-color: #2c5fa8; color: #2c5fa8;
}
.q-item .q-actions button.del:hover {
  background: #fde8e8; border-color: #c62828; color: #c62828;
}

.answer-section {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 2px solid #ddd;
}
.answer-section h3 {
  font-size: 16px;
  margin: 0 0 14px;
  text-align: center;
}
.answer-section .ans-section-title {
  font-size: 13px;
  font-weight: 600;
  margin: 12px 0 6px;
  color: #555;
  border-bottom: 1px dashed #eee;
  padding-bottom: 2px;
}
.answer-section .ans-line {
  font-size: 13px;
  line-height: 2;
  margin-bottom: 2px;
}
.answer-section .ans-line .ans-item {
  display: inline-block;
  margin-right: 18px;
}
.answer-section .ans-line .ans-num {
  color: #888;
  margin-right: 2px;
}

@media print {
  body * { visibility: hidden; }
  .paper, .paper * { visibility: visible; }
  .paper {
    position: absolute; left: 0; top: 0;
    width: 100%; max-width: 100%;
    box-shadow: none; padding: 0;
  }
  .q-item { page-break-inside: avoid; }
  .q-item .q-actions, .q-item .drag-handle { display: none !important; }
  .gen-warn { display: none; }
}

/* Metro 外层：给悬浮返回链接让出空间；顶栏改用主题色变量 */
body { padding-top: 0; }
.topbar h1 { color: var(--mt-accent, #2c5fa8); }
