@import url("https://font.emtech.cc/css/GenKiGothicTW");

:root {
  --primary-bg: #efefef;
  --primary-text: #353d49;
  --secondary-text: #252627;
  --caption-text: #565c5f;
  --link-color: #5c8273;
  --borders: #bbb;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

a {
  color: var(--link-color);
}

body {
  font-family: tauhu-oo, sans-serif;
  background: var(--primary-bg);
  min-height: 100vh;
  padding: 20px;
  color: var(--primary-text);
}

.container {
  max-width: 840px;
  margin: 0 auto;
}

h1 {
  color: var(--secondary-text);
  text-align: center;
  margin-bottom: 30px;
  margin-top: 30px;
  font-size: 2.5em;
  font-weight: normal;
}

h1,
h2,
h3 {
  font-family: GenKiGothicTW;
  font-weight: bold;
}

.setup-area {
  background: transparent;
  padding: 20px 0;
  margin-bottom: 30px;
}

.setup-area h2 {
  color: var(--secondary-text);
  margin-bottom: 20px;
  margin-top: 30px;
  font-weight: 500;
  font-size: 1.2em;
}

.setup-area h3 {
  margin-top: 15px;
  margin-bottom: 5px;
  color: var(--caption-text);
  font-size: 16px;
  font-weight: normal;
}

.setup-area p {
  color: var(--caption-text);
  margin-bottom: 10px;
  font-size: 14px;
}

textarea {
  width: 100%;
  min-height: 100px;
  padding: 15px;
  border: 1px solid var(--borders);
  border-radius: 3px;
  font-size: 16px;
  font-family: inherit;
  resize: vertical;
  background: white;
  color: var(--primary-text);
}

textarea:focus {
  outline: none;
  border-color: var(--link-color);
}

.button-group {
  margin-top: 15px;
  display: flex;
  gap: 10px;
}

button {
  padding: 12px 24px;
  font-size: 16px;
  border: 1px solid var(--borders);
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: normal;
  background: white;
  color: var(--primary-text);
}

button:hover {
  background: var(--link-color);
  color: white;
  border-color: var(--link-color);
}

.start-btn {
  background: var(--link-color);
  margin-top: 20px;
  color: white;
  border-color: var(--link-color);
}

.start-btn:hover {
  opacity: 0.9;
}

.stats-bar {
  background: var(--primary-bg);
  padding: 15px 0;
  margin-bottom: 20px;
  display: none;
  border-top: 1px solid var(--borders);
  border-bottom: 1px solid var(--borders);
  position: sticky;
  top: 0;
  z-index: 100;
}

.stats-bar.active {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  gap: 15px;
}

/* 聚焦輸入框時瀏覽器自動捲動，避免目前行被固定的統計列遮住 */
html:has(.stats-bar.active) {
  scroll-padding-top: 90px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-label {
  padding: 5px 12px;
  border-radius: 3px;
  color: var(--caption-text);
  font-weight: normal;
  font-size: 14px;
  background: transparent;
  border: 1px solid var(--borders);
}

.stat-value {
  font-size: 24px;
  font-weight: normal;
  min-width: 60px;
  color: var(--secondary-text);
}

.practice-area {
  background: transparent;
  padding: 30px 0;
  display: none;
}

.practice-area.active {
  display: block;
}

.info-section {
  margin-bottom: 20px;
}

hr {
  margin: 24px;
}

.info-text {
  padding: 15px;
  /* border: 1px solid var(--borders); */
  border-radius: 3px;
  text-align: left;
  font-size: 16px;
  color: var(--caption-text);
}

.prep-input {
  width: 100%;
  padding: 15px;
  border: 1px solid var(--borders);
  border-radius: 3px;
  font-size: 18px;
  font-family: inherit;
  background: white;
  color: var(--primary-text);
}

.prep-input:focus {
  outline: none;
  border-color: var(--link-color);
}

.typing-section {
  margin-bottom: 20px;
}

.sentence-audio-controls {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 8px;
}

.sentence-audio-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid #5c8273;
  border-radius: 999px;
  background: white;
  color: #5c8273;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sentence-audio-btn::before {
  content: "";
  display: block;
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 11px solid currentColor;
  margin-left: 2px;
}

.sentence-audio-btn.is-playing::before {
  width: 10px;
  height: 12px;
  border: 0;
  margin-left: 0;
  background: linear-gradient(
    to right,
    currentColor 0 3px,
    transparent 3px 7px,
    currentColor 7px 10px
  );
}

.sentence-audio-btn:hover {
  background: #edf3f0;
  color: #5c8273;
  border-color: #5c8273;
}

.sentence-dic-btn {
  width: 32px;
  height: 32px;
  border: 1px solid #5c8273;
  border-radius: 999px;
  background: white;
  color: #5c8273;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.sentence-dic-btn::before {
  content: "📖";
  font-size: 14px;
  line-height: 1;
}

.sentence-dic-btn:hover {
  background: #edf3f0;
  color: #5c8273;
  border-color: #5c8273;
}

.reference-text {
  /* background: white; */
  padding: 15px;
  /* border: 1px solid var(--borders); */
  border-radius: 3px;
  /* margin-bottom: 15px; */
  font-size: 22px;
  line-height: 1.5;
  min-height: 60px;
  /* 避頭點處理 */
  text-indent: 0;
  line-break: auto;
  /* 使用 keep-all 來保持中文詞組不換行，有助於避頭點 */
  word-break: keep-all;
  /* 允許在合適的地方換行，但會尊重避頭點規則 */
  overflow-wrap: anywhere;
}

ruby {
  display: inline-flex;
  flex-direction: column-reverse;
  text-align: center;
  margin: 3px 2px;
  vertical-align: bottom;
}

rt {
  font-size: 15px;
  color: var(--caption-text);
  text-align: center;
  line-height: 1;
  margin-bottom: 0;
  padding-bottom: 0;
}

rb {
  text-align: center;
  margin-top: 1px;
}

.char-mark {
  display: inline-flex;
  flex-direction: column-reverse;
  text-align: center;
  vertical-align: bottom;
}

/* 避頭點處理：防止標點符號出現在行首 */
/* 使用 ::before 偽元素在標點符號前插入不可見的詞連接符 */
.char-mark.punctuation-mark::before {
  content: "\2060"; /* Word Joiner (U+2060) */
  font-size: 0;
  line-height: 0;
  display: inline;
}

/* 為 ruby 元素中的標點符號也添加避頭點處理 */
ruby.char-mark.punctuation-mark::before {
  content: "\2060"; /* Word Joiner (U+2060) */
  font-size: 0;
  line-height: 0;
  display: inline;
}

/* 確保標點符號和前面的字符不會分開 */
.char-mark.punctuation-mark {
  display: inline;
}

ruby.char-mark.punctuation-mark {
  display: inline-flex;
}

/* 避頭點群組：將標點符號和前面的字符包在一起，確保不會分開 */
.kinsoku-group {
  white-space: nowrap;
  display: inline-block;
  /* 確保不會影響垂直對齊 */
  vertical-align: baseline;
}

/* 避頭點輔助元素：在標點符號前添加不可見的詞連接符（Word Joiner, U+2060） */
/* 這個元素不會影響打字判定，因為打字判定只檢查 .char-mark 元素 */
.kinsoku-space {
  display: inline;
  width: 0;
  height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  pointer-events: none;
  user-select: none;
  /* 使用詞連接符（U+2060）來防止換行，比零寬度空格更可靠 */
  font-size: 0;
  line-height: 0;
  overflow: hidden;
  /* 確保不影響布局 */
  vertical-align: baseline;
  /* 確保內容不可見 */
  color: transparent;
  background: transparent;
  /* 確保不會斷行 */
  white-space: nowrap;
}

/* 關鍵：確保標點符號和前面的字符作為一個整體不換行 */
/* 使用通用兄弟選擇器來選擇標點符號前的字符 */
.reference-text
  .char-mark:not(.punctuation-mark)
  + .kinsoku-space
  + .char-mark.punctuation-mark,
.reference-text
  .char-mark:not(.punctuation-mark)
  + .char-mark.punctuation-mark {
  /* 將標點符號和前面的字符綁定在一起 */
  display: inline;
  white-space: nowrap;
}

/* 對於 ruby 元素也做同樣處理 */
.reference-text
  ruby.char-mark:not(.punctuation-mark)
  + .kinsoku-space
  + ruby.char-mark.punctuation-mark,
.reference-text
  ruby.char-mark:not(.punctuation-mark)
  + ruby.char-mark.punctuation-mark {
  display: inline-flex;
  white-space: nowrap;
}

.char-mark.correct {
  color: var(--link-color);
  font-weight: normal;
}

.char-mark.correct rt {
  color: var(--link-color);
}

.char-mark.incorrect {
  color: #c44;
  background: #fee;
  font-weight: normal;
}

.char-mark.incorrect rt {
  color: #c44;
}

.input-area {
  position: relative;
}

.typing-input {
  width: 100%;
  padding: 15px;
  border: 1px solid var(--borders);
  border-radius: 3px;
  font-size: 18px;
  font-family: inherit;
  line-height: 1.8;
  background: white;
  resize: none;
  min-height: 50px;
  max-height: none;
  word-wrap: break-word;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  overflow-y: hidden;
  color: var(--primary-text);
}

.typing-input:focus {
  outline: none;
  border-color: var(--link-color);
}

.typing-input:disabled {
  background: #f5f5f5;
  color: var(--caption-text);
  cursor: not-allowed;
  opacity: 0.7;
}

.typing-input.error {
  border-color: #c44;
}

.typing-input.correct {
  border-color: var(--link-color);
}

.finish-buttons-container {
  margin-top: 20px;
  display: flex;
  gap: 10px;
}

.finish-btn {
  background: var(--link-color);
  color: white;
  border-color: var(--link-color);
  flex: 1;
}

.finish-btn:hover {
  opacity: 0.9;
}

.result-section {
  background: white;
  padding: 30px;
  border-radius: 3px;
  margin-top: 20px;
  border: 1px solid var(--borders);
  text-align: center;
}

.result-section h2 {
  color: var(--secondary-text);
  margin-bottom: 20px;
  font-weight: normal;
  font-size: 1.5em;
}

.result-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.result-modal.active {
  display: flex;
}

.result-content {
  background: white;
  padding: 40px;
  border-radius: 3px;
  max-width: 500px;
  width: 90%;
  text-align: center;
  border: 1px solid var(--borders);
}

.result-content h2 {
  color: var(--secondary-text);
  margin-bottom: 20px;
  font-weight: normal;
  font-size: 1.5em;
}

.result-stats {
  text-align: center;
  margin-bottom: 30px;
}

.speed-main {
  font-size: 72px;
  font-weight: bold;
  color: var(--link-color);
  margin-bottom: 10px;
  line-height: 1;
}

.speed-unit {
  font-size: 24px;
  font-weight: normal;
  color: var(--caption-text);
}

.stats-details {
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid var(--borders);
}

.detail-row {
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--primary-text);
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-label {
  color: var(--caption-text);
}

.detail-value {
  font-weight: normal;
  color: var(--secondary-text);
}

.detail-divider {
  color: var(--borders);
  margin: 0 4px;
}

.seed-info {
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid var(--borders);
  font-size: 13px;
  color: var(--caption-text);
  text-align: center;
}

.seed-label {
  display: inline-block;
  margin-right: 8px;
}

.seed-code {
  display: inline-block;
  background: var(--primary-bg);
  padding: 4px 12px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 14px;
  color: var(--secondary-text);
  border: 1px solid var(--borders);
  margin: 0 8px;
}

.seed-hint {
  display: inline-block;
  font-size: 12px;
  color: var(--caption-text);
}

.close-btn {
  background: var(--link-color);
  color: white;
  border-color: var(--link-color);
}

.close-btn:hover {
  opacity: 0.9;
}

.text-source-selection {
  margin-bottom: 20px;
}

.source-options {
  display: flex;
  position: relative;
  background: white;
  border: 1px solid var(--borders);
  border-radius: 3px;
  padding: 4px;
  gap: 0;
}

.source-option {
  flex: 1;
  position: relative;
  z-index: 2;
}

.source-option input[type="radio"] {
  display: none;
}

.source-option label {
  cursor: pointer;
  padding: 12px 20px;
  display: block;
  text-align: center;
  transition: color 0.3s ease;
  font-size: 16px;
  color: var(--primary-text);
  position: relative;
  z-index: 3;
}

.source-option input[type="radio"]:checked + label {
  color: white;
  font-weight: normal;
}

/* 滑動滑塊 */
.source-options::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(33.333% - 4px);
  height: calc(100% - 8px);
  background: var(--link-color);
  border-radius: 3px;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1;
}

