/* zw.bdfz.net — Claude Monet 《睡蓮》調色板 */

:root {
  /* 取自 Monet 1906 Water Lilies 主色 */
  --pond-deep: #2c3e3a;       /* 池水深處 */
  --pond-mid: #4a6859;        /* 池水中層 */
  --pond-light: #8aa896;      /* 浮葉淺綠 */
  --pond-haze: #c8d5c4;       /* 水霧 */
  --lily-pink: #d99eb4;       /* 蓮粉 */
  --lily-pink-deep: #b8657f;  /* 蓮深粉 */
  --lily-white: #f4e6d8;      /* 蓮花瓣米 */
  --sky-mauve: #b5a2bd;       /* 天光紫 */
  --willow-gold: #c9a76b;     /* 柳金 */

  --ink: #2c3540;
  --ink-soft: #5d6675;
  --ink-faint: #8b94a1;

  /* 紙與玻璃 */
  --canvas: rgba(252, 247, 238, 0.82);
  --canvas-strong: rgba(252, 247, 238, 0.94);
  --canvas-soft: rgba(252, 247, 238, 0.6);
  --edge: rgba(74, 104, 89, 0.18);
  --edge-soft: rgba(74, 104, 89, 0.1);

  --shadow-1: 0 8px 28px rgba(44, 62, 58, 0.14);
  --shadow-2: 0 22px 52px rgba(44, 62, 58, 0.22);

  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "Songti TC",
    "STSong", "PingFang SC", Georgia, serif;
  --font-display: "STKaiti", "Kaiti SC", "Kaiti TC", "Noto Serif SC", "Songti SC",
    serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; }

body {
  font-family: var(--font-serif);
  color: var(--ink);
  background-color: #c8d5c4;
  background-image: url("/bg.webp");
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  min-height: 100vh;
  letter-spacing: 0;
}

/* 印象派水霧覆層:讓畫不刺眼,但保留色彩 */
.bg-veil {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(252, 247, 238, 0.28) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 90%, rgba(180, 200, 195, 0.32) 0%, transparent 60%),
    linear-gradient(180deg, rgba(252, 247, 238, 0.18), rgba(252, 247, 238, 0.42));
}

body.dark {
  --ink: #ebe5d8;
  --ink-soft: #b8b0a2;
  --ink-faint: #8a8478;
  --canvas: rgba(28, 38, 36, 0.74);
  --canvas-strong: rgba(28, 38, 36, 0.92);
  --canvas-soft: rgba(28, 38, 36, 0.55);
  --edge: rgba(200, 213, 196, 0.16);
  --edge-soft: rgba(200, 213, 196, 0.08);
  background-color: #0e1614;
}
body.dark .bg-veil {
  background:
    radial-gradient(ellipse at 30% 30%, rgba(20, 30, 28, 0.55) 0%, transparent 60%),
    linear-gradient(180deg, rgba(10, 18, 16, 0.6), rgba(10, 18, 16, 0.75));
}

/* ---------- 頂欄 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  background: var(--canvas);
  border-bottom: 1px solid var(--edge);
}

.brand { display: flex; align-items: baseline; gap: 12px; }
.brand-mark {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 400;
  color: var(--lily-pink-deep);
  line-height: 1;
  letter-spacing: 0;
  text-shadow: 0 1px 2px rgba(184, 101, 127, 0.18);
}
.brand-title {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0;
}
.brand-sub {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0;
  font-style: italic;
}

.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--edge);
  background: var(--canvas);
  color: var(--ink-soft);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s, color 0.2s, border-color 0.2s;
}
.icon-btn:hover {
  transform: translateY(-1px);
  background: var(--canvas-strong);
  color: var(--lily-pink-deep);
  border-color: var(--lily-pink);
}

/* ---------- 主舞台 ---------- */
.stage {
  position: relative;
  z-index: 1;
  max-width: 880px;
  margin: 0 auto;
  padding: 40px 24px 90px;
}

.step {
  position: relative;
  background: var(--canvas-strong);
  border: 1px solid var(--edge);
  border-radius: var(--radius-lg);
  padding: 42px 38px;
  box-shadow: var(--shadow-1);
  backdrop-filter: blur(22px) saturate(150%);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
}
/* 印象派紙紋:極淺斜紋,模擬畫布肌理 */
.step::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    repeating-linear-gradient(45deg, transparent 0 2px, rgba(74, 104, 89, 0.018) 2px 4px),
    repeating-linear-gradient(-45deg, transparent 0 2px, rgba(74, 104, 89, 0.018) 2px 4px);
}
.step.hidden { display: none; }
.step + .step { margin-top: 22px; }

