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

body {
    font-family: 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
    background: #f5f6fa;
    color: #2c3e50;
    line-height: 1.6;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 30px 10px;
}

.header {
    text-align: center;
    margin-bottom: 10px;
    padding: 30px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

h1 {
    font-size: 2.2em;
    color: #2c3e50;
    margin-bottom: 25px;
    letter-spacing: 0.05em;
}

.subtitle {
    color: #5f6368;
    font-size: 0.9em;
    line-height: 1.8;
    margin: 0 auto;
    padding: 25px 30px;
    background: #f8f9fa;
    border-radius: 10px;
    text-align: left;
}

.subtitle p {
    margin: 0;
    padding: 0;
}

.subtitle .break {
    display: block;
    margin-top: 9px;
    color: #666;
    font-size: 0.85em;
}

.subtitle a {
    color: #3498db;
    text-decoration: none;
    transition: color 0.3s ease;
    font-weight: 500;
}

.subtitle a:hover {
    color: #2980b9;
    text-decoration: underline;
}

.search-form {
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    margin-top: 20px;
}

.search-input {
    width: 100%;
    padding: 15px 20px;
    font-size: 1.1em;
    border: 2px solid #eee;
    border-radius: 10px;
    margin-bottom: 20px;
    transition: all 0.3s ease;
}

.search-input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 10px rgba(52,152,219,0.1);
}

.search-button {
    width: 100%;
    padding: 15px;
    font-size: 1.1em;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.search-button:hover {
    background: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(52,152,219,0.2);
}

.error {
    color: #e74c3c;
    padding: 15px;
    margin-bottom: 20px;
    background-color: #fdf3f2;
    border-radius: 8px;
    border: 1px solid #fadbd8;
    display: none;
}

@media (max-width: 768px) {
    .container {
        padding: 20px;
    }
    
    .header {
        padding: 20px;
        margin-bottom: 30px;
    }

    h1 {
        font-size: 1.8em;
    }

    .subtitle {
        padding: 20px;
        font-size: 0.9em;
        margin: 0 10px;
    }

    .subtitle .break {
        font-size: 0.9em;
    }
}

.loading {
    text-align: center;
    margin: 20px 0;
    display: none;
}

.loading-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.95);
    padding: 12px 20px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-text {
    color: #666;
    font-size: 0.9em;
    white-space: nowrap;
}

#results {
    margin-top: 30px;
}

.result {
    background: white;
    margin: 30px 0;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.05);
    opacity: 0;
    transform: translateY(20px);
    animation: fadeIn 0.5s ease forwards;
    position: relative;
}

.result-number {
    position: absolute;
    top: -15px;
    left: 20px;
    background: #3498db;
    color: white;
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 0.9em;
    box-shadow: 0 3px 6px rgba(0,0,0,0.1);
}

.result-content {
    margin: 15px 0;
    line-height: 1.8;
    color: #2c3e50;
    font-size: 1.05em;
}

.source-content {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

.source-content-title {
    color: #7f8c8d;
    font-size: 0.9em;
    font-weight: 500;
    margin-bottom: 10px;
}

.source-content-text {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #3498db;
    color: #2c3e50;
    font-size: 0.95em;
    line-height: 2.2;
    font-family: 'Courier New', monospace;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* メタデータとIIIFボタンを含む行のレイアウト */
.source-content-text.metadata-with-iiif {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 15px;
}

/* メタデータテキストのリンク */
.metadata-link {
    color: #3498db;
    text-decoration: none;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.metadata-link:hover {
    color: #2980b9;
    text-decoration: underline;
}

/* リンク内の割注とルビもリンク色を継承 */
.metadata-link wari {
    color: inherit;
}

.metadata-link wari::before,
.metadata-link wari::after {
    color: inherit;
    opacity: 0.7;
}

.metadata-link ruby,
.metadata-link rb,
.metadata-link rt {
    color: inherit;
}

/* 通常のリンク（原文・訳文内など） */
.source-content-text a:not(.metadata-link):not(.iiif-button) {
    color: #3498db;
    text-decoration: none;
    transition: all 0.2s ease;
}

.source-content-text a:not(.metadata-link):not(.iiif-button):hover {
    color: #2980b9;
    text-decoration: underline;
}

/* IIIF画像表示ボタン */
.iiif-button {
    display: inline-block;
    padding: 4px 12px;
    background: #3498db;
    color: white !important;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: 500;
    text-decoration: none !important;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    white-space: nowrap;
    flex-shrink: 0;
}

.iiif-button:hover {
    background: #2980b9;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}

.iiif-button:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* ルビ（振り仮名）のスタイル設定 */
.source-content-text ruby {
    /* ルビを上に配置（デフォルト） */
    ruby-position: over;
    ruby-align: center;
}

.source-content-text rt {
    /* ルビ（読み仮名）のスタイル */
    font-size: 0.5em;
    line-height: 1;
    user-select: none;
}

.source-content-text rb {
    /* 親文字（漢字）のスタイル */
}

/* 割注（wariタグ）のスタイル設定 */
.source-content-text wari {
    font-size: 0.8em;
    color: #666;
}

.source-content-text wari::before {
    content: "〔";
    color: #999;
}

.source-content-text wari::after {
    content: "〕";
    color: #999;
}

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

#loading {
    background: rgba(255, 255, 255, 0.9);
    padding: 20px;
    border-radius: 10px;
    margin: 20px 0;
    text-align: center;
    display: none;
}

#endMessage {
    text-align: center;
    color: #7f8c8d;
    background: white;
    padding: 15px;
    border-radius: 10px;
    margin: 20px 0;
    display: none;
    box-shadow: 0 5px 15px rgba(0,0,0,0.05);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.download-button {
    padding: 12px 25px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 0 10px;
}

.download-button:hover {
    background: #2980b9;
    transform: translateY(-2px);
}

.download-button:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
    transform: none;
}

#downloadLoading {
    z-index: 1000;
}

#downloadLoading .loading-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    padding: 15px 25px;
    border-radius: 10px;
}

#downloadLoading .loading-text {
    color: #3498db;
    font-weight: bold;
}
