/* ==========================================================================
   Dark Theme Styles — gutenshop
   統一配色系統（柔和護眼、階層一致，避免刺眼白光與各元件色差）：
   - 主背景: #16181d
   - 次級容器(Header/Sidebar/區塊): #1e2228
   - 第三級背景(輸入框/程式碼/Tag): #252a32
   - 主標題/Header文字: #e2e8f0 (柔和米白，取代刺眼 #f0f6fc)
   - 本文/段落文字: #cbd5e1 (舒適可讀，取代原 #424242)
   - 次級文字/註解/日期: #94a3b8
   - 連結/強調整色: #60a5fa (淡藍，hover: #93c5fd)
   - 邊框/分隔線: #2d333b
   ========================================================================== */

/* 淺色模式背景微調（柔和護眼灰白，取代高刺眼純白 #fff） */
body.theme-light,
body:not(.theme-dark) {
  background-color: #f8f9fa;
}

/* 全域背景與文字 */
body.theme-dark {
  background-color: #16181d;
  color: #cbd5e1;
}

/* 標題系統：統一柔和米白 (#e2e8f0)，告別刺眼高光 */
body.theme-dark h1,
body.theme-dark h2,
body.theme-dark h3,
body.theme-dark h4,
body.theme-dark h5,
body.theme-dark h6,
body.theme-dark .site-title a {
  color: #e2e8f0;
}

/* 本文與段落文字亮度：舒適耐讀 (#cbd5e1) */
body.theme-dark p,
body.theme-dark .entry-content p,
body.theme-dark article p,
body.theme-dark #page p,
body.theme-dark .site-content p,
body.theme-dark li,
body.theme-dark .entry-content li {
  color: #cbd5e1 !important;
}

/* 避免圖片 (figure, img) 與文字太近造成壓迫感 */
figure,
.wp-block-image,
.entry-content figure,
.entry-content .wp-block-image {
  margin-top: 2em !important;
  margin-bottom: 2em !important;
}

figure figcaption,
.wp-block-image figcaption {
  margin-top: 0.6em;
  font-size: 0.9em;
  color: #94a3b8;
  text-align: center;
}

/* 連結基本配色 */
body.theme-dark a {
  color: #60a5fa;
}

body.theme-dark a:hover,
body.theme-dark a:focus {
  color: #93c5fd;
}

/* 文章列表與各頁面標題連結：預設同為標題色 #e2e8f0，懸停 hover 時為重點藍 #60a5fa */
body.theme-dark .blog main article h2 a,
body.theme-dark .search-results main article h2 a,
body.theme-dark .archive main article h2 a,
body.theme-dark .entry-title a,
body.theme-dark article h2 a,
body.theme-dark article h1 a,
body.theme-dark article h3 a,
body.theme-dark article h4 a,
body.theme-dark .related-posts article h4 a,
body.theme-dark .site-main article .entry-header a {
  color: #e2e8f0 !important;
}

body.theme-dark .blog main article h2 a:hover,
body.theme-dark .search-results main article h2 a:hover,
body.theme-dark .archive main article h2 a:hover,
body.theme-dark .entry-title a:hover,
body.theme-dark article h2 a:hover,
body.theme-dark article h1 a:hover,
body.theme-dark article h3 a:hover,
body.theme-dark article h4 a:hover,
body.theme-dark .related-posts article h4 a:hover,
body.theme-dark .site-main article .entry-header a:hover {
  color: #60a5fa !important;
}

/* 文章日期與元資訊 */
body.theme-dark .entry-meta,
body.theme-dark .entry-meta * {
  color: #94a3b8 !important;
}

/* 頂部導覽列 (Header) */
body.theme-dark .navigation-wrapper,
body.theme-dark .site-header {
  background-color: #1e2228;
  color: #cbd5e1;
  border-bottom: 1px solid #2d333b;
}

/* 主選單連結：平常同為柔白 #e2e8f0，懸停重點藍 #60a5fa */
body.theme-dark #primary-menu > li > a {
  color: #e2e8f0;
}

body.theme-dark #primary-menu > li > a:hover,
body.theme-dark #primary-menu > li > a:focus {
  color: #60a5fa;
}

/* 下拉選單 */
body.theme-dark #primary-menu ul {
  background-color: #1e2228;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
  border: 1px solid #2d333b;
}

body.theme-dark #primary-menu ul li a {
  color: #cbd5e1;
}

body.theme-dark #primary-menu ul li a:hover {
  background-color: #252a32;
  color: #60a5fa;
}

/* 行動端側邊選單 */
body.theme-dark #iot-menu-left {
  background-color: #1e2228;
}

body.theme-dark #iot-menu-left a {
  color: #e2e8f0;
}

/* 頁面主體內容區 */
body.theme-dark #page,
body.theme-dark .site-content {
  background-color: #16181d;
}

/* 文章卡片 / 內容容器 */
body.theme-dark .entry-content,
body.theme-dark article.post,
body.theme-dark article.page,
body.theme-dark .hentry {
  background-color: #16181d;
  border-color: #2d333b;
}

/* 引言區塊 (Blockquote) */
body.theme-dark blockquote,
body.theme-dark .wp-block-quote {
  border-left: 4px solid #60a5fa !important;
  color: #94a3b8 !important;
  background-color: #1e2228;
  padding: 0.8em 1.2em;
  margin: 1.5em 0;
}

