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

body {
    font-family: "Helvetica Neue", Helvetica, Arial, "PingFang TC", "微軟正黑體", sans-serif;
    background-color: #f4f4f9;
    color: #333;
    display: flex;
    justify-content: center;
    align-items: center; 
    height: 100dvh; 
    overflow: hidden; 
    padding: 10px 10px 0 10px; 
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    background-color: #ffffff;
    width: 100%;
    max-width: 400px;
    max-height: calc(100dvh - 85px); 
    margin-bottom: 60px; 
    overflow-y: auto; 
    padding: 20px 20px 0 20px; 
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    text-align: center;
    -ms-overflow-style: none; 
    scrollbar-width: none; 
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.container::-webkit-scrollbar {
    display: none;
}

.temple-header {
    background: linear-gradient(135deg, #c62828 0%, #8e0000 100%);
    color: #ffffff;
    margin: -20px -20px 20px -20px; 
    padding: 18px 20px 25px 20px; 
    border-radius: 12px 12px 50% 50% / 12px 12px 18px 18px;
    display: flex;
    align-items: center; 
    justify-content: space-between; 
    box-shadow: 0 6px 12px rgba(183, 28, 28, 0.25);
    border-bottom: 4px solid #ffd54f; 
}

/* 💡 修正：增加 overflow: hidden 防止超出範圍 */
.temple-title-group {
    display: flex;
    flex-direction: row; 
    align-items: center; 
    gap: 8px; 
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden; 
}

/* 💡 修正：設定 flex-shrink: 0 確保主標題不被壓縮 */
.temple-title-text {
    font-size: 21px; 
    font-weight: 900;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 4px;
    letter-spacing: 1px;
    color: #ffd54f;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
    cursor: pointer; 
    transition: opacity 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.temple-title-text:active {
    opacity: 0.7; 
}

/* 💡 修正：當空間不夠時，副標題自動變點點點 */
.temple-subtitle {
    font-size: 13px; 
    color: #ffecb3;
    font-weight: 500;
    letter-spacing: 1px;
    margin-top: 0; 
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
}

/* 💡 修正：拉高層級 z-index，確保按鈕絕對在最上層 */
.header-actions {
    display: flex;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.theme-toggle-btn {
    background: transparent; 
    border: none; 
    color: #ffd54f;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px; 
    transition: all 0.3s ease;
}

.theme-toggle-btn:hover {
    transform: scale(1.1); 
}

/* 💡 新增：讓 SVG 與 Icon 放棄點擊事件，避免干擾按鈕觸發 */
.theme-toggle-btn svg,
.theme-toggle-btn i {
    pointer-events: none;
}

.prayer-card {
    text-align: left;
    background-color: #fafafa;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #eeeeee;
    margin-bottom: 20px;
}

.step-box {
    margin-bottom: 15px;
}

.step-box:last-child {
    margin-bottom: 0;
}

.step-box label {
    font-size: 15px;
    font-weight: bold;
    color: #b71c1c; 
    display: block; 
    margin-bottom: 8px; 
}

.step-box input, 
.step-box select {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 15px;
    background-color: #ffffff;
    outline: none;
    transition: border-color 0.3s, box-shadow 0.3s, background-color 0.3s, color 0.3s;
}

.step-box input:focus, 
.step-box select:focus {
    border-color: #b71c1c;
    box-shadow: 0 0 0 3px rgba(183, 28, 28, 0.1); 
}

.prayer-script-box {
    background-color: #fffaf0; 
    border-left: 5px solid #ff9800;
    padding: 15px 20px;
    margin-bottom: 25px; 
    border-radius: 6px;
    text-align: left;
}

.script-title {
    font-size: 14px;
    color: #555; 
    font-weight: bold;
    margin-bottom: 8px;
}

#prayerScript {
    color: #d84315; 
    font-weight: bold;
    line-height: 1.6;
    font-size: 16px;
}

button#drawBtn {
    width: 100%;
    padding: 16px;
    font-size: 18px;
    font-weight: bold;
    color: #fff;
    background-color: #d32f2f; 
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 10px rgba(211, 47, 47, 0.3);
}

button#drawBtn:hover:not(:disabled) {
    background-color: #b71c1c; 
    transform: translateY(-2px); 
}

button#drawBtn:disabled {
    background-color: #cccccc;
    color: #888888;
    cursor: not-allowed;
    box-shadow: none;
}

.action-buttons {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    width: 100%;
}

.action-btn {
    flex: 1; 
    padding: 14px 10px;
    font-size: 16px;
    font-weight: bold;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    white-space: nowrap; 
}

.action-btn:active {
    transform: scale(0.96); 
}

/* 儲存圖片按鈕 (綠色) */
.btn-save {
    background-color: #2e7d32; 
}
.btn-save:hover:not(:disabled) {
    background-color: #1b5e20;
}

/* 分享結果按鈕 (藍色) */
.btn-share {
    background-color: #1565c0; 
}
.btn-share:hover:not(:disabled) {
    background-color: #0d47a1;
}

.card {
    margin-top: 15px;
    padding: 15px 15px; 
    background-color: #fffaf0; 
    border: 2px solid #b71c1c; 
    position: relative;
    border-radius: 6px;
    transition: opacity 0.5s ease, background-color 0.3s;
}

.card::before {
    content: "";
    position: absolute;
    top: 5px; left: 5px; right: 5px; bottom: 5px;
    border: 1px solid #b71c1c;
    pointer-events: none;
    border-radius: 4px;
}

.result-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    margin-bottom: 12px;
}

#resultGrade {
    color: #d84315;
    font-size: 28px;
    font-weight: 900;
    margin: 0;
}

.stick-number {
    background-color: transparent;
    color: #c62828;
    border: 2px solid #c62828;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 1px;
}