/* 當第二個選項被選中時，滑塊移動到中間 */
.source-options.switcher-right::before {
  left: calc(33.333%);
}

/* 當第三個選項被選中時，滑塊移動到最右邊 */
.source-options.switcher-far-right::before {
  left: calc(66.666%);
}

.text-type-selection {
  margin-bottom: 20px;
}

.text-type-options {
  display: flex;
  position: relative;
  background: white;
  border: 1px solid var(--borders);
  border-radius: 3px;
  padding: 4px;
  gap: 0;
}

.text-type-option {
  flex: 1;
  position: relative;
  z-index: 2;
}

.text-type-option input[type="radio"] {
  display: none;
}

.text-type-option label {
  cursor: pointer;
  padding: 12px 20px;
  display: block;
  text-align: center;
  transition: color 0.3s ease;
  font-size: 16px;
  color: var(--primary-text);
  position: relative;
  z-index: 3;
}

.text-type-option input[type="radio"]:checked + label {
  color: white;
  font-weight: normal;
}

/* 滑動滑塊 */
.text-type-options::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  background: var(--link-color);
  border-radius: 3px;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1;
}

/* 當第二個選項被選中時，滑塊移動到右邊 */
.text-type-options.switcher-right::before {
  left: calc(50%);
}

.random-settings {
  margin-bottom: 20px;
}

