/* Make Me a Hanzi - Modern Calligraphic Stylesheet */

:root {
  --bg-color: #f8fafc;
  --surface-color: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border-color: #e2e8f0;
  --primary-color: #0284c7;
  --primary-hover: #0369a1;
  --accent-red: #dc2626;
  --grid-line: rgba(220, 38, 38, 0.32);
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header Navbar */
header.app-navbar {
  background: var(--surface-color);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-badge {
  font-size: 0.75rem;
  background: #f1f5f9;
  color: var(--text-secondary);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.search-box {
  display: flex;
  align-items: center;
  background: #f1f5f9;
  border-radius: 8px;
  padding: 2px 6px 2px 10px;
  border: 1px solid transparent;
  transition: border-color 0.2s, background 0.2s;
}

.search-box:focus-within {
  border-color: var(--primary-color);
  background: #fff;
}

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  padding: 6px 8px;
  font-size: 0.9rem;
  width: 180px;
}

.search-box button {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--text-secondary);
  border-radius: 6px;
  transition: color 0.15s;
}

.search-box button:hover {
  color: var(--primary-color);
}

.btn-nav {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  background: #f1f5f9;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-nav:hover {
  background: #e2e8f0;
  color: var(--text-primary);
}

/* Main Container */
main.app-main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Common Card & Views */
.view {
  display: block;
}

.hidden {
  display: none !important;
}

/* --- Search / Drawing View --- */
.search-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.search-hero {
  text-align: center;
  max-width: 600px;
}

.search-hero h2 {
  font-size: 1.75rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.search-hero p {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.canvas-panel {
  background: var(--surface-color);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.canvas-wrapper {
  position: relative;
  width: 360px;
  height: 360px;
  max-width: 85vw;
  max-height: 85vw;
  border-radius: 8px;
  overflow: hidden;
  background: #fffdfa;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.04);
}

#handwriting-canvas {
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  display: block;
}

.canvas-controls {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.stroke-badge {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: #f1f5f9;
  padding: 4px 10px;
  border-radius: 6px;
}

.btn-group {
  display: flex;
  gap: 0.5rem;
}

.btn-action {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid var(--border-color);
  background: #ffffff;
  color: var(--text-primary);
  transition: all 0.15s;
}

.btn-action:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.btn-action.btn-danger:hover {
  background: #fee2e2;
  color: #dc2626;
  border-color: #fca5a5;
}

/* Candidates Strip */
.candidates-section {
  width: 100%;
  max-width: 540px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.candidates-header {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.candidates-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 54px;
  align-items: center;
  padding: 0.5rem;
  background: var(--surface-color);
  border-radius: 10px;
  border: 1px solid var(--border-color);
}

.candidate-card {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  font-size: 2rem;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", serif;
  text-decoration: none;
  background: #f8fafc;
  color: var(--text-primary);
  border-radius: 8px;
  border: 1px solid var(--border-color);
  transition: all 0.15s;
  cursor: pointer;
}

.candidate-card:hover {
  background: #e0f2fe;
  color: var(--primary-hover);
  border-color: #7dd3fc;
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.empty-hint {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-style: italic;
  padding: 0.5rem;
}

/* --- Character Detail View --- */
.character-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 860px) {
  .character-layout {
    grid-template-columns: 1fr;
  }
}

.animator-panel {
  background: var(--surface-color);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.svg-container {
  width: 360px;
  height: 360px;
  max-width: 100%;
  max-height: 80vw;
  background: #fffdfa;
  border-radius: 8px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.04);
}

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

/* SVG Stroke styles */
.stroke-base {
  transition: fill 0.2s;
}

.stroke-incomplete {
  fill: #e2e8f0;
}

.stroke-complete {
  fill: #1e293b;
}

.stroke-brush {
  fill: none;
  stroke: #2563eb;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 128px;
}

/* Animation Player Controls */
.anim-controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.anim-buttons {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

.anim-meta-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.anim-meta-bar select {
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: #f8fafc;
  outline: none;
}

/* Metadata Panel */
.details-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.metadata-card {
  background: var(--surface-color);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
}

.char-hero {
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
}

.char-glyph {
  font-size: 4.5rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", serif;
}

.char-sub {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.pinyin-badge {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-color);
}

.radical-badge {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.info-grid {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.info-row {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.info-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.info-value {
  font-size: 0.95rem;
  color: var(--text-primary);
}

/* Decomposition Tree Styles */
.tree-node {
  margin: 0.35rem 0;
}

.node-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.badge-compound {
  background: #f1f5f9;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-weight: 600;
}

.ids-symbol {
  font-size: 1.1rem;
  color: var(--primary-color);
}

.badge-char {
  background: #f8fafc;
  border: 1px solid var(--border-color);
}

.char-link, .inline-char-link {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary-color);
  text-decoration: none;
  border-bottom: 1px dotted var(--primary-color);
}

.char-link:hover, .inline-char-link:hover {
  color: var(--primary-hover);
  border-bottom-style: solid;
}

.gloss-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-left: 0.3rem;
}

.tree-children {
  margin-left: 1.5rem;
  padding-left: 0.75rem;
  border-left: 2px dashed #cbd5e1;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 100;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid #e2e8f0;
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-weight: 600;
  color: var(--text-secondary);
}

/* Footer */
footer.app-footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border-color);
  margin-top: auto;
}

footer a {
  color: var(--text-secondary);
  text-decoration: underline;
}
