:root {
  --bg-1: #f5e39b;
  --bg-2: #edd170;
  --panel: #f8f4df;
  --panel-2: #f2edd2;
  --line: #e4c05e;
  --ink: #2e2a25;
  --muted: #7a7367;
  --accent: #f29a3f;
  --accent-2: #ffcf73;
  --head: #2f3035;
  --paper: #ffffff;
}

* {
  box-sizing: border-box;
  /* Firefox 兼容性 */
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

/* 全局滚动条美化 */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background-color: rgba(228, 192, 94, 0.4); /* 使用 --line 的半透明色 */
  border-radius: 10px;
  transition: background-color 0.3s;
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--line);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Serif SC", "Source Han Serif SC", "Microsoft YaHei", serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% -10%, #fff4c9 0 28%, transparent 29%),
    radial-gradient(circle at 90% 110%, #fbe9aa 0 24%, transparent 25%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
  padding: 28px;
}

.app {
  max-width: 1460px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 450px 1fr 470px;
  gap: 22px;
  height: calc(100vh - 56px);
  animation: app-rise 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.panel {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 8px 18px rgba(91, 68, 18, 0.08);
  overflow: hidden;
  min-height: 0;
  transition:
    transform 0.3s ease,
    box-shadow 0.3s ease;
}

.panel:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(91, 68, 18, 0.12);
}

.left {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
}

.left-top {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 12px;
}