.custom-settings {
  margin-bottom: 20px;
}

.article-selection {
  margin-bottom: 20px;
}

.article-intro-text {
  margin-bottom: 20px;
  padding: 15px;
  background: var(--primary-bg);
  border: 1px solid var(--borders);
  border-radius: 3px;
  font-size: 14px;
  color: var(--caption-text);
  line-height: 1.6;
}

.article-intro-text a {
  color: var(--link-color);
  text-decoration: none;
  transition: color 0.2s;
}

.article-intro-text a:hover {
  text-decoration: underline;
}

.article-search-section {
  margin-bottom: 20px;
}

.article-search-input {
  width: 100%;
  padding: 12px 15px;
  border: 1px solid var(--borders);
  border-radius: 3px;
  font-size: 16px;
  font-family: inherit;
  background: white;
  color: var(--primary-text);
  margin-bottom: 10px;
}

.article-search-input:focus {
  outline: none;
  border-color: var(--link-color);
}

.article-filter-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 15px;
  background: var(--primary-bg);
  border: 1px solid var(--borders);
  border-radius: 3px;
  font-size: 14px;
  color: var(--caption-text);
}

.article-filter-info #filterText {
  flex: 1;
}

.clear-filter-btn {
  padding: 6px 12px;
  font-size: 13px;
  border: 1px solid var(--borders);
  border-radius: 3px;
  background: white;
  color: var(--primary-text);
  cursor: pointer;
  transition: all 0.2s;
}

