/* ===== "Le Petit Prince" 配色：手绘质感 ===== */
:root {
  --cream:        #f1eadb;     /* 浅米色背景 */
  --cream-deep:   #e0d5b5;
  --cream-edge:   #c8b98a;
  --paper:        #f5efde;     /* 笔记本页 */

  --ink:          #26365e;     /* 深普鲁士蓝 */
  --ink-soft:     #4d5b85;
  --ink-faint:    rgba(38, 54, 94, 0.55);

  --ocean:        #d6e0ee;     /* 接近白的淡蓝海面 */
  --ocean-edge:   #b6c4dc;
  --land:         #34406a;     /* 暗暖低饱和大陆，靠近标题色 */
  --land-deep:    #283360;
  --land-stroke:  #1f2a52;

  --blue:         #29396b;     /* 主蓝（强调） */
  --blue-deep:    #182447;
  --blue-light:   #5d6e9c;
  --blue-pale:    #a8b3cf;

  --yellow:       #e8b938;     /* 星星黄（图钉） */
  --yellow-deep:  #c79a26;
  --yellow-light: #f4d278;

  --rust:         #b85a3e;
  --rust-soft:    #d8866a;
  --danger:       #b85a3e;
}

/* ===== 基础 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; min-height: 100vh;
  font-family: 'Cormorant Garamond', 'Noto Serif SC', 'Space Grotesk', Georgia, serif;
  color: var(--ink);
  background: var(--cream);
  overflow-x: hidden;
}

body {
  background:
    radial-gradient(ellipse at 50% 50%, transparent 50%, rgba(38,54,94,0.08) 100%),
    var(--cream);
}
/* 纸张颗粒 */
body::before {
  content:''; position: fixed; inset:0; pointer-events:none; z-index:0;
  opacity: 0.45;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='400' height='400'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.4' numOctaves='2' seed='4'/><feColorMatrix values='0 0 0 0 0.15   0 0 0 0 0.21   0 0 0 0 0.36   0 0 0 0.16 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  mix-blend-mode: multiply;
}

.view {
  display: none;
  width: 100%; min-height: 100vh;
  padding: 20px 24px;
  position: relative; z-index: 1;
}
.view.active { display: flex; flex-direction: column; }

/* ============== AUTH VIEW ============== */
.auth-view.active {
  align-items: center;
  justify-content: center;
}
.auth-card {
  width: min(420px, 92vw);
  background: var(--cream);
  border: 1.5px solid var(--ink);
  padding: 36px 32px 28px;
  box-shadow: 6px 6px 0 var(--yellow-deep);
  text-align: center;
}
.auth-title {
  font-size: clamp(40px, 8vw, 64px);
  margin-bottom: 4px;
}
.auth-subtitle {
  font-family: 'Cormorant Garamond', 'Noto Serif SC', serif;
  font-style: italic;
  font-size: 14px;
  color: var(--ink-soft);
  letter-spacing: 0.12em;
  margin-bottom: 28px;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}
.auth-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.auth-label > span {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--ink-soft);
}
.auth-label input {
  font-family: 'Cormorant Garamond', 'Noto Serif SC', serif;
  font-size: 17px;
  background: white;
  border: 1.2px solid var(--ink);
  padding: 9px 12px;
  color: var(--ink);
  outline: none;
  border-radius: 0;
}
.auth-label input:focus {
  background: rgba(232,185,56,0.18);
  border-color: var(--yellow-deep);
}
.auth-error {
  font-family: 'Cormorant Garamond', 'Noto Serif SC', serif;
  font-style: italic;
  color: var(--rust);
  font-size: 13px;
  min-height: 18px;
}
.auth-submit { margin-top: 6px; width: 100%; padding: 12px; }
.auth-toggle {
  text-align: center;
  margin-top: 12px;
  font-family: 'Cormorant Garamond', 'Noto Serif SC', serif;
  font-style: italic;
  font-size: 14px;
  color: var(--ink-soft);
}
.auth-toggle a {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--ink);
  margin-left: 6px;
}
.auth-toggle a:hover { color: var(--yellow-deep); border-color: var(--yellow-deep); }

/* logout 按钮 */
.globe-footer { display: flex; gap: 12px; align-items: center; justify-content: center; }
#logout-btn { opacity: 0.7; }
#logout-btn:hover { opacity: 1; }

