:root {
    color-scheme: light;
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        "Yu Gothic UI",
        "Yu Gothic",
        Meiryo,
        sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: #eef1f4;
    color: #17202a;
}

button,
input {
    font: inherit;
}

button {
    touch-action: manipulation;
}

[hidden] {
    display: none !important;
}

.scan-app {
    min-height: 100dvh;
}

.scan-header {
    display: flex;
    min-height: 68px;
    padding:
        calc(10px + env(safe-area-inset-top))
        18px
        10px;
    align-items: center;
    justify-content: space-between;
    background: #172433;
    color: #fff;
}

.scan-header__eyebrow {
    margin: 0 0 2px;
    color: #bfcbd7;
    font-size: 11px;
}

.scan-header__title {
    margin: 0;
    font-size: 18px;
}

.scan-header__step {
    padding: 6px 10px;
    border: 1px solid rgb(255 255 255 / 35%);
    border-radius: 999px;
    font-size: 12px;
    white-space: nowrap;
}

.scan-screen {
    width: min(100%, 980px);
    margin: 0 auto;
    padding:
        20px
        14px
        calc(30px + env(safe-area-inset-bottom));
}

.scan-screen--camera {
    width: min(100%, 1280px);
    padding-top: 10px;
}

.guide-card {
    padding: 22px;
    border: 1px solid #d6dce2;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 8px 24px rgb(20 34 48 / 8%);
}

.guide-card--wide {
    width: min(100%, 960px);
}

.guide-card h2 {
    margin: 0 0 16px;
    font-size: 22px;
    text-align: center;
}

.intro-card {
    max-width: 760px;
    margin: 0 auto;
}

/* 撮影前の鍵種別ガイド */

.intro-guide-stage {
    display: grid;
    min-height: 230px;
    margin-bottom: 18px;
    padding: 26px;
    place-items: center;
    border-radius: 12px;
    background: #f3f5f7;
}

.intro-key-guide {
    width: min(92%, 620px);
}

.intro-key-guide svg {
    display: block;
    width: 100%;
    height: auto;
}

.intro-key-guide .key-guide-svg__outer {
    fill: rgb(100 115 128 / 8%);
    stroke: #65717c;
    stroke-width: 8;
}

.intro-key-guide .key-guide-svg__shadow {
    display: none;
}

.intro-key-guide .key-guide-svg__hole,
.intro-key-guide .key-guide-svg__detail,
.intro-key-guide .key-guide-svg__shoulder,
.intro-key-guide .key-guide-svg__angle {
    fill: none;
    stroke: #7b8791;
    stroke-width: 5;
}

.instruction-list {
    margin: 0;
    padding-left: 25px;
    line-height: 1.9;
}

.instruction-list li + li {
    margin-top: 5px;
}

.important-notice {
    margin: 18px 0;
    padding: 13px 15px;
    border: 1px solid #e1bd74;
    border-radius: 8px;
    background: #fff8e8;
    color: #6c4b08;
    font-size: 14px;
    line-height: 1.7;
}

.image-specification {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 18px;
}

.image-specification span {
    padding: 6px 9px;
    border-radius: 999px;
    background: #edf1f4;
    color: #485663;
    font-size: 12px;
}

/* ボタン共通 */

.primary-button,
.secondary-button,
.copy-button,
.retake-button {
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
}

.primary-button {
    display: block;
    width: 100%;
    min-height: 52px;
    padding: 13px 16px;
    background: #1263a8;
    color: #fff;
    font-size: 16px;
}

.primary-button:disabled {
    cursor: wait;
    opacity: 0.55;
}

/* カメラ画面 */

.camera-layout {
    display: grid;
    grid-template-columns:
        minmax(0, 1fr)
        minmax(270px, 340px);
    gap: 16px;
    align-items: center;
}

.camera-stage {
    position: relative;
    display: grid;
    overflow: hidden;
    width: 100%;
    max-width: 940px;
    aspect-ratio: 4 / 3;
    margin: 0 auto;
    place-items: center;
    border-radius: 14px;
    outline: none;
    background: #050708;
    box-shadow: 0 6px 22px rgb(0 0 0 / 18%);
    cursor: crosshair;
    touch-action: manipulation;
}

