/* 模擬 LINE 氣泡核心樣式 */
.line-bubble-render {
  --bubble-fill: #8ce66c;
  --bubble-padding-inline: 12px;
  position: relative;
  font-family: system-ui, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: #111111;
  background-color: var(--bubble-fill);
  padding: 8px var(--bubble-padding-inline);
  border-radius: 14px 4px 14px 14px;
  box-sizing: border-box;
  max-width: min(calc(100% - 6px), calc(var(--bubble-inner-width, 210px) + 2 * var(--bubble-padding-inline)));
  margin-right: 6px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  transition: max-width 0.25s ease;
}

/* 氣泡右上角小尾巴 */
.line-bubble-render::after {
  content: "";
  position: absolute;
  top: 0;
  right: -5px;
  width: 10px;
  height: 9px;
  background: radial-gradient(circle at 100% 100%, transparent 8px, var(--bubble-fill) 8.5px);
}

/* 工作區外觀 */
body.workspace {
  font-family: "Segoe UI", system-ui, "Microsoft JhengHei", sans-serif;
  background: #f4f6f5;
}

.workspace > header {
  background: #fff;
  border-color: #e1e7e3;
}

.workspace header h1 {
  letter-spacing: -.025em;
}

.theme-dark body.workspace {
  color-scheme: dark;
  background: #141817;
  color: #e4ebe7;
}

.theme-dark .workspace > header {
  background: #1c2220;
}

.theme-dark .workspace :is(.bg-white, .bg-slate-50, .bg-slate-100) {
  background-color: #202725;
}

.theme-dark .workspace :is(textarea, select, #editorMore) {
  background-color: #181e1c;
  color: #f1f5f9;
}

.theme-dark .workspace :is(.border-slate-200, .border-slate-300, .divide-slate-100 > *) {
  border-color: #343f3a;
}

.theme-dark .workspace :is(.text-slate-900, .text-slate-800, .text-slate-700, .text-slate-600, .text-slate-500, .text-slate-400) {
  color: #d1dcd6;
}

.theme-dark .workspace :is(.hover\:bg-slate-100, .hover\:bg-slate-50, .hover\:bg-slate-200, .hover\:bg-white):hover {
  background-color: #2b3731;
}