/* ===== 字体 utility ===== */
.display-title {
  font-family: 'Anton', 'Noto Sans SC', sans-serif;
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1;
  color: var(--ink);
  text-transform: uppercase;
}

/* ===== 基础按钮 ===== */
.chip-btn {
  font-family: 'Space Grotesk', 'Noto Sans SC', sans-serif;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  padding: 8px 16px;
  border-radius: 0;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--cream);
  border: 1.2px solid var(--ink);
  color: var(--ink);
  box-shadow: 2px 2px 0 var(--ink-soft);
}
.chip-btn:hover {
  background: var(--ink);
  color: var(--cream);
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--yellow-deep);
}
.chip-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 var(--ink);
}
.chip-btn.small { font-size: 10px; padding: 6px 12px; }
.chip-btn.primary {
  background: var(--ink);
  color: var(--cream);
}
.chip-btn.primary:hover { background: var(--blue-deep); border-color: var(--blue-deep); }
.chip-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: 1px 1px 0 var(--ink-soft);
}

/* ============== GLOBE VIEW ============== */
.globe-header {
  text-align: center;
  margin-bottom: 4px;
}
.globe-header h1.display-title {
  font-size: clamp(48px, 9vw, 96px);
  letter-spacing: 0.02em;
  margin-bottom: 4px;
  color: var(--ink);
}
.globe-header .hint {
  font-family: 'Cormorant Garamond', 'Noto Serif SC', serif;
  font-style: italic;
  font-size: 13px;
  letter-spacing: 0.18em;
  color: var(--ink-soft);
  text-transform: lowercase;
}

#globe-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
#globe {
  width: min(80vmin, 720px);
  height: min(80vmin, 720px);
  cursor: grab;
}
#globe.dragging { cursor: grabbing; }

/* SVG 元素 — 海报感地球（淡蓝海 + 暗低饱和大陆） */
#globe .sphere {
  fill: var(--ocean);
  stroke: var(--ink);
  stroke-width: 1.8;
  filter: url(#sketch-rough);
}
#globe .sphere-shade {
  fill: url(#globe-shade);
  pointer-events: none;
}
#globe .sphere-halftone {
  fill: url(#halftone);
  opacity: 0.55;
  pointer-events: none;
  mix-blend-mode: multiply;
}
#globe .graticule {
  fill: none;
  stroke: var(--land);
  stroke-width: 0.4;
  stroke-opacity: 0.35;
  stroke-dasharray: 1 4;
}
#globe .land-layer { filter: url(#sketch-rough); }
#globe .land {
  fill: var(--land);
  fill-opacity: 0.92;
  stroke: var(--land-stroke);
  stroke-width: 0.6;
  stroke-linejoin: round;
}
#globe .pin-group { cursor: pointer; }
#globe .pin-shadow { fill: rgba(24, 36, 71, 0.35); }
#globe .pin-needle {
  fill: var(--blue-light);
  stroke: var(--ink);
  stroke-width: 0.4;
}
#globe .pin-head {
  fill: var(--yellow);
  stroke: var(--yellow-deep);
  stroke-width: 0.5;
  filter: url(#sticker-shadow);
}
#globe .pin-head-hl {
  fill: var(--yellow-light);
  opacity: 0.85;
}
#globe .pin-label {
  font-family: 'Cormorant Garamond', 'Noto Serif SC', serif;
  font-style: italic;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.02em;
  fill: var(--ink);
  paint-order: stroke;
  stroke: var(--cream);
  stroke-width: 4;
  stroke-linejoin: round;
  pointer-events: none;
}

.globe-footer { text-align: center; padding-top: 12px; }

/* ============== 贴纸（形状裁切，地球后方） ============== */
#globe-container { position: relative; }
#globe { position: relative; z-index: 2; }
.stickers {
  position: absolute;
  inset: -20px;
  pointer-events: none;
  z-index: 1;          /* 在地球之下 */
}
.sticker {
  position: absolute;
  pointer-events: none;
  transform: rotate(var(--rot, 0deg));
  transform-origin: center;
}
.sticker svg {
  display: block;
  overflow: visible;
  filter: drop-shadow(1.5px 2.5px 0.6px rgba(38, 54, 94, 0.45));
}