.camera-stage::before {
    position: absolute;
    z-index: 6;
    top: 50%;
    left: 50%;
    width: 58px;
    height: 58px;
    border: 3px solid transparent;
    border-radius: 50%;
    content: "";
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, -50%);
    transition:
        border-color 0.18s ease,
        transform 0.18s ease,
        opacity 0.18s ease;
}

.camera-stage::after {
    position: absolute;
    z-index: 6;
    right: 12px;
    bottom: 12px;
    padding: 6px 9px;
    border-radius: 999px;
    background: rgb(0 0 0 / 70%);
    color: #fff;
    content: "画面をタップしてピント調整";
    font-size: 11px;
    pointer-events: none;
}

.camera-stage.is-refocusing::before {
    border-color: #ffd65a;
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.84);
}

.camera-stage.is-focus-ready::before {
    border-color: #55d58a;
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.72);
}

.camera-stage.is-focus-ready::after {
    background: rgb(21 111 60 / 88%);
    content: "ピントOK";
}

.camera-stage.is-focus-soft::after {
    background: rgb(169 103 18 / 90%);
    content: "端末を固定して撮影";
}

.camera-source-video {
    position: fixed;
    top: -2px;
    left: -2px;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.camera-preview {
    display: block;
    width: 100%;
    height: 100%;
    background: #050708;
}

/* 鍵種別SVGガイド */

.camera-guide {
    position: absolute;
    z-index: 4;
    top: 50%;
    left: 50%;
    width: 74%;
    pointer-events: none;
    transform: translate(-50%, -50%);
}

.key-guide-svg {
    width: 100%;
}

.key-guide-svg svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}

.key-guide-svg__shadow {
    fill: rgb(255 255 255 / 3%);
    stroke: rgb(0 0 0 / 55%);
    stroke-width: 17;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
}

.key-guide-svg__outer {
    fill: rgb(255 255 255 / 4%);
    stroke: rgb(255 255 255 / 96%);
    stroke-width: 5;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
}

.key-guide-svg__hole {
    fill: rgb(0 0 0 / 10%);
    stroke: rgb(255 255 255 / 88%);
    stroke-width: 4;
    vector-effect: non-scaling-stroke;
}

.key-guide-svg__detail,
.key-guide-svg__shoulder,
.key-guide-svg__angle {
    fill: none;
    stroke: rgb(255 255 255 / 70%);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
}

.camera-guide__left-label,
.camera-guide__right-label {
    position: absolute;
    top: calc(100% + 8px);
    padding: 4px 8px;
    border-radius: 4px;
    background: rgb(0 0 0 / 74%);
    color: #fff;
    font-size: 12px;
    white-space: nowrap;
}

.camera-guide__left-label {
    left: 0;
}

.camera-guide__right-label {
    right: 0;
}

.camera-state {
    position: absolute;
    z-index: 7;
    top: 13px;
    left: 50%;
    max-width: calc(100% - 28px);
    padding: 7px 12px;
    overflow: hidden;
    border-radius: 999px;
    background: rgb(0 0 0 / 74%);
    color: #fff;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
    transform: translateX(-50%);
}

.camera-panel {
    padding: 18px;
    border: 1px solid #d6dce2;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 8px 24px rgb(20 34 48 / 8%);
}

.camera-instruction {
    text-align: center;
}

.camera-instruction strong {
    display: block;
    margin-bottom: 8px;
    font-size: 20px;
}

.camera-instruction span {
    display: block;
    color: #5a6570;
    font-size: 14px;
    line-height: 1.7;
}

.camera-guide-hint {
    margin-top: 13px;
    padding: 10px;
    border: 1px solid #aac7dd;
    border-radius: 8px;
    background: #eef7fd;
    color: #315b78;
    font-size: 13px;
    line-height: 1.6;
}

.camera-direction {
    display: flex;
    margin-top: 12px;
    padding: 9px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 8px;
    background: #f0f3f5;
    color: #4c5965;
    font-size: 12px;
}

.camera-direction__arrow {
    color: #1263a8;
    font-weight: 700;
}

.quality-message {
    margin-top: 14px;
    padding: 11px 13px;
    border-radius: 8px;
    background: #edf1f4;
    color: #4c5965;
    font-size: 14px;
    line-height: 1.6;
}

