/* ===== 基础重置 ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "LXGW WenKai GB", "KaiTi", "STKaiti", "Noto Serif SC", "PingFang SC", serif;
  background: #FAF8F5;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* ===== 登录遮罩 ===== */
#login-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #FAF8F5;
}

#login-overlay.hidden {
  display: none;
}

.login-box {
  text-align: center;
  width: 280px;
  max-width: 85vw;
}

.login-heart {
  font-size: 48px;
  color: #c4886a;
  margin-bottom: 16px;
  line-height: 1;
}


#login-password {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e8ddd3;
  border-radius: 12px;
  font-size: 16px;
  font-family: inherit;
  color: #6b5a4e;
  background: #fff;
  outline: none;
  text-align: center;
  letter-spacing: 4px;
  -webkit-text-security: disc;
}

#login-password:focus {
  border-color: #c4886a;
}

#login-password.shake {
  animation: loginShake 0.4s ease;
  border-color: #c0604a;
}

@keyframes loginShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.login-error {
  font-size: 13px;
  color: #c0604a;
  margin-top: 8px;
  min-height: 20px;
  opacity: 0;
  transition: opacity 0.2s;
}

.login-error.show {
  opacity: 1;
}

.login-btn {
  margin-top: 14px;
  width: 100%;
  padding: 11px 0;
  border: 2px solid #d4b896;
  border-radius: 12px;
  background: #e8ddd3;
  color: #6b5a4e;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 2px;
}

.login-btn:hover {
  background: #d4b896;
  color: #fff;
}

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

.login-btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* ===== 画布容器 ===== */
#canvas-wrapper {
  position: fixed;
  inset: 0;
}

#canvas-wrapper canvas {
  display: block;
  touch-action: none;
}

/* ===== 纪念日天数 ===== */
#day-counter {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  padding: 8px 24px;
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2px solid #e8ddd3;
  border-radius: 16px;
  pointer-events: none;
  white-space: nowrap;
}

#day-number {
  font-size: 18px;
  font-weight: 400;
  color: #b0a090;
  letter-spacing: 1px;
}

#day-number span {
  font-weight: 700;
  color: #c4886a;
  font-size: 22px;
}

/* ===== 状态指示（顶部右侧） ===== */
#status-indicator {
  position: fixed;
  top: 22px;
  right: 24px;
  z-index: 10;
  font-size: 13px;
  color: #b0a090;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  padding: 6px 14px;
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1.5px solid #e8ddd3;
  border-radius: 12px;
}

#status-indicator.show {
  opacity: 1;
}

#status-indicator.ok { color: #9ab89a; }
#status-indicator.err { color: #c4886a; }

/* ===== 浮动工具栏 ===== */
#toolbar {
  position: fixed;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: rgba(255,255,255,0.78);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 2px solid #e8ddd3;
  border-radius: 14px;
  box-shadow: 0 2px 16px rgba(180,150,130,0.08);
  scrollbar-width: none;
}

.tool-btn {
  width: 34px;
  height: 34px;
  border: 2px solid transparent;
  background: transparent;
  border-radius: 12px;
  cursor: pointer;
  color: #b0a090;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  position: relative;
}

.tool-btn svg {
  width: 19px;
  height: 19px;
}

.tool-btn:hover {
  color: #c4886a;
  border-color: #e8ddd3;
}

.tool-btn.active {
  color: #c4886a;
  background: #faf5ef;
  border-color: #d4b896;
}

.tool-btn:active {
  transform: scale(0.93);
}

.tool-btn.danger {
  color: #d4956b;
}

.tool-btn.danger:hover {
  color: #c0604a;
  border-color: #e0c0b8;
}

.toolbar-sep {
  width: 2px;
  height: 16px;
  background: #e8ddd3;
  border-radius: 1px;
  margin: 0 3px;
}

/* ===== 样式设置面板 ===== */
.sub-panel {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: rgba(255,255,255,0.78);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 2px solid #e8ddd3;
  border-radius: 14px;
  transition: opacity 0.25s, transform 0.25s;
}

.sub-panel.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(12px);
}

.sub-panel label {
  font-size: 14px;
  color: #8b7a6e;
  font-weight: 400;
  line-height: 24px;
}

.sub-panel input[type="color"] {
  width: 24px;
  height: 24px;
  border: 2px solid #e8ddd3;
  border-radius: 6px;
  cursor: pointer;
  background: none;
  padding: 1px;
}

.sub-panel input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.sub-panel input[type="color"]::-webkit-color-swatch {
  border-radius: 4px;
  border: none;
}

.sub-panel input[type="range"] {
  width: 80px;
  height: 24px;
  accent-color: #c4886a;
}

#draw-opts,
#text-opts {
  display: flex;
  align-items: center;
  gap: 6px;
}

#draw-opts.hidden,
#text-opts.hidden {
  display: none;
}

/* ===== 文字编辑弹窗 ===== */
#text-edit-dialog {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.15);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

#text-edit-dialog.show {
  opacity: 1;
  pointer-events: auto;
}

#text-edit-dialog .dialog-box {
  background: #fff;
  border: 2px solid #e8ddd3;
  border-radius: 16px;
  padding: 20px 24px;
  width: 380px;
  max-width: 90vw;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

#text-edit-area {
  width: 100%;
  border: 2px solid #e8ddd3;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  color: #6b5a4e;
  resize: vertical;
  outline: none;
  margin-bottom: 14px;
  background: #fdfcfa;
}

#text-edit-area:focus {
  border-color: #d4b896;
}

#text-edit-dialog .dialog-btns {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