.step-title {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.4;
  color: var(--ink);
}
.step-title-small {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: 0;
}
.step-hint {
  margin: 0 0 28px;
  color: var(--ink-soft);
  font-size: 14px;
  font-style: italic;
  letter-spacing: 0;
}

/* ---------- 類型卡片 ---------- */
.type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
  margin-top: 22px;
}
.type-card {
  position: relative;
  text-align: left;
  padding: 26px 22px;
  border-radius: var(--radius-md);
  border: 1px solid var(--edge);
  background: var(--canvas-soft);
  cursor: pointer;
  color: inherit;
  font: inherit;
  transition: transform 0.22s, box-shadow 0.22s, border-color 0.22s, background 0.22s;
  overflow: hidden;
}
.type-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.22s;
  background:
    radial-gradient(circle at 80% 20%, rgba(217, 158, 180, 0.22), transparent 60%);
}
.type-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-1);
  border-color: var(--lily-pink);
  background: var(--canvas-strong);
}
.type-card:hover::after { opacity: 1; }

.type-card[data-mode="micro"] {
  background: linear-gradient(140deg,
    rgba(201, 167, 107, 0.22), rgba(252, 247, 238, 0.62));
}
.type-card[data-mode="long"]  {
  background: linear-gradient(140deg,
    rgba(184, 101, 127, 0.22), rgba(252, 247, 238, 0.62));
}
.type-card[data-mode="play"]  {
  background: linear-gradient(140deg,
    rgba(138, 168, 150, 0.28), rgba(252, 247, 238, 0.62));
}

.type-name {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0;
  margin-bottom: 8px;
  color: var(--ink);
}
.type-desc {
  color: var(--ink-soft);
  font-size: 13.5px;
  line-height: 1.7;
}

/* ---------- 第二步:輸入區 ---------- */
.step-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}
.back-btn {
  border: 1px solid var(--edge);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  letter-spacing: 0;
}
.back-btn:hover { color: var(--lily-pink-deep); border-color: var(--lily-pink); }

.mode-pill {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--lily-pink-deep);
  color: var(--lily-white);
  font-size: 12px;
  letter-spacing: 0;
  font-family: var(--font-display);
  box-shadow: 0 4px 12px rgba(184, 101, 127, 0.3);
}

.assignment-block {
  position: relative;
  margin-bottom: 22px;
  padding: 18px;
  border: 1px solid var(--edge);
  border-radius: var(--radius-md);
  background: linear-gradient(140deg, rgba(201, 167, 107, 0.16), var(--canvas-soft));
}
.assignment-block label {
  display: block;
  margin-bottom: 10px;
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--ink);
}
.assignment-block textarea {
  min-height: 112px;
  background: rgba(252, 247, 238, 0.68);
}
body.dark .assignment-block textarea { background: rgba(28, 38, 36, 0.62); }

.input-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--edge);
}
.tab {
  border: 0;
  background: transparent;
  padding: 10px 18px;
  cursor: pointer;
  color: var(--ink-faint);
  font: inherit;
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 0;
  border-bottom: 2px solid transparent;
  transition: color 0.18s, border-color 0.18s;
  position: relative;
  top: 1px;
}
.tab.active {
  color: var(--ink);
  border-bottom-color: var(--lily-pink-deep);
  font-weight: 600;
}
.tab:hover:not(.active) { color: var(--ink-soft); }

.panel { display: none; }
.panel.active { display: block; }

textarea {
  width: 100%;
  border: 1px solid var(--edge);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.9;
  background: var(--canvas);
  color: var(--ink);
  resize: vertical;
  outline: none;
  transition: border-color 0.18s, background 0.18s, box-shadow 0.18s;
}
textarea:focus {
  border-color: var(--lily-pink);
  background: var(--canvas-strong);
  box-shadow: 0 0 0 4px rgba(217, 158, 180, 0.15);
}
textarea::placeholder { color: var(--ink-faint); font-style: italic; }

