/* ===========================
   練字評分頁面樣式 (score.css)
   =========================== */

.score-container {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* 頁面標題 */
.score-header {
    text-align: center;
    padding: 1rem 0 0;
}

.score-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary, #5a3e28);
    margin: 0 0 0.4rem;
}

.score-subtitle {
    font-size: 1rem;
    color: var(--text-muted, #8a7560);
    margin: 0;
}

/* ── 輸入區 ─────────────────────────────────── */
.score-form-card {
    background: var(--bg-card, #faf6f0);
    border: 1px solid var(--border, #d4bfa0);
    border-radius: 12px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-row {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
    flex-wrap: wrap;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.form-label {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--primary, #5a3e28);
    letter-spacing: 0.02em;
}

.char-input {
    width: 3.5rem;
    height: 3.5rem;
    font-size: 2rem;
    text-align: center;
    border: 2px solid var(--border, #d4bfa0);
    border-radius: 8px;
    background: #fff;
    color: var(--primary, #5a3e28);
    font-family: "Kaiti SC", "KaiTi", "標楷體", serif;
    transition: border-color 0.15s;
    outline: none;
}

.char-input:focus {
    border-color: var(--accent, #8b5a2b);
}

.form-hint {
    font-size: 0.8rem;
    color: var(--text-muted, #8a7560);
    margin: 0.2rem 0 0;
}

/* 上傳區 */
.upload-zone {
    border: 2px dashed var(--border, #d4bfa0);
    border-radius: 10px;
    background: #fff;
    min-height: 160px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    position: relative;
    padding: 1.5rem;
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--accent, #8b5a2b);
    background: var(--accent-light, #f5ede0);
}

.upload-zone.has-file {
    border-style: solid;
    border-color: var(--accent, #8b5a2b);
}

.upload-icon {
    color: var(--text-muted, #8a7560);
    line-height: 0;  /* 避免 SVG 下方多餘空白 */
}

.upload-hint {
    font-size: 0.92rem;
    color: var(--text-muted, #8a7560);
    text-align: center;
}

.upload-hint strong {
    color: var(--accent, #8b5a2b);
}

.upload-file-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

/* 預覽圖 */
.upload-preview {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.upload-preview.show {
    display: flex;
}

.preview-img {
    max-width: 140px;
    max-height: 140px;
    border-radius: 6px;
    border: 1px solid var(--border, #d4bfa0);
    object-fit: contain;
    background: #fafaf8;
}

.preview-filename {
    font-size: 0.8rem;
    color: var(--text-muted, #8a7560);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 送出按鈕 */
.btn-analyze {
    align-self: flex-end;
    padding: 0.75rem 2.2rem;
    background: var(--accent, #8b5a2b);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-analyze:hover:not(:disabled) {
    background: var(--primary, #5a3e28);
}

.btn-analyze:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-analyze .spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.btn-analyze.loading .spinner { display: inline-block; }
.btn-analyze.loading .btn-text { display: none; }

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 錯誤訊息 */
.score-error {
    background: #fff0f0;
    border: 1px solid #f5c6c6;
    border-radius: 8px;
    padding: 1rem 1.2rem;
    color: #c62828;
    font-size: 0.95rem;
    display: none;
}

.score-error.show { display: block; }

/* ── 結果區 ──────────────────────────────────── */
.score-results {
    display: none;
    flex-direction: column;
    gap: 1.5rem;
    animation: fadeInUp 0.4s ease;
}

.score-results.show { display: flex; }

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

/* 書法家比對排行 */
.ranking-section {
    padding-bottom: 0.5rem;
}

.ranking-note {
    font-size: 0.82rem;
    color: var(--text-muted, #8a7560);
    margin: -0.4rem 0 1rem;
    line-height: 1.5;
}

.ranking-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 0.5rem;
}

.ranking-card {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    background: #f5ede0;
    border: 1.5px solid var(--border, #d4bfa0);
    border-radius: 10px;
    padding: 0.45rem 0.7rem;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.ranking-card:hover {
    border-color: var(--accent, #8b5a2b);
}

.ranking-card.active {
    border-color: var(--accent, #8b5a2b);
    background: #fff;
}

.ranking-rank {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--accent, #8b5a2b);
    min-width: 1.5rem;
    text-align: center;
    flex-shrink: 0;
}

.ranking-thumb {
    width: 38px;
    height: 38px;
    object-fit: contain;
    background: #fff;
    border: 1px solid var(--border, #d4bfa0);
    border-radius: 6px;
    flex-shrink: 0;
}

.ranking-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.ranking-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary, #5a3e28);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ranking-scores {
    font-size: 0.8rem;
    color: var(--text-muted, #8a7560);
}

.detail-section {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    border-top: 2px dashed var(--border, #d4bfa0);
    padding-top: 1.5rem;
    margin-top: 0.5rem;
}

/* 分項量測 */
.metrics-section {
    border-top: 1px solid var(--border, #d4bfa0);
    padding-top: 1.2rem;
}

.metrics-note {
    font-size: 0.82rem;
    color: var(--text-muted, #8a7560);
    margin: -0.4rem 0 1rem;
    line-height: 1.5;
}

.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.2rem;
}

.metric-item {
    background: #f5ede0;
    border: 1px solid var(--border, #d4bfa0);
    border-radius: 10px;
    padding: 0.9rem 1rem;
}

.metric-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.5rem;
}

.metric-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary, #5a3e28);
}

.metric-label small {
    font-size: 0.76rem;
    font-weight: 400;
    color: var(--text-muted, #8a7560);
    margin-left: 0.3rem;
}

.metric-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent, #8b5a2b);
}

.metric-bar {
    height: 8px;
    background: #fff;
    border: 1px solid var(--border, #d4bfa0);
    border-radius: 99px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.metric-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--accent, #8b5a2b);
    border-radius: 99px;
    transition: width 0.6s ease-out;
}

.metric-feedback {
    font-size: 0.85rem;
    color: var(--text-muted, #8a7560);
    margin: 0;
    line-height: 1.5;
}

/* 比對圖區 */
.comparison-section {
    border-top: 1px solid var(--border, #d4bfa0);
    padding-top: 1.2rem;
}

.section-title {
    font-size: 1.1rem;
    color: var(--primary, #5a3e28);
    margin: 0 0 1rem;
    font-weight: 600;
}

.comparison-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.comparison-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.comparison-item img {
    width: 100%;
    max-width: 220px;
    aspect-ratio: 1/1;
    object-fit: contain;
    border: 1px solid var(--border, #d4bfa0);
    border-radius: 8px;
    background: #fafaf8;
}

.comparison-label {
    font-size: 0.88rem;
    color: var(--text-muted, #8a7560);
    font-weight: 500;
}

.comparison-label.user-label {
    color: #c62828;
    font-weight: 600;
}

/* 再測按鈕 */
.btn-retry {
    align-self: flex-start;
    padding: 0.6rem 1.4rem;
    background: transparent;
    color: var(--accent, #8b5a2b);
    border: 1.5px solid var(--accent, #8b5a2b);
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.btn-retry:hover {
    background: var(--accent, #8b5a2b);
    color: #fff;
}

/* ── 筆劃差異標示 ────────────────────────────── */
.diff-section {
    border-top: 1px solid var(--border, #d4bfa0);
    padding-top: 1.2rem;
}

.diff-body {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
    flex-wrap: wrap;
}

.diff-canvas-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.diff-img {
    width: 200px;
    height: 200px;
    object-fit: contain;
    border: 1px solid var(--border, #d4bfa0);
    border-radius: 10px;
    background: #f0f0f0;
    cursor: grab;
    flex-shrink: 0;
    image-rendering: pixelated;   /* 保留像素清晰度 */
    transition: transform 0.15s;
    touch-action: none;   /* 拖曳時不要連動頁面捲動 */
    user-select: none;
}

.diff-img:hover {
    transform: scale(1.03);
}

.diff-img:active {
    cursor: grabbing;
}

.diff-drag-hint {
    font-size: 0.72rem;
    color: var(--text-muted, #8a7560);
}

/* --- 手動對齊控制 --- */
.diff-align {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    border-top: 1px dashed var(--border, #d4bfa0);
    padding-top: 0.8rem;
}

.diff-align-label {
    width: 100%;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary, #5a3e28);
}

.diff-drag-toggle {
    display: flex;
    gap: 0.4rem;
}

.diff-drag-btn {
    padding: 0.3rem 0.7rem;
    border: 1.5px solid var(--border, #d4bfa0);
    border-radius: 999px;
    background: #fff;
    font-size: 0.78rem;
    cursor: pointer;
    color: var(--text, #3d2b1a);
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.diff-drag-btn:hover {
    border-color: var(--accent, #8b5a2b);
}

.diff-drag-btn.active {
    background: var(--accent, #8b5a2b);
    border-color: var(--accent, #8b5a2b);
    color: #fff;
}

.diff-reset-btn {
    font-size: 0.78rem;
}

.diff-right {
    flex: 1;
    min-width: 180px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.diff-legend {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.88rem;
    color: var(--text, #3d2b1a);
}

.legend-dot {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
}

.dot-match   { background: #464646; }
.dot-extra   { background: #dc3c3c; }
.dot-missing { background: #3c6edc; }

.diff-hint {
    font-size: 0.82rem;
    color: var(--text-muted, #8a7560);
    line-height: 1.7;
    margin: 0;
    border-top: 1px dashed var(--border, #d4bfa0);
    padding-top: 0.7rem;
}

.diff-sensitivity {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    border-top: 1px dashed var(--border, #d4bfa0);
    padding-top: 0.9rem;
}

.diff-sensitivity-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary, #5a3e28);
}

.diff-sensitivity-label span {
    font-weight: 500;
    color: var(--accent, #8b5a2b);
}

.diff-sensitivity input[type="range"] {
    width: 100%;
    accent-color: var(--accent, #8b5a2b);
    cursor: pointer;
}

.diff-sensitivity-hint {
    font-size: 0.78rem;
    color: var(--text-muted, #8a7560);
    line-height: 1.5;
    margin: 0;
}

/* ── 拍攝小技巧：緊貼在上傳區旁邊的收合區塊（而不是整頁最下方）──── */
.tips-inline {
    font-size: 0.9rem;
    color: var(--text-muted, #8a7560);
}

.tips-inline summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--primary, #5a3e28);
    font-size: 0.92rem;
    list-style: none;
    padding: 0.3rem 0;
}

.tips-inline summary::-webkit-details-marker { display: none; }

.tips-inline[open] summary {
    margin-bottom: 0.3rem;
}

.tips-list {
    display: flex;
    flex-direction: column;
    margin-bottom: 1rem;
}

.tip-row {
    display: flex;
    align-items: baseline;
    gap: 0.9rem;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--border-light, #eee1cf);
}

.tip-row:first-child { border-top: 1px solid var(--border-light, #eee1cf); }

.tip-index {
    font-size: 1rem;
    font-weight: 700;
    color: var(--border, #d4bfa0);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    width: 1.6rem;
}

.tip-body p {
    margin: 0.1rem 0 0;
    font-size: 0.82rem;
    line-height: 1.5;
}

.tip-body strong {
    color: var(--primary, #5a3e28);
}

.tips-note {
    margin: 0;
    font-size: 0.82rem;
    border-top: 1px solid var(--border, #d4bfa0);
    padding-top: 0.7rem;
    line-height: 1.7;
}

/* ── RWD ────────────────────────────────────── */
@media (max-width: 680px) {
    .comparison-grid {
        grid-template-columns: 1fr;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        flex-direction: column;
    }

    .btn-analyze {
        align-self: stretch;
        justify-content: center;
    }

    /* diff-body 在 680px 時不強制 column，
       讓 flex-wrap: wrap 自然處理；
       更窄 (< 480px) 時再見下方 media query */
}

@media (max-width: 480px) {
    .diff-body {
        flex-direction: column;
        align-items: center;
    }

    .diff-img {
        width: 100%;
        max-width: 220px;
        height: auto;
        aspect-ratio: 1 / 1;
    }

    .diff-right {
        width: 100%;
    }
}