.stick-name {
    font-size: 18px;
    font-weight: bold;
    color: #555;
}

.main-text {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    margin-bottom: 10px;
    line-height: 1.5;
    letter-spacing: 2px;
}

.explanation-box {
    background-color: rgba(255, 255, 255, 0.8);
    border-radius: 6px;
    padding: 10px 15px;
    margin-top: 10px;
    text-align: left;
    border-left: 4px solid #b71c1c;
}

.explanation-box strong {
    color: #b71c1c;
    display: block;
    margin-bottom: 8px;
    font-size: 15px;
}

#resultExplanation {
    font-size: 15px;
    line-height: 1.6;
    color: #444;
}

.card-footer {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px dashed #d32f2f; 
    display: flex;
    flex-direction: column; 
    justify-content: center;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #b71c1c;
    opacity: 0.7; 
}

footer {
    width: 100%; 
    margin-top: 30px; 
    padding: 25px 0; 
    border-top: 1px solid #eee;
    text-align: center; 
    font-size: 12px; 
    color: #777; 
    background-color: #fff;
    transition: background-color 0.3s, border-color 0.3s;
}

.footer-copyright {
    padding: 0 15px;
    line-height: 1.6; 
}

.footer-copyright a {
    color: #b71c1c;
    text-decoration: none;
    font-weight: bold;
}

.footer-nav {
    display: flex;
    justify-content: center;
    gap: 6px;
    width: 100%;
    margin-bottom: 15px;
    padding: 0 10px;
}

.footer-nav button {
    background: #f4f4f9;
    color: #555;
    border: 1px solid #ddd;
    padding: 8px 4px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    flex: 1;
    white-space: nowrap;
    transition: all 0.2s;
}

.footer-nav button.share-btn {
    background-color: #b71c1c;
    color: #fff;
    border-color: #b71c1c;
}

.footer-nav button:hover {
    background-color: #e0e0e0;
}

.footer-nav button.share-btn:hover {
    background-color: #8e0000;
}

.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: #ffffff;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); 
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
    z-index: 1000;
    transition: background-color 0.3s, border-color 0.3s;
}

.bottom-bar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: #777; 
    font-size: 11px;
    font-weight: 600;
    gap: 4px;
    transition: color 0.2s;
    flex: 1;
}

.bottom-bar a:hover {
    color: #b71c1c; 
}

.bottom-bar .icon {
    font-size: 22px;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.modal-content {
    background: #fffaf0;
    max-width: 340px;
    width: 90%;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    overflow: hidden;
    border: 2px solid #b71c1c;
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eebb99;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #b71c1c;
    color: white;
}

.modal-title {
    font-size: 18px;
    font-weight: bold;
    letter-spacing: 1px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #fff;
    opacity: 0.8;
}

.modal-body {
    padding: 24px 20px;
    line-height: 1.8; 
    color: #444;
    font-size: 15px;
    text-align: justify; 
    letter-spacing: 0.5px; 
}

.modal-body p {
    margin-bottom: 16px; 
}

.modal-body p:last-child {
    margin-bottom: 0;
}

.modal-body b, .modal-body strong {
    color: #b71c1c; 
    background-color: rgba(183, 28, 28, 0.05); 
    padding: 2px 6px;
    border-radius: 4px;
}

@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}

.shaking {
    animation: shake 0.5s infinite;
    background-color: #f57c00 !important;
    color: #fff;
    box-shadow: none !important;
}

.fade-in {
    animation: fadeIn 0.8s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

.hidden {
    display: none !important;
}

/* 夜間模式 (Dark Mode) 色彩設定 */
body.dark-mode {
    background-color: #121212;
    color: #e0e0e0;
}

body.dark-mode .container {
    background-color: #1e1e1e;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

body.dark-mode .prayer-card {
    background-color: #2c2c2c;
    border-color: #444;
}

body.dark-mode .step-box label {
    color: #ff8a80; 
}

body.dark-mode .step-box input, 
body.dark-mode .step-box select {
    background-color: #333;
    color: #e0e0e0;
    border-color: #555;
}

body.dark-mode .prayer-script-box {
    background-color: #3e2723;
    border-left-color: #ffb300;
}

body.dark-mode .script-title {
    color: #ffcc80;
}

body.dark-mode #prayerScript {
    color: #ffab91;
}

body.dark-mode .card {
    background-color: #2c2c2c;
    border-color: #b71c1c;
}

body.dark-mode .main-text {
    color: #fff;
}

body.dark-mode .stick-name {
    color: #ccc;
}

body.dark-mode .explanation-box {
    background-color: rgba(0, 0, 0, 0.3);
}

body.dark-mode #resultExplanation {
    color: #bbb;
}

body.dark-mode footer {
    background-color: #1e1e1e;
    border-top-color: #333;
    color: #888;
}

body.dark-mode .footer-nav button {
    background: #333;
    color: #ccc;
    border-color: #444;
}

body.dark-mode .bottom-bar {
    background-color: #1e1e1e;
    border-top-color: #333;
}

body.dark-mode .bottom-bar a {
    color: #888;
}

body.dark-mode .bottom-bar a:hover {
    color: #ff8a80;
}

body.dark-mode .bottom-bar a[style*="color: #b71c1c"] {
    color: #ff8a80 !important;
}

body.dark-mode .modal-content {
    background: #2c2c2c;
    border-color: #8e0000;
}

body.dark-mode .modal-body {
    color: #e0e0e0;
}

body.dark-mode .modal-body b, body.dark-mode .modal-body strong {
    color: #ff8a80;
    background-color: rgba(255, 138, 128, 0.1);
}

body.dark-mode .btn-share {
    background-color: #1976d2;
}
body.dark-mode .btn-share:hover:not(:disabled) {
    background-color: #0d47a1;
}