#essay-text, #essay-paste { min-height: 300px; }
#photo-note { min-height: 80px; margin-top: 14px; }
#ocr-result { min-height: 230px; margin-top: 12px; }
#chat-input { min-height: 64px; }

.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--ink-faint);
  font-style: italic;
}

.drop-zone {
  display: block;
  border: 2px dashed var(--edge);
  border-radius: var(--radius-md);
  padding: 44px 22px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s;
  background: var(--canvas-soft);
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--lily-pink);
  background: var(--canvas);
}
.drop-icon { font-size: 34px; margin-bottom: 10px; opacity: 0.65; }
.drop-hint { color: var(--ink-soft); }
.drop-sub { color: var(--ink-faint); font-size: 12.5px; margin-top: 8px; font-style: italic; }

.thumb-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.thumb {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--edge);
  box-shadow: var(--shadow-1);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-x {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 0;
  background: rgba(28, 38, 36, 0.7);
  color: var(--lily-white);
  cursor: pointer;
  font-size: 14px;
  line-height: 20px;
}

.ocr-card {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--edge);
  border-radius: var(--radius-md);
  background: var(--canvas-soft);
}
.ocr-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}
.ocr-title {
  font-family: var(--font-display);
  font-size: 17px;
  color: var(--ink);
}
.ocr-sub {
  margin-top: 4px;
  color: var(--ink-faint);
  font-size: 12.5px;
  line-height: 1.6;
}
.ocr-state {
  margin-top: 12px;
  color: var(--ink-soft);
  font-size: 13px;
  font-style: italic;
}

.action-row { display: flex; justify-content: flex-end; margin-top: 26px; }

.primary-btn {
  border: 0;
  border-radius: 999px;
  padding: 12px 28px;
  background: linear-gradient(135deg, var(--lily-pink-deep), #a0586f);
  color: var(--lily-white);
  font: inherit;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14.5px;
  cursor: pointer;
  letter-spacing: 0;
  transition: transform 0.18s, box-shadow 0.18s, background 0.18s;
  box-shadow: 0 8px 22px rgba(184, 101, 127, 0.38);
}
.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(184, 101, 127, 0.48);
}
.primary-btn:disabled {
  background: #b3a8b2;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.ghost-btn {
  border: 1px solid var(--edge);
  background: transparent;
  border-radius: 999px;
  padding: 7px 16px;
  font: inherit;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  font-family: var(--font-display);
  letter-spacing: 0;
}
.ghost-btn:hover { color: var(--lily-pink-deep); border-color: var(--lily-pink); }

/* ---------- 第三步:對話 ---------- */
.chat-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.session-strip {
  margin: -6px 0 16px;
  padding: 10px 14px;
  border: 1px solid var(--edge-soft);
  border-radius: var(--radius-sm);
  background: var(--canvas-soft);
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.6;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 22px;
  max-height: 62vh;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(74, 104, 89, 0.3) transparent;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: rgba(74, 104, 89, 0.3); border-radius: 3px; }

.msg {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 20px;
  border-radius: var(--radius-md);
  background: var(--canvas);
  border: 1px solid var(--edge);
  line-height: 1.95;
  font-size: 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: var(--font-serif);
}
.message-body {
  white-space: pre-wrap;
}
.assistant-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  white-space: normal;
}
.sun-point,
.sun-section {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--edge-soft);
  border-radius: var(--radius-sm);
  background: var(--canvas);
}
.sun-point-index,
.sun-section-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(184, 101, 127, 0.16);
  color: var(--lily-pink-deep);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
  line-height: 1;
}
.sun-section {
  background: linear-gradient(140deg, rgba(138, 168, 150, 0.14), var(--canvas));
}
.sun-line {
  line-height: 1.95;
}
.sun-line.strong {
  font-family: var(--font-display);
  color: var(--ink);
}
.sun-bullet {
  position: relative;
  padding-left: 20px;
  line-height: 1.85;
}
.sun-bullet::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 0.9em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--lily-pink-deep);
}
.msg.user {
  align-self: flex-end;
  max-width: 92%;
  background: linear-gradient(140deg, rgba(217, 158, 180, 0.22), var(--canvas-strong));
  border-color: rgba(217, 158, 180, 0.4);
}
.msg.assistant {
  align-self: flex-start;
  max-width: 96%;
  background: var(--canvas-strong);
}
.msg .who {
  font-size: 11px;
  letter-spacing: 0;
  color: var(--ink-faint);
  font-family: var(--font-display);
  text-transform: none;
}
.msg .who.sun { color: var(--lily-pink-deep); }
.msg-imgs { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.msg-imgs img {
  max-width: 180px;
  max-height: 180px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--edge);
}

