/* ============================================================
   麦迪文工具 — 全局样式
   高端优雅简洁 · 默认深色主题 · 适配暗黑模式 & 移动端
   ============================================================ */

:root {
  /* 深色主题（默认） */
  --bg: #0a0a0a;
  --bg-elevated: #111111;
  --bg-card: #141414;
  --bg-hover: #1c1c1c;
  --border: #262626;
  --border-strong: #333333;
  --text: #f5f5f5;
  --text-secondary: #a3a3a3;
  --text-muted: #737373;
  --accent: #c4b5fd;
  --accent-strong: #a78bfa;
  --accent-dim: rgba(196, 181, 253, 0.12);
  --success: #4ade80;
  --danger: #f87171;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* 浅色主题：跟随系统 */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #fafafa;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #f4f4f5;
    --border: #e4e4e7;
    --border-strong: #d4d4d8;
    --text: #18181b;
    --text-secondary: #52525b;
    --text-muted: #71717a;
    --accent: #7c3aed;
    --accent-strong: #6d28d9;
    --accent-dim: rgba(124, 58, 237, 0.08);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100dvh;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

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

/* ============================================================
   通用组件
   ============================================================ */

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
  flex: 1;
  width: 100%;
}

@media (max-width: 480px) {
  .container {
    padding: 16px 14px;
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  transition: all 0.15s ease;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--bg-hover);
  border-color: var(--border);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 12px 24px;
  font-size: 15px;
}

.input {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.input::placeholder {
  color: var(--text-muted);
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-hover);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  transition: all 0.15s ease;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tag:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.tag.active {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}

/* ============================================================
   主页 — 标题 + 搜索 + 标签筛选 + 卡片网格
   ============================================================ */

.site-header {
  padding: 40px 20px 0;
  text-align: center;
}

@media (max-width: 480px) {
  .site-header {
    padding: 28px 14px 0;
  }
}

.site-title {
  font-size: clamp(24px, 5vw, 36px);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}

.site-title .accent {
  color: var(--accent);
}

.site-tagline {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 0;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  font-weight: 500;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 28px 0 20px;
}

.search-wrapper {
  position: relative;
}

.search-wrapper svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 18px;
  height: 18px;
  pointer-events: none;
}

.search-wrapper .input {
  padding-left: 42px;
  height: 44px;
  font-size: 15px;
}

.tag-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.tag-bar::-webkit-scrollbar {
  height: 4px;
}

.tag-bar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.tag {
  flex-shrink: 0;
}

.site-footer {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.results-info {
  color: var(--text-muted);
  font-size: 13px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  padding-bottom: 40px;
}

@media (max-width: 480px) {
  .tool-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

.tool-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-card);
  transition: all 0.2s ease;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.tool-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.tool-card:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.tool-card:active {
  transform: translateY(0);
  border-color: var(--accent-strong);
}

.tool-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tool-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--accent-dim);
  color: var(--accent-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  flex-shrink: 0;
}

.tool-name {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.tool-desc {
  color: var(--text-secondary);
  font-size: 13px;
  margin: 0;
  line-height: 1.6;
}

.tool-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: auto;
}

.tool-tags .tag {
  padding: 2px 8px;
  font-size: 11px;
  border-color: var(--accent-dim);
  background: var(--accent-dim);
  color: var(--accent-strong);
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state p {
  margin: 8px 0;
}

/* ============================================================
   工具内部页面 — 顶栏
   ============================================================ */

.tool-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}

@media (max-width: 480px) {
  .tool-header {
    padding: 12px 14px;
    gap: 8px;
  }
}

.tool-header .back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.tool-header .back-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.tool-header .title {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-header .actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

@media (max-width: 480px) {
  .tool-header .actions {
    gap: 6px;
  }

  .tool-header .btn {
    padding: 6px 10px;
    font-size: 13px;
  }

  .tool-header .btn span:not(.icon-only) {
    display: none;
  }
}

/* ============================================================
   JSON 编辑器
   ============================================================ */

.editor-layout {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  max-width: 1000px;
  margin: 0 auto;
  height: calc(100dvh - 70px);
}

@media (max-width: 480px) {
  .editor-layout {
    padding: 12px;
    height: calc(100dvh - 56px);
  }
}

.editor-wrap {
  flex: 1;
  min-height: 300px;
  display: flex;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-card);
  overflow: hidden;
  transition: border-color 0.15s ease;
}

.editor-wrap:focus-within {
  border-color: var(--accent);
}

.editor-wrap.error {
  border-color: var(--danger);
}

.line-numbers {
  margin: 0;
  padding: 16px 12px 16px 16px;
  width: 3.5em;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-muted);
  text-align: right;
  overflow: hidden;
  user-select: none;
  white-space: pre;
}

.line-numbers span.err {
  color: var(--danger);
  background: rgba(248, 113, 113, 0.12);
  border-radius: 2px;
  padding-right: 4px;
}

.editor-textarea {
  flex: 1;
  min-width: 0;
  padding: 16px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  outline: none;
  overflow: auto;
}

.editor-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.editor-status .error-msg {
  color: var(--danger);
}

.editor-status .success-msg {
  color: var(--success);
}

/* ============================================================
   千分位读数练习
   ============================================================ */

.practice-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 32px 20px;
  max-width: 560px;
  margin: 0 auto;
  min-height: calc(100dvh - 70px);
  justify-content: center;
}

@media (max-width: 480px) {
  .practice-layout {
    padding: 20px 14px;
    gap: 20px;
    min-height: calc(100dvh - 56px);
  }
}

.practice-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}

.difficulty-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.difficulty-btn {
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.difficulty-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.difficulty-btn.active {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}

.number-display {
  width: 100%;
  padding: 32px 20px;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  border: 1px solid var(--border);
  text-align: center;
}

@media (max-width: 480px) {
  .number-display {
    padding: 24px 16px;
  }
}

.number-display .num {
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0.05em;
  font-size: clamp(24px, 7vw, 42px);
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}

.hint-text {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 12px;
}

.answer-area {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.answer-text {
  font-size: 18px;
  font-weight: 500;
}

.answer-placeholder {
  font-size: 14px;
  color: var(--text-muted);
}

.answer-style-toggle {
  display: block;
  margin: 6px auto 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}

.answer-style-toggle:hover {
  color: var(--text-secondary);
}

.practice-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.help-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  font-size: 13px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease;
}

.help-btn:hover {
  color: var(--text-secondary);
}

.help-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.help-modal {
  max-width: 440px;
  width: 100%;
  padding: 24px;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.help-modal h3 {
  margin: 0 0 16px;
  font-size: 16px;
}

.help-modal p {
  color: var(--text-secondary);
  font-size: 13px;
  margin: 8px 0;
}

.help-modal .close-modal {
  margin-top: 16px;
  width: 100%;
  padding: 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-hover);
  color: var(--text);
  font-size: 14px;
}

/* ============================================================
   工具通用：面包屑 / 简易分割
   ============================================================ */

.crumb-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.crumb-nav a {
  color: var(--text-secondary);
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 2px;
  transition: text-decoration-color 0.15s ease, color 0.15s ease;
}

.crumb-nav a:hover {
  color: var(--text);
  text-decoration-color: currentColor;
}

.crumb-nav .sep {
  opacity: 0.5;
}