/* 小字帖 · 界面样式（屏幕）
   布局：首页独占整屏；工具页 = 左侧参数 + 右侧预览 两列 */
:root {
  --bg: #f6f4ef;
  --bg-deep: #efebe2;
  --panel: #ffffff;
  --ink: #2f302f;
  --ink-soft: #5d605d;
  --muted: #94978f;
  --line: #e4e0d6;
  --line-soft: #f0ede5;
  --accent: #d9693f;
  --accent-soft: #fdf0e9;
  --teal: #2f8f80;
  --teal-soft: #e9f5f2;
  --gold: #c9a227;
  --radius: 12px;
  --shadow: 0 2px 14px rgba(58, 50, 36, .07);
  --shadow-lg: 0 12px 34px rgba(58, 50, 36, .14);
  --font-ui: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Segoe UI", system-ui, sans-serif;
  --font-kai: "KaiTi", "STKaiti", "Kaiti SC", "楷体", serif;
  --paper-w: 210mm;
  --paper-h: 297mm;
  --paper-pad: 12mm;
  --zoom: .75;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.app-shell { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
body.view-home .workspace, body.view-home .view-tool-only { display: none !important; }
body:not(.view-home) .home-view { display: none !important; }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 64px; flex: none; display: flex; align-items: center; gap: 12px;
  padding: 0 22px; background: var(--panel); border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(0,0,0,.02); z-index: 5;
}
.brand { display: flex; align-items: center; gap: 11px; cursor: pointer; user-select: none; flex: none; }
.brand:focus-visible { outline: 2px solid var(--accent); border-radius: 8px; }
.brand-seal {
  width: 38px; height: 38px; display: grid; place-items: center;
  background: var(--accent); color: #fff; border-radius: 9px;
  font: 700 22px/1 var(--font-kai);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.35);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 17px; letter-spacing: .5px; }
.brand-text small { color: var(--muted); font-size: 11px; letter-spacing: .3px; }
.top-back { padding-left: 4px; padding-right: 8px; font-size: 13px; flex: none; }
.tool-switch { flex: none; }
.tool-switch select {
  min-width: 148px; max-width: 220px; border: 1px solid var(--line); background: #fff;
  color: var(--ink-soft); border-radius: 8px; padding: 7px 26px 7px 10px; font-size: 13px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 16px, calc(100% - 10px) 16px;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.tool-switch select:hover { border-color: var(--accent); }
.topbar-tip { flex: 1; color: var(--muted); font-size: 12px; text-align: right; }
.top-actions { display: flex; gap: 8px; flex: none; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink-soft);
  padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 500;
  transition: .15s ease; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 3px 10px rgba(217,105,63,.24); }
