/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
  color: #1a1a1a;
  background: #f5f0e8;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Header ===== */
#app-header {
  background: linear-gradient(135deg, #8B0000, #A52A2A);
  color: #fff;
  text-align: center;
  padding: 20px 12px 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
#app-header h1 {
  font-size: 1.6rem;
  letter-spacing: .15em;
  margin-bottom: 2px;
}
.subtitle {
  font-size: .78rem;
  opacity: .85;
  letter-spacing: .08em;
}

/* ===== Tab Bar ===== */
.tab-bar {
  display: flex;
  background: #fff;
  border-bottom: 2px solid #e0d5c7;
  position: sticky;
  top: 0;
  z-index: 10;
}
.tab-bar .tab {
  flex: 1;
  border: none;
  background: none;
  padding: 12px;
  font-size: 1rem;
  color: #666;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all .2s;
  -webkit-tap-highlight-color: transparent;
}
.tab-bar .tab.active {
  color: #8B0000;
  border-bottom-color: #8B0000;
  font-weight: 600;
}

/* ===== Tab Content ===== */
.tab-content {
  display: none;
  padding: 14px 12px 24px;
  flex: 1;
}
.tab-content.active { display: block; }

/* ===== Cards & Form ===== */
.card {
  background: #fff;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.card label {
  display: block;
  font-size: .82rem;
  color: #666;
  margin-bottom: 4px;
  font-weight: 500;
}
.row2 { display: flex; gap: 10px; }
.flex1 { flex: 1; }

textarea, input[type="text"], input[type="number"], select {
  width: 100%;
  border: 1.5px solid #ddd;
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 1rem;
  outline: none;
  transition: border-color .2s;
  background: #fafafa;
  font-family: inherit;
}
textarea:focus, input:focus, select:focus {
  border-color: #8B0000;
  background: #fff;
}
input[type="color"] {
  width: 100%;
  height: 40px;
  border: 1.5px solid #ddd;
  border-radius: 8px;
  padding: 3px;
  cursor: pointer;
  background: #fafafa;
}

/* ===== Buttons ===== */
.btn-primary {
  display: block;
  width: 100%;
  padding: 13px;
  background: linear-gradient(135deg, #8B0000, #A52A2A);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: .05em;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .2s, transform .1s;
}
.btn-primary:active { opacity: .85; transform: scale(.98); }

.btn-secondary {
  display: inline-block;
  padding: 10px 18px;
  background: #fff;
  color: #8B0000;
  border: 2px solid #8B0000;
  border-radius: 8px;
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .2s;
}
.btn-secondary:active { background: #fde8e8; }
.btn-sm { padding: 8px 14px; font-size: .88rem; }

#action-bar {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}

/* ===== Canvas Preview ===== */
#preview-area {
  text-align: center;
  margin-top: 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
#seal-canvas {
  max-width: 100%;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
  background: #fff;
}

.font-loading {
  text-align: center;
  font-size: .82rem;
  color: #999;
  margin-top: 8px;
  padding: 6px;
}
.font-loading.ready { color: #2e7d32; }

/* ===== Dictionary ===== */
.search-row { display: flex; gap: 8px; align-items: stretch; }
.search-row input { flex: 1; }
.dict-result {
  margin-bottom: 14px;
}
.dict-char-card {
  background: #fff;
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
.dict-seal-preview {
  width: 80px;
  height: 80px;
  border: 1px solid #e0d5c7;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'ChongXiSmallSeal', serif;
  font-size: 56px;
  background: #fff8e7;
  flex-shrink: 0;
}
.dict-info h3 {
  font-size: 1.4rem;
  margin-bottom: 4px;
}
.dict-info .pinyin {
  color: #8B0000;
  font-size: .95rem;
  margin-bottom: 6px;
}
.dict-info .unicode {
  font-size: .82rem;
  color: #888;
  font-family: monospace;
}
.dict-info .zdic-link {
  display: inline-block;
  margin-top: 8px;
  font-size: .84rem;
  color: #1976d2;
  text-decoration: none;
}
.dict-info .status-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: .76rem;
  margin-top: 6px;
}
.status-tag.has-seal { background: #e8f5e9; color: #2e7d32; }
.status-tag.no-seal { background: #fce4ec; color: #c62828; }

.hint {
  font-size: .8rem;
  color: #999;
  line-height: 1.5;
  margin-bottom: 10px;
}

/* Character Grid */
.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 3px;
  max-height: 50vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px;
  border: 1px solid #e0d5c7;
  border-radius: 8px;
  background: #fff;
}
.char-grid .char-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 4px;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.char-grid .char-cell:hover,
.char-grid .char-cell:active {
  background: #fde8e8;
  color: #8B0000;
}
.loading-hint { grid-column: 1 / -1; text-align: center; color: #999; padding: 20px; }

.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}
.pagination button {
  padding: 6px 14px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: .86rem;
}
.pagination button:disabled { opacity: .4; cursor: default; }
.pagination .page-info {
  display: flex;
  align-items: center;
  font-size: .86rem;
  color: #666;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  background: #fff;
  border-radius: 14px;
  padding: 24px 20px;
  max-width: 360px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  font-size: 1.6rem;
  color: #999;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
}

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 16px 12px 20px;
  font-size: .74rem;
  color: #aaa;
  line-height: 1.6;
  border-top: 1px solid #e0d5c7;
  margin-top: auto;
  background: #f5f0e8;
}
footer a { color: #8B0000; text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ===== Responsive ===== */
@media (min-width: 480px) {
  .char-grid { grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); }
  .dict-seal-preview { width: 100px; height: 100px; font-size: 70px; }
}
@media (min-width: 768px) {
  body { max-width: 640px; margin: 0 auto; box-shadow: 0 0 20px rgba(0,0,0,.08); }
  .char-grid { grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); }
}

/* ===== Font Face ===== */
@font-face {
  font-family: 'ChongXiSmallSeal';
  src: url('../fonts/ChongXiSmallSeal.otf') format('opentype');
  font-display: swap;
}
@font-face {
  font-family: 'LXGWSeal';
  src: url('../fonts/LXGWSeal-Regular.ttf') format('truetype');
  font-display: swap;
}