.quality-message[data-state="success"] {
    background: #e5f6eb;
    color: #17633a;
}

.quality-message[data-state="error"] {
    background: #ffe8e8;
    color: #8e2b2b;
}

.quality-message[data-state="checking"] {
    background: #fff4d2;
    color: #755300;
}

.camera-actions {
    display: grid;
    grid-template-columns: 1fr 92px;
    gap: 16px;
    margin-top: 18px;
    align-items: center;
}

.secondary-button {
    min-height: 46px;
    padding: 10px 12px;
    background: #dfe4e8;
    color: #26333e;
}

.capture-button {
    display: grid;
    width: 82px;
    height: 82px;
    margin: auto;
    padding: 5px;
    place-items: center;
    border: 3px solid #263746;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 12px rgb(0 0 0 / 20%);
    cursor: pointer;
}

.capture-button__inner {
    display: block;
    width: 61px;
    height: 61px;
    border-radius: 50%;
    background: #1263a8;
}

.capture-button:disabled {
    cursor: not-allowed;
    opacity: 0.4;
}

/* 確認画面 */

.review-description {
    color: #59646e;
    line-height: 1.7;
    text-align: center;
}

.review-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin: 20px 0;
}

.review-item {
    padding: 13px;
    border: 1px solid #d6dce2;
    border-radius: 10px;
    background: #f8f9fa;
}

.review-item h3 {
    margin: 0 0 10px;
    text-align: center;
}

.review-item img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: 7px;
    background: #1b2228;
    object-fit: contain;
}

.retake-button {
    width: 100%;
    margin-top: 10px;
    padding: 9px 10px;
    background: #dce3e8;
    color: #26333e;
}

/* 完了・エラー画面 */

.result-card,
.fatal-card {
    max-width: 620px;
    margin: 30px auto 0;
    text-align: center;
}

.result-icon,
.fatal-icon {
    display: grid;
    width: 70px;
    height: 70px;
    margin: 0 auto 16px;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    font-size: 38px;
    font-weight: 700;
}

.result-icon {
    background: #21834b;
}

.fatal-icon {
    background: #b63838;
}

.scan-id-label {
    display: block;
    margin: 22px 0 8px;
    font-weight: 700;
    text-align: left;
}

.scan-id-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.scan-id-input {
    width: 100%;
    min-width: 0;
    padding: 13px;
    border: 2px solid #8fa2b3;
    border-radius: 8px;
    background: #fff;
    font-family: Consolas, monospace;
    font-size: 16px;
    font-weight: 700;
}

.copy-button {
    padding: 10px 16px;
    background: #34495d;
    color: #fff;
}

.return-message {
    margin: 16px 0;
    color: #35684b;
    font-size: 14px;
}

/* 縦向き警告 */

.orientation-warning {
    position: fixed;
    z-index: 99999;
    inset: 0;
    display: grid;
    padding:
        calc(24px + env(safe-area-inset-top))
        24px
        calc(24px + env(safe-area-inset-bottom));
    place-items: center;
    background: #172433;
    color: #fff;
    text-align: center;
}

.orientation-warning__content {
    max-width: 520px;
}

.orientation-warning__phone {
    display: grid;
    width: 150px;
    height: 95px;
    margin: 0 auto 25px;
    place-items: center;
    border: 5px solid #fff;
    border-radius: 16px;
}

.orientation-warning__phone span {
    font-size: 42px;
}

.orientation-warning h2 {
    margin: 0 0 13px;
    font-size: 23px;
}

.orientation-warning p {
    margin: 0;
    color: #d5dde5;
    line-height: 1.8;
}

/* レスポンシブ */

@media (max-width: 900px) {
    .camera-layout {
        grid-template-columns: 1fr;
    }

    .camera-panel {
        max-width: 720px;
        margin: 0 auto;
    }
}

@media (max-width: 700px) {
    .scan-screen {
        padding-right: 9px;
        padding-left: 9px;
    }

    .guide-card {
        padding: 17px 14px;
    }

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

    .review-item {
        display: grid;
        grid-template-columns:
            minmax(0, 1fr)
            150px;
        gap: 10px;
        align-items: center;
    }

    .review-item h3 {
        grid-column: 1 / -1;
    }

    .retake-button {
        margin: 0;
    }
}