/* ============== JOURNAL VIEW ============== */
.back-btn { position: absolute; top: 20px; left: 24px; z-index: 5; }

.journal-header { text-align: center; margin-bottom: 16px; }
.journal-header h2 {
  font-family: 'Cormorant Garamond', 'Noto Serif SC', serif;
  font-style: italic;
  font-weight: 600;
  font-size: clamp(40px, 6.5vw, 68px);
  letter-spacing: 0.05em;
  line-height: 1.1;
  color: var(--ink);
  text-transform: none;
}
.date-nav {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.date-input {
  font-family: 'Cormorant Garamond', monospace;
  font-style: italic;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: var(--cream);
  border: 1.2px solid var(--ink);
  padding: 6px 12px;
  border-radius: 0;
  outline: none;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink-soft);
  font-feature-settings: "tnum";
}
.date-input::-webkit-calendar-picker-indicator {
  opacity: 0.7; cursor: pointer;
  filter: invert(15%) sepia(40%) saturate(800%) hue-rotate(190deg);
}

/* ===== 文本工具条 ===== */
.text-toolbar {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 14px;
  margin: 0 auto 12px;
  background: var(--ink);
  color: var(--cream);
  border: 1.2px solid var(--ink);
  width: fit-content;
  max-width: 95vw;
  flex-wrap: wrap;
  box-shadow: 3px 3px 0 var(--yellow-deep);
}
.text-toolbar.active { display: flex; }
.toolbar-label {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--cream);
  opacity: 0.7;
}
.text-toolbar select, .text-toolbar input[type="range"] {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 12px;
  padding: 3px 6px;
  background: var(--cream);
  color: var(--ink);
  border: none;
  outline: none;
  cursor: pointer;
}
.text-toolbar input[type="range"] { width: 80px; padding: 0; accent-color: var(--yellow); }
.color-swatches { display: flex; gap: 4px; }
.swatch {
  width: 22px; height: 22px;
  padding: 0;
  border: 1.5px solid var(--cream);
  cursor: pointer;
  border-radius: 0;
  transition: transform 0.1s;
}
.swatch:hover { transform: scale(1.15); }
.swatch.active { border-color: var(--yellow); border-width: 2px; }

/* 笔记本（细描边 + 柔和投影） */
.notebook {
  display: flex;
  width: min(95vw, 1280px);
  height: min(68vh, 760px);
  margin: 0 auto;
  position: relative;
  background: transparent;
  padding: 0;
  border: 1.2px solid var(--ink);
  box-shadow: 5px 5px 0 var(--ink-soft);
}
.page {
  flex: 1;
  background: var(--paper);
  position: relative;
  overflow: hidden;
}
.page::before {
  content:''; position: absolute; inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle, rgba(38,54,94,0.04) 0.6px, transparent 1.2px) 0 0 / 4px 4px;
  opacity: 0.6;
}
.page::after {
  content:''; position: absolute; inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='300'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.4' numOctaves='2' seed='9'/><feColorMatrix values='0 0 0 0 0.15   0 0 0 0 0.21   0 0 0 0 0.36   0 0 0 0.14 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  opacity: 0.4;
  mix-blend-mode: multiply;
}
.page-binding {
  width: 1.5px;
  background: var(--ink);
  opacity: 0.6;
}

.add-photo-btn {
  position: absolute;
  top: 12px; right: 12px;
  width: 32px; height: 32px;
  border: 1.2px solid var(--ink);
  background: var(--cream);
  font-family: 'Anton', sans-serif;
  font-size: 20px;
  color: var(--ink);
  cursor: pointer;
  z-index: 50;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  transition: all 0.12s;
  box-shadow: 2px 2px 0 var(--ink-soft);
}
.page-left .add-photo-btn { right: auto; left: 12px; }
.add-photo-btn:hover {
  background: var(--ink);
  color: var(--cream);
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--yellow-deep);
}

