* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}

#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100%;
}

/* ============ 左侧阅读区 ============ */
#reader {
  flex: 1 1 55%;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #e5e7eb;
  min-width: 0;
  background: #f3f4f6;
}

#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #ffffff;
  border-bottom: 1px solid #e5e7eb;
  flex-wrap: wrap;
}

.btn {
  padding: 8px 14px;
  border: 1px solid #d1d5db;
  background: #fff;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  color: #111827;
  white-space: nowrap;
}

.btn.primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.btn.active {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #92400e;
}

#pageInfo {
  margin-left: auto;
  font-size: 13px;
  color: #6b7280;
}

#pdfContainer {
  flex: 1;
  position: relative;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
}

#canvasWrapper {
  position: relative;
  flex-shrink: 0;
}

#pdfCanvas {
  display: block;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  background: #fff;
  max-width: none;
}

#inkCanvas {
  position: absolute;
  top: 0;
  left: 0;
  touch-action: none;
  cursor: crosshair;
}

#hint {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #9ca3af;
  font-size: 15px;
  text-align: center;
  pointer-events: none;
  max-width: 240px;
  line-height: 1.6;
}

/* ============ 右侧对话区 ============ */
#chat {
  flex: 1 1 45%;
  display: flex;
  flex-direction: column;
  background: #fafafa;
  min-width: 0;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user {
  align-self: flex-end;
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.ai {
  align-self: flex-start;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}

.msg .snap {
  display: block;
  max-width: 100%;
  border-radius: 8px;
  margin-bottom: 8px;
  border: 1px solid #e5e7eb;
}

.msg.loading {
  color: #9ca3af;
  background: transparent;
  border: none;
}

.msg.ai .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0;
}

.msg.ai p {
  margin: 0.4em 0;
}

#chatInput {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  align-items: flex-end;
}

#question {
  flex: 1;
  resize: none;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 10px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
}

#askBtn {
  height: 42px;
}

/* 窄屏(iPhone)时上下堆叠 */
@media (max-width: 768px) {
  #app {
    flex-direction: column;
  }
  #reader {
    flex: 1 1 55%;
    border-right: none;
    border-bottom: 1px solid #e5e7eb;
  }
  #chat {
    flex: 1 1 45%;
  }
}