@media (orientation: landscape) and (max-height: 560px) {
    .scan-header {
        min-height: 46px;
        padding-top: 4px;
        padding-bottom: 4px;
    }

    .scan-header__eyebrow {
        display: none;
    }

    .scan-header__title {
        font-size: 15px;
    }

    .scan-screen--camera {
        padding-top: 5px;
        padding-bottom: 5px;
    }

    .camera-layout {
        grid-template-columns:
            minmax(0, 1fr)
            minmax(235px, 290px);
        gap: 8px;
    }

    .camera-stage {
        width: min(
            100%,
            calc((100dvh - 58px) * 4 / 3)
        );
    }

    .camera-panel {
        padding: 10px;
    }

    .camera-instruction strong {
        margin-bottom: 3px;
        font-size: 16px;
    }

    .camera-instruction span {
        font-size: 12px;
        line-height: 1.4;
    }

    .camera-guide-hint,
    .camera-direction {
        margin-top: 6px;
        padding: 5px;
        font-size: 11px;
    }

    .quality-message {
        margin-top: 7px;
        padding: 7px 8px;
        font-size: 12px;
        line-height: 1.35;
    }

    .camera-actions {
        margin-top: 7px;
    }

    .capture-button {
        width: 64px;
        height: 64px;
    }

    .capture-button__inner {
        width: 46px;
        height: 46px;
    }

    .camera-stage::after {
        right: 8px;
        bottom: 8px;
        padding: 4px 7px;
        font-size: 10px;
    }
}

@media (max-width: 390px) {
    .scan-id-row {
        grid-template-columns: 1fr;
    }
}

/* KEYCODE PROFILE-6 STEP UI START */

#cameraStage {
    position: relative;
}

.keycode-step-badge {
    position: absolute;
    z-index: 40;
    top: max(12px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    min-width: 180px;
    padding: 9px 18px;
    border: 2px solid rgba(255, 255, 255, 0.92);
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.72);
    color: #ffffff;
    font-size: 15px;
    font-weight: 800;
    line-height: 1.25;
    letter-spacing: 0.08em;
    text-align: center;
    white-space: nowrap;
    pointer-events: none;
}

.keycode-face-alert {
    position: absolute;
    z-index: 41;
    top: max(62px, calc(env(safe-area-inset-top) + 50px));
    left: 50%;
    transform: translateX(-50%);
    width: min(88%, 680px);
    padding: 12px 18px;
    border: 3px solid #ffffff;
    border-radius: 14px;
    background: rgba(180, 35, 35, 0.94);
    color: #ffffff;
    font-size: clamp(15px, 2.5vw, 20px);
    font-weight: 900;
    line-height: 1.4;
    text-align: center;
    box-shadow: 0 5px 18px rgba(0, 0, 0, 0.38);
    pointer-events: none;
}

.keycode-face-alert[hidden] {
    display: none !important;
}

#cameraStage.is-back-step {
    box-shadow:
        inset 0 0 0 5px rgba(255, 214, 64, 0.95);
}

#scanApp[data-current-role="back"] #captureTitle {
    font-weight: 900;
    text-decoration:
        underline 4px rgba(255, 214, 64, 0.95);
    text-underline-offset: 7px;
}

#scanApp[data-current-role="back"] #captureGuideHint {
    font-weight: 800;
}

@media (max-height: 520px) {
    .keycode-step-badge {
        top: 7px;
        padding: 6px 14px;
        font-size: 13px;
    }

    .keycode-face-alert {
        top: 46px;
        padding: 8px 13px;
        font-size: 14px;
    }
}

/* KEYCODE PROFILE-6 STEP UI END */

/* KEYCODE PROFILE-7 GUIDE STYLE START */

#keyGuideSvg svg {
    opacity: 0.58 !important;
}

#keyGuideSvg svg,
#keyGuideSvg svg * {
    fill: none !important;
}

#keyGuideSvg svg * {
    stroke: rgba(255, 255, 255, 0.68) !important;
    stroke-width: 18px !important;
    stroke-linecap: round !important;
    stroke-linejoin: round !important;
}