#text-edit-dialog .dialog-btn {
  padding: 8px 22px;
  border: 2px solid #e8ddd3;
  border-radius: 12px;
  background: #fff;
  color: #6b5a4e;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

#text-edit-dialog .dialog-btn:hover {
  border-color: #d4b896;
  color: #c4886a;
}

#text-edit-dialog .dialog-btn.confirm {
  background: #e8ddd3;
  border-color: #e8ddd3;
}

#text-edit-dialog .dialog-btn.confirm:hover {
  background: #d4b896;
  border-color: #d4b896;
  color: #fff;
}

/* ===== 确认弹窗 ===== */
#confirm-dialog {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.15);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

#confirm-dialog.show {
  opacity: 1;
  pointer-events: auto;
}

#confirm-dialog .dialog-box {
  background: #fff;
  border: 2px solid #e8ddd3;
  border-radius: 16px;
  padding: 24px 28px;
  text-align: center;
  max-width: 320px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

#confirm-dialog .dialog-msg {
  font-size: 15px;
  color: #6b5a4e;
  margin-bottom: 18px;
  line-height: 1.6;
}

#confirm-dialog .dialog-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
}

#confirm-dialog .dialog-btn {
  padding: 8px 22px;
  border: 2px solid #e8ddd3;
  border-radius: 12px;
  background: #fff;
  color: #6b5a4e;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

#confirm-dialog .dialog-btn:hover {
  border-color: #d4b896;
  color: #c4886a;
}

#confirm-dialog .dialog-btn.confirm {
  background: #e8ddd3;
  border-color: #e8ddd3;
}

#confirm-dialog .dialog-btn.confirm:hover {
  background: #d4b896;
  border-color: #d4b896;
  color: #fff;
}

/* ===== 移动端适配 ===== */
@media (max-width: 768px) {
  #toolbar {
    gap: 3px;
    padding: 6px 10px;
    bottom: 22px;
    bottom: max(22px, env(safe-area-inset-bottom, 22px));
    left: 12px;
    right: 12px;
    transform: none;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start;
    border-radius: 16px;
  }
  #toolbar::-webkit-scrollbar { display: none; }
  #toolbar { -ms-overflow-style: none; }

  .tool-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    flex-shrink: 0;
    border-radius: 12px;
  }

  .tool-btn svg {
    width: 18px;
    height: 18px;
  }

  .toolbar-sep {
    margin: 0 2px;
    flex-shrink: 0;
    height: 16px;
  }

  #day-counter {
    top: 12px;
    top: max(12px, env(safe-area-inset-top, 12px));
    padding: 8px 20px;
    border-radius: 20px;
  }

  #day-number { font-size: 17px; }
  #day-number span { font-size: 22px; }

  #status-indicator {
    top: 10px;
    top: max(10px, env(safe-area-inset-top, 10px));
    right: 12px;
    font-size: 12px;
    padding: 5px 12px;
  }

  #bottom-links {
    bottom: 6px;
    bottom: max(6px, env(safe-area-inset-bottom, 6px));
    right: 16px;
    font-size: 13px;
  }

  .sub-panel {
    bottom: 80px;
    bottom: calc(max(16px, env(safe-area-inset-bottom, 16px)) + 80px);
    left: 12px;
    right: 12px;
    transform: none;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 12px;
    border-radius: 16px;
  }

  .sub-panel.hidden {
    transform: translateY(12px);
  }

  .sub-panel input[type="range"] {
    width: 60px;
  }

  .sub-panel label {
    font-size: 13px;
  }

  #text-edit-dialog .dialog-box {
    width: calc(100vw - 40px);
    max-width: 340px;
    padding: 18px 20px;
  }

  #confirm-dialog .dialog-box {
    width: calc(100vw - 48px);
    max-width: 300px;
    padding: 20px 22px;
  }

  #text-edit-area {
    font-size: 16px;
  }

  #text-edit-dialog .dialog-btn,
  #confirm-dialog .dialog-btn {
    padding: 10px 24px;
    font-size: 15px;
    min-height: 44px;
  }

  .login-box {
    width: 260px;
  }

  .login-title {
    font-size: 24px;
  }
}

/* ===== 横屏手机 ===== */
@media (max-width: 768px) and (orientation: landscape) {
  #toolbar {
    bottom: 8px;
    padding: 5px 8px;
    border-radius: 14px;
  }

  .tool-btn {
    width: 30px;
    height: 30px;
    min-width: 30px;
    border-radius: 12px;
  }

  .tool-btn svg {
    width: 15px;
    height: 15px;
  }

  .toolbar-sep {
    height: 14px;
  }

  .sub-panel {
    bottom: 56px;
    bottom: calc(max(6px, env(safe-area-inset-bottom, 6px)) + 56px);
  }

  #day-counter {
    top: 6px;
    padding: 5px 14px;
  }

  #day-number { font-size: 14px; }
  #day-number span { font-size: 18px; }

  #status-indicator {
    top: 10px;
    right: 8px;
    font-size: 11px;
  }

  #bottom-links {
    bottom: 8px;
    right: 10px;
  }
}

/* ===== 底部链接（导出/导入/重置） ===== */
#bottom-links {
  position: fixed;
  bottom: 8px;
  right: 18px;
  z-index: 11;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #c8bfb2;
  user-select: none;
}
#bottom-links span {
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: color 0.2s;
}
#bottom-links span:hover {
  color: #c0604a;
}
.bottom-sep {
  color: #ddd6cc;
  cursor: default !important;
  pointer-events: none;
}
