/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", sans-serif;
    background: #111;
    color: #eee;
    -webkit-user-select: none;
    user-select: none;
}

.hidden {
    display: none !important;
}

/* === Modal === */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 1000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.login-wrapper {
    width: 90%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 60px 0 40px;
}

.modal-content {
    background: #222;
    border-radius: 16px;
    padding: 32px 24px;
    width: 100%;
    text-align: center;
}

.modal-content h2 {
    font-size: 18px;
    margin-bottom: 20px;
    color: #fff;
}

.modal-content input {
    width: 100%;
    padding: 14px;
    border: 1px solid #444;
    border-radius: 10px;
    background: #333;
    color: #fff;
    font-size: 16px;
    margin-bottom: 16px;
    outline: none;
}

.modal-content input:focus {
    border-color: #4a9eff;
}

.login-desc {
    font-size: 14px;
    color: #aaa;
    margin-bottom: 24px;
}

/* === Google Login Button === */
.btn-google {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 10px;
    background: #fff;
    color: #333;
    font-size: 16px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.btn-google:active {
    background: #f0f0f0;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.google-icon {
    flex-shrink: 0;
}

/* === Guest Start Button === */
.btn-guest {
    display: block;
    width: 100%;
    padding: 14px;
    margin-top: 12px;
    border: 2px solid #666;
    border-radius: 10px;
    background: transparent;
    color: #ccc;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-guest:active {
    background: #333;
    border-color: #888;
}

/* === Info Sections (Top Page) === */
.info-sections {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.info-section {
    background: #1a1a1a;
    border-radius: 12px;
    padding: 16px;
    border: 1px solid #2a2a2a;
}

.info-heading {
    font-size: 14px;
    font-weight: 600;
    color: #4a9eff;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #2a2a2a;
}

.info-item {
    margin-bottom: 10px;
}

.info-item:last-child {
    margin-bottom: 0;
}

.info-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    margin-bottom: 4px;
}

.info-badge.login {
    background: #2ed573;
    color: #000;
}

.info-badge.guest {
    background: #ffa502;
    color: #000;
}

.info-badge.step {
    background: #444;
    color: #ddd;
}

.info-item p {
    font-size: 13px;
    color: #aaa;
    line-height: 1.6;
}

/* === Diagrams (Top Page) === */

/* カメラ画面イメージ図 */
.diagram-phone {
    background: #000;
    border: 2px solid #444;
    border-radius: 10px;
    overflow: hidden;
    margin: 10px 0;
}

.diagram-statusbar {
    background: rgba(0, 0, 0, 0.7);
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 600;
    color: #4a9eff;
}

.diagram-camera {
    padding: 20px 16px 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.diagram-guide {
    width: 70%;
    aspect-ratio: 91 / 55;
    border: 2px dashed rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 12px;
}

.diagram-guide-text {
    font-size: 11px;
    color: #888;
    text-align: center;
}

/* フロー図 */
.diagram-flow {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin: 12px 0 4px;
    padding: 10px 0;
}

.diagram-step-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.diagram-step-num {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #333;
    color: #aaa;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
}

.diagram-step-item.current .diagram-step-num {
    background: #4a9eff;
    color: #fff;
}

.diagram-step-label {
    font-size: 11px;
    color: #aaa;
}

.diagram-arrow-line {
    width: 24px;
    height: 2px;
    background: #444;
    margin: 0 4px;
    margin-bottom: 18px;
}

.diagram-flow-note {
    font-size: 11px;
    color: #666;
    text-align: center;
    margin-bottom: 10px;
}

/* 確認画面イメージ図 */
.diagram-confirm {
    background: #111;
    border: 2px solid #444;
    border-radius: 10px;
    overflow: hidden;
    margin: 10px 0;
}

.diagram-confirm-hd {
    background: #1a1a2e;
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 600;
    color: #4a9eff;
    text-align: center;
}

.diagram-confirm-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-bottom: 1px solid #2a2a2a;
    font-size: 11px;
}

.diagram-cb {
    font-size: 14px;
    color: #666;
    width: 18px;
    flex-shrink: 0;
}

.diagram-confirm-row.editing .diagram-cb {
    color: #4a9eff;
}

.diagram-fld-label {
    color: #888;
    width: 44px;
    flex-shrink: 0;
    font-size: 10px;
}

.diagram-fld-value {
    color: #ccc;
    font-size: 11px;
}

.diagram-fld-input {
    font-size: 11px;
    color: #fff;
    background: #2a2a3e;
    border: 1px solid #4a9eff;
    border-radius: 4px;
    padding: 2px 6px;
    flex: 1;
}

.diagram-confirm-btns {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
}

.diagram-btn-p {
    flex: 2;
    background: #4a9eff;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 4px 0;
    border-radius: 6px;
    text-align: center;
}

.diagram-btn-s {
    flex: 1;
    border: 1px solid #666;
    color: #aaa;
    font-size: 10px;
    padding: 4px 0;
    border-radius: 6px;
    text-align: center;
}

/* === Buttons === */
.btn-primary {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 10px;
    background: #4a9eff;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:active {
    background: #3580d4;
}

.btn-secondary {
    padding: 12px 24px;
    border: 2px solid #666;
    border-radius: 10px;
    background: transparent;
    color: #ccc;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:active {
    background: #333;
    border-color: #888;
}

/* === Status Bar === */
#status-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 100;
    display: flex;
    flex-direction: column;
}

#status-row-top {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 8px 12px;
}

#status-row-bottom {
    padding: 2px 12px 8px;
}

#status-text {
    font-size: 15px;
    font-weight: 600;
}