/* 側邊欄 & Widget */
body.theme-dark #secondary,
body.theme-dark .sidebar-inner,
body.theme-dark .widget {
  background-color: #1e2228 !important;
  color: #cbd5e1;
  border-color: #2d333b;
}

body.theme-dark .sidebar-inner a {
  color: #cbd5e1;
}

body.theme-dark .sidebar-inner a:hover {
  color: #60a5fa;
}

body.theme-dark .widget-title {
  color: #e2e8f0;
  border-color: #2d333b;
}

/* 側邊欄列表項（如近期文章、分類）深色分隔線 */
body.theme-dark #secondary ul li {
  border-bottom: 1px solid #2d333b !important;
}

body.theme-dark #secondary ul li:last-child {
  border-bottom: none !important;
}

/* 標籤雲 (Tag Cloud) 深色模式樣式 */
body.theme-dark .tagcloud,
body.theme-dark #secondary .tagcloud {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

body.theme-dark .tagcloud a,
body.theme-dark #secondary .tagcloud a {
  background-color: #252a32 !important;
  border-color: #2d333b !important;
  color: #cbd5e1 !important;
  max-width: 100%;
  box-sizing: border-box;
  word-break: break-word;
  white-space: normal;
}

body.theme-dark .tagcloud a:hover,
body.theme-dark #secondary .tagcloud a:hover {
  background-color: #2d333b !important;
  border-color: #60a5fa !important;
  color: #60a5fa !important;
}

/* 輸入框與表單元件 */
body.theme-dark input[type="text"],
body.theme-dark input[type="email"],
body.theme-dark input[type="password"],
body.theme-dark input[type="search"],
body.theme-dark input[type="url"],
body.theme-dark select,
body.theme-dark textarea {
  background-color: #252a32;
  color: #e2e8f0;
  border-color: #2d333b;
}

/* 程式碼區塊與行內代碼 */
body.theme-dark pre,
body.theme-dark .wp-block-preformatted {
  background-color: #1a1e24 !important;
  color: #e2e8f0 !important;
  border: 1px solid #2d333b;
  border-radius: 6px;
}

body.theme-dark code,
body.theme-dark kbd,
body.theme-dark tt,
body.theme-dark var {
  background-color: #252a32;
  color: #e2e8f0;
}

body.theme-dark pre code {
  background-color: transparent !important;
  color: inherit !important;
}

/* 頁尾 */
body.theme-dark .footer-container,
body.theme-dark .site-footer {
  background-color: #121417;
  color: #94a3b8;
  border-top: 1px solid #2d333b;
}

body.theme-dark .site-footer a {
  color: #94a3b8;
}

body.theme-dark .site-footer a:hover {
  color: #e2e8f0;
}

/* ============================================================
   深色模式切換連結 — 作為 #primary-menu 最後一個 <li> 插入
   ============================================================ */

/* 桌面版導覽列項目對齊（與一般選單連結維持一致的行高與 baseline 垂直置中） */
#primary-menu > li.menu-item-theme-switch,
.main-navigation li.menu-item-theme-switch {
  display: inline-flex;
  align-items: center;
  float: left;
  position: relative;
  height: 38px; /* 對標選單 line-height: 38px，確保整行平齊 */
  margin-left: 6px;
}

/* 弱化極簡版切換按鈕：背景融入導覽列/body，去除突兀邊框與陰影 */
.theme-switch-link {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50% !important;
  text-decoration: none !important;
  cursor: pointer;
  transition: all 0.2s ease;
  box-sizing: border-box;
  padding: 0 !important;
  
  /* 淺色模式：透明/極淡底色融入 Header，搭配自然柔和深灰圖示 (#64748b)，不搶眼 */
  background-color: transparent !important;
  border: 1px solid rgba(0, 0, 0, 0.08) !important;
  color: #64748b !important;
  box-shadow: none !important;
}

.theme-switch-link:hover,
.theme-switch-link:focus {
  /* 懸停時僅微幅加深，不突兀跳色 */
  background-color: rgba(0, 0, 0, 0.05) !important;
  border-color: rgba(0, 0, 0, 0.15) !important;
  color: #334155 !important;
  transform: none !important;
  outline: none;
}

/* 深色模式：底色融入 Header (#1e2228)，搭配柔和靜謐米灰圖示 (#94a3b8) */
body.theme-dark .theme-switch-link {
  background-color: transparent !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
  color: #94a3b8 !important;
  box-shadow: none !important;
}

body.theme-dark .theme-switch-link:hover,
body.theme-dark .theme-switch-link:focus {
  background-color: rgba(255, 255, 255, 0.06) !important;
  border-color: rgba(255, 255, 255, 0.2) !important;
  color: #cbd5e1 !important;
  transform: none !important;
}

.theme-switch-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  line-height: 1;
}

.theme-switch-icon svg {
  width: 17px;
  height: 17px;
  display: block;
}

/* 實心圖示填滿樣式 */
.theme-switch-icon svg.icon-moon,
.theme-switch-icon svg.icon-sun {
  fill: currentColor;
}

/* 淺色模式顯示實心月亮，深色模式顯示太陽 */
.theme-switch-icon .icon-sun  { display: none; }
.theme-switch-icon .icon-moon { display: inline-block; }

body.theme-dark .theme-switch-icon .icon-sun  { display: inline-block; }
body.theme-dark .theme-switch-icon .icon-moon { display: none; }
