/* ============================================================
   style.css  - 名刺スキャナー v5
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@300;400;500;700&family=Space+Mono:wght@400;700&display=swap');

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

:root {
    --bg:        #0a0a0f;
    --surface:   #12121a;
    --panel:     #1a1a26;
    --border:    rgba(255,255,255,0.08);
    --accent:    #00e5ff;
    --accent2:   #7c3aed;
    --good:      #22c55e;
    --warn:      #f59e0b;
    --error:     #ef4444;
    --text:      #e2e8f0;
    --muted:     #64748b;
    --radius:    12px;
    --font-ui:   'Noto Sans JP', sans-serif;
    --font-mono: 'Space Mono', monospace;
    --footer-h:  80px;
}

html, body {
    height: 100%;
    width: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.5;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* ============================================================
   常時表示フッターバー（最下部固定・z-index最上位）
   ============================================================ */
#globalFooterBar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--footer-h);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 0 16px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(10, 10, 15, 0.95);
    border-top: 1px solid rgba(0, 229, 255, 0.18);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

#globalTopBtn {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(0, 229, 255, 0.1);
    border: 1.5px solid rgba(0, 229, 255, 0.5);
    color: var(--accent);
    font-family: var(--font-ui);
    font-size: 15px;
    font-weight: 700;
    padding: 0 16px;
    height: 50px;
    border-radius: 25px;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
    flex: 1;
    max-width: 320px;
    letter-spacing: 0.03em;
    white-space: nowrap;
    -webkit-appearance: none;
    appearance: none;
}
#globalTopBtn:hover {
    background: rgba(0, 229, 255, 0.22);
    box-shadow: 0 0 20px rgba(0, 229, 255, 0.35);
}
#globalTopBtn:active {
    transform: scale(0.96);
    background: rgba(0, 229, 255, 0.3);
}

/* スキャン中止ボタン（処理中画面のみ表示） */
#cancelScanBtn {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(220, 38, 38, 0.85);
    border: 1.5px solid rgba(255, 80, 80, 0.7);
    color: #ffffff;
    font-family: var(--font-ui);
    font-size: 15px;
    font-weight: 700;
    padding: 0 16px;
    height: 50px;
    border-radius: 25px;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
    flex: 1;
    max-width: 320px;
    letter-spacing: 0.03em;
    white-space: nowrap;
    -webkit-appearance: none;
    appearance: none;
}
#cancelScanBtn:hover {
    background: rgba(220, 38, 38, 1);
    box-shadow: 0 0 20px rgba(220, 38, 38, 0.5);
}
#cancelScanBtn:active {
    transform: scale(0.96);
}

/* スキャン再開ボタン */
#resumeScanBtn {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #00e5ff;
    border: none;
    color: #000;
    font-family: var(--font-ui);
    font-size: 15px;
    font-weight: 700;
    padding: 0 16px;
    height: 50px;
    border-radius: 25px;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
    flex: 1;
    max-width: 320px;
    letter-spacing: 0.03em;
    white-space: nowrap;
    -webkit-appearance: none;
    appearance: none;
}
#resumeScanBtn:hover {
    background: #33eeff;
    box-shadow: 0 0 20px rgba(0, 229, 255, 0.5);
}
#resumeScanBtn:active {
    transform: scale(0.96);
}

/* ============================================================
   レイアウト（フッター分を下に確保）
   ============================================================ */
#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-bottom: var(--footer-h);
    position: relative;
}

.screen { height: 100%; display: flex; flex-direction: column; position: relative; }
[hidden] { display: none !important; }

/* ============================================================
   スタート画面
   ============================================================ */
#screen-start {
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 50px 24px 32px;
    text-align: center;
    background: radial-gradient(ellipse at 50% 0%, rgba(0,229,255,0.08) 0%, transparent 70%);
    overflow-y: auto;
}

.brand-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #00e5ff 0%, #7c3aed 100%);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    box-shadow: 0 0 40px rgba(0,229,255,0.15);
    animation: pulse-glow 4s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 30px rgba(0,229,255,0.15); }
    50%       { box-shadow: 0 0 50px rgba(0,229,255,0.3); }
}

.brand-title {
    font-size: 34px;
    font-weight: 700;
    letter-spacing: 1px;
    color: #ffffff;
    margin-bottom: 4px;
}

