/* ============ 全局 ============ */
:root {
  --red: #c0392b;          /* 低饱和主红 */
  --red-dark: #962d22;
  --red-soft: #f6e6e4;
  --gray-9: #1f2329;
  --gray-7: #4e5969;
  --gray-5: #86909c;
  --gray-3: #c9cdd4;
  --gray-1: #f2f3f5;
  --white: #ffffff;
  --shadow: 0 8px 30px rgba(31, 35, 41, 0.12);
  --radius: 12px;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--gray-9);
  background: var(--gray-1);
}

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

/* ============ 顶部栏 ============ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid rgba(192, 57, 43, 0.12);
  box-shadow: 0 2px 12px rgba(31, 35, 41, 0.06);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(192, 57, 43, 0.35);
}
.brand-mark::after {
  content: "山";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 18px;
}
.brand-text h1 {
  font-size: 18px; font-weight: 700; letter-spacing: 2px;
  color: var(--red-dark);
  line-height: 1.2;
}
.brand-text p {
  font-size: 11px; color: var(--gray-5); letter-spacing: 1px;
}

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  max-width: 520px;
  background: var(--gray-1);
  border: 1px solid var(--gray-3);
  border-radius: 999px;
  padding: 4px 6px 4px 16px;
  transition: all .2s;
}
.search-box:focus-within {
  border-color: var(--red);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.12);
}
.search-box input {
  flex: 1;
  border: none; outline: none; background: transparent;
  height: 34px; font-size: 14px; color: var(--gray-9);
  min-width: 0;
}
.search-box input::placeholder { color: var(--gray-5); }
#searchBtn {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--white);
  background: var(--red);
  flex-shrink: 0;
  transition: background .2s;
}
#searchBtn:hover { background: var(--red-dark); }

.top-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-7);
  background: var(--gray-1);
  transition: all .2s;
}
.icon-btn:hover { color: var(--red); background: var(--red-soft); }
.icon-btn.active { color: var(--white); background: var(--red); }

.restore-btn {
  height: 38px; padding: 0 16px;
  border-radius: 999px;
  background: var(--red);
  color: var(--white);
  font-size: 13px; font-weight: 600;
  letter-spacing: 0.5px;
  transition: all .2s;
  white-space: nowrap;
}
.restore-btn:hover { background: var(--red-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(192, 57, 43, 0.3); }

/* ============ 地图 ============ */
#mapContainer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 1;
}

/* ============ 侧边弹窗 ============ */
.side-panel {
  position: fixed;
  top: 72px;
  right: 18px;
  width: 380px;
  max-height: calc(100vh - 100px);
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideIn .28s ease;
}
@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
.hidden { display: none !important; }

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--gray-1);
  gap: 12px;
}
.panel-title { min-width: 0; flex: 1; }
.panel-title h2 {
  font-size: 18px; font-weight: 700;
  color: var(--red-dark);
  margin-bottom: 4px;
}
.poem-title {
  display: inline-block;
  font-size: 14px;
  color: var(--gray-9);
  font-weight: 600;
  margin-top: 2px;
}
.poem-author {
  font-size: 13px;
  color: var(--gray-5);
  margin-left: 4px;
}
.sub-name { font-size: 13px; color: var(--gray-5); }

.close-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  color: var(--gray-5);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all .2s;
}
.close-btn:hover { background: var(--gray-1); color: var(--red); }

.panel-body {
  padding: 16px 20px 20px;
  overflow-y: auto;
  flex: 1;
}

/* 诗词 */
.poem-box {
  background: var(--red-soft);
  border-left: 3px solid var(--red);
  border-radius: 0 8px 8px 0;
  padding: 16px 18px;
  margin-bottom: 16px;
  min-height: 60px;
}
.poem-content {
  font-size: 16px;
  line-height: 2;
  color: var(--gray-9);
  white-space: pre-wrap;
  letter-spacing: 1px;
  font-weight: 500;
}
.poem-content::after {
  content: "▌";
  color: var(--red);
  animation: blink 1s steps(1) infinite;
  margin-left: 2px;
}
.poem-content.done::after { display: none; }
@keyframes blink { 50% { opacity: 0; } }

.poem-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* 按钮 */
.ghost-btn, .primary-btn {
  height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all .2s;
}
.ghost-btn {
  background: var(--gray-1);
  color: var(--gray-7);
}
.ghost-btn:hover { background: var(--red-soft); color: var(--red-dark); }
.primary-btn {
  background: var(--red);
  color: var(--white);
}
.primary-btn:hover { background: var(--red-dark); }
.primary-btn:disabled { background: var(--gray-3); cursor: not-allowed; }

/* 历史面板 */
.history-img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 14px;
  background: var(--gray-1);
}
.history-text {
  font-size: 14px;
  line-height: 1.9;
  color: var(--gray-7);
  white-space: pre-wrap;
}
.img-source {
  margin-top: 14px;
  font-size: 11px;
  color: var(--gray-5);
  text-align: right;
}

/* 编辑表单 */
.edit-form { display: flex; flex-direction: column; gap: 14px; }
.edit-form label { display: flex; flex-direction: column; gap: 6px; }
.edit-form label span { font-size: 13px; font-weight: 600; color: var(--gray-7); }
.edit-form input, .edit-form textarea {
  width: 100%;
  border: 1px solid var(--gray-3);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--gray-9);
  background: var(--white);
  outline: none;
  transition: border-color .2s;
}
.edit-form input:focus, .edit-form textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(192,57,43,0.12); }
.edit-form textarea { resize: vertical; line-height: 1.7; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.form-tip { margin-top: 14px; font-size: 12px; color: var(--gray-5); line-height: 1.6; }

/* ============ Toast ============ */
.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: rgba(31, 35, 41, 0.9);
  color: var(--white);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: all .3s;
  max-width: 80vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ 底部 ============ */
.footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 50;
  padding: 8px 18px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(192, 57, 43, 0.1);
  text-align: center;
}
.footer p {
  font-size: 12px;
  color: var(--gray-5);
  line-height: 1.5;
}

/* ============ 移动端 ============ */
@media (max-width: 768px) {
  .topbar {
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 8px;
  }
  .brand-text p { display: none; }
  .brand-text h1 { font-size: 16px; }
  .search-box {
    order: 3;
    flex-basis: 100%;
    max-width: 100%;
  }
  .top-actions { margin-left: auto; }
  .restore-btn { font-size: 12px; padding: 0 12px; height: 34px; }

  .side-panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 70vh;
    border-radius: 16px 16px 0 0;
  }
  .panel-body { padding: 14px 16px 18px; }
  .panel-header { padding: 14px 16px 10px; }
  .poem-content { font-size: 15px; }

  .footer p { font-size: 10px; }
}