#status-text.front {
    color: #4a9eff;
}

#status-text.back {
    color: #ff9f43;
}

#status-text.done {
    color: #2ed573;
}

#operator-display {
    font-size: 12px;
    color: #999;
    margin-right: auto;
}

.btn-sheet {
    padding: 4px 10px;
    border: 1px solid #4285F4;
    border-radius: 6px;
    background: transparent;
    color: #8ab4f8;
    font-size: 11px;
    text-decoration: none;
    white-space: nowrap;
}

.btn-logout {
    padding: 4px 10px;
    border: 1px solid #666;
    border-radius: 6px;
    background: transparent;
    color: #ccc;
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
}

/* === Camera === */
#camera-screen {
    width: 100%;
    height: 100%;
    position: relative;
}

#camera-container {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

#camera-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#overlay-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#guide-frame {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 85%;
    aspect-ratio: 91 / 55; /* 名刺比率 */
    border: 2px dashed rgba(255, 255, 255, 0.4);
    border-radius: 8px;
    pointer-events: none;
    transition: border-color 0.3s;
}

#guide-frame.detected {
    border-color: #ffa502;
    border-style: solid;
}

#guide-frame.stable {
    border-color: #2ed573;
    border-style: solid;
    box-shadow: 0 0 20px rgba(46, 213, 115, 0.3);
}

/* === Camera Guide Message === */
#camera-guide {
    position: absolute;
    bottom: 24%;
    left: 0;
    right: 0;
    text-align: center;
    pointer-events: none;
    z-index: 50;
    padding: 0 20px;
}

#camera-guide-main {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
    margin-bottom: 4px;
}

#camera-guide-sub {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

/* === Front Thumbnail === */
#front-thumbnail {
    position: fixed;
    top: 22%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.7);
    padding: 6px 12px;
    border-radius: 10px;
    z-index: 100;
}

#front-thumb-img {
    width: 60px;
    height: 36px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #444;
}

#front-thumbnail span {
    font-size: 11px;
    color: #aaa;
}

/* === Skip Button === */
#skip-back-btn {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
}

/* === Guest CSV Button (Camera Screen) === */
#guest-csv-btn {
    position: fixed;
    bottom: 24px;
    right: 16px;
    z-index: 100;
    padding: 10px 16px;
    border: none;
    border-radius: 10px;
    background: #2ed573;
    color: #000;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

#guest-csv-btn:active {
    background: #27ae60;
}

/* === Flash === */
#flash-overlay {
    position: fixed;
    inset: 0;
    background: white;
    z-index: 200;
    opacity: 0;
    animation: flash-anim 0.3s ease-out;
}

@keyframes flash-anim {
    0% { opacity: 0.8; }
    100% { opacity: 0; }
}

/* === Processing Overlay === */
#processing-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #333;
    border-top-color: #4a9eff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

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

#processing-overlay p {
    font-size: 16px;
    color: #ccc;
}

/* === Toast === */
#toast-container {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 90%;
    max-width: 400px;
}

.toast {
    padding: 14px 18px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    animation: toast-in 0.3s ease-out, toast-out 0.3s ease-in 3.7s;
    animation-fill-mode: forwards;
}

.toast.success {
    background: #2ed573;
    color: #000;
}

.toast.duplicate {
    background: #ffa502;
    color: #000;
}

.toast.error {
    background: #ff4757;
    color: #fff;
}

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

@keyframes toast-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* === Confirm Screen === */
#confirm-screen {
    position: fixed;
    inset: 0;
    background: #111;
    z-index: 400;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#confirm-header {
    padding: 14px 16px;
    background: #1a1a2e;
    font-size: 16px;
    font-weight: 600;
    color: #4a9eff;
    text-align: center;
    flex-shrink: 0;
}

#confirm-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    -webkit-overflow-scrolling: touch;
}

.confirm-select-all {
    padding: 8px 0 12px;
    border-bottom: 1px solid #444;
    margin-bottom: 4px;
}

.confirm-select-all label {
    font-size: 13px;
    color: #4a9eff;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.confirm-field {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #2a2a2a;
    padding: 10px 0;
}

.confirm-check {
    width: 28px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.confirm-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #4a9eff;
}

.confirm-label {
    width: 80px;
    flex-shrink: 0;
    font-size: 12px;
    color: #888;
    padding-top: 2px;
}

.confirm-value-wrap {
    flex: 1;
    min-width: 0;
}

.confirm-value {
    font-size: 14px;
    color: #eee;
    word-break: break-all;
}

.confirm-value.empty {
    color: #555;
    font-style: italic;
}

.confirm-input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #4a9eff;
    border-radius: 6px;
    background: #2a2a3e;
    color: #fff;
    font-size: 14px;
    outline: none;
}

.confirm-input:focus {
    border-color: #6bb5ff;
    box-shadow: 0 0 6px rgba(74, 158, 255, 0.3);
}

#confirm-buttons {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
    background: #1a1a1a;
    border-top: 1px solid #333;
}

.confirm-buttons-row {
    display: flex;
    gap: 12px;
}

.confirm-buttons-row .btn-primary {
    flex: 2;
}

.confirm-buttons-row .btn-secondary {
    flex: 1;
}

.btn-csv {
    width: 100%;
    padding: 12px;
    border: 2px solid #2ed573;
    border-radius: 10px;
    background: transparent;
    color: #2ed573;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-csv:active {
    background: rgba(46, 213, 115, 0.15);
}

/* === Capture Canvas (hidden) === */
#capture-canvas {
    position: absolute;
    top: -9999px;
    left: -9999px;
}