.brand-sub {
    font-size: 13px;
    color: #ffffff;
    opacity: 0.9;
    margin-top: 4px;
}

.feature-list {
    list-style: none;
    text-align: left;
    background: #1c1c28;
    border: none;
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 360px;
    align-self: stretch;
    margin: 0 auto;
    box-sizing: border-box;
}

.feature-list li {
    font-size: 14px;
    color: #ffffff;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.feature-list li:last-child { border-bottom: none; }
.feature-list li::before { content: '→ '; color: var(--accent); }

/* ============================================================
   撮影画面
   ============================================================ */
#screen-scanning {
    position: relative;
    overflow: hidden;
}

video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}

.overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}
.overlay button { pointer-events: auto; }

/* ============================================================
   コーナーガイド（常時表示・消えない設計）
   ============================================================ */
.corners {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.card-guide {
    position: absolute;
    top: 5px;
    bottom: 5px;
    left: 5px;
    right: 5px;
}

.guide-label {
    position: absolute;
    top: -34px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 13px;
    font-weight: 700;
    color: #ffffff;
    font-family: var(--font-ui);
    white-space: nowrap;
    background: rgba(0, 0, 0, 0.9);
    padding: 6px 20px;
    border-radius: 6px;
    letter-spacing: 0.05em;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

/* ============================================================
   コーナーマーカー — ステートはクラス名で管理
   corner--idle / corner--detecting / corner--locked
   ============================================================ */
.corner {
    position: absolute;
    width: 30px;
    height: 30px;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.corner-tl { top: 0;    left: 0;    border-top: 3px solid;    border-left: 3px solid; }
.corner-tr { top: 0;    right: 0;   border-top: 3px solid;    border-right: 3px solid; }
.corner-bl { bottom: 0; left: 0;    border-bottom: 3px solid; border-left: 3px solid; }
.corner-br { bottom: 0; right: 0;   border-bottom: 3px solid; border-right: 3px solid; }

/* ステートクラス（JSで付け替える） */
.corner--idle      { border-color: rgba(255,255,255,0.55); }
.corner--detecting { border-color: var(--warn); box-shadow: 0 0 10px rgba(245,158,11,0.6); }
.corner--locked    {
    border-color: var(--good);
    box-shadow: 0 0 14px rgba(34,197,94,0.8);
    animation: corner-pulse 0.6s ease-in-out infinite alternate;
}

@keyframes corner-pulse {
    from { box-shadow: 0 0 8px rgba(34,197,94,0.6); }
    to   { box-shadow: 0 0 22px rgba(34,197,94,1); }
}

/* フォーカスインジケーター */
.focus-bar-wrap {
    position: absolute;
    bottom: 68px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    max-width: 320px;
    background: rgba(0,0,0,0.6);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 8px 14px;
    backdrop-filter: blur(8px);
}

.focus-label {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: rgba(255,255,255,0.6);
    margin-bottom: 6px;
    font-family: var(--font-mono);
}

.focus-track {
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    overflow: hidden;
}

#focusBar {
    height: 100%;
    width: 0%;
    border-radius: 3px;
    background: var(--error);
    transition: width 0.3s ease, background 0.3s ease;
}

.status-bar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    max-width: 90%;
    background: rgba(0,0,0,0.7);
    border-radius: 20px;
    padding: 8px 18px;
    text-align: center;
    font-size: 13px;
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    white-space: nowrap;
}

#status[data-type="info"]  { color: rgba(255,255,255,0.9); }
#status[data-type="warn"]  { color: var(--warn); }
#status[data-type="good"]  { color: var(--good); }
#status[data-type="error"] { color: var(--error); }

#flash {
    position: absolute;
    inset: 0;
    background: #fff;
    opacity: 0;
    pointer-events: none;
    z-index: 100;
    transition: opacity 0.05s;
}
#flash.active { animation: flash-out 0.25s ease-out forwards; }

@keyframes flash-out {
    0%   { opacity: 1; }
    100% { opacity: 0; }
}

/* ============================================================
   処理中画面
   ============================================================ */
#screen-processing {
    align-items: center;
    justify-content: center;
    gap: 24px;
    background: var(--bg);
}