.btn-primary:hover { background: #c95c34; border-color: #c95c34; color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg-deep); color: var(--ink); }
.btn-danger { border-color: #e6b6a6; color: #b04a2f; }
.btn-danger:hover { border-color: #b04a2f; background: #fdf0e9; color: #b04a2f; }
.link-btn { border: 0; background: none; color: var(--teal); padding: 0; font-size: 12px; text-decoration: underline; }

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

.workspace { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tool-head {
  flex: none; display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; padding: 14px 24px 12px; border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.tool-crumb { font-size: 11px; color: var(--teal); letter-spacing: 1px; }
.tool-head h1 { margin: 2px 0 2px; font-size: 20px; font-weight: 650; letter-spacing: .5px; }
.tool-head p { margin: 0; font-size: 12.5px; color: var(--muted); max-width: 760px; }
.tool-head-actions { flex: none; }

.work-grid { flex: 1; display: flex; min-height: 0; }
.panel {
  width: 332px; flex: none; overflow-y: auto; background: var(--panel);
  border-right: 1px solid var(--line); padding: 18px 18px 44px;
}
.preview-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.preview-toolbar {
  height: 40px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; border-bottom: 1px solid var(--line); background: #fbfaf6;
  font-size: 12px; color: var(--muted);
}
.preview-info .dot { margin: 0 8px; color: var(--line); }
.preview-zoom { display: flex; align-items: center; gap: 6px; }
.preview-zoom span { min-width: 40px; text-align: center; font-variant-numeric: tabular-nums; }
.zoom-btn {
  width: 24px; height: 24px; line-height: 1; border: 1px solid var(--line);
  background: #fff; border-radius: 6px; color: var(--ink-soft); font-size: 15px;
}
.zoom-btn:hover { border-color: var(--accent); color: var(--accent); }
.preview-viewport { flex: 1; overflow: auto; padding: 24px 24px 60px; }
.preview { zoom: var(--zoom); display: flex; flex-direction: column; align-items: center; gap: 18px; }

.statusbar {
  height: 28px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: #fbfaf6; border-top: 1px solid var(--line);
  font-size: 11px; color: var(--muted);
}

/* ---------- 表单控件 ---------- */
.field { margin-bottom: 15px; }
.field-label { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.field-label:empty { display: none; }
.field-label .hint { font-weight: 400; color: var(--muted); font-size: 11px; }
.field input[type=text], .field input[type=number], .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  background: #fff; color: var(--ink); outline: none; transition: .15s;
}
.field textarea { resize: vertical; min-height: 82px; line-height: 1.7; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 15px, calc(100% - 11px) 15px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 28px; }
.field-input-row { display: flex; gap: 8px; }
.field-input-row > * { flex: 1; min-width: 0; }
.field-inline { display: flex; gap: 10px; align-items: center; }
.field-inline > * { flex: 1; }
.field-note { font-size: 11px; color: var(--muted); margin-top: 5px; line-height: 1.6; }

.seg { display: flex; flex-wrap: wrap; gap: 5px; }
.seg button {
  flex: 1 1 auto; min-width: 52px; border: 1px solid var(--line); background: #fff;
  color: var(--ink-soft); padding: 6px 8px; border-radius: 7px; font-size: 12px; transition: .14s;
}
.seg button:hover { border-color: var(--accent); }
.seg button.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.check { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 12.5px; color: var(--ink-soft); cursor: pointer; }
.check input { width: 15px; height: 15px; accent-color: var(--accent); }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input[type=range] { flex: 1; accent-color: var(--accent); }
.range-row .val { min-width: 46px; text-align: right; font-size: 12px; color: var(--accent); font-variant-numeric: tabular-nums; }
.color-row { display: flex; align-items: center; gap: 8px; }
.color-row input[type=color] { width: 38px; height: 30px; border: 1px solid var(--line); border-radius: 7px; padding: 2px; background: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--ink-soft);
  border-radius: 20px; padding: 4px 10px; font-size: 11.5px; transition: .14s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.chip.on { background: var(--teal); border-color: var(--teal); color: #fff; }
.panel-section { border-top: 1px dashed var(--line); margin: 18px 0 14px; padding-top: 14px; }
.panel-section-title { font-size: 12px; font-weight: 700; color: var(--ink); margin-bottom: 12px; display: flex; align-items: center; gap: 7px; }
.panel-section-title::before { content: ""; width: 3px; height: 13px; background: var(--accent); border-radius: 2px; }
.panel-btn { width: 100%; padding: 9px; margin-top: 4px; }
.field-group-title { font-size: 11px; color: var(--muted); margin: 10px 0 6px; }

/* ---------- 首页（整屏工具总览） ---------- */
.home-view { flex: 1; min-width: 0; overflow-y: auto; background:
  radial-gradient(900px 380px at 12% -8%, #fdf0e5 0%, rgba(253,240,229,0) 70%),
  radial-gradient(760px 340px at 92% 4%, #e9f5f2 0%, rgba(233,245,242,0) 72%), var(--bg); }
.home { width: min(1180px, 100%); margin: 0 auto; padding: 40px 34px 56px; }
.home-hero { padding: 8px 0 26px; border-bottom: 1px dashed var(--line); margin-bottom: 26px; }
.home-eyebrow { font-size: 12px; color: var(--teal); letter-spacing: 2px; margin-bottom: 10px; }
.home-hero h2 { margin: 0 0 12px; font: 700 34px/1.35 var(--font-kai); letter-spacing: 3px; }
.home-hero p { margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 2;}
.home-stats { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.home-stat {
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 16px; min-width: 116px;
}
.home-stat b { display: block; font: 700 20px/1.3 var(--font-kai); color: var(--accent); }
.home-stat span { font-size: 11px; color: var(--muted); }
.home-recent { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 18px; }
.home-recent-label { font-size: 12px; color: var(--muted); }
.home-recent .chip { background: #fff; }

.home-toolbar { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; flex-wrap: wrap; }
.home-toolbar h3 { margin: 0; font-size: 15px; letter-spacing: 1px; }
.home-search { position: relative; margin-left: auto; width: 260px; max-width: 100%; }
.home-search input {
  width: 100%; border: 1px solid var(--line); border-radius: 9px; background: #fff;
  padding: 9px 12px 9px 34px; font-size: 13px; outline: none;
}
.home-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.home-search::before {
  content: "⌕"; position: absolute; left: 11px; top: 50%; transform: translateY(-52%);
  color: var(--muted); font-size: 18px; line-height: 1;
}
.home-group { margin-top: 26px; }
.home-group-title {
  display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted);
  letter-spacing: 1px; margin: 0 0 12px;
}
.home-group-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.tool-card {
  display: flex; gap: 13px; align-items: flex-start; text-align: left; min-height: 96px;
  border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 16px;
  transition: .16s; color: var(--ink); box-shadow: 0 1px 2px rgba(58,50,36,.02);
}
.tool-card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-2px); }
.tool-card .seal {
  width: 38px; height: 38px; flex: none; display: grid; place-items: center; border-radius: 9px;
  background: var(--accent-soft); color: var(--accent);
  font: 700 20px/1 var(--font-kai);
}
.tool-card b { display: block; font-size: 14px; margin-bottom: 5px; }
.tool-card small { display: block; color: var(--muted); font-size: 11.5px; line-height: 1.65; }
.tool-card .arrow { margin-left: auto; align-self: center; color: var(--line); font-size: 18px; transition: .16s; }
.tool-card:hover .arrow { color: var(--accent); transform: translateX(3px); }
.home-empty { color: var(--muted); font-size: 13px; padding: 26px 4px; }
.home-foot {
  margin-top: 34px; padding: 20px 22px; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; font-size: 12px; color: var(--muted); line-height: 2;
}
.home-foot b { color: var(--ink-soft); }
.home-foot .foot-title { color: var(--ink); font-size: 13px; font-weight: 600; margin-bottom: 4px; }

/* ---------- 互动区（笔顺演示、汉字查询等） ---------- */
.demo-card {
  width: min(880px, 100%); background: #fff; border: 1px solid var(--line);
  border-radius: 14px; padding: 20px 24px; box-shadow: var(--shadow); margin-bottom: 4px;
}
.demo-card h3 { margin: 0 0 12px; font-size: 15px; }
.demo-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.demo-stage { position: relative; width: 220px; height: 220px; flex: none; border: 1px solid var(--line); border-radius: 10px; background: #fff; overflow: hidden; }
.demo-stage .stage-grid {
  position: absolute; inset: 0; border: 1px solid #d9a08b;
  background:
    linear-gradient(to right, transparent 49.7%, #e9c8ba 49.7%, #e9c8ba 50.3%, transparent 50.3%),
    linear-gradient(to bottom, transparent 49.7%, #e9c8ba 49.7%, #e9c8ba 50.3%, transparent 50.3%);
}
.demo-controls { display: flex; flex-direction: column; gap: 10px; flex: 1; min-width: 220px; }
.demo-controls .btn { align-self: flex-start; }
.demo-tip { font-size: 12px; color: var(--muted); line-height: 1.8; }
.kv-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.kv-table th, .kv-table td { border-bottom: 1px solid var(--line-soft); padding: 9px 8px; text-align: left; vertical-align: top; }
.kv-table th { width: 92px; color: var(--muted); font-weight: 500; }
.kv-table td { color: var(--ink); }
.py-click { cursor: pointer; border-bottom: 1px dashed var(--accent); }
.py-click:hover { background: var(--accent-soft); }

/* ---------- 弹层 / 提示 ---------- */
.modal-mask { position: fixed; inset: 0; background: rgba(35,32,26,.4); z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal-mask[hidden] { display: none; }
.modal { width: min(620px, 100%); max-height: 86vh; overflow: auto; background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-close { border: 0; background: none; font-size: 22px; color: var(--muted); line-height: 1; }
.modal-body { padding: 18px 20px; font-size: 13px; line-height: 1.9; color: var(--ink-soft); }
.modal-body h3 { font-size: 13px; color: var(--ink); margin: 16px 0 6px; }
.modal-body p { margin: 0 0 8px; }
.modal-body ol, .modal-body ul { margin: 0 0 10px; padding-left: 20px; }
.modal-body code { background: var(--bg-deep); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.modal-foot { padding: 12px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }
.modal .form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 12px; }
.modal .form-grid .full { grid-column: 1 / -1; }
.modal .field textarea { min-height: 108px; }
.toast { position: fixed; bottom: 44px; left: 50%; transform: translateX(-50%); background: #2f302f; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13px; z-index: 80; box-shadow: var(--shadow-lg); }
.toast[hidden] { display: none; }
.loading { color: var(--muted); font-size: 13px; padding: 40px; text-align: center; }

/* ---------- 自建诗库管理 ---------- */
.pl-list { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 14px; }
.pl-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 9px; background: #fff;
}
.pl-item .pl-main { flex: 1; min-width: 0; }
.pl-item .pl-main b { display: block; font-size: 13px; color: var(--ink); }
.pl-item .pl-main small { display: block; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-item .btn { padding: 5px 10px; font-size: 12px; }
.pl-empty { color: var(--muted); font-size: 12.5px; padding: 18px 2px; }
.pl-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

/* ---------- 响应式 ---------- */
@media (max-width: 1180px) {
  .topbar-tip { display: none; }
  .home-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}
@media (max-width: 900px) {
  .panel { width: 280px; }
  .home { padding: 28px 20px 44px; }
  .home-hero h2 { font-size: 28px; }
}
@media (max-width: 760px) {
  .app-shell { height: auto; min-height: 100vh; overflow: visible; }
  .work-grid { flex-direction: column; }
  .panel { width: 100%; border-right: 0; border-bottom: 1px solid var(--line); max-height: none; }
  .preview-viewport { padding: 14px; }
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 12px; gap: 10px; }
  .top-actions { width: 100%; }
  .top-actions .btn { flex: 1; padding: 8px 6px; font-size: 12px; }
  .tool-switch { flex: 1; }
  .tool-switch select { width: 100%; }
  .home-grid { grid-template-columns: 1fr; }
  .home-search { width: 100%; margin-left: 0; }
  .modal .form-grid { grid-template-columns: 1fr; }
  .statusbar { display: none; }
}