.clear-filter-btn:hover {
  background: var(--link-color);
  color: white;
  border-color: var(--link-color);
}

.no-articles {
  text-align: center;
  padding: 40px 20px;
  color: var(--caption-text);
  font-size: 16px;
}

.article-list {
  display: grid;
  gap: 15px;
  margin-top: 15px;
}

.article-card {
  background: white;
  border: 1px solid var(--borders);
  border-radius: 3px;
  padding: 20px;
  transition: all 0.2s;
}

.article-card:hover {
  border-color: var(--link-color);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.article-header {
  margin-bottom: 12px;
}

.article-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.article-title {
  font-size: 18px;
  font-weight: bold;
  color: var(--secondary-text);
  margin: 0;
  font-family: GenKiGothicTW;
}

.article-new-badge {
  display: inline-block;
  padding: 4px 10px;
  background: #769983;
  color: white;
  border-radius: 12px;
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.article-meta {
  font-size: 14px;
  color: var(--caption-text);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.article-source {
  color: var(--caption-text);
}

.article-source a {
  color: var(--link-color);
  text-decoration: none;
  transition: color 0.2s;
}

.article-source a:hover {
  text-decoration: underline;
}

.article-syllable-count {
  color: var(--caption-text);
  font-size: 13px;
}

.article-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.article-tag {
  display: inline-block;
  padding: 4px 12px;
  background: var(--primary-bg);
  border: 1px solid var(--borders);
  border-radius: 12px;
  font-size: 12px;
  color: var(--caption-text);
}

.clickable-tag {
  cursor: pointer;
  transition: all 0.2s;
}

.clickable-tag:hover {
  background: var(--link-color);
  color: white;
  border-color: var(--link-color);
}

.article-preview {
  color: var(--primary-text);
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 15px;
  padding: 12px;
  background: var(--primary-bg);
  border-radius: 3px;
}

.preview-hanji {
  margin-bottom: 8px;
  color: var(--primary-text);
}

.preview-tailo {
  color: var(--caption-text);
  font-size: 14px;
}

.article-select-btn {
  width: auto;
  padding: 12px 20px;
  background: var(--link-color);
  color: white;
  border: 1px solid var(--link-color);
  border-radius: 3px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.article-select-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.mode-selection {
  margin-top: 0;
}

.mode-options {
  display: flex;
  position: relative;
  background: white;
  border: 1px solid var(--borders);
  border-radius: 3px;
  padding: 4px;
  gap: 0;
}

.mode-option {
  flex: 1;
  position: relative;
  z-index: 2;
}

.mode-option input[type="radio"] {
  display: none;
}

.mode-option label {
  cursor: pointer;
  padding: 12px 20px;
  display: block;
  text-align: center;
  transition: color 0.3s ease;
  font-size: 16px;
  color: var(--primary-text);
  position: relative;
  z-index: 3;
  line-height: 1.4;
}

.mode-option label small {
  display: block;
  font-size: 13px;
  margin-top: 4px;
  opacity: 0.9;
}

.mode-option input[type="radio"]:checked + label {
  color: white;
  font-weight: normal;
}

/* 滑動滑塊 */
.mode-options::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  background: var(--link-color);
  border-radius: 3px;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1;
}

/* 當第二個選項被選中時，滑塊移動到右邊 */
.mode-options.switcher-right::before {
  left: calc(50%);
}

.romanization-selection {
  margin-top: 0;
}

.romanization-options {
  display: flex;
  position: relative;
  background: white;
  border: 1px solid var(--borders);
  border-radius: 3px;
  padding: 4px;
  gap: 0;
}

.romanization-option {
  flex: 1;
  position: relative;
  z-index: 2;
}

.romanization-option input[type="radio"] {
  display: none;
}

.romanization-option label {
  cursor: pointer;
  padding: 12px 20px;
  display: block;
  text-align: center;
  transition: color 0.3s ease;
  font-size: 16px;
  color: var(--primary-text);
  position: relative;
  z-index: 3;
}

.romanization-option input[type="radio"]:checked + label {
  color: white;
  font-weight: normal;
}

/* 滑動滑塊 */
.romanization-options::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  background: var(--link-color);
  border-radius: 3px;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1;
}

/* 當第二個選項被選中時，滑塊移動到右邊 */
.romanization-options.switcher-right::before {
  left: calc(50%);
}

/* 羅馬字輔助（三選項） */
.roman-assist-selection {
  margin-top: 0;
}

.roman-assist-options {
  display: flex;
  position: relative;
  background: white;
  border: 1px solid var(--borders);
  border-radius: 3px;
  padding: 4px;
  gap: 0;
}

.roman-assist-option {
  flex: 1;
  position: relative;
  z-index: 2;
}

.roman-assist-option input[type="radio"] {
  display: none;
}

.roman-assist-option label {
  cursor: pointer;
  padding: 12px 20px;
  display: block;
  text-align: center;
  transition: color 0.3s ease;
  font-size: 16px;
  color: var(--primary-text);
  position: relative;
  z-index: 3;
}

.roman-assist-option input[type="radio"]:checked + label {
  color: white;
  font-weight: normal;
}

.roman-assist-options::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(33.333% - 4px);
  height: calc(100% - 8px);
  background: var(--link-color);
  border-radius: 3px;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1;
}

.roman-assist-options.switcher-right::before {
  left: calc(33.333%);
}

.roman-assist-options.switcher-far-right::before {
  left: calc(66.666%);
}

/* 羅馬字聲調輔助文字 */
.tone-assist {
  display: block;
  font-size: 12px;
  color: var(--caption-text);
  opacity: 0.65;
  line-height: 1.15;
  font-weight: normal;
  letter-spacing: 0.02em;
  pointer-events: none;
  user-select: none;
  margin-bottom: 3px;
}

rt.has-tone-assist {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.char-mark.correct .tone-assist,
.char-mark.correct rt .tone-assist {
  color: var(--link-color);
  opacity: 0.55;
}

.char-mark.incorrect .tone-assist,
.char-mark.incorrect rt .tone-assist {
  color: #c44;
  opacity: 0.55;
}

/* 羅馬字轉換工具 */
.romanization-conversion {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.conversion-btn {
  flex: 1;
  padding: 12px 20px;
  border: 1px solid var(--borders);
  border-radius: 3px;
  background: white;
  color: var(--primary-text);
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.conversion-btn:hover {
  border-color: var(--link-color);
  background: var(--link-color);
  color: white;
}

.conversion-btn:active {
  transform: scale(0.98);
}

/* RWD 响应式设计 */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }

  .container {
    max-width: 100%;
    padding: 15px;
    margin: 10px auto;
  }

  .site-header h1 {
    font-size: 1.05rem;
  }

  .page-nav {
    gap: 14px;
  }

  .page-nav a {
    font-size: 15px;
  }

  h2 {
    font-size: 18px;
    margin-bottom: 15px;
  }

  h3 {
    font-size: 16px;
  }

  .setup-area textarea,
  .prep-input,
  .typing-input {
    font-size: 16px;
    padding: 12px;
  }

  .reference-text {
    font-size: 21px;
    padding: 12px;
    line-height: 1.4;
  }

  ruby {
    margin: 3px 1px;
  }

  rt {
    font-size: 13px;
  }

  .tone-assist {
    font-size: 11px;
  }

  .stats-bar {
    padding: 6px 0;
  }

  .stats-bar.active {
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 4px;
  }

  html:has(.stats-bar.active) {
    scroll-padding-top: 60px;
  }

  .stat-item {
    flex: 1 1 0;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    padding: 0 2px;
    white-space: nowrap;
    text-align: center;
    gap: 1px;
  }

  .stat-label {
    padding: 0;
    border: 0;
    font-size: 11px;
    line-height: 1.2;
  }

  .stat-value {
    min-width: 0;
    font-size: 18px;
    line-height: 1.1;
  }

  .sample-texts {
    margin-bottom: 15px;
  }

  .sample-texts > div {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 8px;
  }

  .sample-btn {
    width: 100%;
    padding: 12px;
  }

  #randomCount {
    width: 100%;
  }

  .result-content {
    width: 95%;
    padding: 20px;
    max-height: 90vh;
    overflow-y: auto;
  }

  .speed-main {
    font-size: 56px;
  }

  .speed-unit {
    font-size: 20px;
  }

  .detail-row {
    font-size: 13px;
  }

  .info-text {
    font-size: 14px;
  }

  .info-text small {
    font-size: 12px;
  }

  .finish-buttons-container {
    flex-direction: column;
  }

  .finish-btn {
    font-size: 16px;
    padding: 12px;
    width: 100%;
  }
}

@media (max-width: 480px) {
  .site-header {
    gap: 12px;
  }

  .site-header h1 {
    font-size: 1rem;
  }

  .setup-area {
    padding-top: 5px;
  }

  .speed-main {
    font-size: 48px;
  }

  .speed-unit {
    font-size: 18px;
  }

  .detail-row {
    font-size: 12px;
  }

  .reference-text {
    font-size: 19px;
    padding: 10px;
  }

  .typing-input {
    font-size: 14px;
    padding: 10px;
  }

  .stat-item {
    flex: 1 1 0;
    padding: 0 1px;
  }

  .stat-label {
    font-size: 11px;
  }

  .stat-value {
    font-size: 17px;
  }

  rt {
    font-size: 13px;
  }
}

/* Footer 樣式 */
.site-footer {
  margin-top: 60px;
  padding: 30px 20px;
  text-align: center;
}

.footer-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.footer-link {
  font-size: 14px;
}

.footer-link a {
  /* color: var(--caption-text); */
  margin: 0px 5px;
  text-decoration: none;
  transition: 0.2s;
}

.footer-link a:hover {
  color: var(--link-color);
}

@media (max-width: 768px) {
  .site-footer {
    margin-top: 40px;
    padding: 20px 10px;
  }

  .footer-link {
    font-size: 13px;
  }

  .article-card {
    padding: 15px;
  }

  .article-title {
    font-size: 16px;
  }

  .article-preview {
    font-size: 14px;
    padding: 10px;
  }
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 0 8px;
  padding-bottom: 12px;
}

.site-header h1 {
  margin: 0;
  padding: 0;
  text-align: left;
  font-size: 1.25rem;
  font-weight: bold;
  line-height: 1.3;
  color: var(--secondary-text);
}

.page-nav {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 20px;
}

.page-nav a {
  text-decoration: none;
  padding: 4px 2px;
  border-bottom: 2px solid transparent;
  color: var(--caption-text);
  font-family: GenKiGothicTW;
  font-weight: bold;
  font-size: 16px;
  line-height: 1.3;
}

.page-nav a:hover {
  color: var(--link-color);
}

.page-nav a.is-current {
  color: var(--link-color);
  border-bottom-color: var(--link-color);
}

.page-nav a:focus-visible {
  outline: 2px solid var(--link-color);
  outline-offset: 2px;
}

.practice-page .practice-area {
  padding: 8px 0 24px;
}

.key-panel {
  padding-top: 20px;
  border-top: 1px solid var(--borders);
}

.key-panel-settings {
  margin-bottom: 12px;
}

.key-panel-settings summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding: 0;
  cursor: pointer;
  list-style: none;
  font-size: 14px;
  line-height: 1.6;
}

