/* ==========================================================================
   閱讀輔助元件：跳到內文、關於選單、對話框、反白選單、popover、燈箱、toast
   ========================================================================== */

/* 跳到內文（鍵盤使用者） */
.skip-link {
  position: absolute; left: 8px; top: -100px; z-index: 100;
  padding: .5em 1em; background: var(--primary); color: var(--on-primary); border-radius: var(--radius);
  text-decoration: none;
}
.skip-link:focus { top: 8px; }

/* 關於選單 */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 55;
  min-width: 11rem; margin: 0; padding: .35rem; list-style: none;
  background: var(--bg); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow);
}
.menu-item {
  display: flex; align-items: center; gap: .4em; width: 100%;
  padding: .5em .8em; border: 0; border-radius: 4px; background: transparent;
  color: var(--text); font: inherit; text-align: left; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-sep { height: 1px; margin: .35rem .5rem; background: var(--rule); }
.icon-sm { width: .9em; height: .9em; color: var(--muted); }

/* 對話框 */
dialog.dialog {
  width: min(600px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem);
  padding: 0; border: 1px solid var(--rule); border-radius: 10px;
  background: var(--bg); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: var(--scrim); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .9rem 1rem .6rem 1.25rem; border-bottom: 1px solid var(--rule); }
.dialog-title { margin: 0; font-family: var(--font-serif); font-size: 1.1rem; font-weight: 600; letter-spacing: .06em; color: var(--head); }
.dialog-body { padding: 1rem 1.25rem; overflow: auto; max-height: calc(100vh - 12rem); }
.dialog-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: .75rem 1.25rem 1rem; }
.dialog-body > .dialog-foot { padding-left: 0; padding-right: 0; padding-bottom: 0; }
.prose { font-size: .95rem; line-height: 1.8; }
.prose h3 { font-size: 1rem; margin: 1.2em 0 .4em; color: var(--head); }
.prose ul, .prose ol { padding-left: 1.5em; margin: .4em 0; }
.prose li { margin: .25em 0; }
.prose p { margin: .4em 0; }

.seg-radio { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; margin-bottom: .75rem; }
.seg-radio label { position: relative; }
.seg-radio input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.seg-radio span { display: block; padding: .4em 1em; color: var(--muted); cursor: pointer; border-left: 1px solid var(--rule); }
.seg-radio label:first-child span { border-left: 0; }
.seg-radio input:checked + span { background: var(--primary); color: var(--on-primary); }
.seg-radio input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: -2px; }
.cite-output { font-family: var(--font-serif); line-height: 1.8; resize: vertical; min-height: 9rem; }

.form-row { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; }
.form-label { font-size: .85rem; color: var(--muted); }
.form-static {
  margin: 0; padding: .5em .7em; background: var(--surface); border-radius: var(--radius);
  font-family: var(--font-serif); font-size: .9rem; line-height: 1.7; max-height: 7em; overflow: auto;
}
.form-error { color: var(--accent); font-size: .9rem; margin: -.3rem 0 .6rem; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
textarea.input { padding: .5em .7em; line-height: 1.6; }

/* 反白選單 */
.selmenu {
  position: absolute; z-index: 70;
  display: flex; align-items: stretch;
  background: var(--bg); border: 1px solid var(--rule); border-radius: 8px; box-shadow: var(--shadow);
  font-family: var(--font-ui); font-size: .875rem;
}
.selmenu[hidden] { display: none; }
.selmenu-item {
  display: inline-flex; align-items: center; gap: .3em;
  padding: .5em .8em; border: 0; border-left: 1px solid var(--rule); background: transparent;
  color: var(--text); font: inherit; cursor: pointer; white-space: nowrap;
}
.selmenu > .selmenu-item:first-child { border-left: 0; }
.selmenu-item:hover, .selmenu-item:focus-visible { background: var(--surface-2); color: var(--primary); outline: none; }
.selmenu-item .icon { width: .9em; height: .9em; }
.selmenu-dict { position: relative; display: flex; }
.selmenu-sub {
  position: absolute; left: 0; top: calc(100% + 4px); z-index: 71;
  min-width: 11rem; margin: 0; padding: .3rem; list-style: none;
  background: var(--bg); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow);
}
.selmenu-sub[hidden] { display: none; }
.selmenu-subitem {
  display: block; width: 100%; padding: .45em .8em; border: 0; border-radius: 4px; background: transparent;
  color: var(--text); font: inherit; text-align: left; cursor: pointer; white-space: nowrap;
}
.selmenu-subitem:hover, .selmenu-subitem:focus-visible { background: var(--surface-2); outline: none; }

/* popover（校勘、異體字、缺字） */
.popover {
  position: absolute; z-index: 65; max-width: min(340px, calc(100vw - 16px));
  padding: .5rem .8rem .7rem; background: var(--bg); border: 1px solid var(--rule); border-radius: 8px; box-shadow: var(--shadow);
  font-family: var(--font-ui); font-size: .875rem; line-height: 1.6; outline: none;
}
.popover[hidden] { display: none; }
.pop-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .25rem; }
.pop-title { font-size: .75rem; letter-spacing: .15em; color: var(--muted); }
.pop-close { width: 28px; height: 28px; min-height: 28px; color: var(--muted); font-size: 1.1rem; line-height: 1; }
.pop-row { display: flex; gap: .6em; padding: .15em 0; }
.pop-label { flex: none; min-width: 4.2em; color: var(--muted); }
.pop-value { font-family: var(--font-body); font-size: 1.02em; overflow-wrap: anywhere; }
.pop-wit { margin-left: .35em; color: var(--muted); font-family: var(--font-ui); font-size: .85em; }
.doc .app:focus-visible, .doc .choice:focus-visible, .doc .gaiji:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; border-radius: 2px; }
.doc .choice { border-bottom: 1px dotted var(--muted); cursor: help; }
.doc .gaiji { cursor: help; }

/* 圖片燈箱 */
dialog.lightbox {
  max-width: 100vw; max-height: 100vh; width: 100vw; height: 100vh;
  margin: 0; padding: 2rem; border: 0; background: rgba(12, 14, 18, .92); color: #fff;
  flex-direction: column; align-items: center; justify-content: center;
}
dialog.lightbox[open] { display: flex; }
dialog.lightbox::backdrop { background: transparent; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 6rem); object-fit: contain; cursor: zoom-out; }
.lightbox-caption { margin-top: .8rem; color: #d8d3c8; font-size: .9rem; min-height: 1.2em; }
.lightbox-close { position: absolute; top: .75rem; right: .75rem; color: #fff; background: rgba(255, 255, 255, .08); }
.lightbox-close:hover { background: rgba(255, 255, 255, .18); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; z-index: 90; transform: translate(-50%, 10px);
  padding: .6em 1.1em; background: var(--text); color: var(--bg); border-radius: 999px; font-size: .9rem;
  box-shadow: var(--shadow); opacity: 0; transition: opacity var(--ease), transform var(--ease);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
/* 重排提示：整篇重排是同步的，提示要在下一次繪製就完全顯示，不能還在淡入 */
.toast.is-instant { transition: none; }

@media (max-width: 767px) {
  dialog.dialog { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: 14px 14px 0 0; border-bottom: 0; }
  .selmenu { font-size: .95rem; }
}
