.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.btn {
  font: inherit; font-size: 14.5px; font-weight: 500; cursor: pointer; border-radius: 999px;
  padding: 8px 16px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  transition: border-color .15s, background .15s, opacity .15s; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.danger:hover:not(:disabled) { color: #e5484d; border-color: #e5484d; }
select, input, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 12px;
}
select:focus, input:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 22px;
  padding: 32px 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px;
}
.login h1 { margin: 12px 0 0; font-size: 30px; letter-spacing: -.02em; }
.login p { margin: 0 0 8px; }
.login label { font-size: 14px; color: var(--muted); }
.login .btn { margin-top: 6px; padding: 11px; }
.form-msg { min-height: 1.4em; color: #e5484d; font-size: 14px; }

/* ---- layout ---- */
.studio-body { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.st-top {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: var(--bg); flex: none;
}
.st-conv { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.st-conv select { flex: 1; min-width: 0; max-width: 460px; }
.st-tabs { display: none; }
.st-main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(340px, 1fr) 1.3fr; }
.st-main, .ct-main { max-width: none; margin: 0; }
.st-main { padding: 0; width: 100%; }
.pane { min-height: 0; display: flex; flex-direction: column; }
.chat-pane { border-right: 1px solid var(--line); }

/* ---- messages ---- */
.messages { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 14px; }
.welcome { margin: auto 0; text-align: center; padding: 20px 8px; }
.welcome h2 { margin: 0 0 6px; font-size: 26px; letter-spacing: -.02em; }
.ideas { display: grid; gap: 8px; margin-top: 18px; }
.idea {
  font: inherit; font-size: 14.5px; text-align: left; cursor: pointer; padding: 12px 14px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.idea:hover { border-color: var(--accent); }
.msg { max-width: 92%; padding: 10px 14px; border-radius: 16px; font-size: 15.5px; line-height: 1.65; overflow-wrap: anywhere; }
.msg p { margin: 0 0 8px; }
.msg p:last-child { margin-bottom: 0; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9em; background: var(--bg); padding: 1px 5px; border-radius: 6px; }
.msg.user code { background: rgba(255, 255, 255, .2); }
.msg pre { margin: 8px 0; padding: 10px 12px; background: var(--bg); border-radius: 10px; overflow-x: auto; font-size: 13px; }
.msg pre code { background: none; padding: 0; }
.msg .err { color: #e5484d; font-size: 14px; }
.work-chip {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; width: 100%; margin: 8px 0; padding: 10px 14px;
  font: inherit; font-size: 14.5px; font-weight: 700; text-align: left; color: var(--ink); cursor: pointer;
  background: var(--accent-soft); border: 1px solid transparent; border-radius: 12px;
}
.work-chip span { font-weight: 400; color: var(--muted); font-size: 13px; }
.work-chip:hover { border-color: var(--accent); }
.work-chip.writing, .work-chip.muted-chip { cursor: default; font-weight: 500; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.typing { display: flex; gap: 5px; padding: 6px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.composer { display: flex; gap: 8px; align-items: flex-end; padding: 12px 16px 16px; border-top: 1px solid var(--line); background: var(--bg); }
.composer textarea { flex: 1; resize: none; min-height: 44px; max-height: 200px; line-height: 1.5; padding: 10px 14px; border-radius: 16px; }
.composer .btn { height: 44px; }

/* ---- preview ---- */
.pv-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.pv-bar select { max-width: 280px; min-width: 0; }
.pv-status { font-size: 13px; color: #2ecc71; }
.pv-actions { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.pv-frame { position: relative; flex: 1; min-height: 0; background: repeating-conic-gradient(var(--line) 0% 25%, transparent 0% 50%) 50% / 22px 22px; }
.pv-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
.pv-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 18px; background: var(--bg); }

dialog { border: 1px solid var(--line); border-radius: 20px; padding: 0; background: var(--surface); color: var(--ink); width: min(440px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dlg { display: flex; flex-direction: column; gap: 8px; padding: 24px; }
.dlg h3 { margin: 0 0 8px; }
.dlg label { font-size: 14px; color: var(--muted); }
.dlg .muted { font-size: 13px !important; margin: 4px 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

@media (max-width: 900px) {
  .st-top { flex-wrap: wrap; }
  .st-top .brand { font-size: 16px; }
  .st-conv { order: 3; flex-basis: 100%; }
  .st-tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
  .st-tabs button { flex: 1; font: inherit; font-size: 15px; padding: 10px; background: none; border: 0; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; }
  .st-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 700; }
  #tab-badge { color: var(--accent); }
  .st-main { grid-template-columns: 1fr; }
  .pane { display: none; }
  .pane.active { display: flex; }
  .chat-pane { border-right: 0; }
  .pv-bar select { flex: 1; max-width: none; }
  .pv-actions { margin-left: 0; width: 100%; }
  .pv-actions .btn { flex: 1; padding: 8px 10px; }
}

/* ---- 工作室 / 網站內容 切換 ---- */
.st-nav { display: flex; gap: 4px; }
.st-nav a { text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 999px; font-size: 14.5px; }
.st-nav a:hover { color: var(--ink); background: var(--surface); }
.st-nav a[aria-current="page"] { color: var(--ink); background: var(--surface); border: 1px solid var(--line); font-weight: 700; }

/* ---- 網站內容編輯（全版） ---- */
.content-body .st-top { position: sticky; top: 0; z-index: 5; padding-left: 24px; padding-right: 24px; }
.ct-actions { display: flex; gap: 8px; margin-left: auto; }
.ct-actions .btn { text-decoration: none; }
.ct-main { width: 100%; padding: 16px 24px 80px; display: flex; flex-direction: column; gap: 18px; }
.ct-msg { margin: 0; min-height: 1.5em; font-size: 15px; font-weight: 500; }
.ct-msg.ok { color: #2ecc71; }
.ct-msg.err { color: #e5484d; }

/* 上排：基本資料 | 關於我 | 技能 + 聯絡方式 */
.ct-row { display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 18px; align-items: start; }
.ct-stack { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.ct-row > * { min-width: 0; }

.ct-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.ct-card h2 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.ct-card .muted { margin: 0; font-size: 13.5px !important; }
.ct-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; color: var(--muted); }
.ct-card input, .ct-card textarea { width: 100%; font-size: 15px; color: var(--ink); background: var(--bg); }
.ct-card textarea { resize: vertical; line-height: 1.6; }
.ct-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.ct-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ct-grid-proj { grid-template-columns: 76px 1fr; }
.ct-grid-contact { grid-template-columns: 1fr; gap: 6px; flex: 1; min-width: 0; }   /* 窄欄：名稱 / 網址上下兩行 */
.ct-list { display: flex; flex-direction: column; gap: 10px; }
.ct-list:empty::before { content: "（目前沒有）"; color: var(--muted); font-size: 14px; }
.ct-item { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.ct-item > textarea { flex: 1; min-width: 0; }
.ct-tools { display: flex; flex-direction: column; gap: 4px; flex: none; }
.ct-tools button {
  width: 32px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg);
  color: var(--muted); cursor: pointer; font: inherit; font-size: 14px; line-height: 1;
}
.ct-tools button:hover { color: var(--ink); border-color: var(--accent); }
.ct-tools [data-del]:hover { color: #e5484d; border-color: #e5484d; }

/* Projects：卡片格狀，工具列在上 */
.ct-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.ct-cards:empty { display: block; }
.ct-project { flex-direction: column; align-items: stretch; height: 100%; }
.ct-project .ct-tools { flex-direction: row; justify-content: flex-end; }
.ct-proj-fields { flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.ct-proj-fields textarea { min-height: 96px; }

@media (max-width: 1200px) {
  .ct-row { grid-template-columns: 1fr 1fr; }
  .ct-stack { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
}
@media (max-width: 760px) {
  .content-body .st-top { flex-wrap: wrap; padding-left: 16px; padding-right: 16px; }
  .ct-main { padding: 16px 16px 80px; }
  .ct-actions { width: 100%; }
  .ct-actions .btn { flex: 1; text-align: center; }
  .ct-row, .ct-stack { grid-template-columns: 1fr; display: flex; flex-direction: column; }
  .ct-grid { grid-template-columns: 1fr; }
  .ct-grid-proj { grid-template-columns: 70px 1fr; }
  .ct-cards { grid-template-columns: 1fr; }
  .ct-item:not(.ct-project) { flex-direction: column; }
  .ct-item:not(.ct-project) .ct-tools { flex-direction: row; }
  .ct-item > textarea { width: 100%; }
}

/* ---- Shield 登入頁 ---- */
.form-ok { color: #2ecc71; font-size: 14px; margin: 0; }
.login .remember { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.login .remember input { width: auto; }
.st-top a.btn { text-decoration: none; }