.esc {
  display: grid;
  place-items: center;
  background: #fffdf5;
  border: 2px solid var(--line);
  border-radius: 16px;
  color: #6f5e48;
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.esc i {
  font-size: 22px;
  line-height: 1;
}

.esc:hover {
  transform: translateY(-2px);
}

.status {
  background: #fffdf5;
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}

.config-group {
  display: flex;
  gap: 8px;
}

.config-group select {
  flex: 1;
  height: 36px;
  padding: 0 36px 0 12px;
  border-radius: 10px;
  border: 2px solid #e2b14b;
  background-color: #fffdf6;
  background-image: linear-gradient(45deg, transparent 50%, #a67b2c 50%),
    linear-gradient(135deg, #a67b2c 50%, transparent 50%);
  background-position:
    calc(100% - 16px) 15px,
    calc(100% - 10px) 15px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  font-size: 14px;
  color: #6f5427;
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.config-group select:hover {
  border-color: #d49a2f;
  background-color: #fff9ea;
}

.config-group select:focus {
  outline: none;
  border-color: #f0a13f;
  box-shadow: 0 0 0 3px rgba(240, 161, 63, 0.16);
}

.mode-switch {
  width: 100%;
  height: 36px;
  padding: 2px;
  border-radius: 10px;
  border: 2px solid #e2b14b;
  background: #fff9ea;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
}

.mode-btn {
  position: relative;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #8a6a2f;
  font-size: 14px;
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-btn:hover {
  background: #fff5da;
}

.mode-btn::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%) translateY(6px);
  background: rgba(50, 43, 31, 0.95);
  color: #fff6dd;
  font-size: 12px;
  line-height: 1.35;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: all 0.18s ease;
  z-index: 5;
}

.mode-btn::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 4px);
  transform: translateX(-50%) translateY(6px);
  border: 6px solid transparent;
  border-top-color: rgba(50, 43, 31, 0.95);
  opacity: 0;
  pointer-events: none;
  transition: all 0.18s ease;
  z-index: 5;
}

.mode-btn:hover::after,
.mode-btn:hover::before {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.mode-btn.active {
  background: linear-gradient(120deg, #f8bf6a, #f19a43);
  color: #fff;
  box-shadow: 0 2px 6px rgba(241, 154, 67, 0.35);
}

.status-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.4px;
  color: #f3b13f;
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-bar {
  width: 100%;
  height: 16px;
  background: #efe8d5;
  border-radius: 999px;
  overflow: hidden;
}

.status-fill {
  width: 32%;
  height: 100%;
  background: linear-gradient(90deg, #f0a96a, #f59d48);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.status-sub {
  text-align: right;
  color: #e48f3f;
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

.character {
  position: relative;
  background: url("../assets/img/xy.png") center bottom / cover no-repeat;
  border: 2px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  min-height: 670px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 20px;
  isolation: isolate;
}

.character::before {
  content: none;
}

.character::after {
  content: "AI导师";
  position: absolute;
  top: 24px;
  right: 24px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 245, 220, 0.87);
  border: 1px solid #f6d488;
  font-size: 14px;
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
  color: #6c522d;
}

.character-bubble {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 20px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid #f2d385;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 16px;
  line-height: 1.5;
  color: #2a2a2a;
  backdrop-filter: blur(2px);
  transition:
    opacity 0.3s ease,
    transform 0.3s ease;
}

.chat {
  display: grid;
  grid-template-rows: 52px auto minmax(0, 1fr) 70px;
  gap: 12px;
  padding: 0;
  min-height: 0;
}

.head {
  background: linear-gradient(90deg, #3e3d41, #2e2e31);
  color: #f8ce66;
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  padding: 0 18px;
  letter-spacing: 0.6px;
}

.question-card {
  background: #eedf9e;
  border: 2px solid #edd277;
  border-radius: 12px;
  margin: 0 16px;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr 100px;
  gap: 10px;
  min-height: 230px;
}

.preview-box {
  background: #fff;
  border-radius: 10px;
  border: 2px solid #ecd67d;
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
}

.preview-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
  background: white;
}

.placeholder {
  text-align: center;
  color: #7f7152;
  padding: 20px;
  font-size: 16px;
  line-height: 1.6;
}

.q-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
  min-width: 0;
}

.q-actions button {
  border: 2px solid #efcc6f;
  background: #fff5d8;
  color: #b6812d;
  font-size: 18px;
  border-radius: 14px;
  height: 56px;
  line-height: 1;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
  transition: all 0.2s ease;
}

.q-actions button:hover {
  transform: translateY(-1px);
  background: #ffefc4;
}

/* 引导点击的呼吸灯动画 */
@keyframes pulse-gold {
  0% {
    box-shadow: 0 0 0 0 rgba(242, 154, 63, 0.4);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(242, 154, 63, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(242, 154, 63, 0);
  }
}

.btn-pulse {
  animation: pulse-gold 2s infinite;
  border-color: var(--accent) !important;
}

.chat-feed {
  padding: 0 18px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.msg {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: start;
  animation: msg-in 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.msg-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(160deg, #d3973a, #ffdf80);
  border: 2px solid #e3b352;
  display: grid;
  place-items: center;
  font-size: 18px;
  flex-shrink: 0;
  overflow: hidden;
}

.msg-avatar.ai {
  background: url("../assets/img/avatar.png") center / cover no-repeat;
  color: transparent;
  font-size: 0;
}

.msg-avatar.user {
  background: url("../assets/img/user_avatar.png") center / cover no-repeat;
  border-color: #9db9f2;
  color: transparent;
  font-size: 0;
}

.msg.user-msg {
  grid-template-columns: 1fr 44px;
}

.msg.user-msg .msg-avatar {
  order: 2;
}

.msg.user-msg .msg-body {
  order: 1;
  justify-self: end;
  text-align: right;
}

.msg-body {
  font-size: 16px;
  line-height: 1.65;
  color: #222;
  background: transparent;
  overflow-wrap: break-word;
}

.msg-body.error-box {
  background: #fff6ef;
  border: 2px solid #f2c186;
  border-radius: 12px;
  padding: 10px 14px;
  color: #8a531c;
  box-shadow: 0 3px 10px rgba(170, 112, 46, 0.12);
}

.msg-body p {
  margin: 0 0 0.8em;
}
.msg-body p:last-child {
  margin-bottom: 0;
}
.msg-body code {
  font-family: "Consolas", "Monaco", monospace;
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 0.9em;
}
.msg-body pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 14px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 1em 0;
  border: 1px solid #333;
}
.msg-body pre code {
  background: transparent;
  padding: 0;
  font-size: 14px;
}
.msg-body ul,
.msg-body ol {
  padding-left: 20px;
  margin: 0.8em 0;
}
.msg-body blockquote {
  border-left: 4px solid var(--line);
  margin: 0;
  padding-left: 12px;
  color: var(--muted);
}
.msg-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: 14px;
}
.msg-body th,
.msg-body td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: left;
}
.msg-body th {
  background: var(--panel-2);
}
.msg-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

/* 骨架屏样式 */
.skeleton {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 450px;
  padding-top: 8px;
}

.skeleton-bar {
  height: 14px;
  background: linear-gradient(
    90deg,
    rgba(228, 192, 94, 0.1) 25%,
    rgba(228, 192, 94, 0.25) 50%,
    rgba(228, 192, 94, 0.1) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite linear;
  border-radius: 6px;
}

.skeleton-bar:nth-child(2) {
  width: 85%;
}
.skeleton-bar:nth-child(3) {
  width: 60%;
}

@keyframes skeleton-shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

.ask {
  margin: 0 16px 14px;
  border-radius: 16px;
  border: 2px solid #eed88b;
  background: #fff;
  display: flex;
  overflow: hidden;
  min-height: 54px;
}

.ask input {
  border: none;
  outline: none;
  flex: 1;
  font-size: 16px;
  padding: 0 16px;
  color: #333;
  font-family: "Noto Serif SC", "Microsoft YaHei", serif;
}

.ask button {
  border: none;
  background: linear-gradient(120deg, #f8bf6a, #f19a43);
  color: #fff;
  font-size: 16px;
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
  min-width: 78px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}

.draft {
  display: grid;
  grid-template-rows: 52px 1fr;
}

.draft-box {
  padding: 12px;
  background: #f5f5f5;
}

.draft-box textarea {
  width: 100%;
  height: 100%;
  border: none;
  resize: none;
  background: #f5f5f5;
  color: #2f2f2f;
  font-size: 16px;
  line-height: 1.6;
  outline: none;
  font-family: "LXGW WenKai", "KaiTi", serif;
}

.tip {
  font-size: 12px;
  color: #8a835f;
  margin: 2px 0 0;
  line-height: 1.3;
  text-align: center;
  white-space: normal;
  overflow-wrap: break-word;
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
}

.mode-toast {
  position: fixed;
  top: 26px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: rgba(47, 40, 29, 0.95);
  color: #fff4d6;
  border: 1px solid #e2b14b;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 13px;
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
  box-shadow: 0 8px 20px rgba(35, 26, 14, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 9999;
}

.mode-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.settings-modal {
  position: fixed;
  inset: 0;
  background: rgba(28, 22, 14, 0.42);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.settings-modal.show {
  display: flex;
}

.settings-card {
  width: min(460px, calc(100vw - 40px));
  background: #fffdf5;
  border: 2px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 14px 30px rgba(32, 24, 11, 0.2);
  padding: 16px;
}

.settings-title {
  font-size: 18px;
  font-weight: 700;
  color: #8a6525;
  margin-bottom: 12px;
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
}

.settings-card input {
  width: 100%;
  height: 42px;
  border-radius: 10px;
  border: 2px solid #e3be67;
  padding: 0 12px;
  font-size: 14px;
  outline: none;
}

.settings-fields {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.settings-field {
  display: grid;
  gap: 6px;
}

.settings-field label {
  font-size: 13px;
  color: #9a7838;
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
}

.settings-card select {
  width: 100%;
  height: 38px;
  border-radius: 10px;
  border: 2px solid #e3be67;
  padding: 0 10px;
  font-size: 14px;
  outline: none;
  background: #fffdf6;
}

.settings-card input:focus {
  border-color: #eea447;
  box-shadow: 0 0 0 3px rgba(238, 164, 71, 0.16);
}

.settings-card select:focus {
  border-color: #eea447;
  box-shadow: 0 0 0 3px rgba(238, 164, 71, 0.16);
}

.settings-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.settings-actions button {
  border: none;
  height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
  background: linear-gradient(120deg, #f8bf6a, #f19a43);
  color: #fff;
}

.settings-actions button.ghost {
  background: #fff4d7;
  color: #9f742e;
  border: 1px solid #ebcb83;
}

@keyframes app-rise {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1280px) {
  .app {
    grid-template-columns: 1fr;
    height: auto;
  }

  .left {
    grid-template-rows: auto 560px;
  }

  .character {
    min-height: 560px;
  }

  .chat {
    min-height: 780px;
  }

  .draft {
    min-height: 500px;
  }
}

@media (max-width: 680px) {
  body {
    padding: 12px;
  }
  .left {
    grid-template-rows: auto;
    gap: 10px;
  }
  .character {
    display: none;
  }
  .status-head,
  .status-sub {
    font-size: 13px;
  }
  .head {
    font-size: 22px;
  }
  .placeholder,
  .msg-body,
  .ask input,
  .draft-box textarea {
    font-size: 14px;
  }
  .q-actions button,
  .ask button {
    font-size: 18px;
  }
  .character-bubble {
    font-size: 14px;
  }
  .chat {
    grid-template-rows: 44px auto 1fr 52px;
  }
  .question-card {
    min-height: 190px;
  }
}