.key-panel-settings summary::-webkit-details-marker {
  display: none;
}

.key-panel-settings summary:focus-visible {
  outline: 2px solid var(--link-color);
  outline-offset: 2px;
}

.key-panel-note {
  color: var(--primary-text);
}

.key-panel-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.key-panel-current {
  color: var(--caption-text);
}

.key-panel-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--borders);
  border-radius: 3px;
  background: white;
  color: var(--primary-text);
  transition: all 0.2s;
}

.key-panel-label svg {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.key-panel-settings[open] .key-panel-label svg {
  transform: rotate(60deg);
}

.key-panel-settings summary:hover .key-panel-label,
.key-panel-settings[open] .key-panel-label {
  background: var(--link-color);
  border-color: var(--link-color);
  color: white;
}

.practice-settings-body {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  padding: 12px 0 0;
}

.practice-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--caption-text);
}

.select-native {
  display: none;
}

.select-menu {
  position: relative;
}

.select-menu-button {
  width: 100%;
  padding: 8px 36px 8px 12px;
  border: 1px solid var(--borders);
  border-radius: 3px;
  background: white
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%23565c5f' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    no-repeat right 12px center / 12px 12px;
  color: var(--primary-text);
  font-family: tauhu-oo, sans-serif;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s;
}

.select-menu-button:hover,
.select-menu-button:focus,
.select-menu.is-open .select-menu-button {
  outline: none;
  border-color: var(--link-color);
}