.add-text-btn {
  position: absolute;
  top: 12px;
  width: 32px; height: 32px;
  border: 1.2px solid var(--ink);
  background: var(--cream);
  font-family: 'Anton', sans-serif;
  font-size: 16px;
  color: var(--ink);
  cursor: pointer;
  z-index: 50;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  letter-spacing: 0.05em;
  transition: all 0.12s;
  box-shadow: 2px 2px 0 var(--ink-soft);
}
.page-left  .add-text-btn { left: 52px; }
.page-right .add-text-btn { right: 52px; }
.add-text-btn:hover {
  background: var(--yellow);
  color: var(--ink);
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--ink);
}
.add-text-btn.active {
  background: var(--ink);
  color: var(--yellow);
  box-shadow: 0 0 0 var(--ink);
  transform: translate(2px, 2px);
}

/* === Text-create mode === */
body.text-create-mode .canvas-layer { cursor: crosshair; }
body.text-create-mode .journal-photo,
body.text-create-mode .text-frame {
  pointer-events: none !important;
}
body.text-create-mode .canvas-layer::after {
  content: '';
  position: absolute; inset: 0;
  background: rgba(38,54,94,0.04);
  pointer-events: none;
}

.text-frame-preview {
  position: absolute;
  border: 1.5px dashed var(--ink);
  background: rgba(232,185,56,0.12);
  pointer-events: none;
  z-index: 9999;
}

.add-spread-btn {
  position: absolute;
  bottom: 10px; right: 10px;
  width: 24px; height: 24px;
  border: 1.2px solid var(--ink);
  background: var(--cream);
  font-family: 'Anton', sans-serif;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  z-index: 50;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  box-shadow: 1.5px 1.5px 0 var(--ink-soft);
}
.add-spread-btn:hover {
  background: var(--yellow);
  color: var(--ink);
}

.canvas-layer {
  position: absolute;
  inset: 28px 20px 28px 20px;
}

.page-number {
  position: absolute;
  bottom: 10px; left: 0; right: 0;
  text-align: center;
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  color: var(--ink);
  font-size: 16px;
  letter-spacing: 0.08em;
  font-feature-settings: "tnum";
  pointer-events: none;
  opacity: 0.7;
}
.page-right .page-number { right: 50px; }

.journal-tip {
  text-align: center;
  margin-top: 12px;
  font-family: 'Cormorant Garamond', 'Noto Serif SC', serif;
  font-style: italic;
  font-size: 13px;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
}

/* ============== 照片（拍立得） ============== */
.journal-photo {
  position: absolute;
  background: white;
  padding: 8px 8px 24px 8px;
  cursor: grab;
  user-select: none;
  touch-action: none;
  box-shadow:
    0 1px 2px rgba(38,54,94,0.25),
    2px 2px 0 var(--ink-soft);
  transition: box-shadow 0.15s;
}
.journal-photo:hover {
  box-shadow:
    0 1px 3px rgba(38,54,94,0.3),
    3px 3px 0 var(--ink);
}
.journal-photo.dragging {
  cursor: grabbing;
  z-index: 9999 !important;
}
.journal-photo.selected {
  outline: 1.5px dashed var(--ink);
  outline-offset: 4px;
  z-index: 500 !important;
}
.journal-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
}
.journal-photo .photo-caption {
  position: absolute;
  bottom: 4px; left: 0; right: 0;
  text-align: center;
  font-family: 'Caveat', cursive;
  color: var(--ink);
  font-size: 14px;
}

/* 调整手柄 */
.handle {
  position: absolute;
  width: 12px; height: 12px;
  background: var(--cream);
  border: 1.5px solid var(--ink);
  display: none;
  z-index: 10;
}
.journal-photo.selected .handle { display: block; }
.handle.tl { top: -7px;  left: -7px;  cursor: nwse-resize; }
.handle.tr { top: -7px;  right: -7px; cursor: nesw-resize; }
.handle.bl { bottom: -7px; left: -7px;  cursor: nesw-resize; }
.handle.br { bottom: -7px; right: -7px; cursor: nwse-resize; }
.handle.rotate {
  top: -28px;
  left: 50%;
  margin-left: -7px;
  border-radius: 50%;
  background: var(--yellow);
  border-color: var(--ink);
  cursor: grab;
}
.handle.rotate::before {
  content:'';
  position: absolute;
  top: 11px; left: 50%; width: 1px; height: 12px;
  background: var(--ink);
  transform: translateX(-50%);
}

