:root {
  --bg: #f5f0fa;
  --card: #fff;
  --accent: #4e167d;
  --text: #222;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Serif TC", "PingFang TC", serif;
  background: var(--bg) url('BG-pattern.webp') repeat;
  min-height: 100dvh; /* 使用 dvh 避免手機瀏覽器網址列與鍵盤影響高度 */
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 預設在手機上滿版自適應，在電腦或平板上維持卡片比例置中 */
.wrap {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background-size: 100% 100% !important; /* 寬高皆 100% 貼合，完全不裁切 */
  background-position: center center !important;
}

/* 螢幕寬度大於 480px（平板與電腦）時，才限制成手機卡片比例 */
@media (min-width: 481px) {
  .wrap {
    max-width: 430px;
    min-height: auto;
    aspect-ratio: 393 / 850;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
    border-radius: 12px;
  }
}

/* 首頁表單：改用百分比定位與較好點擊的寬度 */
form {
  position: absolute;
  bottom: 13%; /* 改用百分比，隨圖片高度自動調整位置 */
  left: 50%;
  transform: translateX(-50%);
  width: 65%;
  max-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: transparent;
}

label {
  font-weight: bold;
  text-align: center;
  display: block;
  font-size: 1.15rem;
  text-shadow: 0 1px 4px rgba(255, 255, 255, 0.9);
}

input {
  width: 100%;
  padding: 0.75rem;
  font-size: 16px; /* 必須 >= 16px，否則 iPhone 點擊輸入框會強制自動放大畫面 */
  border: 1px solid rgba(78, 22, 125, 0.4);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  text-align: center;
}

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type=number] {
  -moz-appearance: textfield;
}

button {
  width: 100%;
  padding: 0.75rem;
  font-size: 1.1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

button:hover {
  opacity: 0.9;
}

/* 結果頁籤詩容器 */
#content {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 1.25rem 1rem 2.5rem;
  background: transparent;
}

.err {
  color: #c00;
  text-align: center;
  background: rgba(255, 255, 255, 0.9);
  padding: 1rem;
  border-radius: 8px;
}

/* 籤詩表格改為彈性寬度，避免在小手機爆版 */
.poem-table {
  width: 100%;
  max-width: 360px;
  border-collapse: collapse;
  background: rgba(255, 255, 255, 0.92);
  margin: 0 auto;
}

.poem-table caption {
  caption-side: top;
  font-size: 1.05rem;
  font-weight: normal;
  padding: 0.6rem;
  background: #d7b26d;
  border: 1px solid #c9a961;
}

.poem-table caption .c1 {
  color: #000000;
  font-weight: normal;
}

.poem-table caption .c2 {
  color: #401268;
  font-weight: bold;
}

.poem-table th,
.poem-table td {
  border: 1px solid #c9a961;
  padding: 0.5rem;
  vertical-align: top;
}

.poem-table th {
  width: 3.2em; /* 改用字元寬度，適應不同字級 */
  background: #fff0dc;
  color: #000000;
  font-weight: bold;
}

.poem-table td {
  width: auto; /* 讓內容欄自動填滿剩餘寬度 */
  background: #ffffff;
  line-height: 1.6;
}