.select-menu-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 50;
  max-height: 340px;
  overflow-y: auto;
  padding: 4px;
  list-style: none;
  background: white;
  border: 1px solid var(--borders);
  border-radius: 3px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.select-menu-list:focus {
  outline: none;
}

.select-menu-option {
  padding: 8px 10px;
  border-radius: 3px;
  color: var(--primary-text);
  font-size: 16px;
  cursor: pointer;
}

.select-menu-option.is-active {
  background: #edf3f0;
}

.select-menu-option[aria-selected="true"] {
  background: var(--link-color);
  color: white;
}

.practice-skip {
  padding: 8px 16px;
  font-size: 14px;
}

.practice-settings-actions {
  margin-top: 12px;
}

.practice-next {
  margin-top: 10px;
  color: var(--link-color);
  font-size: 14px;
}

.practice-next-btn {
  display: none;
  margin-top: 12px;
  background: var(--link-color);
  border-color: var(--link-color);
  color: white;
  font-family: inherit;
}

.practice-next-btn:hover {
  background: var(--link-color);
  border-color: var(--link-color);
  color: white;
  opacity: 0.9;
}

/* 最濟鍵的模式（25 鍵）佇 840px 嘛愛排一逝 */
.key-tiles {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 5px;
}

.key-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 32px;
  border: 1px solid var(--borders);
  border-radius: 3px;
  background: white;
  color: var(--primary-text);
  font-family: tauhu-oo, sans-serif;
  font-size: 16px;
  line-height: 1;
  transition: background 0.2s, color 0.2s;
}