.theme-dark #draftButtons button[aria-pressed="true"]:hover { background-color: #315843; }
.workspace :is(#inputEditor, #languageSelect, #aiProviderSelect) { border-color: #75847b; }
.theme-dark .workspace :is(#inputEditor, #languageSelect, #aiProviderSelect) { border-color: #81958a; }
.workspace #inputEditor::placeholder { color: #526258; }
.theme-dark #inputEditor::placeholder { color: #a2b2aa; }
#lineAnalysisList :is(.text-slate-300, .text-slate-400) { color: #526258; }
.theme-dark #lineAnalysisList .text-slate-400,
.theme-dark #lineAnalysisList .text-slate-300 { color: #9eaea6; }
.theme-dark #lineAnalysisList .bg-emerald-100 { background: #203e30; color: #a9eac8; border-color: #3b654e; }
.theme-dark #lineAnalysisList .bg-amber-100 { background: #443718; color: #f8da88; border-color: #6b5427; }
.theme-dark #lineAnalysisList .bg-rose-100 { background: #4b2932; color: #ffc2d0; border-color: #76424f; }
.theme-dark #lineAnalysisList .bg-slate-100 { background: #343f3a; }

#wrapStatus { color: #126546; }
.theme-dark #wrapStatus { color: #a1e4be; }

.workspace button {
  border-radius: 9px;
  transition: background-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.workspace button:active:not(:disabled) {
  transform: translateY(1px);
}

.workspace :is(button, a, select, summary, input):focus-visible {
  outline: 2px solid #13875a;
  outline-offset: 2px;
}
.theme-dark .workspace :is(button, a, select, summary, input):focus-visible { outline-color: #a1e4be; }

.workspace button:disabled {
  cursor: not-allowed;
}
.workspace .tool-control:disabled { opacity: .58; }

.workspace-panel {
  border-radius: 16px;
  box-shadow: 0 1px 2px rgb(15 35 24 / 4%);
}

.workspace-shell {
  width: 100%;
  max-width: clamp(1100px, 84vw, 1680px);
  margin-inline: auto;
  padding-inline: clamp(12px, 2vw, 32px);
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "editor" "preview" "analysis";
  align-items: start;
  gap: clamp(12px, 1.3vw, 24px);
  padding-block: clamp(12px, 2vw, 32px);
}

.editor-panel { grid-area: editor; }
.preview-region { grid-area: preview; }
.analysis-panel { grid-area: analysis; }
#inputEditor { height: clamp(144px, 28vh, 260px); }
.preview-panel { height: clamp(280px, 46vh, 440px); }
#lineAnalysisList { max-height: clamp(200px, 38vh, 440px); }
.preview-canvas { min-height: 0; }
.line-bubble-render { flex-shrink: 0; }
.preview-options { max-width: 100%; }

@media (min-width: 800px) {
  .workspace-grid {
    grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
    grid-template-areas: "editor preview" "analysis preview";
    grid-template-rows: auto 1fr;
  }
  #inputEditor { height: clamp(220px, 34vh, 520px); }
  .preview-panel { height: clamp(440px, 68vh, 980px); }
  #lineAnalysisList { max-height: clamp(220px, 36vh, 620px); }
}

@media (min-width: 1440px) and (min-aspect-ratio: 2/1) {
  .workspace-shell { max-width: clamp(1440px, 86vw, 2180px); }
  .workspace-grid {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, .9fr) minmax(0, 1fr);
    grid-template-areas: "editor preview analysis";
    grid-template-rows: auto;
  }
  #inputEditor { height: clamp(260px, 55vh, 800px); }
  #lineAnalysisList { max-height: clamp(320px, 68vh, 960px); }
}

.workspace textarea:focus {
  box-shadow: inset 0 0 0 2px #55b988;
}

#draftButtons button[aria-pressed="true"] {
  background-color: #e0f5e8;
  color: #145b3b;
  box-shadow: inset 0 0 0 1px #38815d;
}
.theme-dark #draftButtons button[aria-pressed="true"] {
  background-color: #254936;
  color: #b5ebc9;
  box-shadow: inset 0 0 0 1px #86d4aa;
}

.workspace .action-primary { background-color: #087d48; color: #fff; }
.workspace .action-primary:hover { background-color: #06663b; }
.editor-footer {
  border-top: 1px solid #e1e7e3;
  padding-block: 9px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 12px;
}
.theme-dark .editor-footer { border-color: #343f3a; }
.editor-footer > :is(#editorMore, #wrapStatus, #aiStatus) { flex-basis: 100%; order: 1; }
.workspace .tool-control {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding-inline: 9px;
  border-radius: 9px;
  font-weight: 600;
}
.workspace .tool-control[hidden] { display: none; }
.toolbar-icon {
  width: 15px;
  height: 15px;
  flex: none;
}
.theme-picker { position: relative; display: inline-flex; }
.header-settings { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 6px; }
.theme-segments {
  display: inline-flex;
  padding: 2px;
  border: 1px solid #dfe7e2;
  border-radius: 9999px;
  background: #f1f5f3;
}
.workspace .theme-segments button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 30px;
  border-radius: 9999px;
}
.theme-segments button:hover { background: #e7eeea; }
.theme-segments button[aria-pressed="true"] { background: #d0f1dd; box-shadow: inset 0 0 0 1px #38815d; }
.theme-dark .theme-segments { background: #222927; border-color: #3d4742; }
.theme-dark .theme-segments button:hover { background: #34423a; }
.theme-dark .theme-segments button[aria-pressed="true"] { background: #315f46; box-shadow: inset 0 0 0 1px #a1e4be; }
.theme-picker select { appearance: none; min-height: 32px; padding: 0 30px 0 9px; border-radius: 9px; }
.language-picker select { padding-inline-start: 29px; }
.theme-picker .language-icon { inset-inline-start: 8px; inset-inline-end: auto; }
@media (max-width: 480px) {
  .workspace-header { flex-wrap: nowrap; padding-block: 6px; gap: 6px; }
  .workspace-header > div:first-child { gap: 6px; }
  .workspace-header h1 { font-size: 12px; line-height: 1.2; }
  .workspace-header .brand-logo { width: 26px; height: 26px; }
  .brand-subtitle { display: none; }
  .header-settings { flex: none; flex-wrap: nowrap; gap: 4px; }
  .workspace .workspace-header .theme-segments button { width: 28px; height: 30px; }
  .workspace-header .theme-segments img { width: 13px; height: 13px; }
  .workspace-header .language-picker select { padding-inline: 20px 19px; font-size: 11px; }
  .workspace-header .language-picker .toolbar-icon { width: 12px; height: 12px; inset-inline-end: 4px; }
  .workspace-header .language-picker .language-icon { inset-inline-start: 5px; inset-inline-end: auto; }
}
.theme-picker .toolbar-icon {
  position: absolute;
  inset-inline-end: 9px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}
.tool-checkbox {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 1px solid #758179;
  border-radius: 4px;
}
.tool-checkbox:checked {
  background: #8ee6a9 url("../icons/check.svg") center / 13px no-repeat;
}
.workspace #btnDeleteDraft:disabled { display: none; }
.workspace .draft-delete {
  background-color: #fff1f2;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px #fecdd3;
}
.workspace .draft-delete:hover { background-color: #ffe4e6; }
.theme-dark .workspace .draft-delete {
  background-color: #3c242b;
  box-shadow: inset 0 0 0 1px #70434e;
}
.theme-dark .workspace .draft-delete:hover { background-color: #50303a; }
@media (forced-colors: active) {
  .theme-picker select, .tool-checkbox { appearance: auto; }
  .theme-picker .toolbar-icon { display: none; }
}
.action-primary .toolbar-icon,
.theme-dark .toolbar-icon {
  filter: invert(1);
}
.workspace .tool-icon { min-width: 32px; padding-inline: 0; }
.workspace summary.tool-control::-webkit-details-marker { display: none; }
@media (pointer: coarse) {
  .workspace .theme-segments button { width: 44px; height: 40px; }
  .workspace .tool-control {
    min-height: 44px;
    border-block: 6px solid transparent;
    background-clip: padding-box;
  }
  .workspace .tool-icon { min-width: 44px; }
  .workspace .draft-delete { border-block: 0; }
}

.preview-canvas {
  background: #91add4;
}
.preview-toolbar, .preview-meta {
  background: #fff;
  color: #18181a;
  border-color: #e7e7e9;
}
.preview-meta { color: #656569; }
.preview-options { background: #f1f1f3; color: #525256; border-radius: 11px; }
.theme-dark :is(.preview-toolbar, .preview-meta) {
  background: #1c1c1e;
  color: #f4f4f5;
  border-color: #333336;
}
.theme-dark .preview-meta { color: #b8b8bf; }
.theme-dark .preview-options { background: #2b2b2e; color: #d4d4d8; }
.preview-options .device-btn[aria-pressed="false"]:hover { background: rgb(128 128 128 / 14%); }
.preview-options .device-btn[aria-pressed="true"] {
  background: #06c755;
  color: #072315;
  font-weight: 600;
}
.theme-dark #lineAnalysisList > * + * { border-color: #343f3a; }

@media (prefers-reduced-motion: reduce) {
  .workspace button, .line-bubble-render { transition: none; }
}

/* 自訂捲軸 */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}
.theme-dark ::-webkit-scrollbar-thumb { background: #53655c; }