#keyGuideSvg svg .cls-1 {
    fill: none !important;
    stroke: rgba(255, 255, 255, 0.68) !important;
    stroke-width: 18px !important;
    stroke-linecap: round !important;
    stroke-linejoin: round !important;
}

#keyGuideSvg,
#cameraGuide {
    pointer-events: none;
}

/* KEYCODE PROFILE-7 GUIDE STYLE END */


/* =========================================================
   MIWA PR realtime capture v17.2
   ========================================================= */

.step-confirm-panel {
    margin-top: 18px;
    padding: 18px;
    border: 2px solid rgba(255, 255, 255, 0.20);
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.52);
    text-align: center;
}

.step-confirm-panel[hidden] {
    display: none !important;
}

.step-confirm-panel strong,
.step-confirm-panel span {
    display: block;
}

.step-confirm-panel strong {
    margin-bottom: 8px;
    font-size: 1.15rem;
}

.step-confirm-panel span {
    line-height: 1.55;
}

.step-confirm-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-top: 16px;
}

.camera-stage.is-step-paused::after {
    content: "撮影済み";
    background: rgba(0, 0, 0, 0.62);
}

@media (max-width: 720px) {
    .camera-layout {
        display: block;
    }

    .camera-stage {
        width: 100%;
    }

    .camera-panel {
        width: 100%;
        margin-top: 12px;
    }
}

/* MIWA PR v17.2.4 temporary camera diagnostics */
.camera-debug {
    margin: 10px 0 0;
    padding: 10px 12px;
    max-height: 240px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.78);
    color: #9effa2;
    font-family: monospace;
    font-size: 11px;
    line-height: 1.35;
    text-align: left;
}

/* MIWA PR v17.3b capture confirmation */
.step-confirm-preview {
    display: block;
    width: 100%;
    max-width: 720px;
    max-height: 45vh;
    margin: 14px auto 0;
    object-fit: contain;
    border-radius: 10px;
    background: #000;
}

.step-confirm-preview[hidden] {
    display: none !important;
}

/* =========================================================
   MIWA PR v17.4.1
   sideガイドは108%の大きさを維持し、
   はみ出し分を左側だけへ逃がす。
   右端（鍵先端側）は必ず表示する。
   ========================================================= */

#scanApp[data-current-role="side"] #cameraGuide {
    left: auto;
    right: 0;
    transform: translateY(-50%);
}

/* =========================================================
   MIWA PR capture build version
   ========================================================= */

.camera-build-version {
    display: block;
    width: fit-content;
    max-width: calc(100% - 24px);
    margin: 8px auto 10px;
    padding: 5px 10px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.72);
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.4;
    text-align: center;
    letter-spacing: 0.02em;
}

/* =========================================================
   MIWA PR v17.5 UI
   ========================================================= */

/*
 * version / step は上部の既存タイトル位置へ統合。
 */
.camera-build-version {
    display: none !important;
}

/*
 * カメラ内部のSTEPバッジも重複するため非表示。
 */
#captureStepBadge {
    display: none !important;
}

/*
 * デバッグ数値はサーバーへ自動保存するため
 * 顧客画面には表示しない。
 */
.camera-debug {
    display: none !important;
}

/*
 * side:
 * ガイドを左基準にする。
 * widthはprofile側の86%。
 */
#scanApp[data-current-role="side"] #cameraGuide {
    left: 0 !important;
    right: auto !important;
    transform: translateY(-50%) !important;
}

/*
 * ガイド内文字はviewBoxやSVGクロップとは
 * 独立した位置に固定する。
 */
#scanApp[data-current-role="side"] .camera-guide__left-label {
    left: 10px !important;
    right: auto !important;
    transform: none !important;
    white-space: nowrap;
}

#scanApp[data-current-role="side"] .camera-guide__right-label {
    left: auto !important;
    right: 10px !important;
    transform: none !important;
    white-space: nowrap;
}


/* =========================================================
   MIWA PR v17.6b side
   ========================================================= */

#scanApp[data-current-role="side"] #cameraGuide {
    width: 80% !important;
    left: 6% !important;
    right: auto !important;
    transform: translateY(-50%) !important;
}

#scanApp[data-current-role="side"] .camera-guide__left-label,
#scanApp[data-current-role="side"] .camera-guide__right-label {
    display: none !important;
}