/* --key-mix：0% 紅（慢）到 100% 綠（到目標速度） */
.key-tile.has-speed {
  background: color-mix(in oklch, var(--link-color) var(--key-mix), #c44);
  border-color: transparent;
  color: white;
}

.key-tile.is-idle {
  border-style: dotted;
  color: var(--caption-text);
}

.key-tile.is-locked {
  background: transparent;
  border-style: dashed;
  color: var(--borders);
}

.key-tile.is-focus {
  outline: 2px solid var(--secondary-text);
  outline-offset: 2px;
}

.key-tooltip {
  position: fixed;
  z-index: 80;
  max-width: 220px;
  padding: 8px 12px;
  background: white;
  border: 1px solid var(--borders);
  border-radius: 3px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  color: var(--primary-text);
  font-size: 13px;
  line-height: 1.45;
  pointer-events: none;
}

.key-tooltip[hidden] {
  display: none;
}

.key-tooltip-key {
  color: var(--caption-text);
  font-size: 13px;
}

.key-tooltip-speed {
  color: var(--secondary-text);
  font-size: 20px;
  font-weight: bold;
  line-height: 1.2;
  white-space: nowrap;
}

.key-tooltip-speed.is-measured {
  color: color-mix(in oklch, var(--link-color) var(--tip-mix, 0%), #c44);
}

.key-tooltip-speed.is-empty {
  color: var(--caption-text);
  font-size: 14px;
  font-weight: normal;
  white-space: normal;
}

.key-tooltip-unit {
  font-size: 13px;
  font-weight: normal;
  color: var(--caption-text);
}

.key-tooltip-meta {
  color: var(--caption-text);
}

.practice-banner {
  margin-top: 10px;
  color: #999;
  font-size: 14px;
  line-height: 1.5;
}

.char-mark.current {
  box-shadow: inset 0 -2px 0 var(--link-color);
}

.word-gap {
  display: inline-block;
  min-width: 0.45em;
  white-space: pre;
}

@media (max-width: 768px) {
  .practice-settings-body {
    grid-template-columns: 1fr 1fr;
  }

  .key-panel-settings summary {
    font-size: 13px;
  }

  .practice-area .typing-input {
    font-size: 16px;
  }

  .practice-next {
    display: none;
  }

  .practice-next-btn:not([hidden]) {
    display: block;
    width: 100%;
  }

  .key-tiles {
    gap: 4px;
  }

  .key-tile {
    width: 26px;
    height: 30px;
    font-size: 15px;
  }
}

.practice-guide {
  margin: 0 0 16px;
  text-align: center;
}

.mapping-changes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 12px;
  margin-bottom: 8px;
}

.select-menu-option[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}

.mapping-new,
.mapping-removed {
  padding: 2px 8px;
  border-radius: 6px;
}

.mapping-new {
  color: #176344;
  background: #e6f4ec;
}

.mapping-removed {
  color: #9b3541;
  background: #fbecef;
}