.chat-form {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
.chat-form textarea { flex: 1; }

.thinking {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
  font-style: italic;
}
.thinking::after {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--edge);
  border-top-color: var(--lily-pink-deep);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 設置彈窗 ---------- */
dialog.settings {
  border: 0;
  border-radius: var(--radius-lg);
  padding: 30px;
  max-width: 540px;
  width: calc(100% - 32px);
  background: var(--canvas-strong);
  color: var(--ink);
  box-shadow: var(--shadow-2);
  font-family: var(--font-serif);
}
dialog.settings::backdrop {
  background: rgba(20, 30, 28, 0.5);
  backdrop-filter: blur(4px);
}
.settings h3 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: 0;
}
.settings-hint {
  color: var(--ink-soft);
  font-size: 13.5px;
  margin: 0 0 16px;
  line-height: 1.7;
}
.settings textarea { min-height: 160px; font-size: 14.5px; }
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

/* ---------- 手機適配 ---------- */
@media (max-width: 720px) {
  body {
    background-attachment: scroll;
    min-height: 100dvh;
  }
  .topbar {
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
  }
  .brand {
    min-width: 0;
    flex-wrap: wrap;
    gap: 6px 9px;
  }
  .brand-mark { font-size: 30px; }
  .brand-title { font-size: 17px; }
  .brand-sub { display: none; }
  .top-actions {
    flex: 0 0 auto;
    gap: 6px;
  }
  .icon-btn {
    width: 34px;
    height: 34px;
    font-size: 14px;
  }
  .stage {
    max-width: 100%;
    padding: 18px 12px calc(132px + env(safe-area-inset-bottom));
  }
  .step {
    padding: 22px 16px;
    border-radius: 18px;
  }
  .step-title {
    font-size: 23px;
    line-height: 1.35;
  }
  .step-title-small {
    font-size: 18px;
    line-height: 1.4;
  }
  .step-header,
  .chat-toolbar,
  .ocr-head {
    align-items: stretch;
    flex-direction: column;
  }
  .mode-pill,
  .back-btn,
  .ocr-head .ghost-btn {
    width: fit-content;
  }
  .assignment-block,
  .ocr-card {
    padding: 14px;
  }
  .input-tabs {
    overflow-x: auto;
    padding-bottom: 1px;
    scrollbar-width: none;
  }
  .input-tabs::-webkit-scrollbar { display: none; }
  .tab {
    flex: 0 0 auto;
    padding: 10px 14px;
    font-size: 14px;
  }
  textarea {
    font-size: 16px;
    line-height: 1.75;
    padding: 14px;
  }
  #essay-text,
  #essay-paste {
    min-height: 260px;
  }
  #ocr-result {
    min-height: 240px;
  }
  .drop-zone {
    padding: 32px 16px;
  }
  .meta-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
  .action-row {
    justify-content: stretch;
  }
  .primary-btn,
  .ghost-btn {
    min-height: 42px;
  }
  .action-row .primary-btn,
  .chat-form .primary-btn {
    width: 100%;
  }
  .messages {
    max-height: none;
    min-height: 38dvh;
    padding-right: 0;
  }
  .msg,
  .msg.user,
  .msg.assistant {
    max-width: 100%;
    font-size: 15px;
    padding: 14px;
  }
  .sun-point,
  .sun-section {
    grid-template-columns: 24px 1fr;
    padding: 9px 10px;
  }
  .sun-point-index,
  .sun-section-index {
    width: 22px;
    height: 22px;
  }
  .msg-imgs img {
    max-width: 44vw;
    max-height: 150px;
  }
  .chat-form {
    position: sticky;
    bottom: calc(94px + env(safe-area-inset-bottom));
    z-index: 8;
    flex-direction: column;
    align-items: stretch;
    padding: 10px;
    margin: 0 -8px -8px;
    border: 1px solid var(--edge);
    border-radius: var(--radius-md);
    background: var(--canvas-strong);
    box-shadow: var(--shadow-1);
  }
  .chat-form textarea {
    min-height: 96px;
  }
  dialog.settings {
    padding: 22px;
  }
}