/* ============== 文本框 ============== */
.text-frame {
  position: absolute;
  min-width: 60px; min-height: 24px;
  padding: 4px 8px;
  font-family: 'Anton', 'Noto Sans SC', sans-serif;
  font-size: 28px;
  line-height: 1.1;
  color: var(--ink);
  letter-spacing: 0.02em;
  cursor: grab;
  outline: none;
  user-select: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: transparent;
}
.text-frame.dragging { cursor: grabbing; z-index: 9999 !important; }
.text-frame.selected {
  outline: 1.5px dashed var(--ink);
  outline-offset: 2px;
  z-index: 500 !important;
}
.text-frame.editing {
  cursor: text;
  user-select: text;
}
.text-frame .handle { display: none; }
.text-frame.selected:not(.editing) .handle { display: block; }

.text-frame[data-empty="true"]:not(.editing):not(.selected)::before {
  content: '输入文字...';
  color: var(--ink-faint);
  font-style: italic;
}

/* ============== Lightbox ============== */
.lightbox {
  display: none;
  position: fixed; inset: 0;
  background: rgba(24, 36, 71, 0.92);
  z-index: 2000;
  align-items: center; justify-content: center;
}
.lightbox.active { display: flex; }
.lightbox img {
  max-width: 92vw; max-height: 88vh;
  background: white;
  padding: 12px;
  box-shadow: 8px 8px 0 var(--yellow-deep);
}
.lightbox-close {
  position: absolute;
  top: 24px; right: 32px;
  background: var(--cream);
  border: 1.2px solid var(--ink);
  color: var(--ink);
  width: 38px; height: 38px;
  font-family: 'Anton', sans-serif;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink-soft);
}

/* ============== Modal ============== */
.modal {
  display: none;
  position: fixed; inset: 0;
  background: rgba(24, 36, 71, 0.6);
  z-index: 1500;
  align-items: center; justify-content: center;
}
.modal.active { display: flex; }
.modal-card {
  background: var(--cream);
  border: 1.5px solid var(--ink);
  padding: 28px;
  width: min(420px, 92vw);
  box-shadow: 6px 6px 0 var(--yellow-deep);
}
.modal-card h3 {
  font-size: 36px;
  margin-bottom: 8px;
  color: var(--ink);
}
.modal-hint {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 14px;
  letter-spacing: 0.03em;
  margin-bottom: 20px;
  color: var(--ink-soft);
}
.modal-card label {
  display: block;
  margin-bottom: 16px;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--ink-soft);
}
.modal-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  font-family: 'Cormorant Garamond', 'Noto Serif SC', serif;
  font-size: 18px;
  background: white;
  border: 1.2px solid var(--ink);
  color: var(--ink);
  outline: none;
}
.modal-card input:focus { background: rgba(232,185,56,0.18); border-color: var(--yellow-deep); }
.modal-actions {
  display: flex; justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

/* ============== Context menu ============== */
.ctx-menu {
  position: fixed;
  display: none;
  flex-direction: column;
  min-width: 160px;
  padding: 4px;
  z-index: 3000;
  background: var(--ink);
  border: 1.2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--yellow-deep);
  font-family: 'Space Grotesk', 'Noto Sans SC', sans-serif;
}
.ctx-menu.active { display: flex; }
.ctx-menu button {
  appearance: none;
  background: transparent;
  border: none;
  text-align: left;
  padding: 7px 12px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--cream);
  cursor: pointer;
}
.ctx-menu button:hover { background: var(--blue-light); }
.ctx-menu button.danger { color: var(--rust-soft); }
.ctx-menu button.danger:hover { background: var(--rust); color: var(--cream); }
.ctx-menu hr { border: none; border-top: 1px solid rgba(236,228,203,0.15); margin: 4px 0; }
.pin-ctx-name {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-weight: 600;
  font-size: 16px;
  color: var(--cream);
  padding: 8px 12px 6px;
  border-bottom: 1px solid rgba(236,228,203,0.18);
  margin-bottom: 4px;
  letter-spacing: 0.04em;
}

/* 顶部短提示 */
#flash-hint {
  position: fixed;
  top: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--cream);
  padding: 10px 22px;
  font-family: 'Cormorant Garamond', 'Noto Serif SC', serif;
  font-style: italic;
  font-size: 14px;
  letter-spacing: 0.06em;
  z-index: 3000;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  box-shadow: 3px 3px 0 var(--yellow-deep);
}
#flash-hint.active { opacity: 1; }