#previewImg {
    width: 85%;
    max-width: 360px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: 0 0 40px rgba(0,229,255,0.2);
}

.spinner {
    width: 44px;
    height: 44px;
    border: 3px solid rgba(0,229,255,0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-yellow {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100px;
    height: 100px;
    border: 12px solid #f59e0b;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin-centered 1s linear infinite;
    z-index: 20;
    box-shadow: 0 0 30px rgba(245,158,11,0.5);
}

@keyframes spin-centered {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to   { transform: translate(-50%, -50%) rotate(360deg); }
}

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

.processing-text {
    font-size: 15px;
    font-weight: 500;
    color: rgba(255,255,255,0.9);
    background: rgba(0, 0, 0, 0.6);
    padding: 10px 24px;
    border-radius: 24px;
    backdrop-filter: blur(4px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

/* ============================================================
   結果画面
   ============================================================ */
#screen-result {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;
}

.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}

.result-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--accent);
}

.result-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#cardFields {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-row {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    background: #1e1e2e; /* 項目ごとの背景パネル */
    border-radius: 8px;
    border: none !important; /* 個別の枠線は不要 */
    animation: slide-in 0.25s ease both;
}

.field-label {
    min-width: 90px;
    font-size: 13px;
    color: #ffffff !important; /* 項目名は白 */
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.field-value {
    flex: 1;
    font-size: 16px;
    color: #ffffff;
    font-weight: 500;
    word-break: break-all;
}

@keyframes slide-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.field-label {
    min-width: 82px;
    font-size: 11px;
    color: var(--muted);
    font-family: var(--font-mono);
    flex-shrink: 0;
}

.field-value {
    font-size: 14px;
    color: var(--text);
    word-break: break-all;
}

.field-none {
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 13px;
    letter-spacing: 0.1em;
}

.field-value a {
    color: var(--accent);
    text-decoration: none;
}
.field-value a:hover { text-decoration: underline; }

.card-thumb-wrap { margin-top: 4px; }

.thumb-label {
    font-size: 11px;
    color: var(--muted);
    font-family: var(--font-mono);
    margin-bottom: 8px;
}

.card-thumb-wrap {
    margin-top: 4px;
    overflow: visible;
}

.card-preview-thumb {
    width: 100%;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: block;
    cursor: zoom-in;
    transition: transform 0.2s ease;
    transform-origin: center center;
}

.result-actions {
    padding: 10px 14px;
    display: flex;
    gap: 10px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}

/* ============================================================
   共通ボタン
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-family: var(--font-ui);
    font-weight: 600;
    transition: filter 0.15s, transform 0.1s;
    -webkit-appearance: none;
}
.btn:active { transform: scale(0.96); filter: brightness(0.9); }

.btn-primary {
    padding: 14px 32px;
    font-size: 16px;
    background: linear-gradient(135deg, var(--accent) 0%, #0099cc 100%);
    color: #000;
    box-shadow: 0 0 24px rgba(0,229,255,0.4);
}

.btn-secondary {
    flex: 1;
    padding: 11px 14px;
    font-size: 13px;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-outline {
    padding: 7px 14px;
    font-size: 13px;
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 8px;
}

canvas { display: none; }

/* スクロールバー */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ============================================================
   画像ライトボックス
   ============================================================ */
#imgLightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    align-items: center;
    justify-content: center;
}
#imgLightbox.active {
    display: flex;
    animation: lb-fadein 0.18s ease;
}
@keyframes lb-fadein {
    from { opacity: 0; }
    to   { opacity: 1; }
}
#imgLightboxInner {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 16px;
    box-sizing: border-box;
}
#imgLightboxImg {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 0 60px rgba(0, 229, 255, 0.15);
    touch-action: none;
    transform-origin: center center;
    transition: transform 0.15s ease;
    cursor: zoom-in;
    user-select: none;
    -webkit-user-select: none;
}
#imgLightboxClose {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    transition: background 0.15s;
}
#imgLightboxClose:hover { background: rgba(255, 255, 255, 0.28); }
#imgLightboxHint {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: rgba(255, 255, 255, 0.45);
    white-space: nowrap;
    font-family: var(--font-mono);
    pointer-events: none;
}

/* サムネイルをクリックできることを示す */
.card-preview-thumb {
    cursor: zoom-in;
}

